Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,18 @@ def extract_text_from_pdf(pdf_path: str) -> str:
|
|
| 23 |
return text
|
| 24 |
|
| 25 |
def classify_topic(text: str, topics: List[str]) -> str:
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
result = classifier(text[:1000], candidate_labels=topics)
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def generate_audio(text: str, output_path: str):
|
| 31 |
tts = gTTS(text)
|
|
@@ -58,8 +67,12 @@ if submitted and uploaded_file and topic_input:
|
|
| 58 |
|
| 59 |
text = extract_text_from_pdf(file_path)
|
| 60 |
topic_list = [t.strip() for t in topic_input.split(",") if t.strip()]
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
st.markdown(f"### 🧠 Classified Topic: `{classified_topic}`")
|
| 65 |
st.markdown("### ✍️ Summary:")
|
|
|
|
| 23 |
return text
|
| 24 |
|
| 25 |
def classify_topic(text: str, topics: List[str]) -> str:
|
| 26 |
+
if not text.strip():
|
| 27 |
+
return "Unknown (no text extracted)"
|
| 28 |
+
if not topics:
|
| 29 |
+
return "Unknown (no topics provided)"
|
| 30 |
+
|
| 31 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 32 |
result = classifier(text[:1000], candidate_labels=topics)
|
| 33 |
+
|
| 34 |
+
if 'labels' in result and len(result['labels']) > 0:
|
| 35 |
+
return result['labels'][0]
|
| 36 |
+
return "Unknown (classification failed)"
|
| 37 |
+
|
| 38 |
|
| 39 |
def generate_audio(text: str, output_path: str):
|
| 40 |
tts = gTTS(text)
|
|
|
|
| 67 |
|
| 68 |
text = extract_text_from_pdf(file_path)
|
| 69 |
topic_list = [t.strip() for t in topic_input.split(",") if t.strip()]
|
| 70 |
+
if not text.strip():
|
| 71 |
+
st.error("❌ No text could be extracted from the PDF. Try another file.")
|
| 72 |
+
else:
|
| 73 |
+
classified_topic = classify_topic(text, topic_list)
|
| 74 |
+
summary = summarize_text(text)
|
| 75 |
+
|
| 76 |
|
| 77 |
st.markdown(f"### 🧠 Classified Topic: `{classified_topic}`")
|
| 78 |
st.markdown("### ✍️ Summary:")
|