Arsala Grey
commited on
Commit
•
a2b2617
1
Parent(s):
1ab5b08
cleaned up and prepared demo
Browse files- index.html +27 -12
- index.js +4 -2
- main.css +0 -1
index.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<head>
|
4 |
<meta charset="utf-8" />
|
5 |
<meta name="viewport" content="width=device-width" />
|
6 |
-
<title>Image
|
7 |
<link rel="stylesheet" href="pico.classless.min.css" />
|
8 |
<link rel="stylesheet" href="main.css" />
|
9 |
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
@@ -13,7 +13,9 @@
|
|
13 |
<h1>Classifying Random Unsplash Images</h1>
|
14 |
<div class="grid grid-cols-2 gap-2">
|
15 |
<div>
|
16 |
-
<label for="hf-token"
|
|
|
|
|
17 |
<input
|
18 |
id="hf-token"
|
19 |
v-model="token"
|
@@ -32,17 +34,30 @@
|
|
32 |
<button class="btn-info" @click="shuffle">RANDOM IMAGE</button>
|
33 |
<button class="btn-success" @click="run">CLASSIFY</button>
|
34 |
</div>
|
35 |
-
<
|
36 |
-
<div class="
|
37 |
-
<div
|
38 |
-
|
39 |
-
<
|
40 |
-
|
41 |
-
</div>
|
42 |
-
<div class="image-container">
|
43 |
-
<div id="image-wrapper">
|
44 |
-
<img :src="imageUrl" id="current-image" />
|
45 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
</div>
|
47 |
</div>
|
48 |
<script type="module" src="./index.js"></script>
|
|
|
3 |
<head>
|
4 |
<meta charset="utf-8" />
|
5 |
<meta name="viewport" content="width=device-width" />
|
6 |
+
<title>Image Classification Vue - HuggingFace.js Live Examples</title>
|
7 |
<link rel="stylesheet" href="pico.classless.min.css" />
|
8 |
<link rel="stylesheet" href="main.css" />
|
9 |
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
|
|
13 |
<h1>Classifying Random Unsplash Images</h1>
|
14 |
<div class="grid grid-cols-2 gap-2">
|
15 |
<div>
|
16 |
+
<label for="hf-token"
|
17 |
+
>Hugging Face Token (optional but limited if absent)</label
|
18 |
+
>
|
19 |
<input
|
20 |
id="hf-token"
|
21 |
v-model="token"
|
|
|
34 |
<button class="btn-info" @click="shuffle">RANDOM IMAGE</button>
|
35 |
<button class="btn-success" @click="run">CLASSIFY</button>
|
36 |
</div>
|
37 |
+
<h3>{{statusMessage}}</h3>
|
38 |
+
<div class="grid grid-cols-2 gap-2">
|
39 |
+
<div class="image-container">
|
40 |
+
<div id="image-wrapper">
|
41 |
+
<img :src="imageUrl" id="current-image" />
|
42 |
+
</div>
|
|
|
|
|
|
|
|
|
43 |
</div>
|
44 |
+
<table v-if="classificationLabels.length > 0">
|
45 |
+
<thead>
|
46 |
+
<tr>
|
47 |
+
<th>Label</th>
|
48 |
+
<th>Score</th>
|
49 |
+
</tr>
|
50 |
+
</thead>
|
51 |
+
<tbody>
|
52 |
+
<tr
|
53 |
+
v-for="classificationLabel in classificationLabels"
|
54 |
+
:key="classificationLabel.label"
|
55 |
+
>
|
56 |
+
<td>{{classificationLabel.label}}</td>
|
57 |
+
<td>{{Math.floor(classificationLabel.score * 100, 2)}}%</td>
|
58 |
+
</tr>
|
59 |
+
</tbody>
|
60 |
+
</table>
|
61 |
</div>
|
62 |
</div>
|
63 |
<script type="module" src="./index.js"></script>
|
index.js
CHANGED
@@ -14,7 +14,7 @@ const getImageBuffer = async (imageUrl) => {
|
|
14 |
const app = createApp({
|
15 |
setup() {
|
16 |
const token = ref(localStorage.getItem("token") || "");
|
17 |
-
const models = ref(["google/vit-base-patch16-224"]);
|
18 |
const selectedModel = ref("");
|
19 |
const imageUrl = ref("");
|
20 |
const loading = ref(false);
|
@@ -27,6 +27,7 @@ const app = createApp({
|
|
27 |
})
|
28 |
|
29 |
const run = async () => {
|
|
|
30 |
loading.value = true;
|
31 |
try {
|
32 |
const hf = new HfInference(token.value);
|
@@ -49,8 +50,9 @@ const app = createApp({
|
|
49 |
}
|
50 |
|
51 |
const shuffle = async () => {
|
52 |
-
imageUrl.value =
|
53 |
reset()
|
|
|
54 |
};
|
55 |
|
56 |
onMounted(async () => {
|
|
|
14 |
const app = createApp({
|
15 |
setup() {
|
16 |
const token = ref(localStorage.getItem("token") || "");
|
17 |
+
const models = ref(["google/vit-base-patch16-224", "microsoft/resnet-50", "timm/mobilenetv3_large_100.ra_in1k"]);
|
18 |
const selectedModel = ref("");
|
19 |
const imageUrl = ref("");
|
20 |
const loading = ref(false);
|
|
|
27 |
})
|
28 |
|
29 |
const run = async () => {
|
30 |
+
reset()
|
31 |
loading.value = true;
|
32 |
try {
|
33 |
const hf = new HfInference(token.value);
|
|
|
50 |
}
|
51 |
|
52 |
const shuffle = async () => {
|
53 |
+
imageUrl.value = ""
|
54 |
reset()
|
55 |
+
imageUrl.value = await getRandomImageUrl()
|
56 |
};
|
57 |
|
58 |
onMounted(async () => {
|
main.css
CHANGED
@@ -162,7 +162,6 @@ h1, h2, h3, h4, h5, h6 {
|
|
162 |
.image-container {
|
163 |
display: flex;
|
164 |
justify-content: center;
|
165 |
-
padding: 2rem;
|
166 |
}
|
167 |
|
168 |
#detected-objects-container {
|
|
|
162 |
.image-container {
|
163 |
display: flex;
|
164 |
justify-content: center;
|
|
|
165 |
}
|
166 |
|
167 |
#detected-objects-container {
|