rbbist commited on
Commit
1526f04
·
verified ·
1 Parent(s): 5434acc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
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
- classifier = pipeline("zero-shot-classification", model="valhalla/distilbart-mnli-12-3")
 
 
 
 
 
27
  result = classifier(text[:1000], candidate_labels=topics)
28
- return result['labels'][0]
 
 
 
 
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
- classified_topic = classify_topic(text, topic_list)
62
- summary = summarize_text(text)
 
 
 
 
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:")