-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatclassifier.html
More file actions
68 lines (58 loc) · 2.06 KB
/
catclassifier.html
File metadata and controls
68 lines (58 loc) · 2.06 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cat Classifier</title>
<style>
#results {
text-align: center;
margin-top: 20px;
}
#loading {
display: none;
text-align: center;
margin-top: 20px;
}
#error {
color: red;
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Cat Classifier</h1>
<input id="photo" type="file">
<div id="loading">Loading...</div>
<div id="results"></div>
<div id="error"></div>
<script type="module">
import { client } from "https://cdn.jsdelivr.net/npm/@gradio/client@0.1.4/dist/index.min.js";
const photoInput = document.getElementById("photo");
const resultsDiv = document.getElementById("results");
const loadingDiv = document.getElementById("loading");
const errorDiv = document.getElementById("error");
async function loaded(reader) {
loadingDiv.style.display = "none";
resultsDiv.innerHTML = `<br/> <img src="${reader.result}" width="500">`;
try {
const app = await client("https://mmchowdhury-catclassifier.hf.space/--replicas/079b5/");
const response = await app.predict("/predict", [reader.result]);
const label = response['data'][0]['label'];
resultsDiv.innerHTML += `<p>${label}</p>`;
} catch (error) {
errorDiv.innerHTML = `An error occurred: ${error.message}`;
}
}
function read() {
errorDiv.innerHTML = ""; // Clear previous error messages
loadingDiv.style.display = "block";
const reader = new FileReader();
reader.addEventListener('load', () => loaded(reader));
reader.readAsDataURL(photoInput.files[0]);
}
photoInput.addEventListener('input', read);
</script>
</body>
</html>