Spaces:
Running
Running
Tobias Cornille
commited on
Commit
·
6296a62
1
Parent(s):
fd01f49
Update index.js
Browse files
index.js
CHANGED
|
@@ -9,7 +9,8 @@ const fileUpload = document.getElementById('upload');
|
|
| 9 |
const imageContainer = document.getElementById('container');
|
| 10 |
const example = document.getElementById('example');
|
| 11 |
const labels = document.getElementById('labels');
|
| 12 |
-
let
|
|
|
|
| 13 |
|
| 14 |
const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/astronaut.png';
|
| 15 |
|
|
@@ -32,22 +33,26 @@ fileUpload.addEventListener('change', function (e) {
|
|
| 32 |
|
| 33 |
|
| 34 |
// Set up a callback when the file is loaded
|
| 35 |
-
reader.onload = e2 =>
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
reader.readAsDataURL(file);
|
| 38 |
});
|
| 39 |
|
| 40 |
|
| 41 |
labels.addEventListener('blur', (e) => {
|
| 42 |
-
|
| 43 |
-
console.warn(
|
| 44 |
-
if (
|
| 45 |
-
|
|
|
|
| 46 |
}
|
| 47 |
});
|
| 48 |
|
| 49 |
// Detect objects in the image
|
| 50 |
-
async function detect(img) {
|
| 51 |
imageContainer.innerHTML = '';
|
| 52 |
imageContainer.style.backgroundImage = `url(${img})`;
|
| 53 |
|
|
|
|
| 9 |
const imageContainer = document.getElementById('container');
|
| 10 |
const example = document.getElementById('example');
|
| 11 |
const labels = document.getElementById('labels');
|
| 12 |
+
let parsedLabels = ['human face', 'rocket', 'helmet', 'american flag'];
|
| 13 |
+
let img;
|
| 14 |
|
| 15 |
const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/astronaut.png';
|
| 16 |
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
// Set up a callback when the file is loaded
|
| 36 |
+
reader.onload = e2 => {
|
| 37 |
+
img = e2.target.result;
|
| 38 |
+
detect(img, parsedLabels);
|
| 39 |
+
}
|
| 40 |
|
| 41 |
reader.readAsDataURL(file);
|
| 42 |
});
|
| 43 |
|
| 44 |
|
| 45 |
labels.addEventListener('blur', (e) => {
|
| 46 |
+
parsedLabels = e.target.value.split(",");
|
| 47 |
+
console.warn(parsedLabels, reader);
|
| 48 |
+
if (img) {
|
| 49 |
+
status.textContent = 'Analysing...';
|
| 50 |
+
detect(img, parsedLabels);
|
| 51 |
}
|
| 52 |
});
|
| 53 |
|
| 54 |
// Detect objects in the image
|
| 55 |
+
async function detect(img, candidate_labels) {
|
| 56 |
imageContainer.innerHTML = '';
|
| 57 |
imageContainer.style.backgroundImage = `url(${img})`;
|
| 58 |
|