File size: 2,196 Bytes
3f642da db273bf 3f642da db273bf 3f642da db273bf 3f642da db273bf f3136cc db273bf f3136cc db273bf |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import gradio as gr
import torch
from diffusers import StableDiffusionPipeline, AutoencoderKL
# Prompt negativo general
NEGATIVE_PROMPT = (
"blurry, low quality, lowres, bad anatomy, bad proportions, deformed, distorted, disfigured, mutated, "
"missing limbs, extra limbs, bad hands, fused fingers, missing fingers, bad feet, flat feet, fused toes, "
"bad legs, short legs, long arms, malformed body, asymmetric body, unnatural pose, broken limbs, bad perspective, "
"unnatural expression, strange eyes, cross-eyed, lazy eye, extra eyes, fused eyes, one eye, bad eyes, bad face, "
"multiple faces, deformed face, mutated face, distorted face, ugly face, pale skin, unrealistic skin, overexposed, "
"underexposed, high contrast, jpeg artifacts, watermark, text, logo, signature, cropped, cartoon, anime, sketch, painting"
)
# Seleccionar dispositivo
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
# Cargar pipeline base
pipe = StableDiffusionPipeline.from_pretrained(
"SG161222/Realistic_Vision_V6.0_B1_noVAE",
torch_dtype=dtype,
safety_checker=None
).to(device)
# Cargar VAE
pipe.vae = AutoencoderKL.from_pretrained(
"stabilityai/sd-vae-ft-mse",
torch_dtype=dtype
).to(device)
# Cargar LoRA
try:
pipe.load_lora_weights("DRDELATV/Woman_Asiatic_Defi")
pipe.set_adapters(["default_0"], adapter_weights=[1.0])
except Exception as e:
print("Error cargando LoRA:", e)
# Función para generar imagen
def generar(prompt, steps, scale):
image = pipe(
prompt,
negative_prompt=NEGATIVE_PROMPT,
num_inference_steps=steps,
guidance_scale=scale
).images[0]
return image
# Interfaz
gr.Interface(
fn=generar,
inputs=[
gr.Textbox(label="Escribe el promt de tu modelo"),
gr.Slider(20, 100, value=50, step=5, label="Inference Steps"),
gr.Slider(1.0, 15.0, value=5.5, step=0.5, label="Guidance Scale")
],
outputs=gr.Image(label="Imagen generada"),
title="Generador Woman x Global",
description="-------------------------------------------------------------------------",
).launch()
|