cobramv12 commited on
Commit
0c871a6
·
verified ·
1 Parent(s): 929a354

Add app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import torch
4
+ from diffusers import DiffusionPipeline
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ # Cargamos el modelo base - usaremos SDXL como base
8
+ # Podés cambiar esto por cualquier modelo de HuggingFace
9
+ MODEL_ID = "stabilityai/stable-diffusion-xl-base-1.0"
10
+ pipe = None
11
+
12
+ def load_pipeline():
13
+ global pipe
14
+ if pipe is None:
15
+ pipe = DiffusionPipeline.from_pretrained(
16
+ MODEL_ID,
17
+ torch_dtype=torch.float16,
18
+ use_safetensors=True,
19
+ variant="fp16"
20
+ )
21
+ return pipe
22
+
23
+ @spaces.GPU(duration=120)
24
+ def generate(prompt, negative_prompt, steps, cfg_scale, width, height, seed):
25
+ global pipe
26
+ pipe = load_pipeline()
27
+ pipe = pipe.to("cuda")
28
+
29
+ generator = torch.Generator("cuda").manual_seed(int(seed))
30
+
31
+ images = pipe(
32
+ prompt=prompt,
33
+ negative_prompt=negative_prompt,
34
+ num_inference_steps=int(steps),
35
+ guidance_scale=cfg_scale,
36
+ width=int(width),
37
+ height=int(height),
38
+ generator=generator
39
+ ).images
40
+
41
+ pipe = pipe.to("cpu") # Liberar VRAM despues de generar
42
+ torch.cuda.empty_cache()
43
+
44
+ return images[0]
45
+
46
+ with gr.Blocks(title="Studio Privado", theme=gr.themes.Soft()) as demo:
47
+ gr.Markdown("## 🎨 Studio Privado - Generador de Imágenes")
48
+ gr.Markdown("*Tus creaciones son privadas. Nadie más puede verlas.*")
49
+
50
+ with gr.Row():
51
+ with gr.Column(scale=1):
52
+ prompt = gr.Textbox(label="Prompt", placeholder="Describe lo que querés generar...", lines=3)
53
+ negative_prompt = gr.Textbox(label="Negative Prompt", value="blurry, low quality, bad anatomy", lines=2)
54
+
55
+ with gr.Row():
56
+ steps = gr.Slider(10, 50, value=30, step=1, label="Pasos")
57
+ cfg = gr.Slider(1, 20, value=7.5, step=0.5, label="CFG Scale")
58
+
59
+ with gr.Row():
60
+ width = gr.Slider(512, 1024, value=1024, step=64, label="Ancho")
61
+ height = gr.Slider(512, 1024, value=1024, step=64, label="Alto")
62
+
63
+ seed = gr.Number(value=42, label="Seed (-1 para random)")
64
+ btn = gr.Button("🚀 Generar", variant="primary", size="lg")
65
+
66
+ with gr.Column(scale=1):
67
+ output = gr.Image(label="Resultado", type="pil")
68
+
69
+ btn.click(
70
+ fn=generate,
71
+ inputs=[prompt, negative_prompt, steps, cfg, width, height, seed],
72
+ outputs=output
73
+ )
74
+
75
+ demo.launch()