Spaces:
Runtime error
Runtime error
Update app.py
Browse filesUpdated to add minimum and additional text
app.py
CHANGED
@@ -5,31 +5,31 @@ from PyPDF2 import PdfReader
|
|
5 |
|
6 |
st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!')
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
reader = PdfReader(uploaded_file)
|
14 |
-
|
15 |
-
|
16 |
-
print(X)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
i = i + 1
|
31 |
-
st.write("π That's the whole PDF! Have an awesome day! π")
|
32 |
-
|
33 |
|
34 |
prompt = st.chat_input("Copy/Paste or type in text to have read aloud")
|
35 |
if prompt:
|
@@ -38,5 +38,4 @@ if prompt:
|
|
38 |
sound_file = BytesIO()
|
39 |
tts = gTTS(prompt, lang='en')
|
40 |
tts.write_to_fp(sound_file)
|
41 |
-
|
42 |
st.audio(sound_file)
|
|
|
5 |
|
6 |
st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!')
|
7 |
|
8 |
+
st.markdown("## Ready for an Epic PDF Adventure? π")
|
9 |
+
st.markdown("Buckle up! Upload your PDF, set your preferences, and let's explore the text together!")
|
10 |
|
11 |
+
# Sliders for page range selection
|
12 |
+
start_page = st.slider('Select the starting page', min_value=1, max_value=400, value=1)
|
13 |
+
end_page = st.slider('Select the number of pages you wish to transcribe', min_value=1, max_value=400, value=100)
|
14 |
+
|
15 |
+
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
16 |
+
if uploaded_file is not None:
|
17 |
reader = PdfReader(uploaded_file)
|
18 |
+
total_pages = len(reader.pages)
|
19 |
+
st.write(f"The uploaded PDF has {total_pages} pages.")
|
|
|
20 |
|
21 |
+
if start_page <= total_pages:
|
22 |
+
for i in range(start_page - 1, min(end_page, total_pages)):
|
23 |
+
page = reader.pages[i]
|
24 |
+
text = page.extract_text()
|
25 |
+
sound_file = BytesIO()
|
26 |
+
tts = gTTS(text, lang='en')
|
27 |
+
tts.write_to_fp(sound_file)
|
28 |
+
st.audio(sound_file)
|
29 |
+
st.write(f"Page {i + 1} of {total_pages} has been read aloud.")
|
30 |
+
st.write("π Adventure complete! Have a fantastic day! π")
|
31 |
+
else:
|
32 |
+
st.write("β οΈ The starting page exceeds the total number of pages in the PDF.")
|
|
|
|
|
|
|
33 |
|
34 |
prompt = st.chat_input("Copy/Paste or type in text to have read aloud")
|
35 |
if prompt:
|
|
|
38 |
sound_file = BytesIO()
|
39 |
tts = gTTS(prompt, lang='en')
|
40 |
tts.write_to_fp(sound_file)
|
|
|
41 |
st.audio(sound_file)
|