Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
from
|
4 |
-
import
|
5 |
-
|
6 |
|
7 |
#Definir 2 modelos uno de imagen a texto y otro de texto a audio que inyecta
|
8 |
# el resultado del primero modelo(texto generado) en la entrada del 2潞 modelo
|
@@ -10,26 +9,21 @@ import torch
|
|
10 |
|
11 |
|
12 |
# Cargar el modelo que convierte imagen a texto
|
13 |
-
image_to_text_model = pipeline("image-classification")
|
14 |
|
15 |
# Cargar el modelo que genera audio a partir de texto
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
model=gr.Interface.load("models/timm/mobilenetv3_large_100.ra_in1k").launch()
|
22 |
-
text_output = image_to_text_model(model)[0]['label']
|
23 |
-
# get model specific transforms (normalization, resize)
|
24 |
-
audio_output = text_to_audio_model(model)['audio']
|
25 |
-
|
26 |
-
|
27 |
|
|
|
28 |
# Interfaz Gradio
|
29 |
iface = gr.Interface(
|
30 |
-
fn=
|
31 |
-
inputs=
|
32 |
-
outputs=
|
33 |
live=True,
|
34 |
interpretation="default",
|
35 |
capture_session=True
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from gtts import gTTS
|
4 |
+
import IPython.display as ipd
|
|
|
5 |
|
6 |
#Definir 2 modelos uno de imagen a texto y otro de texto a audio que inyecta
|
7 |
# el resultado del primero modelo(texto generado) en la entrada del 2潞 modelo
|
|
|
9 |
|
10 |
|
11 |
# Cargar el modelo que convierte imagen a texto
|
12 |
+
image_to_text_model = pipeline("image-classification",model="models/timm/mobilenetv3_large_100_ra_in1k")
|
13 |
|
14 |
# Cargar el modelo que genera audio a partir de texto
|
15 |
+
# Funci贸n para convertir texto a audio
|
16 |
+
def text_to_audio(text):
|
17 |
+
tts = gTTS(text=text, lang='es')
|
18 |
+
tts.save('output.mp3')
|
19 |
+
return ipd.Audio('output.mp3')
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
|
22 |
# Interfaz Gradio
|
23 |
iface = gr.Interface(
|
24 |
+
fn=image_to_text_model,
|
25 |
+
inputs=gr.Image(),
|
26 |
+
outputs=[gr.Textbox(), gr.Audio(fn=text_to_audio)],
|
27 |
live=True,
|
28 |
interpretation="default",
|
29 |
capture_session=True
|