-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
39 lines (36 loc) · 1.27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digit Classifier</title>
</head>
<body>
<input type="file" id="imageInput" accept="image/*">
<button onclick="uploadImage()">Classify</button>
<p id="predictionResult"></p>
<script type="text/javascript">
async function uploadImage() {
const input = document.getElementById('imageInput');
if (!input.files[0]) {
alert("Please select a file to upload")
return;
}
const file = input.files[0]
const formData = new FormData();
formData.append('file', file);
try {
const response = await fetch('http://127.0.0.1:8000/predict-image/', {
method: 'POST',
body: formData
});
const result = await response.json()
document.getElementById('predictionResult').textContent = `Prediction: ${result.prediction}`;
} catch (error) {
console.error('Error:', error);
alert('Failed!')
}
}
</script>
</body>
</html>