SamuelWHS commited on
Commit
19564f5
Β·
verified Β·
1 Parent(s): 467b79d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +67 -44
index.html CHANGED
@@ -20,6 +20,8 @@
20
  -->
21
 
22
  <!DOCTYPE html>
 
 
23
  <html lang="en">
24
  <head>
25
  <meta charset="utf-8" />
@@ -167,6 +169,15 @@
167
  border-radius: 8px;
168
  }
169
 
 
 
 
 
 
 
 
 
 
170
  @media (max-width: 600px) {
171
  .card {
172
  padding: 20px;
@@ -189,7 +200,11 @@
189
  <body>
190
  <div class="card">
191
  <h1>πŸ“ AI Text Summarization</h1>
192
- <div class="subtitle">Powered by FalconsAI T5 Sequence-to-Sequence model</div>
 
 
 
 
193
 
194
  <div>
195
  <label for="inputText">Input text to summarize:</label>
@@ -201,7 +216,7 @@
201
  </div>
202
 
203
  <div class="button-group">
204
- <button id="summarizeButton">✨ Summarize</button>
205
  <button id="clearButton" class="clear-btn">πŸ—‘οΈ Clear</button>
206
  </div>
207
 
@@ -230,39 +245,56 @@
230
  const tokenInfo = document.getElementById('tokenInfo');
231
  const summarizeBtn = document.getElementById('summarizeButton');
232
  const clearBtn = document.getElementById('clearButton');
 
233
 
234
- // Initialize the summarization pipeline lazily (only when needed)
235
  let summarizer = null;
 
236
 
237
- async function getSummarizer() {
238
- if (!summarizer) {
239
- try {
240
- outputText.textContent = 'Loading model... This may take a moment.';
241
- outputText.className = 'loading';
242
- summarizeBtn.disabled = true;
243
-
244
- // Load the ONNX version of the model
245
- summarizer = await pipeline(
246
- 'summarization',
247
- 'onnx-community/Falconsai-text_summarization-ONNX'
248
- );
249
-
250
- outputText.textContent = 'Ready! Enter text and click Summarize.';
251
- outputText.className = '';
252
- summarizeBtn.disabled = false;
253
- } catch (error) {
254
- console.error('Failed to load model:', error);
255
- outputText.textContent = 'Failed to load the summarization model. Please refresh the page.';
256
- outputText.className = 'error';
257
- summarizeBtn.disabled = false;
258
- return null;
259
- }
 
 
 
 
 
 
 
 
 
 
260
  }
261
- return summarizer;
262
  }
263
 
264
  // Main summarize function
265
  async function summarize() {
 
 
 
 
 
 
266
  const text = inputText.value.trim();
267
 
268
  // Validate input
@@ -279,7 +311,7 @@
279
  if (inputTokens < 5) {
280
  outputText.textContent = 'Insufficient text to summarize. Please enter at least 5 words.';
281
  outputText.className = 'error';
282
- tokenInfo.textContent = `Input tokens: ${inputTokens}`;
283
  return;
284
  }
285
 
@@ -290,18 +322,11 @@
290
  tokenInfo.textContent = '';
291
 
292
  try {
293
- // Get the summarizer
294
- const summarizerInstance = await getSummarizer();
295
- if (!summarizerInstance) {
296
- summarizeBtn.disabled = false;
297
- return;
298
- }
299
-
300
  // Run summarization
301
- const result = await summarizerInstance(text, {
302
  truncation: true,
303
- max_length: 150, // Adjust as needed
304
- min_length: 30 // Adjust as needed
305
  });
306
 
307
  // Extract the summary
@@ -315,7 +340,7 @@
315
  outputText.className = '';
316
  tokenInfo.textContent = `πŸ“Š Input tokens: ${inputTokens} | Output tokens: ${outputTokens}`;
317
 
318
- console.log(`Input tokens: ${inputTokens}, Output tokens: ${outputTokens}`); // Debug
319
 
320
  } catch (error) {
321
  console.error('Summarization error:', error);
@@ -346,11 +371,9 @@
346
  }
347
  });
348
 
349
- // Preload the model on page load (optional)
350
- // Uncomment the line below if you want to preload the model immediately
351
- // getSummarizer();
352
-
353
- console.log('✨ AI Text Summarization app loaded!');
354
  </script>
355
  </body>
356
  </html>
 
20
  -->
21
 
22
  <!DOCTYPE html>
23
+
24
+ <!DOCTYPE html>
25
  <html lang="en">
26
  <head>
27
  <meta charset="utf-8" />
 
169
  border-radius: 8px;
170
  }
171
 
172
+ .model-status {
173
+ margin: 10px 0;
174
+ padding: 10px;
175
+ background: #f0f7ff;
176
+ border-radius: 8px;
177
+ font-size: 0.9rem;
178
+ color: #4a5568;
179
+ }
180
+
181
  @media (max-width: 600px) {
182
  .card {
183
  padding: 20px;
 
200
  <body>
201
  <div class="card">
202
  <h1>πŸ“ AI Text Summarization</h1>
203
+ <div class="subtitle">Powered by T5 model (running in your browser)</div>
204
+
205
+ <div id="modelStatus" class="model-status">
206
+ ⏳ Loading model... Please wait.
207
+ </div>
208
 
209
  <div>
210
  <label for="inputText">Input text to summarize:</label>
 
216
  </div>
217
 
218
  <div class="button-group">
219
+ <button id="summarizeButton" disabled>✨ Summarize</button>
220
  <button id="clearButton" class="clear-btn">πŸ—‘οΈ Clear</button>
221
  </div>
222
 
 
245
  const tokenInfo = document.getElementById('tokenInfo');
246
  const summarizeBtn = document.getElementById('summarizeButton');
247
  const clearBtn = document.getElementById('clearButton');
248
+ const modelStatus = document.getElementById('modelStatus');
249
 
250
+ // Initialize the summarization pipeline
251
  let summarizer = null;
252
+ let isModelReady = false;
253
 
254
+ async function initModel() {
255
+ try {
256
+ modelStatus.innerHTML = '⏳ Loading T5 summarization model... This may take 10-30 seconds.';
257
+ modelStatus.style.background = '#fef3c7';
258
+ modelStatus.style.color = '#92400e';
259
+ summarizeBtn.disabled = true;
260
+
261
+ // Load the model - using a known working model
262
+ summarizer = await pipeline(
263
+ 'summarization',
264
+ 'Xenova/t5-small', // This is the model that works
265
+ {
266
+ // Optional: Use quantized version for faster loading
267
+ quantized: true
268
+ }
269
+ );
270
+
271
+ isModelReady = true;
272
+ modelStatus.innerHTML = 'βœ… Model loaded successfully! Ready to summarize.';
273
+ modelStatus.style.background = '#d1fae5';
274
+ modelStatus.style.color = '#065f46';
275
+ summarizeBtn.disabled = false;
276
+
277
+ console.log('βœ… Model loaded successfully!');
278
+
279
+ } catch (error) {
280
+ console.error('Failed to load model:', error);
281
+ modelStatus.innerHTML = '❌ Failed to load model. Please refresh the page or try again later.';
282
+ modelStatus.style.background = '#fee2e2';
283
+ modelStatus.style.color = '#991b1b';
284
+ summarizeBtn.disabled = true;
285
+ outputText.textContent = 'Failed to load the summarization model. Please refresh the page.';
286
+ outputText.className = 'error';
287
  }
 
288
  }
289
 
290
  // Main summarize function
291
  async function summarize() {
292
+ if (!isModelReady || !summarizer) {
293
+ outputText.textContent = 'Model is still loading. Please wait...';
294
+ outputText.className = 'error';
295
+ return;
296
+ }
297
+
298
  const text = inputText.value.trim();
299
 
300
  // Validate input
 
311
  if (inputTokens < 5) {
312
  outputText.textContent = 'Insufficient text to summarize. Please enter at least 5 words.';
313
  outputText.className = 'error';
314
+ tokenInfo.textContent = `πŸ“Š Input tokens: ${inputTokens}`;
315
  return;
316
  }
317
 
 
322
  tokenInfo.textContent = '';
323
 
324
  try {
 
 
 
 
 
 
 
325
  // Run summarization
326
+ const result = await summarizer(text, {
327
  truncation: true,
328
+ max_length: 150,
329
+ min_length: 30
330
  });
331
 
332
  // Extract the summary
 
340
  outputText.className = '';
341
  tokenInfo.textContent = `πŸ“Š Input tokens: ${inputTokens} | Output tokens: ${outputTokens}`;
342
 
343
+ console.log(`βœ… Input tokens: ${inputTokens}, Output tokens: ${outputTokens}`);
344
 
345
  } catch (error) {
346
  console.error('Summarization error:', error);
 
371
  }
372
  });
373
 
374
+ // Initialize the model when the page loads
375
+ console.log('πŸš€ Loading summarization model...');
376
+ initModel();
 
 
377
  </script>
378
  </body>
379
  </html>