File size: 1,205 Bytes
5c5a283
9e26359
b767750
 
fac92f6
d6da658
 
 
 
 
9e26359
2b081ea
57714f9
fac92f6
9e26359
b767750
 
 
 
 
57714f9
 
 
 
 
 
 
 
 
 
b767750
9e26359
 
57714f9
e13c1c8
c47375f
9e26359
 
 
 
5c5a283
9e26359
d6da658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from transformers import pipeline
from gtts import gTTS
import IPython.display as ipd

#Definir 2 modelos uno de imagen a texto y otro de texto a audio que inyecta
# el resultado del primero modelo(texto generado) en la entrada del 2º modelo
# texto to audio

    
# Cargar el modelo que convierte imagen a texto
image_to_text_model = pipeline("image-classification")
text_to_audio_model = pipeline("text-to-speech")

# Cargar el modelo que genera audio a partir de texto
# Función para convertir texto a audio
def text_to_audio(text):
    tts = gTTS(text=text, lang='es')
    tts.save('output.mp3')
    return ipd.Audio('output.mp3')

# Función para la interfaz de Gradio
def image_to_audio(input_image):
    # Convertir la imagen a texto
    text_output = image_to_text_model(input_image)[0]['label']

    # Generar audio a partir del texto
    audio_output = text_to_audio_model(text_output)[0]['audio']

    return audio_output
   
# Interfaz Gradio
iface = gr.Interface(
    fn=image_to_audio,
    inputs=gr.Image(type='pil'),
    outputs=[gr.Textbox(), gr.Audio()],
    live=True,
    interpretation="default",
    capture_session=True
)

# Ejecutar la interfaz
iface.launch()