File size: 787 Bytes
14273f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
<!DOCTYPE html>
<html>
<body>
<input id="photo" type="file">
<div id="results"></div>
<script>
  async function loaded(reader) {
    const response = await fetch('https://hf.space/embed/choucrifahed/fastai2/+/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'];
    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>
</body>
</html>