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"); } }