fastai-deploy / index.html
thescripterr's picture
Added ui
9eb7ea5
---
title: 1. Single file
layout: page
---
<input id="photo" type="file">
<div id="results"></div>
<script>
async function loaded(reader) {
const response = await fetch('https://hf.space/embed/jph00/pets/+/api/predict/', {
// https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png
// https://thescripterr-fastai-deploy.hf.space/
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'];
results.innerHTML = `<br/><img src="${reader.result}" width="300"> <p>${label}</p>`
}
function read() {
const reader = new FileReader();
reader.addEventListener('load', () => loaded(reader))
reader.readAsDataURL(photo.files[0]);
}
photo.addEventListener('input', read);
</script>