Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,22 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
import spaces
|
| 6 |
|
| 7 |
-
# 1. Cargar el
|
| 8 |
-
|
| 9 |
-
pipe =
|
| 10 |
-
"Qwen/Qwen-Image-Edit-2511",
|
| 11 |
-
torch_dtype=torch.bfloat16
|
| 12 |
-
)
|
| 13 |
-
pipe.load_lora_weights("WarmBloodAban/AnyoneCosplay")
|
| 14 |
pipe.to("cuda")
|
| 15 |
|
| 16 |
-
# 2.
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
def generate_cosplay(human_img, anime_img):
|
| 20 |
-
# El modelo espera una sola imagen unida.
|
| 21 |
-
# Pegamos la foto humana (Figura 1) y el anime (Figura 2) lado a lado.
|
| 22 |
-
w1, h1 = human_img.size
|
| 23 |
-
w2, h2 = anime_img.size
|
| 24 |
-
|
| 25 |
-
# Ajustamos la altura de la imagen anime para que coincida con la humana
|
| 26 |
-
new_w2 = int((h1 / h2) * w2)
|
| 27 |
-
anime_img_resized = anime_img.resize((new_w2, h1))
|
| 28 |
-
|
| 29 |
-
combined_img = Image.new('RGB', (w1 + new_w2, h1))
|
| 30 |
-
combined_img.paste(human_img, (0, 0))
|
| 31 |
-
combined_img.paste(anime_img_resized, (w1, 0))
|
| 32 |
-
|
| 33 |
-
# Palabra clave de activación requerida por el autor del modelo
|
| 34 |
-
prompt = "Let the person in Figure 1 cosplay the role in Figure 2"
|
| 35 |
-
|
| 36 |
-
with torch.inference_mode():
|
| 37 |
-
# Ejecutamos la inferencia con los parámetros recomendados para Qwen
|
| 38 |
-
output = pipe(
|
| 39 |
-
image=combined_img,
|
| 40 |
-
prompt=prompt,
|
| 41 |
-
num_inference_steps=50,
|
| 42 |
-
true_cfg_scale=4.0
|
| 43 |
-
).images[0]
|
| 44 |
-
|
| 45 |
-
return output
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
with gr.Row():
|
| 53 |
-
human_in = gr.Image(type="pil", label="Tu foto (Figura 1)")
|
| 54 |
-
anime_in = gr.Image(type="pil", label="Personaje Anime (Figura 2)")
|
| 55 |
-
|
| 56 |
-
btn = gr.Button("✨ Generar Cosplay", variant="primary")
|
| 57 |
-
output_image = gr.Image(label="Resultado final")
|
| 58 |
-
|
| 59 |
-
btn.click(fn=generate_cosplay, inputs=[human_in, anime_in], outputs=output_image)
|
| 60 |
|
| 61 |
-
#
|
|
|
|
| 62 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
+
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
+
# 1. Cargar el pipeline base (asegúrate de tener acceso/permisos si es necesario)
|
| 6 |
+
base_model_id = "black-forest-labs/FLUX.1-dev"
|
| 7 |
+
pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.bfloat16)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
pipe.to("cuda")
|
| 9 |
|
| 10 |
+
# 2. Cargar el adaptador LoRA desde el Hub
|
| 11 |
+
# Al cargar el LoRA así, el pipeline lo integra automáticamente
|
| 12 |
+
pipe.load_lora_weights("joyfox/Kontext-Cosplay-Lora", weight_name="kontext_cosplay_lora_20000.safetensors")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
def generate_image(prompt):
|
| 15 |
+
# La trigger phrase 'r2cos' es esencial según la documentación del autor
|
| 16 |
+
full_prompt = f"{prompt}, r2cos"
|
| 17 |
+
image = pipe(full_prompt, guidance_scale=3.5).images[0]
|
| 18 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Interfaz Gradio
|
| 21 |
+
demo = gr.Interface(fn=generate_image, inputs="text", outputs="image")
|
| 22 |
demo.launch()
|