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