Choucri FAHED commited on
Commit
14273f0
1 Parent(s): 51badb6

consume API

Browse files
Files changed (1) hide show
  1. index.html +26 -0
index.html ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <body>
4
+ <input id="photo" type="file">
5
+ <div id="results"></div>
6
+ <script>
7
+ async function loaded(reader) {
8
+ const response = await fetch('https://hf.space/embed/choucrifahed/fastai2/+/api/predict', {
9
+ method: 'POST', body: JSON.stringify({ 'data': [reader.result] }),
10
+ headers: { 'Content-Type': 'application/json' },
11
+ });
12
+ const json = await response.json();
13
+ const label = json['data'][0]['confidences'][0]['label'];
14
+ results.innerHTML = `<br/><img src="${reader.result}" width="300"> <p>${label}</p>`;
15
+ }
16
+
17
+ function read() {
18
+ const reader = new FileReader();
19
+ reader.addEventListener('load', () => loaded(reader));
20
+ reader.readAsDataURL(photo.files[0]);
21
+ }
22
+
23
+ photo.addEventListener('input', read);
24
+ </script>
25
+ </body>
26
+ </html>