File size: 982 Bytes
69c9c59 019c023 69c9c59 fe05874 69c9c59 019c023 29085f8 019c023 69c9c59 019c023 |
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 |
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
# 1锔忊儯 Carga el modelo de Hugging Face con optimizaci贸n
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16 if device=="cuda" else torch.float32
)
pipe = pipe.to(device)
# 2锔忊儯 Funci贸n para generar imagen r谩pida
def generar(prompt):
with torch.autocast(device):
image = pipe(prompt, num_inference_steps=25).images[0] # Reducimos pasos a 25 para velocidad
return image
# 3锔忊儯 Interfaz Gradio
iface = gr.Interface(
fn=generar,
inputs=gr.Textbox(label="Escribe tu descripci贸n", placeholder="Lo mejor de Blax / The Best of Blax"),
outputs="image",
title="Lo mejor de Blax / The Best of Blax",
description="Genera im谩genes con IA (Stable Diffusion v1.5) en ~30 segundos"
)
# 4锔忊儯 Lanzar app
iface.launch() |