File size: 859 Bytes
f0d6519 | 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://hf.space/embed/jph00/pets/+/api/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> |