rbbist commited on
Commit
e599ea9
·
verified ·
1 Parent(s): 7493fc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -12,8 +12,22 @@ import streamlit as st
12
 
13
  # ---------- CONFIG ----------
14
  def summarize_text(text: str) -> str:
15
- summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
16
- return summarizer(text, max_length=200, min_length=30, do_sample=False)[0]['summary_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  def extract_text_from_pdf(pdf_path: str) -> str:
19
  doc = fitz.open(pdf_path)
 
12
 
13
  # ---------- CONFIG ----------
14
  def summarize_text(text: str) -> str:
15
+ if not text.strip():
16
+ return "Summary not available (empty text)."
17
+
18
+ try:
19
+ # Truncate long text safely
20
+ if len(text) > 2000:
21
+ text = text[:2000]
22
+
23
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
24
+ result = summarizer(text, max_length=200, min_length=30, do_sample=False)
25
+
26
+ if result and 'summary_text' in result[0]:
27
+ return result[0]['summary_text']
28
+ return "Summary not available (model did not return text)."
29
+ except Exception as e:
30
+ return f"Summary failed: {str(e)}"
31
 
32
  def extract_text_from_pdf(pdf_path: str) -> str:
33
  doc = fitz.open(pdf_path)