boazchung commited on
Commit
9fdce57
1 Parent(s): 9988f55

Update mobilevit.html

Browse files
Files changed (1) hide show
  1. mobilevit.html +12 -7
mobilevit.html CHANGED
@@ -6,8 +6,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>
@@ -111,7 +111,8 @@
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,20 +120,24 @@
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
 
6
  <title>Image Classification - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
9
+ // 허깅페이스의 pipeline 모듈을 import하십시오.
10
+ // To-Do: ???
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
+ // pipeline 함수를 이용하여 Xenova/mobilevit-small 모델의 인스턴스를 생성하여 이를 classifier에 저정하십시오. 인스턴스 생성 시 quantized 파라미터의 값을 false 설정하십시오.
115
+ // To-Do: ???
116
  }
117
  async function classifyImage() {
118
  const textFieldValue = document.getElementById("imageClassificationURLText").value.trim();
 
120
  document.getElementById("outputArea").innerText = JSON.stringify(result, null, 2);
121
  }
122
  async function classifyImageLocal() {
123
+ // HTML DOM의 element Id가 imageClassificationLocalFile인 element의 값을 fileInput으로 저장하십시오.
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
+ // classifier에 url을 입력하여 출력된 결과를 result 저장하십시오.
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
+ // classifier에 textFieldValue를 입력 변수로, topk 파라미터 값을 3으로 설정하여 classifer를 수행하고 그 결과를 result에 저장하십시오.
140
+ // To-Do: ???
141
  document.getElementById("outputAreaTop").innerText = JSON.stringify(result, null, 2);
142
  }
143
  // Initialize the model after the DOM is completely loaded