diabetes-fastapi / static /script.js
Oni117
fix: add static folder for frontend
c4ac664
Raw
History Blame Contribute Delete
776 Bytes
async function uploadImage() {
const input = document.getElementById("imageInput");
const file = input.files[0];
if (!file) {
alert("Please select an image!");
return;
}
// preview image
const preview = document.getElementById("preview");
preview.src = URL.createObjectURL(file);
const formData = new FormData();
formData.append("file", file);
try {
const response = await fetch("/predict", {
method: "POST",
body: formData
});
const data = await response.json();
document.getElementById("result").innerText =
"Prediction: " + data.prediction;
} catch (error) {
console.error(error);
alert("Error connecting to API");
}
}