File size: 876 Bytes
d1d11ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
function uploadImage() {
    let fileInput = document.getElementById("fileInput");
    let file = fileInput.files[0];
    
    if (!file) {
        alert("Please select an image file.");
        return;
    }

    let formData = new FormData();
    formData.append("file", file);

    fetch("http://127.0.0.1:5000/predict", {
        method: "POST",
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        if (data.error) {
            document.getElementById("result").innerText = "Error: " + data.error;
        } else {
            document.getElementById("result").innerText = `Result: ${data.result} (Confidence: ${data.confidence}%)`;
        }
    })
    .catch(error => {
        console.error("Error:", error);
        document.getElementById("result").innerText = "Prediction failed.";
    });
}