Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,30 @@
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
pipe.load_lora_weights(LORA_LIGHTNING, weight_name="Qwen-Image-Lightning-8steps-V1.0.safetensors", adapter_name="lightning")
|
| 22 |
-
pipe.set_adapters(["cosplay", "lightning"], adapter_weights=[0.85, 1.0])
|
| 23 |
-
|
| 24 |
-
@spaces.GPU
|
| 25 |
-
def process_cosplay_edit(base_image, reference_image, prompt, steps, cfg, seed):
|
| 26 |
-
# Movemos el modelo a la GPU activamente al iniciar la generaci贸n
|
| 27 |
-
pipe.to("cuda")
|
| 28 |
-
|
| 29 |
-
# Redimensionamiento (m煤ltiplos de 8)
|
| 30 |
-
width, height = 1024, 1024
|
| 31 |
-
base_resized = base_image.resize((width, height), Image.Resampling.LANCZOS)
|
| 32 |
-
ref_resized = reference_image.resize((width, height), Image.Resampling.LANCZOS)
|
| 33 |
-
|
| 34 |
-
generator = torch.Generator("cuda").manual_seed(int(seed))
|
| 35 |
-
|
| 36 |
-
output = pipe(
|
| 37 |
-
image=[base_resized, ref_resized],
|
| 38 |
-
prompt=prompt,
|
| 39 |
-
width=width,
|
| 40 |
-
height=height,
|
| 41 |
-
num_inference_steps=int(steps),
|
| 42 |
-
true_cfg_scale=float(cfg),
|
| 43 |
-
generator=generator
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
# Al finalizar la funci贸n, el modelo se retira de la GPU autom谩ticamente por ZeroGPU
|
| 47 |
-
return output.images[0]
|
| 48 |
-
|
| 49 |
-
# Interfaz
|
| 50 |
-
with gr.Blocks() as demo:
|
| 51 |
-
with gr.Row():
|
| 52 |
-
base_input = gr.Image(label="Persona Real", type="pil")
|
| 53 |
-
ref_input = gr.Image(label="Referencia Anime", type="pil")
|
| 54 |
-
|
| 55 |
-
prompt_input = gr.Textbox(label="Prompt", value="high quality, cosplay style transfer")
|
| 56 |
-
generate_btn = gr.Button("Generar", variant="primary")
|
| 57 |
-
output_display = gr.Image(label="Resultado")
|
| 58 |
-
|
| 59 |
-
generate_btn.click(process_cosplay_edit, inputs=[base_input, ref_input, prompt_input, gr.Slider(4, 12, 8), gr.Slider(1, 5, 1.5), gr.Number(1337)], outputs=output_display)
|
| 60 |
-
|
| 61 |
-
demo.queue().launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# 1. Cargar el modelo
|
| 6 |
+
# Aseg煤rate de tener tu token de Hugging Face configurado en el Space
|
| 7 |
+
model_id = "Bigfawg6669/create-nsfw"
|
| 8 |
+
|
| 9 |
+
# Usamos 'pipeline' para simplificar.
|
| 10 |
+
# Si el modelo requiere tareas espec铆ficas (ej. text-generation), c谩mbialo en el primer argumento.
|
| 11 |
+
try:
|
| 12 |
+
pipe = pipeline("text-classification", model=model_id, device="cpu") # Usa "cuda" si tienes GPU
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print(f"Error al cargar el modelo: {e}")
|
| 15 |
+
|
| 16 |
+
# 2. Funci贸n de predicci贸n
|
| 17 |
+
def analizar_contenido(texto):
|
| 18 |
+
resultado = pipe(texto)
|
| 19 |
+
return resultado
|
| 20 |
+
|
| 21 |
+
# 3. Interfaz de Gradio
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=analizar_contenido,
|
| 24 |
+
inputs=gr.Textbox(label="Entrada"),
|
| 25 |
+
outputs=gr.JSON(label="Resultado"),
|
| 26 |
+
title="Analizador de Contenido"
|
| 27 |
)
|
| 28 |
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|