imabhi commited on
Commit
6e7743b
1 Parent(s): dcdfb46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gtts import gTTS
3
+ import PyPDF2
4
+ from tqdm import tqdm
5
+
6
+ def pdf_to_audio(pdf_file,x,y,Language):
7
+ whole = ''
8
+ pdfreader = PyPDF2.PdfReader(pdf_file)
9
+ pages = pdfreader.pages
10
+
11
+ for num in tqdm(range(int(x), int(y))):
12
+ Page = pdfreader.pages[num]
13
+ text = Page.extract_text()
14
+ whole += text
15
+ whole = GoogleTranslator(source='auto', target=Language).translate(whole)
16
+ myobj = gTTS(text=whole, lang=Language,tld='co.in', slow=False)
17
+ myobj.save("test.wav")
18
+ return 'test.wav',whole
19
+
20
+
21
+
22
+ gr.Interface(fn=pdf_to_audio, inputs=[
23
+ gr.inputs.File(label="Book PDF"),
24
+
25
+ gr.inputs.Slider(label="Start Page"),
26
+ gr.inputs.Slider(label="End Page"),gr.Dropdown(label="Language you want", ['mr','hi','en'])
27
+ ], outputs= ['audio', gr.Textbox(label="Text")], title="Book Translator",description = ' Upload your book, select the start page and end page using slider and language of your choice . Here hi- hidni,mr - marathi, en- english',
28
+ ).launch()