Solshine commited on
Commit
04bcda5
β€’
1 Parent(s): a1f5b6e

Update app.py

Browse files

Updated to add minimum and additional text

Files changed (1) hide show
  1. app.py +22 -23
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
- x = st.slider('Select the number of pages you wish to transcribe')
 
9
 
10
- uploaded_file = st.file_uploader("Choose a file", "pdf")
11
- if uploaded_file is not None:
12
- # creating a pdf reader object
 
 
 
13
  reader = PdfReader(uploaded_file)
14
- # printing number of pages in pdf file
15
- X = len(reader.pages)
16
- print(X)
17
 
18
- i = 0
19
- while i <= X and i <= x:
20
- # getting a specific page from the pdf file
21
- page = reader.pages[i]
22
- # extracting text from page
23
- text = page.extract_text()
24
- print("Created text of page", i )
25
- sound_file = BytesIO()
26
- tts = gTTS(text, lang='en')
27
- tts.write_to_fp(sound_file)
28
- st.audio(sound_file)
29
- print("Read aloud", i, "pages of", X, "total pages.")
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)