File size: 869 Bytes
19fa8b2
1a2afdb
5504e73
19fa8b2
5504e73
1a2afdb
 
 
 
5504e73
19fa8b2
1a2afdb
 
19fa8b2
1a2afdb
 
5504e73
19fa8b2
 
1a2afdb
 
 
 
 
19fa8b2
5504e73
19fa8b2
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
import gradio as gr
from diffusers import StableDiffusionPipeline
from PIL import Image
import torch

# Cargar un modelo ligero de ejemplo
model_id = "OFA-Sys/small-stable-diffusion-v0"
pipe = StableDiffusionPipeline.from_pretrained(model_id)
pipe = pipe.to("cpu")  # usar "cuda" si hay GPU

# Función que Gradio llamará
def generar_imagen(prompt):
    if not prompt:
        return None
    image = pipe(prompt).images[0]
    return image  # No hacemos image.save(), Gradio lo mostrará y permitirá descargarlo

# Interfaz Gradio
demo = gr.Interface(
    fn=generar_imagen,
    inputs=gr.Textbox(label="Prompt"),
    outputs=gr.Image(type="pil"),  # type="pil" permite descargar la imagen
    title="Generador de imágenes ligero",
    description="Introduce un prompt y el modelo generará la imagen. Podrás descargarla con el botón de Gradio."
)

demo.launch()