Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 ~
|
| 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+
|
| 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 >
|
| 32 |
summaries.append("β οΈ Stopped early")
|
| 33 |
break
|
| 34 |
try:
|
| 35 |
-
summary = summarizer(chunk, max_length=
|
| 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 ~
|
| 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__":
|