tejovanth commited on
Commit
9a7487f
·
verified ·
1 Parent(s): c83f77f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -46
app.py DELETED
@@ -1,46 +0,0 @@
1
- import gradio as gr
2
- import fitz
3
- import torch
4
- from transformers import pipeline
5
- import time, io
6
-
7
- device = 0 if torch.cuda.is_available() else -1
8
- if device == -1: raise RuntimeError("GPU required for 5–10s target")
9
-
10
- summarizer = pipeline("summarization", model="google/pegasus-xsum", device=device, torch_dtype=torch.int8)
11
-
12
- def extract_text(file_bytes):
13
- if file_bytes[:4].startswith(b'%PDF'):
14
- doc = fitz.open(stream=file_bytes, filetype="pdf")
15
- text = "".join(page.get_text("text", flags=16) for page in doc)
16
- doc.close()
17
- return text
18
- try: return file_bytes.decode("utf-8")
19
- except: return "❌ Unsupported format (PDF/TXT only)"
20
-
21
- async def summarize_file(file_bytes):
22
- start = time.time()
23
- text = extract_text(file_bytes)[:300000] or "❌ No text found"
24
- if len(text.strip()) == 0: return text
25
- chunks = [text[i:i+15000] for i in range(0, len(text), 15000)]
26
- if not chunks: return "❌ No chunks to summarize"
27
- summaries = []
28
- for i in range(0, len(chunks), 10):
29
- if time.time() - start > 7:
30
- summaries.append("⚠️ Stopped early")
31
- break
32
- batch = chunks[i:i+10]
33
- try:
34
- batch_summaries = summarizer(batch, max_length=40, min_length=10, do_sample=False, batch_size=10)
35
- summaries.extend(f"**Chunk {i+j+1}**:\n{s['summary_text']}" for j, s in enumerate(batch_summaries))
36
- except: summaries.append(f"**Chunk {i+1}**: ❌ Error")
37
- return f"**Chars**: {len(text)}\n**Time**: {time.time()-start:.2f}s\n\n" + "\n\n".join(summaries)
38
-
39
- demo = gr.Interface(
40
- fn=summarize_file, inputs=gr.File(label="📄 PDF/TXT Notes"),
41
- outputs=gr.Textbox(label="📝 Summary"),
42
- title="Fast Summarizer", description="300,000+ chars in ~5s (GPU)"
43
- )
44
-
45
- if __name__ == "__main__":
46
- demo.launch(share=False)