add html sample
Browse files
pet.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Pet Classifier
|
| 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/etiennefd/minimal/+/api/predict',
|
| 11 |
+
method: "POST", body: JSON.stringify({"data": [reader.result] }),
|
| 12 |
+
headers: { "Content-Type": "application/json"}
|
| 13 |
+
)};
|
| 14 |
+
const json = await response.json();
|
| 15 |
+
const label = json['data'][0]['confidences'][0]['label'];
|
| 16 |
+
results.innerHTML = `<br/><img src="${reader.result}" width="300"> <p>${label}</p>`
|
| 17 |
+
}
|
| 18 |
+
function read() {
|
| 19 |
+
const reader = new FileReader();
|
| 20 |
+
reader.addEventListener('load', () => loaded(reader))
|
| 21 |
+
reader.readAsDataURL(photo.files[0]);
|
| 22 |
+
}
|
| 23 |
+
photo.addEventListener('input', read);
|
| 24 |
+
</script>
|