Update app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ def summarize_text(text: str) -> str:
|
|
| 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:
|
|
@@ -45,13 +45,16 @@ def classify_topic(text: str, topics: List[str]) -> str:
|
|
| 45 |
classifier = pipeline("zero-shot-classification", model="valhalla/distilbart-mnli-12-3")
|
| 46 |
result = classifier(text[:1000], candidate_labels=topics)
|
| 47 |
|
| 48 |
-
if 'labels' in result and len(result['labels']) > 0:
|
| 49 |
return result['labels'][0]
|
| 50 |
return "Unknown (classification failed)"
|
| 51 |
|
| 52 |
def generate_audio(text: str, output_path: str):
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
# ---------- STREAMLIT UI ----------
|
| 57 |
st.set_page_config(page_title="Research Paper Summarizer", layout="centered")
|
|
@@ -79,6 +82,7 @@ if submitted and uploaded_file and topic_input:
|
|
| 79 |
f.write(uploaded_file.read())
|
| 80 |
|
| 81 |
text = extract_text_from_pdf(file_path)
|
|
|
|
| 82 |
|
| 83 |
if not text.strip():
|
| 84 |
st.error("❌ No text could be extracted from the PDF. Try another file.")
|
|
|
|
| 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 isinstance(result, list) 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:
|
|
|
|
| 45 |
classifier = pipeline("zero-shot-classification", model="valhalla/distilbart-mnli-12-3")
|
| 46 |
result = classifier(text[:1000], candidate_labels=topics)
|
| 47 |
|
| 48 |
+
if 'labels' in result and isinstance(result['labels'], list) and len(result['labels']) > 0:
|
| 49 |
return result['labels'][0]
|
| 50 |
return "Unknown (classification failed)"
|
| 51 |
|
| 52 |
def generate_audio(text: str, output_path: str):
|
| 53 |
+
try:
|
| 54 |
+
tts = gTTS(text)
|
| 55 |
+
tts.save(output_path)
|
| 56 |
+
except Exception as e:
|
| 57 |
+
raise RuntimeError(f"Audio generation failed: {str(e)}")
|
| 58 |
|
| 59 |
# ---------- STREAMLIT UI ----------
|
| 60 |
st.set_page_config(page_title="Research Paper Summarizer", layout="centered")
|
|
|
|
| 82 |
f.write(uploaded_file.read())
|
| 83 |
|
| 84 |
text = extract_text_from_pdf(file_path)
|
| 85 |
+
st.info(f"Extracted text length: {len(text)} characters")
|
| 86 |
|
| 87 |
if not text.strip():
|
| 88 |
st.error("❌ No text could be extracted from the PDF. Try another file.")
|