Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # --- CARGA DE LOS MODELOS --- | |
| # MODELO A: (Imagen -> Texto Inglés) BLIP Genera la descripción en inglés. | |
| captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base") | |
| # MODELO B:(Texto Inglés -> Texto Español) Traductor. | |
| translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es") | |
| # MODELO C: Voz (Texto Español -> Audio) Crea audio en español. | |
| tts = pipeline("text-to-speech", model="facebook/mms-tts-spa") | |
| # --- LÓGICA --- | |
| #Retornona texto y audio en español | |
| def procesar_imagen(imagen): | |
| if imagen is None: | |
| return "No hay imagen", None | |
| texto_ingles = captioner(imagen)[0]['generated_text'] | |
| texto_espanol = translator(texto_ingles)[0]['translation_text'] | |
| salida_audio = tts(texto_espanol) | |
| audio_data = salida_audio['audio'][0] | |
| sampling_rate = salida_audio['sampling_rate'] | |
| return texto_espanol, (sampling_rate, audio_data) | |
| # ---INTERFAZ --- | |
| interfaz = gr.Interface( | |
| fn=procesar_imagen, | |
| inputs=gr.Image(label="Sube una imagen", type="pil"), | |
| outputs=[ | |
| gr.Textbox(label="Descripción en Español"), | |
| gr.Audio(label="Audio") | |
| ], | |
| title="Asistente para Invidentes (Español)", | |
| description="Sube una imagen y la aplicación te dirá qué contiene.", | |
| ) | |
| if __name__ == "__main__": | |
| interfaz.launch() |