Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import PyPDF2
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
|
| 6 |
+
# Function to read the PDF and extract text
|
| 7 |
+
def extract_text_from_pdf(pdf_file):
|
| 8 |
+
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
|
| 9 |
+
text = ""
|
| 10 |
+
for page_num in range(pdf_reader.numPages):
|
| 11 |
+
text += pdf_reader.getPage(page_num).extract_text()
|
| 12 |
+
return text
|
| 13 |
+
|
| 14 |
+
# Function to generate discussion points
|
| 15 |
+
def generate_discussion_points(text):
|
| 16 |
+
summarizer = pipeline('summarization')
|
| 17 |
+
summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
|
| 18 |
+
return summary[0]['summary_text']
|
| 19 |
+
|
| 20 |
+
# Function to convert text to speech
|
| 21 |
+
def text_to_speech(text):
|
| 22 |
+
tts = gTTS(text=text, lang='en')
|
| 23 |
+
tts.save("discussion_points.mp3")
|
| 24 |
+
|
| 25 |
+
# Streamlit app
|
| 26 |
+
st.title("PDF Discussion Points Generator")
|
| 27 |
+
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
| 28 |
+
|
| 29 |
+
if uploaded_file is not None:
|
| 30 |
+
text = extract_text_from_pdf(uploaded_file)
|
| 31 |
+
discussion_points = generate_discussion_points(text)
|
| 32 |
+
st.subheader("Generated Discussion Points")
|
| 33 |
+
st.write(discussion_points)
|
| 34 |
+
|
| 35 |
+
text_to_speech(discussion_points)
|
| 36 |
+
audio_file = open("discussion_points.mp3", "rb")
|
| 37 |
+
audio_bytes = audio_file.read()
|
| 38 |
+
st.audio(audio_bytes, format='audio/mp3')
|