File size: 1,392 Bytes
75b5d8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
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()