Spaces:
Runtime error
Runtime error
File size: 1,693 Bytes
474f4cc cc84c76 9f8e59c 474f4cc 9e1c381 04bcda5 4b5b0e4 04bcda5 9f8e59c 04bcda5 ad135b5 04bcda5 cc84c76 0b298e3 e2bb816 b56acb6 0b298e3 0acfb8a |
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 40 41 42 |
import streamlit as st
from gtts import gTTS
from io import BytesIO
from PyPDF2 import PdfReader
st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!')
st.markdown("## Ready for an Epic PDF Adventure? π")
st.markdown("Buckle up! Upload your PDF, set your preferences, and let's explore the text together!")
# Sliders for page range selection
start_page = st.slider('Select the starting page', min_value=1, max_value=400, value=1)
end_page = st.slider('Select the number of pages you wish to transcribe', min_value=1, max_value=400, value=100)
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
if uploaded_file is not None:
reader = PdfReader(uploaded_file)
total_pages = len(reader.pages)
st.write(f"The uploaded PDF has {total_pages} pages.")
if start_page <= total_pages:
for i in range(start_page - 1, min(end_page, total_pages)):
page = reader.pages[i]
text = page.extract_text()
sound_file = BytesIO()
tts = gTTS(text, lang='en')
tts.write_to_fp(sound_file)
st.audio(sound_file)
st.write(f"Page {i + 1} of {total_pages} has been read aloud.")
st.write("π Adventure complete! Have a fantastic day! π")
else:
st.write("β οΈ The starting page exceeds the total number of pages in the PDF.")
prompt = st.chat_input("Copy/Paste or type in text to have read aloud")
if prompt:
st.write(prompt)
with st.popover("β¨ Open your text-to-speech from text input β¨"):
sound_file = BytesIO()
tts = gTTS(prompt, lang='en')
tts.write_to_fp(sound_file)
st.audio(sound_file)
|