I'm going over the fastai ML course and got stuck in the second lesson with a minor problem - a classifier app that works fine on huggingface spaces doesn't get called correctly by a script suggested by the course team. Here's the code:
Having trouble deploying the java script website, what could be wrong with the code:
---
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://hiddenmiddle-fastai-lesson2.hf.space/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'];
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>
What is the correct way to use gradio+huggingface API? When I click "use via API" on hugginface, there are only instructions for python