Solshine commited on
Commit
9f8e59c
1 Parent(s): a4898be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -1,26 +1,25 @@
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
- import fitz
5
 
6
  x = st.slider('Select a value')
7
  slider_reply = x, 'squared is', x * x
8
  st.write(slider_reply)
9
 
10
  uploaded_file = st.file_uploader("Choose a file", "pdf")
11
- if uploaded_file is not None:
12
- doc = fitz.open(uploaded_file)
 
 
 
13
 
14
- element = ""
15
-
16
- for page in doc:
17
- element+=page.get_text()
18
-
19
- element = output.getvalue()
20
- print("Created element")
21
  with st.popover("Open popover"):
22
  sound_file = BytesIO()
23
- tts = gTTS(element, lang='en')
24
  tts.write_to_fp(sound_file)
25
 
26
  st.audio(sound_file)
 
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
+ from PyPDF2 import PdfReader
5
 
6
  x = st.slider('Select a value')
7
  slider_reply = x, 'squared is', x * x
8
  st.write(slider_reply)
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
+ # getting a specific page from the pdf file
15
+ pages = reader.pages
16
 
17
+ # extracting text from page
18
+ text = page.extract_text()
19
+ print("Created text")
 
 
 
 
20
  with st.popover("Open popover"):
21
  sound_file = BytesIO()
22
+ tts = gTTS(text, lang='en')
23
  tts.write_to_fp(sound_file)
24
 
25
  st.audio(sound_file)