Spaces:
Running on Zero
Running on Zero
update app
Browse files
app.py
CHANGED
|
@@ -114,8 +114,6 @@ pipe_small_decoder.enable_model_cpu_offload()
|
|
| 114 |
pipe_lock_standard = threading.Lock()
|
| 115 |
pipe_lock_small = threading.Lock()
|
| 116 |
|
| 117 |
-
|
| 118 |
-
# ── dimension helper ────────────────────────────────────────────────────────
|
| 119 |
def calc_dimensions(pil_img: Image.Image):
|
| 120 |
"""
|
| 121 |
Given a PIL image return (width, height) snapped to multiples of 8,
|
|
@@ -157,8 +155,6 @@ def update_dimensions_from_image(image_list):
|
|
| 157 |
|
| 158 |
return calc_dimensions(img)
|
| 159 |
|
| 160 |
-
|
| 161 |
-
# ── image parser ─────────────────────────────────────────────────────────────
|
| 162 |
def parse_and_resize_images(input_images, width: int, height: int):
|
| 163 |
"""
|
| 164 |
Parse the gallery input and resize every frame to (width, height).
|
|
@@ -190,23 +186,18 @@ def parse_and_resize_images(input_images, width: int, height: int):
|
|
| 190 |
if not raw_list:
|
| 191 |
return None
|
| 192 |
|
| 193 |
-
# ── KEY FIX: resize every image to the exact pipeline dimensions ──
|
| 194 |
resized = [
|
| 195 |
img.resize((width, height), Image.LANCZOS)
|
| 196 |
for img in raw_list
|
| 197 |
]
|
| 198 |
return resized
|
| 199 |
|
| 200 |
-
|
| 201 |
-
# ── pipeline runner ───────────────────────────────────────────────────────────
|
| 202 |
def run_pipeline(pipe, lock, kwargs, seed):
|
| 203 |
with lock:
|
| 204 |
gen = torch.Generator(device="cpu").manual_seed(seed)
|
| 205 |
result = pipe(**kwargs, generator=gen).images[0]
|
| 206 |
return result
|
| 207 |
|
| 208 |
-
|
| 209 |
-
# ── main inference ────────────────────────────────────────────────────────────
|
| 210 |
@spaces.GPU(duration=120)
|
| 211 |
def infer(
|
| 212 |
prompt,
|
|
@@ -265,7 +256,7 @@ def infer(
|
|
| 265 |
if image_list is not None:
|
| 266 |
shared_kwargs["image"] = image_list
|
| 267 |
|
| 268 |
-
progress(0.
|
| 269 |
|
| 270 |
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
| 271 |
future_std = executor.submit(
|
|
@@ -279,7 +270,7 @@ def infer(
|
|
| 279 |
return_when=concurrent.futures.ALL_COMPLETED,
|
| 280 |
)
|
| 281 |
|
| 282 |
-
progress(0.
|
| 283 |
|
| 284 |
out_standard = future_std.result()
|
| 285 |
out_small = future_small.result()
|
|
@@ -379,7 +370,6 @@ with gr.Blocks() as demo:
|
|
| 379 |
|
| 380 |
run_button = gr.Button("Run Comparison", variant="primary")
|
| 381 |
|
| 382 |
-
# ── RIGHT COLUMN: outputs ───────────────────────────────────────
|
| 383 |
with gr.Column():
|
| 384 |
with gr.Row():
|
| 385 |
with gr.Column():
|
|
|
|
| 114 |
pipe_lock_standard = threading.Lock()
|
| 115 |
pipe_lock_small = threading.Lock()
|
| 116 |
|
|
|
|
|
|
|
| 117 |
def calc_dimensions(pil_img: Image.Image):
|
| 118 |
"""
|
| 119 |
Given a PIL image return (width, height) snapped to multiples of 8,
|
|
|
|
| 155 |
|
| 156 |
return calc_dimensions(img)
|
| 157 |
|
|
|
|
|
|
|
| 158 |
def parse_and_resize_images(input_images, width: int, height: int):
|
| 159 |
"""
|
| 160 |
Parse the gallery input and resize every frame to (width, height).
|
|
|
|
| 186 |
if not raw_list:
|
| 187 |
return None
|
| 188 |
|
|
|
|
| 189 |
resized = [
|
| 190 |
img.resize((width, height), Image.LANCZOS)
|
| 191 |
for img in raw_list
|
| 192 |
]
|
| 193 |
return resized
|
| 194 |
|
|
|
|
|
|
|
| 195 |
def run_pipeline(pipe, lock, kwargs, seed):
|
| 196 |
with lock:
|
| 197 |
gen = torch.Generator(device="cpu").manual_seed(seed)
|
| 198 |
result = pipe(**kwargs, generator=gen).images[0]
|
| 199 |
return result
|
| 200 |
|
|
|
|
|
|
|
| 201 |
@spaces.GPU(duration=120)
|
| 202 |
def infer(
|
| 203 |
prompt,
|
|
|
|
| 256 |
if image_list is not None:
|
| 257 |
shared_kwargs["image"] = image_list
|
| 258 |
|
| 259 |
+
progress(0.30, desc="Launching both pipelines simultaneously...")
|
| 260 |
|
| 261 |
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
| 262 |
future_std = executor.submit(
|
|
|
|
| 270 |
return_when=concurrent.futures.ALL_COMPLETED,
|
| 271 |
)
|
| 272 |
|
| 273 |
+
progress(0.80, desc="✅ Both pipelines done!")
|
| 274 |
|
| 275 |
out_standard = future_std.result()
|
| 276 |
out_small = future_small.result()
|
|
|
|
| 370 |
|
| 371 |
run_button = gr.Button("Run Comparison", variant="primary")
|
| 372 |
|
|
|
|
| 373 |
with gr.Column():
|
| 374 |
with gr.Row():
|
| 375 |
with gr.Column():
|