radames commited on
Commit
c4f7f40
·
1 Parent(s): e78b203

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +11 -8
index.html CHANGED
@@ -13,18 +13,21 @@
13
  import { HfInference } from 'https://cdn.skypack.dev/@huggingface/[email protected]';
14
  let hf = new HfInference();
15
 
16
- document.querySelector("#token").addEventListener("change", (e) => {
17
- hf = new HfInference(e.target.value)
 
 
18
  })
19
 
20
  document.addEventListener("DOMContentLoaded", async () => {
21
- const image = document.querySelector("#example-img");
22
- const imgBlob = await fetch(image.src).then((r) => r.blob());
23
- detectObjects(imgBlob, image.naturalWidth, image.naturalHeight);
24
  })
25
-
 
 
 
 
26
  async function detectObjects(imgBlob, imgW, imgH) {
27
- console.log(imgBlob, imgW, imgH)
28
  try {
29
  const objectDetectionRes = await hf.objectDetection({
30
  data: imgBlob,
@@ -73,7 +76,7 @@
73
  <label for="token">HF Token</label>
74
  <div style="display: flex">
75
  <input style="flex: 2 1 0%" type="password" id="token" />
76
- <button style="flex: 1 1 0%">Set Token</button>
77
  </div>
78
  </div>
79
 
 
13
  import { HfInference } from 'https://cdn.skypack.dev/@huggingface/[email protected]';
14
  let hf = new HfInference();
15
 
16
+ document.querySelector("#tokenBtn").addEventListener("click", (e) => {
17
+ const token = document.querySelector("#token").value;
18
+ hf = new HfInference(token)
19
+ init()
20
  })
21
 
22
  document.addEventListener("DOMContentLoaded", async () => {
23
+ init();
 
 
24
  })
25
+ function init() {
26
+ const img = document.querySelector("#example-img");
27
+ const blob = new Blob([img.src], { type: "image/png" });
28
+ detectObjects(blob, img.naturalWidth, img.naturalHeight);
29
+ }
30
  async function detectObjects(imgBlob, imgW, imgH) {
 
31
  try {
32
  const objectDetectionRes = await hf.objectDetection({
33
  data: imgBlob,
 
76
  <label for="token">HF Token</label>
77
  <div style="display: flex">
78
  <input style="flex: 2 1 0%" type="password" id="token" />
79
+ <button style="flex: 1 1 0%" id="tokenBtn">Set Token</button>
80
  </div>
81
  </div>
82