SamuelWHS commited on
Commit
7403b8d
Β·
verified Β·
1 Parent(s): 19564f5

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +44 -39
index.html CHANGED
@@ -21,6 +21,7 @@
21
 
22
  <!DOCTYPE html>
23
 
 
24
  <!DOCTYPE html>
25
  <html lang="en">
26
  <head>
@@ -28,7 +29,6 @@
28
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
29
  <title>AI Text Summarization</title>
30
  <style>
31
- /* All styles in one file for simplicity */
32
  * {
33
  margin: 0;
34
  padding: 0;
@@ -68,6 +68,16 @@
68
  padding-bottom: 10px;
69
  }
70
 
 
 
 
 
 
 
 
 
 
 
71
  label {
72
  display: block;
73
  font-weight: 600;
@@ -84,6 +94,7 @@
84
  font-family: inherit;
85
  resize: vertical;
86
  transition: border-color 0.3s;
 
87
  }
88
 
89
  textarea:focus {
@@ -160,6 +171,10 @@
160
  color: #e53e3e;
161
  }
162
 
 
 
 
 
163
  .token-info {
164
  margin-top: 10px;
165
  font-size: 0.9rem;
@@ -169,15 +184,6 @@
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,10 +206,10 @@
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>
@@ -253,41 +259,40 @@
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...';
@@ -297,7 +302,7 @@
297
 
298
  const text = inputText.value.trim();
299
 
300
- // Validate input
301
  if (!text) {
302
  outputText.textContent = 'Please enter document text to summarize.';
303
  outputText.className = 'error';
@@ -305,11 +310,12 @@
305
  return;
306
  }
307
 
308
- // Simple token count (split by whitespace)
309
  const inputTokens = text.split(/\s+/).length;
310
 
 
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;
@@ -322,26 +328,25 @@
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
333
- const summary = result[0].summary_text;
334
 
335
- // Count output tokens
336
- const outputTokens = summary.split(/\s+/).length;
 
 
 
337
 
338
  // Update UI
339
- outputText.textContent = 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);
347
  outputText.textContent = `An error occurred: ${error.message || 'Unknown error'}`;
@@ -363,7 +368,7 @@
363
  summarizeBtn.addEventListener('click', summarize);
364
  clearBtn.addEventListener('click', clearAll);
365
 
366
- // Optional: Allow Ctrl+Enter to summarize
367
  inputText.addEventListener('keydown', (e) => {
368
  if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
369
  e.preventDefault();
@@ -372,7 +377,7 @@
372
  });
373
 
374
  // Initialize the model when the page loads
375
- console.log('πŸš€ Loading summarization model...');
376
  initModel();
377
  </script>
378
  </body>
 
21
 
22
  <!DOCTYPE html>
23
 
24
+ <!DOCTYPE html>
25
  <!DOCTYPE html>
26
  <html lang="en">
27
  <head>
 
29
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
30
  <title>AI Text Summarization</title>
31
  <style>
 
32
  * {
33
  margin: 0;
34
  padding: 0;
 
68
  padding-bottom: 10px;
69
  }
70
 
71
+ .model-status {
72
+ margin: 10px 0 20px 0;
73
+ padding: 12px;
74
+ background: #f0f7ff;
75
+ border-radius: 8px;
76
+ font-size: 0.95rem;
77
+ color: #4a5568;
78
+ border-left: 4px solid #667eea;
79
+ }
80
+
81
  label {
82
  display: block;
83
  font-weight: 600;
 
94
  font-family: inherit;
95
  resize: vertical;
96
  transition: border-color 0.3s;
97
+ min-height: 150px;
98
  }
99
 
100
  textarea:focus {
 
171
  color: #e53e3e;
172
  }
173
 
174
+ .success {
175
+ color: #065f46;
176
+ }
177
+
178
  .token-info {
179
  margin-top: 10px;
180
  font-size: 0.9rem;
 
184
  border-radius: 8px;
185
  }
186
 
 
 
 
 
 
 
 
 
 
187
  @media (max-width: 600px) {
188
  .card {
189
  padding: 20px;
 
206
  <body>
207
  <div class="card">
208
  <h1>πŸ“ AI Text Summarization</h1>
209
+ <div class="subtitle">Powered by FalconsAI T5 Sequence-to-Sequence model</div>
210
 
211
  <div id="modelStatus" class="model-status">
212
+ ⏳ Loading model... Please wait (this may take 10-30 seconds)
213
  </div>
214
 
215
  <div>
 
259
 
260
  async function initModel() {
261
  try {
262
+ modelStatus.innerHTML = '⏳ Downloading FalconsAI T5 model... This may take 10-30 seconds.';
263
  modelStatus.style.background = '#fef3c7';
264
+ modelStatus.style.borderLeftColor = '#f59e0b';
265
  summarizeBtn.disabled = true;
266
 
267
+ // Load the ONNX version of Falconsai/text_summarization
268
  summarizer = await pipeline(
269
  'summarization',
270
+ 'onnx-community/Falconsai-text_summarization-ONNX',
271
  {
272
+ quantized: true // Use quantized version for faster loading
 
273
  }
274
  );
275
 
276
  isModelReady = true;
277
  modelStatus.innerHTML = 'βœ… Model loaded successfully! Ready to summarize.';
278
  modelStatus.style.background = '#d1fae5';
279
+ modelStatus.style.borderLeftColor = '#10b981';
280
  summarizeBtn.disabled = false;
281
 
282
+ console.log('βœ… FalconsAI summarization model loaded successfully!');
283
 
284
  } catch (error) {
285
  console.error('Failed to load model:', error);
286
  modelStatus.innerHTML = '❌ Failed to load model. Please refresh the page or try again later.';
287
  modelStatus.style.background = '#fee2e2';
288
+ modelStatus.style.borderLeftColor = '#ef4444';
289
  summarizeBtn.disabled = true;
290
  outputText.textContent = 'Failed to load the summarization model. Please refresh the page.';
291
  outputText.className = 'error';
292
  }
293
  }
294
 
295
+ // Main summarize function (mirrors your Python app.py logic)
296
  async function summarize() {
297
  if (!isModelReady || !summarizer) {
298
  outputText.textContent = 'Model is still loading. Please wait...';
 
302
 
303
  const text = inputText.value.trim();
304
 
305
+ // Check if input is empty or only whitespace
306
  if (!text) {
307
  outputText.textContent = 'Please enter document text to summarize.';
308
  outputText.className = 'error';
 
310
  return;
311
  }
312
 
313
+ // Approximate token count using words
314
  const inputTokens = text.split(/\s+/).length;
315
 
316
+ // Check if word count is less than 5
317
  if (inputTokens < 5) {
318
+ outputText.textContent = 'Insufficient text to summarize.';
319
  outputText.className = 'error';
320
  tokenInfo.textContent = `πŸ“Š Input tokens: ${inputTokens}`;
321
  return;
 
328
  tokenInfo.textContent = '';
329
 
330
  try {
331
+ // Proceed with summarization
332
  const result = await summarizer(text, {
333
+ truncation: true
 
 
334
  });
335
 
336
+ // Get summary text
337
+ const summaryText = result[0].summary_text;
338
 
339
+ // Calculate output tokens (approximate using word count)
340
+ const outputTokens = summaryText.split(/\s+/).length;
341
+
342
+ // Debug print statement (visible in browser console)
343
+ console.log(`Input tokens: ${inputTokens}, Output tokens: ${outputTokens}`);
344
 
345
  // Update UI
346
+ outputText.textContent = summaryText;
347
+ outputText.className = 'success';
348
  tokenInfo.textContent = `πŸ“Š Input tokens: ${inputTokens} | Output tokens: ${outputTokens}`;
349
 
 
 
350
  } catch (error) {
351
  console.error('Summarization error:', error);
352
  outputText.textContent = `An error occurred: ${error.message || 'Unknown error'}`;
 
368
  summarizeBtn.addEventListener('click', summarize);
369
  clearBtn.addEventListener('click', clearAll);
370
 
371
+ // Allow Ctrl+Enter to summarize (same as your Python version)
372
  inputText.addEventListener('keydown', (e) => {
373
  if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
374
  e.preventDefault();
 
377
  });
378
 
379
  // Initialize the model when the page loads
380
+ console.log('πŸš€ Loading FalconsAI summarization model...');
381
  initModel();
382
  </script>
383
  </body>