Update mobilevit.html
Browse files- mobilevit.html +7 -12
mobilevit.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
| 6 |
<title>Image Classification - Hugging Face Transformers.js</title>
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
-
//
|
| 10 |
-
|
| 11 |
// Make it available globally
|
| 12 |
window.pipeline = pipeline;
|
| 13 |
</script>
|
|
@@ -111,8 +111,7 @@
|
|
| 111 |
let classifier;
|
| 112 |
// Initialize the sentiment analysis model
|
| 113 |
async function initializeModel() {
|
| 114 |
-
|
| 115 |
-
// To-Do: ???
|
| 116 |
}
|
| 117 |
async function classifyImage() {
|
| 118 |
const textFieldValue = document.getElementById("imageClassificationURLText").value.trim();
|
|
@@ -120,24 +119,20 @@
|
|
| 120 |
document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
|
| 121 |
}
|
| 122 |
async function classifyImageLocal() {
|
| 123 |
-
|
| 124 |
-
// To-Do: const fileInput = ???
|
| 125 |
-
|
| 126 |
const file = fileInput.files[0];
|
| 127 |
if (!file) {
|
| 128 |
alert('Please select an image file first.');
|
| 129 |
return;
|
| 130 |
}
|
| 131 |
-
|
| 132 |
const url = URL.createObjectURL(file);
|
| 133 |
-
|
| 134 |
-
// To-Do: ???
|
| 135 |
document.getElementById("outputAreaLocal").innerText = JSON.stringify(result, null, 2);
|
| 136 |
}
|
| 137 |
async function classifyTopImage() {
|
| 138 |
const textFieldValue = document.getElementById("imageClassificationTopURLText").value.trim();
|
| 139 |
-
|
| 140 |
-
// To-Do: ???
|
| 141 |
document.getElementById("outputAreaTop").innerText = JSON.stringify(result, null, 2);
|
| 142 |
}
|
| 143 |
// Initialize the model after the DOM is completely loaded
|
|
|
|
| 6 |
<title>Image Classification - Hugging Face Transformers.js</title>
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
+
// Import the library
|
| 10 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.4';
|
| 11 |
// Make it available globally
|
| 12 |
window.pipeline = pipeline;
|
| 13 |
</script>
|
|
|
|
| 111 |
let classifier;
|
| 112 |
// Initialize the sentiment analysis model
|
| 113 |
async function initializeModel() {
|
| 114 |
+
classifier = await pipeline('image-classification', 'Xenova/mobilevit-small', { quantized: false });
|
|
|
|
| 115 |
}
|
| 116 |
async function classifyImage() {
|
| 117 |
const textFieldValue = document.getElementById("imageClassificationURLText").value.trim();
|
|
|
|
| 119 |
document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
|
| 120 |
}
|
| 121 |
async function classifyImageLocal() {
|
| 122 |
+
const fileInput = document.getElementById("imageClassificationLocalFile");
|
|
|
|
|
|
|
| 123 |
const file = fileInput.files[0];
|
| 124 |
if (!file) {
|
| 125 |
alert('Please select an image file first.');
|
| 126 |
return;
|
| 127 |
}
|
| 128 |
+
// Create a Blob URL from the file
|
| 129 |
const url = URL.createObjectURL(file);
|
| 130 |
+
const result = await classifier(url);
|
|
|
|
| 131 |
document.getElementById("outputAreaLocal").innerText = JSON.stringify(result, null, 2);
|
| 132 |
}
|
| 133 |
async function classifyTopImage() {
|
| 134 |
const textFieldValue = document.getElementById("imageClassificationTopURLText").value.trim();
|
| 135 |
+
const result = await classifier(textFieldValue, { topk: 3 });
|
|
|
|
| 136 |
document.getElementById("outputAreaTop").innerText = JSON.stringify(result, null, 2);
|
| 137 |
}
|
| 138 |
// Initialize the model after the DOM is completely loaded
|