boazchung commited on
Commit
ef3a3e4
1 Parent(s): 439792e

Create refs/_imgclf.html

Browse files
Files changed (1) hide show
  1. refs/_imgclf.html +135 -0
refs/_imgclf.html ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
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>
14
+
15
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet">
16
+
17
+ <link rel="stylesheet" href="css/styles.css">
18
+ </head>
19
+
20
+ <body>
21
+ <div class="container-main">
22
+
23
+ <!-- Back to Home button -->
24
+ <div class="row mt-5">
25
+ <div class="col-md-12 text-center">
26
+ <a href="index.html" class="btn btn-outline-secondary"
27
+ style="color: #3c650b; border-color: #3c650b;">Back to Main Page</a>
28
+ </div>
29
+ </div>
30
+
31
+ <!-- Content -->
32
+ <div class="container mt-5">
33
+ <!-- Centered Titles -->
34
+ <div class="text-center">
35
+ <h2>Computer Vision</h2>
36
+ <h4>Image Classification</h4>
37
+ </div>
38
+
39
+ <!-- Actual Content of this page -->
40
+ <div id="image-classification-container" class="container mt-4">
41
+ <h5>Classify an Image:</h5>
42
+ <div class="d-flex align-items-center">
43
+ <label for="imageClassificationURLText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter
44
+ image URL:</label>
45
+ <input type="text" class="form-control flex-grow-1" id="imageClassificationURLText"
46
+ value="https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg"
47
+ placeholder="Enter image" style="margin-right: 15px; margin-left: 15px;">
48
+ <button id="ClassifyButton" class="btn btn-primary" onclick="classifyImage()">Classify</button>
49
+ </div>
50
+ <div class="mt-4">
51
+ <h4>Output:</h4>
52
+ <pre id="outputArea"></pre>
53
+ </div>
54
+ </div>
55
+
56
+ <hr> <!-- Line Separator -->
57
+
58
+ <div id="image-classification-local-container" class="container mt-4">
59
+ <h5>Classify a Local Image:</h5>
60
+ <div class="d-flex align-items-center">
61
+ <label for="imageClassificationLocalFile" class="mb-0 text-nowrap"
62
+ style="margin-right: 15px;">Select Local Image:</label>
63
+ <input type="file" id="imageClassificationLocalFile" accept="image/*" />
64
+ <button id="ClassifyButtonLocal" class="btn btn-primary"
65
+ onclick="classifyImageLocal()">Classify</button>
66
+ </div>
67
+ <div class="mt-4">
68
+ <h4>Output:</h4>
69
+ <pre id="outputAreaLocal"></pre>
70
+ </div>
71
+ </div>
72
+
73
+ <hr> <!-- Line Separator -->
74
+
75
+ <div id="image-classification-top-container" class="container mt-4">
76
+ <h5>Classify an Image and Return Top n Classes:</h5>
77
+ <div class="d-flex align-items-center">
78
+ <label for="imageClassificationTopURLText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter
79
+ image URL:</label>
80
+ <input type="text" class="form-control flex-grow-1" id="imageClassificationTopURLText"
81
+ value="https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg"
82
+ placeholder="Enter image" style="margin-right: 15px; margin-left: 15px;">
83
+ <button id="ClassifyTopButton" class="btn btn-primary" onclick="classifyTopImage()">Classify</button>
84
+ </div>
85
+ <div class="mt-4">
86
+ <h4>Output:</h4>
87
+ <pre id="outputAreaTop"></pre>
88
+ </div>
89
+ </div>
90
+
91
+ <!-- Back to Home button -->
92
+ <div class="row mt-5">
93
+ <div class="col-md-12 text-center">
94
+ <a href="index.html" class="btn btn-outline-secondary"
95
+ style="color: #3c650b; border-color: #3c650b;">Back to Main Page</a>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </div>
100
+
101
+ <script>
102
+ let classifier;
103
+ // Initialize the sentiment analysis model
104
+ async function initializeModel() {
105
+ classifier = await pipeline('image-classification', 'Xenova/vit-base-patch16-224');
106
+
107
+ }
108
+ async function classifyImage() {
109
+ const textFieldValue = document.getElementById("imageClassificationURLText").value.trim();
110
+ const result = await classifier(textFieldValue);
111
+ document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
112
+ }
113
+ async function classifyImageLocal() {
114
+ const fileInput = document.getElementById("imageClassificationLocalFile");
115
+ const file = fileInput.files[0];
116
+ if (!file) {
117
+ alert('Please select an image file first.');
118
+ return;
119
+ }
120
+ // Create a Blob URL from the file
121
+ const url = URL.createObjectURL(file);
122
+ const result = await classifier(url);
123
+ document.getElementById("outputAreaLocal").innerText = JSON.stringify(result, null, 2);
124
+ }
125
+ async function classifyTopImage() {
126
+ const textFieldValue = document.getElementById("imageClassificationTopURLText").value.trim();
127
+ const result = await classifier(textFieldValue, { topk: 3 });
128
+ document.getElementById("outputAreaTop").innerText = JSON.stringify(result, null, 2);
129
+ }
130
+ // Initialize the model after the DOM is completely loaded
131
+ window.addEventListener("DOMContentLoaded", initializeModel);
132
+ </script>
133
+ </body>
134
+
135
+ </html>