Arslan17121 commited on
Commit
498090e
·
verified ·
1 Parent(s): f6aefc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -30
app.py CHANGED
@@ -17,15 +17,23 @@ def extract_text_from_pdf(pdf_file):
17
 
18
  # Function to generate discussion points
19
  def generate_discussion_points(text):
20
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
21
- summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
22
- return summary[0]['summary_text']
 
 
 
 
23
 
24
  # Function to convert text to speech
25
  def text_to_speech(text, output_file="output.mp3"):
26
- tts = gTTS(text)
27
- tts.save(output_file)
28
- return output_file
 
 
 
 
29
 
30
  # Streamlit app starts here
31
  st.title("📄 PDF Discussion Points Generator")
@@ -45,37 +53,34 @@ if uploaded_file:
45
 
46
  # Generate discussion points
47
  with st.spinner("Generating discussion points..."):
48
- try:
49
- discussion_points = generate_discussion_points(pdf_text)
 
50
  st.write("### Discussion Points")
51
  st.text_area("Discussion Points", discussion_points, height=150)
52
- except Exception as e:
53
- st.error(f"Error during summarization: {e}")
54
 
55
- # Convert discussion points to audio
56
- with st.spinner("Converting discussion points to audio..."):
57
- try:
58
  audio_file = text_to_speech(discussion_points)
59
- st.success("Audio file generated successfully!")
60
- except Exception as e:
61
- st.error(f"Error during text-to-speech conversion: {e}")
62
- audio_file = None
63
 
64
- if audio_file:
65
- # Audio playback
66
- st.write("### Listen to the Discussion Points")
67
- audio_bytes = open(audio_file, "rb").read()
68
- st.audio(audio_bytes, format="audio/mp3")
 
 
69
 
70
- # Option to download the audio file
71
- st.download_button(
72
- label="Download Audio",
73
- data=audio_bytes,
74
- file_name="discussion_points.mp3",
75
- mime="audio/mp3"
76
- )
 
 
77
  else:
78
  st.error("No text was extracted from the uploaded PDF. Please try with another file.")
79
  else:
80
  st.info("Upload a PDF file to start.")
81
-
 
17
 
18
  # Function to generate discussion points
19
  def generate_discussion_points(text):
20
+ try:
21
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
22
+ summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
23
+ return summary[0]['summary_text']
24
+ except Exception as e:
25
+ st.error(f"Error during summarization: {e}")
26
+ return None
27
 
28
  # Function to convert text to speech
29
  def text_to_speech(text, output_file="output.mp3"):
30
+ try:
31
+ tts = gTTS(text)
32
+ tts.save(output_file)
33
+ return output_file
34
+ except Exception as e:
35
+ st.error(f"Error during text-to-speech conversion: {e}")
36
+ return None
37
 
38
  # Streamlit app starts here
39
  st.title("📄 PDF Discussion Points Generator")
 
53
 
54
  # Generate discussion points
55
  with st.spinner("Generating discussion points..."):
56
+ discussion_points = generate_discussion_points(pdf_text)
57
+
58
+ if discussion_points:
59
  st.write("### Discussion Points")
60
  st.text_area("Discussion Points", discussion_points, height=150)
 
 
61
 
62
+ # Convert discussion points to audio
63
+ with st.spinner("Converting discussion points to audio..."):
 
64
  audio_file = text_to_speech(discussion_points)
 
 
 
 
65
 
66
+ if audio_file:
67
+ st.success("Audio file generated successfully!")
68
+
69
+ # Audio playback
70
+ st.write("### Listen to the Discussion Points")
71
+ audio_bytes = open(audio_file, "rb").read()
72
+ st.audio(audio_bytes, format="audio/mp3")
73
 
74
+ # Option to download the audio file
75
+ st.download_button(
76
+ label="Download Audio",
77
+ data=audio_bytes,
78
+ file_name="discussion_points.mp3",
79
+ mime="audio/mp3"
80
+ )
81
+ else:
82
+ st.error("Failed to generate discussion points. Please try again.")
83
  else:
84
  st.error("No text was extracted from the uploaded PDF. Please try with another file.")
85
  else:
86
  st.info("Upload a PDF file to start.")