forked from yanchick/Practice-ML-DEV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
248 lines (209 loc) · 7.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liver Disease Lifespan</title>
<style>
body {
font-family: 'Arial', sans-serif;
display: flex;
max-width: 800px;
margin: auto;
padding: 20px;
}
.column {
flex: 1;
padding: 0 10px;
}
h1, h2 {
color: #333;
}
form {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input, select, button {
width: 100%;
padding: 8px;
margin-bottom: 10px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
p {
margin-bottom: 10px;
}
#balance {
font-weight: bold;
}
</style>
</head>
<body>
<div class="column">
<h1>Account</h1>
<!-- Login Form -->
<div>
<h2>Login</h2>
<form id="loginForm">
<label for="loginUsername">Username:</label>
<input type="text" id="loginUsername" name="loginUsername" required>
<label for="loginPassword">Password:</label>
<input type="password" id="loginPassword" name="loginPassword" required>
<button type="button" onclick="login()">Login</button>
</form>
</div>
<!-- Register Form -->
<div>
<h2>Register</h2>
<form id="registerForm">
<label for="registerName">Name:</label>
<input type="text" id="registerName" name="registerName" required>
<label for="registerEmail">Email:</label>
<input type="email" id="registerEmail" name="registerEmail" required>
<label for="registerPassword">Password:</label>
<input type="password" id="registerPassword" name="registerPassword" required>
<button type="button" onclick="register()">Register</button>
</form>
</div>
<!-- Get Me Button -->
<div>
<h2>User Info</h2>
<button type="button" onclick="getUserInfo()">Get Me</button>
<p id="balance">Balance: Loading...</p>
</div>
</div>
<div class="column">
<h1>Liver Disease Life Expectancy Prediction v0.3</h1>
<!-- Model Selection -->
<div>
<h2>Choose Model</h2>
<select id="modelSelection">
<option value="lasso">Lasso: 100 C</option>
</select>
</div>
<!-- Upload CSV Form -->
<div>
<h2>Upload CSV File</h2>
<form id="uploadForm">
<input type="file" id="csvFile" name="csvFile" accept=".csv" required>
<button type="button" onclick="uploadFile()">Predict</button>
</form>
</div>
<!-- Check Prediction Status -->
<div>
<h2>Check Prediction Status</h2>
<form id="statusForm">
<label for="predictionId">Prediction ID:</label>
<input type="text" id="predictionId" name="predictionId" required>
<button type="button" onclick="checkStatus()">Check Status</button>
</form>
<p id="predictionStatus">Status: Not checked</p>
<p id="predictionResult">Result: N/A</p>
</div>
</div>
<script>
let accessToken; // Variable to store the access token
async function login() {
const username = document.getElementById('loginUsername').value;
const password = document.getElementById('loginPassword').value;
const response = await fetch('http://localhost:7999/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: username,
password: password,
}),
});
const data = await response.json();
accessToken = data.access_token; // Save the access token
alert('Successfully logged in!');
console.log(data);
getBalance();
}
async function register() {
const name = document.getElementById('registerName').value;
const email = document.getElementById('registerEmail').value;
const password = document.getElementById('registerPassword').value;
const response = await fetch('http://localhost:7999/api/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: name,
email: email,
password: password,
}),
});
const data = await response.json();
accessToken = data.access_token; // Save the access token
alert('Successfully registered!');
console.log(data);
getBalance();
}
async function getUserInfo() {
const response = await fetch('http://localhost:7999/api/auth/me', {
headers: {
'Authorization': `Bearer ${accessToken}`, // Include the access token
},
});
const data = await response.json();
console.log(data);
alert(data);
getBalance();
}
async function getBalance() {
const response = await fetch('http://localhost:7999/api/auth/balance', {
headers: {
'Authorization': `Bearer ${accessToken}`, // Include the access token
},
});
const data = await response.json();
document.getElementById('balance').innerText = `Balance: ${data.balance} coins`;
}
async function uploadFile() {
const model = document.getElementById('modelSelection').value;
const fileInput = document.getElementById('csvFile');
const file = fileInput.files[0];
const formData = new FormData();
formData.append('file', file);
const response = await fetch(`http://localhost:7999/api/predict/${model}`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`, // Include the access token
},
body: formData,
});
const data = await response.json();
alert(`Prediction ID: ${data}`);
getBalance(); // Update balance after making a prediction
}
async function checkStatus() {
const predictionId = document.getElementById('predictionId').value;
const response = await fetch(`http://localhost:7999/api/predict/${predictionId}`, {
method: 'GET', // Ensure the correct method is specified
headers: {
'Authorization': `Bearer ${accessToken}`, // Include the access token
},
});
const data = await response.json();
document.getElementById('predictionStatus').innerText = `Is ready: ${data.is_finished}`;
document.getElementById('predictionResult').innerText = `Result: ${data.output || 'N/A'}`;
}
</script>
</body>
</html>