SandraCLV commited on
Commit
1a7973f
1 Parent(s): d62d8ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -1,26 +1,34 @@
1
- import gradio as gr
2
- from PIL import Image
3
- import pytesseract
4
  from gtts import gTTS
 
 
5
  import os
6
 
7
- # Funci贸n para convertir imagen a texto
8
- def image_to_text(imagen):
9
- texto = pytesseract.image_to_string(Image.open(imagen))
10
- return texto
11
 
12
- # Funci贸n para convertir texto a audio
13
- def text_to_audio(texto):
14
- audio = gTTS(text=texto, lang='es', slow=False)
15
- audio.save("audio.mp3")
16
- return "audio.mp3"
 
 
 
 
 
 
 
17
 
18
- # Funci贸n que combina las dos funciones anteriores
19
- def imagen_a_audio(imagen):
20
- texto = image_to_text(imagen)
21
- audio = text_to_audio(texto)
22
- return audio
 
 
 
 
 
 
 
23
 
24
- # Crear la interfaz de usuario con Gradio
25
- iface = gr.Interface(fn=imagen_a_audio, inputs="Image", outputs="Audio")
26
  iface.launch()
 
1
+ import os
 
 
2
  from gtts import gTTS
3
+ from pdfminer.high_level import extract_text
4
+ import gradio as gr
5
  import os
6
 
 
 
 
 
7
 
8
+ def pdf_to_text(file_obj):
9
+ text = extract_text(file_obj.name)
10
+ myobj = gTTS(text=text, lang='en', slow=False)
11
+ myobj.save("test.wav")
12
+ return 'test.wav'
13
+
14
+
15
+ examples = [
16
+ [os.path.abspath("short-pdf.pdf")],
17
+ [os.path.abspath("long-pdf.pdf")]
18
+ ]
19
+
20
 
21
+ iface = gr.Interface(fn = pdf_to_text,
22
+ inputs = 'file',
23
+ outputs = 'audio',
24
+ verbose = True,
25
+ title = 'PDF to Audio Application',
26
+ description = 'A simple application to convert PDF files in audio speech. Upload your own file, or click one of the examples to load them.',
27
+ article =
28
+ '''<div>
29
+ <p style="text-align: center"> All you need to do is to upload the pdf file and hit submit, then wait for compiling. After that click on Play/Pause for listing to the audio. The audio is saved in a wav format.</p>
30
+ </div>''',
31
+ examples=examples
32
+ )
33
 
 
 
34
  iface.launch()