Spaces:
Running
Running
refactor: Change file to object url
Browse files
index.js
CHANGED
|
@@ -21,18 +21,14 @@ example.addEventListener('click', (e) => {
|
|
| 21 |
detect(EXAMPLE_URL);
|
| 22 |
});
|
| 23 |
|
| 24 |
-
fileUpload.addEventListener('change', function (e) {
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
// Set up a callback when the file is loaded
|
| 33 |
-
reader.onload = e2 => detect(e2.target.result);
|
| 34 |
-
|
| 35 |
-
reader.readAsDataURL(file);
|
| 36 |
});
|
| 37 |
|
| 38 |
|
|
@@ -52,6 +48,6 @@ async function detect(img) {
|
|
| 52 |
|
| 53 |
// Decode the model outputs
|
| 54 |
const generated_text = processor.batch_decode(outputs.logits).generated_text;
|
| 55 |
-
status.textContent =
|
| 56 |
console.log(generated_text);
|
| 57 |
}
|
|
|
|
| 21 |
detect(EXAMPLE_URL);
|
| 22 |
});
|
| 23 |
|
| 24 |
+
fileUpload.addEventListener('change', async function (e) {
|
| 25 |
+
const file = e.target.files[0];
|
| 26 |
+
if (!file) {
|
| 27 |
+
return;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
const file_url = URL.createObjectURL(file);
|
| 31 |
+
await detect(file_url);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
});
|
| 33 |
|
| 34 |
|
|
|
|
| 48 |
|
| 49 |
// Decode the model outputs
|
| 50 |
const generated_text = processor.batch_decode(outputs.logits).generated_text;
|
| 51 |
+
status.textContent = generated_text[0];
|
| 52 |
console.log(generated_text);
|
| 53 |
}
|