Prasanna18 commited on
Commit
c2915c1
·
verified ·
1 Parent(s): 30f42e1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gtts import gTTS
2
+ import streamlit as st
3
+ import PyPDF2
4
+ import io
5
+
6
+ from PyPDF2 import PdfReader
7
+
8
+ def read_pdf(uploaded_file):
9
+ file_buffer = io.BytesIO(uploaded_file.read())
10
+ pdf_reader = PdfReader(file_buffer)
11
+ text = ""
12
+ for page in pdf_reader.pages:
13
+ text += page.extract_text()
14
+ return text
15
+
16
+ def speak_text(text):
17
+ tts = gTTS(text=text, lang='en')
18
+ tts.save("output.mp3")
19
+ st.audio("output.mp3", format='audio/mp3')
20
+
21
+ def main():
22
+ st.title("Lazy Coder's PDF Reader")
23
+
24
+ uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
25
+
26
+ if uploaded_file is not None:
27
+ st.write("Uploaded PDF file:", uploaded_file.name)
28
+
29
+ if st.button("Send"):
30
+ text = read_pdf(uploaded_file)
31
+ speak_text(text)
32
+
33
+ if __name__ == "__main__":
34
+ main()