kimhyunwoo commited on
Commit
32922f8
·
verified ·
1 Parent(s): 9c24e6f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +12 -9
index.html CHANGED
@@ -5,7 +5,7 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Gemma Chatbot</title>
7
  <style>
8
- /* (Same CSS as before - good styling) */
9
  body {
10
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
  display: flex;
@@ -159,17 +159,22 @@
159
  async function initializePipeline() {
160
  loadingIndicator.style.display = 'block';
161
  try {
 
162
  generator = await pipeline(
163
  "text-generation",
164
- "onnx-community/gemma-3-1b-it-ONNX", // Use correct model name
165
  {
166
- dtype: "q4", // Use quantized weights (smaller, faster)
167
  progress_callback: (progress) => {
168
  if (progress.status === 'progress') {
169
  loadingIndicator.textContent = `Loading... ${progress.file} - ${Math.round(progress.loaded / 1000000)}MB/${Math.round(progress.total / 1000000)}MB`;
170
  }
171
  if (progress.status === 'loaded') {
172
  loadingIndicator.textContent = 'Model Loaded!';
 
 
 
 
173
  }
174
  },
175
  }
@@ -177,18 +182,17 @@
177
 
178
  } catch (error) {
179
  console.error("Error loading model:", error);
180
- loadingIndicator.textContent = "Error loading model. Check console, internet, and browser.";
181
  loadingIndicator.style.color = "red";
182
  sendButton.disabled = true;
183
  return;
184
  }
185
- // Don't hide until 'loaded' in progress_callback
186
  addMessage("bot", "Hello! I'm ready to chat. Ask me anything!");
187
  }
188
 
189
  initializePipeline();
190
 
191
-
192
  function addMessage(role, content) {
193
  const messageDiv = document.createElement('div');
194
  messageDiv.classList.add('message', `${role}-message`);
@@ -214,10 +218,10 @@
214
  try {
215
  const output = await generator(chatHistory, {
216
  max_new_tokens: 512,
217
- do_sample: false // Try setting to `true` for varied responses.
218
  });
219
 
220
- const botResponse = output[0].generated_text.at(-1).content;
221
  addMessage('assistant', botResponse);
222
 
223
  } catch (error) {
@@ -229,7 +233,6 @@
229
  }
230
  }
231
 
232
-
233
  sendButton.addEventListener('click', sendMessage);
234
  userInput.addEventListener('keypress', (event) => {
235
  if (event.key === 'Enter') {
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Gemma Chatbot</title>
7
  <style>
8
+ /* (Same good CSS as before) */
9
  body {
10
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
  display: flex;
 
159
  async function initializePipeline() {
160
  loadingIndicator.style.display = 'block';
161
  try {
162
+ // Correct Gemma 3 model name and text-generation pipeline
163
  generator = await pipeline(
164
  "text-generation",
165
+ "onnx-community/gemma-3-1b-it-ONNX",
166
  {
167
+ dtype: "q4", // Quantization
168
  progress_callback: (progress) => {
169
  if (progress.status === 'progress') {
170
  loadingIndicator.textContent = `Loading... ${progress.file} - ${Math.round(progress.loaded / 1000000)}MB/${Math.round(progress.total / 1000000)}MB`;
171
  }
172
  if (progress.status === 'loaded') {
173
  loadingIndicator.textContent = 'Model Loaded!';
174
+ // Optional: Hide after a short delay, so the user sees it.
175
+ setTimeout(() => {
176
+ loadingIndicator.style.display = 'none';
177
+ }, 1500); // 1.5 seconds
178
  }
179
  },
180
  }
 
182
 
183
  } catch (error) {
184
  console.error("Error loading model:", error);
185
+ loadingIndicator.textContent = "Error loading model. Check console, ensure a modern browser, and internet connection.";
186
  loadingIndicator.style.color = "red";
187
  sendButton.disabled = true;
188
  return;
189
  }
190
+ // Don't hide it here anymore: let the progress_callback and timeout handle it.
191
  addMessage("bot", "Hello! I'm ready to chat. Ask me anything!");
192
  }
193
 
194
  initializePipeline();
195
 
 
196
  function addMessage(role, content) {
197
  const messageDiv = document.createElement('div');
198
  messageDiv.classList.add('message', `${role}-message`);
 
218
  try {
219
  const output = await generator(chatHistory, {
220
  max_new_tokens: 512,
221
+ do_sample: false // Try setting to `true` for varied responses.
222
  });
223
 
224
+ const botResponse = output[0].generated_text.at(-1).content; // Correctly access generated text
225
  addMessage('assistant', botResponse);
226
 
227
  } catch (error) {
 
233
  }
234
  }
235
 
 
236
  sendButton.addEventListener('click', sendMessage);
237
  userInput.addEventListener('keypress', (event) => {
238
  if (event.key === 'Enter') {