Spaces:
Running
Running
Update index.html
Browse files- 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("#
|
17 |
-
|
|
|
|
|
18 |
})
|
19 |
|
20 |
document.addEventListener("DOMContentLoaded", async () => {
|
21 |
-
|
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 |
|