forked from fastai/tinypets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2multi.html
25 lines (24 loc) · 869 Bytes
/
2multi.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
---
title: 2. Multi-file
layout: page
---
<input id="photos" type="file" multiple="">
<script>
async function loaded(reader) {
const response = await fetch('https://alphonce-pet-classifier-demo.hf.space/run/predict', {
method: "POST", body: JSON.stringify({ "data": [reader.result] }),
headers: { "Content-Type": "application/json" }
});
const json = await response.json();
const label = json['data'][0]['confidences'][0]['label'];
const div = document.createElement('div');
div.innerHTML = `<br/><img src="${reader.result}" width="300"> <p>${label}</p>`
document.body.append(div);
}
function read(file) {
const reader = new FileReader();
reader.addEventListener('load', () => loaded(reader))
reader.readAsDataURL(file);
}
photos.addEventListener('input', () => { [...photos.files].map(read) });
</script>