-
Notifications
You must be signed in to change notification settings - Fork 0
/
food_recognizer.html
40 lines (35 loc) · 1.02 KB
/
food_recognizer.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
40
---
title: Food Classifier
layout: page
---
<!DOCTYPE html>
<html>
<head>
<title>Food Classifier</title>
</head>
<body>
<input id="photo" type="file" />
<div id="results"></div>
<script>
async function loaded(reader) {
const response = await fetch(
"https://tdnathmlenthusiast-food-classifier.hf.space/run/predict",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ data: [reader.result] }),
}
);
const json = await response.json();
const label = json["data"][0]["label"];
results.innerHTML = `<br/> <img src="${reader.result}" width="500"> <p>${label}</p>`;
}
function read() {
const reader = new FileReader();
reader.addEventListener("load", () => loaded(reader));
reader.readAsDataURL(photo.files[0]);
}
photo.addEventListener("input", read);
</script>
</body>
</html>