Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,20 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
from diffusers import FluxPipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
# Usamos schnell porque es mucho m谩s ligero que 'dev' y perfecto para Spaces
|
| 7 |
model_id = "black-forest-labs/FLUX.1-schnell"
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
print("Cargando el pipeline base...")
|
| 11 |
-
# Usamos bfloat16 para ahorrar VRAM y mantener calidad
|
| 12 |
-
pipe = FluxPipeline.from_pretrained(
|
| 13 |
-
model_id,
|
| 14 |
-
torch_dtype=torch.bfloat16
|
| 15 |
-
).to(device)
|
| 16 |
-
|
| 17 |
-
# 2. Cargar el LoRA
|
| 18 |
-
print("Cargando LoRA...")
|
| 19 |
pipe.load_lora_weights("joyfox/Kontext-Cosplay-Lora", weight_name="kontext_cosplay_lora_20000.safetensors")
|
| 20 |
|
|
|
|
|
|
|
| 21 |
def generate_image(prompt):
|
| 22 |
-
# 'r2cos' es el trigger obligatorio del modelo
|
| 23 |
full_prompt = f"{prompt}, r2cos"
|
| 24 |
-
|
| 25 |
-
# Schnell requiere menos pasos (4) que dev (20-50)
|
| 26 |
-
image = pipe(
|
| 27 |
-
full_prompt,
|
| 28 |
-
num_inference_steps=4,
|
| 29 |
-
guidance_scale=0.0
|
| 30 |
-
).images[0]
|
| 31 |
return image
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
demo = gr.Interface(
|
| 35 |
-
|
| 36 |
-
inputs=gr.Textbox(label="Describe a tu personaje"),
|
| 37 |
-
outputs=gr.Image(label="Resultado Cosplay"),
|
| 38 |
-
title="Generador de Cosplay con Kontext-LoRA"
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
if __name__ == "__main__":
|
| 42 |
-
demo.launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
+
import spaces # <--- IMPORTANTE
|
| 3 |
from diffusers import FluxPipeline
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
# Carga fuera de la funci贸n (esto ya lo ten铆as bien)
|
|
|
|
| 7 |
model_id = "black-forest-labs/FLUX.1-schnell"
|
| 8 |
+
pipe = FluxPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
pipe.load_lora_weights("joyfox/Kontext-Cosplay-Lora", weight_name="kontext_cosplay_lora_20000.safetensors")
|
| 10 |
|
| 11 |
+
# ESTA ES LA CLAVE: Decora la funci贸n con @spaces.GPU
|
| 12 |
+
@spaces.GPU
|
| 13 |
def generate_image(prompt):
|
|
|
|
| 14 |
full_prompt = f"{prompt}, r2cos"
|
| 15 |
+
image = pipe(full_prompt, num_inference_steps=4, guidance_scale=0.0).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return image
|
| 17 |
|
| 18 |
+
# Interfaz
|
| 19 |
+
demo = gr.Interface(fn=generate_image, inputs="text", outputs="image")
|
| 20 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|