cobramv12 commited on
Commit
6f96683
Β·
verified Β·
1 Parent(s): c2ac748

Fix: Simplify UI to avoid API errors

Browse files
Files changed (1) hide show
  1. app.py +71 -40
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import sys
 
2
  try:
3
  import audioop
4
  except ImportError:
@@ -18,7 +19,6 @@ import tempfile, os
18
  # ─── CONFIGURACIΓ“N DE MODELOS ──────────────────────────────────────────────────
19
  BASE_MODEL = "cyberdelia/CyberRealisticPony"
20
  LTX_MODEL = "Lightricks/LTX-Video"
21
- DEFAULT_LORA = "John6666/nsfw-master-flux-lora-merged"
22
  LTX_NSFW_LORA = "Lora-Daddy/Ltx2.3-real-nudity-early-alpha-30k-steps"
23
 
24
  pipe_t2i = None
@@ -34,10 +34,10 @@ def load_t2i(lora_id=None, lora_scale=1.0):
34
  pipe_t2i = StableDiffusionXLPipeline.from_pretrained(
35
  BASE_MODEL, torch_dtype=torch.float16, use_safetensors=True, variant="fp16"
36
  )
37
- if lora_id:
38
  try:
39
  pipe_t2i.unload_lora_weights()
40
- pipe_t2i.load_lora_weights(lora_id)
41
  pipe_t2i.fuse_lora(lora_scale=lora_scale)
42
  except: pass
43
  return pipe_t2i
@@ -52,36 +52,68 @@ def load_video():
52
  except: pass
53
  return pipe_video
54
 
55
- # ─── FUNCIONES ─────────────────────────────────────────────────────────────────
56
- @spaces.GPU(duration=120)
57
- def generate_t2i(prompt, neg, lora_id, lora_scale, steps, cfg, w, h, seed):
58
- pipe = load_t2i(lora_id if lora_id else None, lora_scale).to("cuda")
59
- gen = torch.Generator("cuda").manual_seed(int(seed))
60
- img = pipe(prompt=prompt, negative_prompt=neg, num_inference_steps=int(steps),
61
- guidance_scale=cfg, width=int(w), height=int(h), generator=gen).images[0]
62
- pipe.to("cpu"); torch.cuda.empty_cache()
63
- return img
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  @spaces.GPU(duration=200)
66
- def generate_video(prompt, neg, init_image, num_frames, fps, steps, lora_scale, seed):
 
 
 
 
 
 
67
  from diffusers.utils import export_to_video
68
  pipe = load_video().to("cuda")
69
- gen = torch.Generator("cuda").manual_seed(int(seed))
70
- kwargs = {"prompt": prompt, "negative_prompt": neg, "num_frames": int(num_frames),
71
- "num_inference_steps": int(steps), "generator": gen}
 
 
 
 
 
 
 
72
  if init_image is not None:
73
  kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
 
74
  if lora_scale > 0:
75
  kwargs["cross_attention_kwargs"] = {"scale": lora_scale}
 
76
  output = pipe(**kwargs)
77
  tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
78
- export_to_video(output.frames[0], tmp.name, fps=int(fps))
79
- pipe.to("cpu"); torch.cuda.empty_cache()
 
 
80
  return tmp.name
81
 
82
- # ─── UI CAMUFLADA ──────────────────────────────────────────────────────────────
83
- with gr.Blocks(theme=gr.themes.Default(primary_hue="slate", neutral_hue="slate"), title="Image Utility v2.1") as demo:
84
- gr.HTML("<h1 style='text-align:center; color:#374151;'>πŸ›  Image Processing Utility v2.1.4</h1>")
85
 
86
  with gr.Tabs():
87
  with gr.Tab("D-Processor (T2I)"):
@@ -89,19 +121,19 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="slate", neutral_hue="slate")
89
  with gr.Column():
90
  t2i_p = gr.Textbox(label="Input Data String", lines=3)
91
  t2i_n = gr.Textbox(label="Excluded Data", value=NEG_DEFAULT)
 
 
92
  with gr.Row():
93
- t2i_lora = gr.Textbox(label="Extension ID")
94
- t2i_ls = gr.Slider(0, 1.5, 0.8, label="Extension Weight")
95
- with gr.Row():
96
- t2i_w = gr.Slider(512, 1280, 1024, step=64, label="X-Axis")
97
- t2i_h = gr.Slider(512, 1280, 1024, step=64, label="Y-Axis")
98
- # Componentes ocultos definidos como variables
99
- t2i_steps = gr.Number(value=30, visible=False)
100
- t2i_cfg = gr.Number(value=7.0, visible=False)
101
- t2i_seed = gr.Number(value=42, visible=False)
102
- t2i_btn = gr.Button("Execute Process")
103
  t2i_out = gr.Image(label="Output Preview")
104
- t2i_btn.click(generate_t2i, [t2i_p, t2i_n, t2i_lora, t2i_ls, t2i_steps, t2i_cfg, t2i_w, t2i_h, t2i_seed], t2i_out)
 
 
 
 
 
105
 
106
  with gr.Tab("M-Sequence (Video)"):
107
  with gr.Row():
@@ -109,14 +141,13 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="slate", neutral_hue="slate")
109
  v_p = gr.Textbox(label="Motion Vector String", lines=3)
110
  v_img = gr.Image(label="Source Buffer", type="numpy")
111
  v_ls = gr.Slider(0, 1.5, 0.8, label="Motion Weight")
112
- # Componentes ocultos definidos como variables para el tab de video
113
- v_neg = gr.Textbox(value=NEG_DEFAULT, visible=False)
114
- v_frames = gr.Number(value=49, visible=False)
115
- v_fps = gr.Number(value=24, visible=False)
116
- v_steps = gr.Number(value=30, visible=False)
117
- v_seed = gr.Number(value=42, visible=False)
118
- v_btn = gr.Button("Process Sequence")
119
  v_out = gr.Video(label="Sequence Output")
120
- v_btn.click(generate_video, [v_p, v_neg, v_img, v_frames, v_fps, v_steps, v_ls, v_seed], v_out)
 
 
 
 
 
121
 
122
  demo.launch()
 
1
  import sys
2
+ # Parche de audio al principio absoluto
3
  try:
4
  import audioop
5
  except ImportError:
 
19
  # ─── CONFIGURACIΓ“N DE MODELOS ──────────────────────────────────────────────────
20
  BASE_MODEL = "cyberdelia/CyberRealisticPony"
21
  LTX_MODEL = "Lightricks/LTX-Video"
 
22
  LTX_NSFW_LORA = "Lora-Daddy/Ltx2.3-real-nudity-early-alpha-30k-steps"
23
 
24
  pipe_t2i = None
 
34
  pipe_t2i = StableDiffusionXLPipeline.from_pretrained(
35
  BASE_MODEL, torch_dtype=torch.float16, use_safetensors=True, variant="fp16"
36
  )
37
+ if lora_id and len(lora_id.strip()) > 5:
38
  try:
39
  pipe_t2i.unload_lora_weights()
40
+ pipe_t2i.load_lora_weights(lora_id.strip())
41
  pipe_t2i.fuse_lora(lora_scale=lora_scale)
42
  except: pass
43
  return pipe_t2i
 
52
  except: pass
53
  return pipe_video
54
 
55
+ # ─── FUNCIONES DE GENERACIΓ“N ──────────────────────────────────────────────────
56
+ @spaces.GPU(duration=100)
57
+ def generate_t2i(prompt, neg, lora_id, lora_scale, w, h):
58
+ # Valores internos para evitar errores de API
59
+ steps = 30
60
+ cfg = 7.0
61
+ seed = 42
62
+
63
+ pipe = load_t2i(lora_id, lora_scale).to("cuda")
64
+ gen = torch.Generator("cuda").manual_seed(seed)
65
+
66
+ result = pipe(
67
+ prompt=prompt,
68
+ negative_prompt=neg,
69
+ num_inference_steps=steps,
70
+ guidance_scale=cfg,
71
+ width=int(w),
72
+ height=int(h),
73
+ generator=gen
74
+ ).images[0]
75
+
76
+ pipe.to("cpu")
77
+ torch.cuda.empty_cache()
78
+ return result
79
 
80
  @spaces.GPU(duration=200)
81
+ def generate_video(prompt, init_image, lora_scale):
82
+ # Valores internos fijos
83
+ steps = 30
84
+ num_frames = 49
85
+ fps = 24
86
+ seed = 42
87
+
88
  from diffusers.utils import export_to_video
89
  pipe = load_video().to("cuda")
90
+ gen = torch.Generator("cuda").manual_seed(seed)
91
+
92
+ kwargs = {
93
+ "prompt": prompt,
94
+ "negative_prompt": NEG_DEFAULT,
95
+ "num_frames": num_frames,
96
+ "num_inference_steps": steps,
97
+ "generator": gen
98
+ }
99
+
100
  if init_image is not None:
101
  kwargs["image"] = Image.fromarray(init_image).convert("RGB").resize((768, 512))
102
+
103
  if lora_scale > 0:
104
  kwargs["cross_attention_kwargs"] = {"scale": lora_scale}
105
+
106
  output = pipe(**kwargs)
107
  tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
108
+ export_to_video(output.frames[0], tmp.name, fps=fps)
109
+
110
+ pipe.to("cpu")
111
+ torch.cuda.empty_cache()
112
  return tmp.name
113
 
114
+ # ─── INTERFAZ TΓ‰CNICA ──────────────────────────────────────────────────────────
115
+ with gr.Blocks(title="Image Utility v2.1") as demo:
116
+ gr.HTML("<h1 style='text-align:center;'>πŸ›  Image Processing Utility v2.1.4</h1>")
117
 
118
  with gr.Tabs():
119
  with gr.Tab("D-Processor (T2I)"):
 
121
  with gr.Column():
122
  t2i_p = gr.Textbox(label="Input Data String", lines=3)
123
  t2i_n = gr.Textbox(label="Excluded Data", value=NEG_DEFAULT)
124
+ t2i_lora = gr.Textbox(label="Extension ID", placeholder="HuggingFace LoRA ID")
125
+ t2i_ls = gr.Slider(0, 1.5, 0.8, label="Extension Weight")
126
  with gr.Row():
127
+ t2i_w = gr.Slider(512, 1024, 1024, step=64, label="X-Axis")
128
+ t2i_h = gr.Slider(512, 1024, 1024, step=64, label="Y-Axis")
129
+ t2i_btn = gr.Button("Execute Process", variant="primary")
 
 
 
 
 
 
 
130
  t2i_out = gr.Image(label="Output Preview")
131
+
132
+ t2i_btn.click(
133
+ fn=generate_t2i,
134
+ inputs=[t2i_p, t2i_n, t2i_lora, t2i_ls, t2i_w, t2i_h],
135
+ outputs=t2i_out
136
+ )
137
 
138
  with gr.Tab("M-Sequence (Video)"):
139
  with gr.Row():
 
141
  v_p = gr.Textbox(label="Motion Vector String", lines=3)
142
  v_img = gr.Image(label="Source Buffer", type="numpy")
143
  v_ls = gr.Slider(0, 1.5, 0.8, label="Motion Weight")
144
+ v_btn = gr.Button("Process Sequence", variant="primary")
 
 
 
 
 
 
145
  v_out = gr.Video(label="Sequence Output")
146
+
147
+ v_btn.click(
148
+ fn=generate_video,
149
+ inputs=[v_p, v_img, v_ls],
150
+ outputs=v_out
151
+ )
152
 
153
  demo.launch()