tejovanth commited on
Commit
a725b8a
Β·
verified Β·
1 Parent(s): f6b4c1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -6,7 +6,7 @@ import time, logging
6
 
7
  logging.basicConfig(level=logging.ERROR)
8
  device = -1 # CPU-only
9
- print("⚠️ CPU-only. Expect ~15–25s for 300,000 chars.")
10
 
11
  try:
12
  summarizer = pipeline("summarization", model="t5-small", device=device, torch_dtype=torch.float32)
@@ -23,16 +23,16 @@ def summarize_file(file_bytes):
23
  return f"❌ Text extraction failed: {str(e)}"
24
  if not text.strip(): return "❌ No text found"
25
  text = text[:300000]
26
- chunks = [text[i:i+8000] for i in range(0, len(text), 8000)]
27
  print(f"Chunks created: {len(chunks)}")
28
  if not chunks: return "❌ No chunks to summarize"
29
  summaries = []
30
  for i, chunk in enumerate(chunks):
31
- if time.time() - start > 12:
32
  summaries.append("⚠️ Stopped early")
33
  break
34
  try:
35
- summary = summarizer(chunk, max_length=40, min_length=10, do_sample=False)[0]['summary_text']
36
  summaries.append(f"**Chunk {i+1}**:\n{summary}")
37
  except Exception as e:
38
  summaries.append(f"**Chunk {i+1}**: ❌ Error: {str(e)}")
@@ -41,7 +41,7 @@ def summarize_file(file_bytes):
41
  demo = gr.Interface(
42
  fn=summarize_file, inputs=gr.File(label="πŸ“„ PDF/TXT Notes", type="binary"),
43
  outputs=gr.Textbox(label="πŸ“ Summary"),
44
- title="Fast Summarizer", description="300,000+ chars in ~15–25s (CPU)"
45
  )
46
 
47
  if __name__ == "__main__":
 
6
 
7
  logging.basicConfig(level=logging.ERROR)
8
  device = -1 # CPU-only
9
+ print("⚠️ CPU-only. Expect ~20–30s for 300,000 chars.")
10
 
11
  try:
12
  summarizer = pipeline("summarization", model="t5-small", device=device, torch_dtype=torch.float32)
 
23
  return f"❌ Text extraction failed: {str(e)}"
24
  if not text.strip(): return "❌ No text found"
25
  text = text[:300000]
26
+ chunks = [text[i:i+2000] for i in range(0, len(text), 2000)]
27
  print(f"Chunks created: {len(chunks)}")
28
  if not chunks: return "❌ No chunks to summarize"
29
  summaries = []
30
  for i, chunk in enumerate(chunks):
31
+ if time.time() - start > 15:
32
  summaries.append("⚠️ Stopped early")
33
  break
34
  try:
35
+ summary = summarizer(chunk, max_length=60, min_length=10, do_sample=False)[0]['summary_text']
36
  summaries.append(f"**Chunk {i+1}**:\n{summary}")
37
  except Exception as e:
38
  summaries.append(f"**Chunk {i+1}**: ❌ Error: {str(e)}")
 
41
  demo = gr.Interface(
42
  fn=summarize_file, inputs=gr.File(label="πŸ“„ PDF/TXT Notes", type="binary"),
43
  outputs=gr.Textbox(label="πŸ“ Summary"),
44
+ title="Fast Summarizer", description="300,000+ chars in ~20–30s (CPU)"
45
  )
46
 
47
  if __name__ == "__main__":