File size: 1,117 Bytes
c99f2fe
 
 
 
8538fb0
c99f2fe
 
 
 
0e81829
 
 
8d263d2
 
c99f2fe
 
4a17a2c
 
 
8538fb0
 
4a17a2c
 
8d263d2
 
c99f2fe
0e81829
0b5dbbf
 
 
 
 
 
 
 
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
from PIL import Image
import gradio as gr
from transformers import BlipProcessor, BlipForConditionalGeneration

model_id = "Salesforce/blip-image-captioning-base"

model = BlipForConditionalGeneration.from_pretrained(model_id)
processor = BlipProcessor.from_pretrained(model_id)

def launch(input_file):
    # Abrir la imagen subida por el usuario
    image = Image.open(input_file).convert('RGB')
    
    # Procesar la imagen y generar el texto
    inputs = processor(image, return_tensors="pt")
    out = model.generate(**inputs)
    generated_text = processor.decode(out[0], skip_special_tokens=True)
    
    # Agregar prefijo y sufijo al texto generado
    prefijo = "Texture, "
    sufijo = " top view, flat, hq, detailed"
    result = f"{prefijo}{generated_text}{sufijo}"
    
    # Devolver tanto la imagen como el texto
    return image, result

# Cambiar la configuración de Gradio para que la entrada sea un archivo y la salida incluya imagen y texto
iface = gr.Interface(
    fn=launch, 
    inputs="file", 
    outputs=["image", "text"], 
    title="GENERADOR DE TEXTO DEL DR. SERGIO"
)

iface.launch()