-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (27 loc) · 996 Bytes
/
script.js
File metadata and controls
32 lines (27 loc) · 996 Bytes
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
document.getElementById("leafForm").addEventListener("submit", async (event) => {
event.preventDefault();
const fileInput = document.getElementById("leafImage");
const file = fileInput.files[0];
if (!file) {
alert("Please upload an image.");
return;
}
const formData = new FormData();
formData.append("file", file);
try {
const response = await fetch("http://127.0.0.1:5000/upload", {
method: "POST",
body: formData,
});
if (!response.ok) {
throw new Error("Failed to identify leaf.");
}
const data = await response.json();
document.getElementById("result").innerHTML = `
<h2>Species: ${data.species}</h2>
<p><strong>Uses:</strong> ${data.uses}</p>
`;
} catch (error) {
document.getElementById("result").innerHTML = `<p style="color: red;">${error.message}</p>`;
}
});