cobramv12 commited on
Commit
4282ad2
Β·
verified Β·
1 Parent(s): c52be34

Fix: Upgrade to Gradio 5 + cleanup inputs

Browse files
Files changed (1) hide show
  1. app.py +17 -40
app.py CHANGED
@@ -14,7 +14,6 @@ import torch
14
  import numpy as np
15
  from PIL import Image
16
  import tempfile, os
17
- from huggingface_hub import hf_hub_download
18
 
19
  # ─── CONFIGURACIΓ“N DE MODELOS ──────────────────────────────────────────────────
20
  BASE_MODEL = "cyberdelia/CyberRealisticPony"
@@ -44,21 +43,6 @@ def load_t2i(lora_id=None, lora_scale=1.0):
44
  except: pass
45
  return pipe_t2i
46
 
47
- def load_i2i(lora_id=None, lora_scale=1.0):
48
- global pipe_i2i
49
- from diffusers import StableDiffusionXLImg2ImgPipeline
50
- if pipe_i2i is None:
51
- pipe_i2i = StableDiffusionXLImg2ImgPipeline.from_pretrained(
52
- BASE_MODEL, torch_dtype=torch.float16, use_safetensors=True, variant="fp16"
53
- )
54
- if lora_id:
55
- try:
56
- pipe_i2i.unload_lora_weights()
57
- pipe_i2i.load_lora_weights(lora_id)
58
- pipe_i2i.fuse_lora(lora_scale=lora_scale)
59
- except: pass
60
- return pipe_i2i
61
-
62
  def load_video():
63
  global pipe_video
64
  from diffusers import LTXPipeline
@@ -79,17 +63,6 @@ def generate_t2i(prompt, neg, lora_id, lora_scale, steps, cfg, w, h, seed):
79
  pipe.to("cpu"); torch.cuda.empty_cache()
80
  return img
81
 
82
- @spaces.GPU(duration=120)
83
- def generate_i2i(prompt, neg, init_image, strength, lora_id, lora_scale, steps, cfg, seed):
84
- if init_image is None: return None
85
- pipe = load_i2i(lora_id if lora_id else None, lora_scale).to("cuda")
86
- gen = torch.Generator("cuda").manual_seed(int(seed))
87
- img = Image.fromarray(init_image).convert("RGB").resize((1024, 1024))
88
- res = pipe(prompt=prompt, negative_prompt=neg, image=img, strength=strength,
89
- num_inference_steps=int(steps), guidance_scale=cfg, generator=gen).images[0]
90
- pipe.to("cpu"); torch.cuda.empty_cache()
91
- return res
92
-
93
  @spaces.GPU(duration=200)
94
  def generate_video(prompt, neg, init_image, num_frames, fps, steps, lora_scale, seed):
95
  from diffusers.utils import export_to_video
@@ -108,29 +81,28 @@ def generate_video(prompt, neg, init_image, num_frames, fps, steps, lora_scale,
108
  return tmp.name
109
 
110
  # ─── UI CAMUFLADA ──────────────────────────────────────────────────────────────
111
- THEME = gr.themes.Default(primary_hue="slate", neutral_hue="slate").set(
112
- body_background_fill="#f3f4f6", block_background_fill="#ffffff",
113
- )
114
-
115
- with gr.Blocks(theme=THEME, title="Image Utility v2.1") as demo:
116
  gr.HTML("<h1 style='text-align:center; color:#374151;'>πŸ›  Image Processing Utility v2.1.4</h1>")
117
- gr.HTML("<p style='text-align:center; color:#6b7280;'>Herramienta tΓ©cnica para el procesamiento y escalado de matrices de pΓ­xeles.</p>")
118
 
119
  with gr.Tabs():
120
  with gr.Tab("D-Processor (T2I)"):
121
  with gr.Row():
122
  with gr.Column():
123
- t2i_p = gr.Textbox(label="Input Data String", lines=3, placeholder="Enter parameters...")
124
  t2i_n = gr.Textbox(label="Excluded Data", value=NEG_DEFAULT)
125
  with gr.Row():
126
- t2i_lora = gr.Textbox(label="Extension ID", placeholder="Module ID (optional)")
127
  t2i_ls = gr.Slider(0, 1.5, 0.8, label="Extension Weight")
128
  with gr.Row():
129
  t2i_w = gr.Slider(512, 1280, 1024, step=64, label="X-Axis")
130
  t2i_h = gr.Slider(512, 1280, 1024, step=64, label="Y-Axis")
131
- t2i_btn = gr.Button("Execute Process", variant="secondary")
 
 
 
 
132
  t2i_out = gr.Image(label="Output Preview")
133
- t2i_btn.click(generate_t2i, [t2i_p, t2i_n, t2i_lora, t2i_ls, gr.Number(30), gr.Number(7.5), t2i_w, t2i_h, gr.Number(42)], t2i_out)
134
 
135
  with gr.Tab("M-Sequence (Video)"):
136
  with gr.Row():
@@ -138,8 +110,13 @@ with gr.Blocks(theme=THEME, title="Image Utility v2.1") as demo:
138
  v_p = gr.Textbox(label="Motion Vector String", lines=3)
139
  v_img = gr.Image(label="Source Buffer", type="numpy")
140
  v_ls = gr.Slider(0, 1.5, 0.8, label="Motion Weight")
141
- v_btn = gr.Button("Process Sequence", variant="secondary")
 
 
 
 
 
142
  v_out = gr.Video(label="Sequence Output")
143
- v_btn.click(generate_video, [v_p, gr.Textbox(value=NEG_DEFAULT), v_img, gr.Number(49), gr.Number(24), gr.Number(30), v_ls, gr.Number(42)], v_out)
144
 
145
- demo.launch()
 
14
  import numpy as np
15
  from PIL import Image
16
  import tempfile, os
 
17
 
18
  # ─── CONFIGURACIΓ“N DE MODELOS ──────────────────────────────────────────────────
19
  BASE_MODEL = "cyberdelia/CyberRealisticPony"
 
43
  except: pass
44
  return pipe_t2i
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def load_video():
47
  global pipe_video
48
  from diffusers import LTXPipeline
 
63
  pipe.to("cpu"); torch.cuda.empty_cache()
64
  return img
65
 
 
 
 
 
 
 
 
 
 
 
 
66
  @spaces.GPU(duration=200)
67
  def generate_video(prompt, neg, init_image, num_frames, fps, steps, lora_scale, seed):
68
  from diffusers.utils import export_to_video
 
81
  return tmp.name
82
 
83
  # ─── UI CAMUFLADA ──────────────────────────────────────────────────────────────
84
+ with gr.Blocks(theme=gr.themes.Default(primary_hue="slate", neutral_hue="slate"), title="Image Utility v2.1") as demo:
 
 
 
 
85
  gr.HTML("<h1 style='text-align:center; color:#374151;'>πŸ›  Image Processing Utility v2.1.4</h1>")
 
86
 
87
  with gr.Tabs():
88
  with gr.Tab("D-Processor (T2I)"):
89
  with gr.Row():
90
  with gr.Column():
91
+ t2i_p = gr.Textbox(label="Input Data String", lines=3)
92
  t2i_n = gr.Textbox(label="Excluded Data", value=NEG_DEFAULT)
93
  with gr.Row():
94
+ t2i_lora = gr.Textbox(label="Extension ID")
95
  t2i_ls = gr.Slider(0, 1.5, 0.8, label="Extension Weight")
96
  with gr.Row():
97
  t2i_w = gr.Slider(512, 1280, 1024, step=64, label="X-Axis")
98
  t2i_h = gr.Slider(512, 1280, 1024, step=64, label="Y-Axis")
99
+ with gr.Row():
100
+ t2i_steps = gr.Number(value=30, label="P-Steps", visible=False)
101
+ t2i_cfg = gr.Number(value=7.0, label="P-Cfg", visible=False)
102
+ t2i_seed = gr.Number(value=42, label="P-Seed", visible=False)
103
+ t2i_btn = gr.Button("Execute Process")
104
  t2i_out = gr.Image(label="Output Preview")
105
+ 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)
106
 
107
  with gr.Tab("M-Sequence (Video)"):
108
  with gr.Row():
 
110
  v_p = gr.Textbox(label="Motion Vector String", lines=3)
111
  v_img = gr.Image(label="Source Buffer", type="numpy")
112
  v_ls = gr.Slider(0, 1.5, 0.8, label="Motion Weight")
113
+ with gr.Row():
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, gr.Textbox(value=NEG_DEFAULT, visible=False), v_img, v_frames, v_fps, v_steps, v_ls, v_seed], v_out)
121
 
122
+ demo.launch(server_name="0.0.0.0", server_port=7860)