Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,34 @@
|
|
1 |
-
import
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|