appinitdev commited on
Commit
56f2d04
verified
1 Parent(s): af69f02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -57
app.py CHANGED
@@ -1,61 +1,30 @@
1
  import torch
2
  import gradio as gr
3
- from PIL import Image
4
- from diffusers import QwenImageEditPlusPipeline, FlowMatchEulerDiscreteScheduler
5
- import spaces
6
-
7
- # Configuraci贸n
8
- BASE_MODEL = "prithivMLmods/Qwen-Image-Edit-AIO-FP8"
9
- LORA_COSPLAY = "joyfox/Qwen-Image-Edit-Cosplay"
10
- LORA_LIGHTNING = "lightx2v/Qwen-Image-Lightning"
11
-
12
- # Inicializaci贸n b谩sica del modelo
13
- pipe = QwenImageEditPlusPipeline.from_pretrained(
14
- BASE_MODEL,
15
- torch_dtype=torch.float16, # Usamos float16 para ahorrar VRAM
16
- use_safetensors=True
 
 
 
 
 
 
 
 
 
 
17
  )
18
 
19
- # Cargamos los adaptadores de una vez al inicio
20
- pipe.load_lora_weights(LORA_COSPLAY, adapter_name="cosplay")
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()