Spaces:
Sleeping
Sleeping
Commit
·
9eb7ea5
1
Parent(s):
071942b
Added ui
Browse files- index.html +26 -0
index.html
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: 1. Single file
|
3 |
+
layout: page
|
4 |
+
---
|
5 |
+
|
6 |
+
<input id="photo" type="file">
|
7 |
+
<div id="results"></div>
|
8 |
+
<script>
|
9 |
+
async function loaded(reader) {
|
10 |
+
const response = await fetch('https://hf.space/embed/jph00/pets/+/api/predict/', {
|
11 |
+
// https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png
|
12 |
+
// https://thescripterr-fastai-deploy.hf.space/
|
13 |
+
method: "POST", body: JSON.stringify({ "data": [reader.result] }),
|
14 |
+
headers: { "Content-Type": "application/json" }
|
15 |
+
});
|
16 |
+
const json = await response.json();
|
17 |
+
const label = json['data'][0]['confidences'][0]['label'];
|
18 |
+
results.innerHTML = `<br/><img src="${reader.result}" width="300"> <p>${label}</p>`
|
19 |
+
}
|
20 |
+
function read() {
|
21 |
+
const reader = new FileReader();
|
22 |
+
reader.addEventListener('load', () => loaded(reader))
|
23 |
+
reader.readAsDataURL(photo.files[0]);
|
24 |
+
}
|
25 |
+
photo.addEventListener('input', read);
|
26 |
+
</script>
|