Spaces:
Build error
Build error
| 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") | |
| # 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'] | |
| print('text_output is :'+text_output) | |
| # Generar audio a partir del texto | |
| audio_output = text_to_audio_model(text_output)[0]['audio'] | |
| print('audio_output is :'+audio_output) | |
| return audio_output | |
| # Interfaz Gradio | |
| iface = gr.Interface( | |
| fn=image_to_audio, | |
| inputs=gr.Image(type='pil'), | |
| outputs=[gr.Textbox(value=image_to_text_model, label="Output"), gr.Audio()], | |
| live=True, | |
| interpretation="default", | |
| capture_session=True | |
| ) | |
| # Ejecutar la interfaz | |
| iface.launch() |