Spaces:
Running on Zero
Running on Zero
Commit ·
a3f2ffd
1
Parent(s): 84855d6
Load mode toggle JS via demo.load instead of stripped <script> tag
Browse files- app.py +6 -3
- static/mode_toggle.js +8 -0
- templates/app.html +0 -9
app.py
CHANGED
|
@@ -33,7 +33,7 @@ torch.backends.cudnn.allow_tf32 = True
|
|
| 33 |
print("[startup] TF32 enabled", flush=True)
|
| 34 |
|
| 35 |
print("[startup] importing dimensions...", flush=True)
|
| 36 |
-
from dimensions import compute_output_dimensions,
|
| 37 |
print("[startup] importing diffusers...", flush=True)
|
| 38 |
from diffusers import FlowMatchEulerDiscreteScheduler
|
| 39 |
print("[startup] importing QwenImageEditPlusPipeline...", flush=True)
|
|
@@ -316,6 +316,9 @@ with open("static/wire_outputs.js") as _f:
|
|
| 316 |
with open("static/run_preprocess.js") as _f:
|
| 317 |
run_preprocess_js = _f.read()
|
| 318 |
|
|
|
|
|
|
|
|
|
|
| 319 |
with open("static/negative_prompt.txt") as _f:
|
| 320 |
negative_prompt = _f.read().strip()
|
| 321 |
|
|
@@ -359,8 +362,7 @@ def infer(images_b64_json, prompt, seed, randomize_seed, guidance_scale, steps,
|
|
| 359 |
|
| 360 |
seed = _resolve_seed(seed, randomize_seed)
|
| 361 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 362 |
-
|
| 363 |
-
width, height = update_dimensions_on_upload(pil_images[0], max_dim)
|
| 364 |
print(f"[infer] input={pil_images[0].size}, output={width}x{height}, seed={seed}")
|
| 365 |
|
| 366 |
# Per-step callback: syncs the GPU then records a CUDA event so elapsed_time()
|
|
@@ -433,6 +435,7 @@ with gr.Blocks() as demo:
|
|
| 433 |
|
| 434 |
demo.load(fn=None, js=gallery_js)
|
| 435 |
demo.load(fn=None, js=wire_outputs_js)
|
|
|
|
| 436 |
|
| 437 |
run_btn.click(
|
| 438 |
fn=infer,
|
|
|
|
| 33 |
print("[startup] TF32 enabled", flush=True)
|
| 34 |
|
| 35 |
print("[startup] importing dimensions...", flush=True)
|
| 36 |
+
from dimensions import compute_output_dimensions, max_dim_for_mode
|
| 37 |
print("[startup] importing diffusers...", flush=True)
|
| 38 |
from diffusers import FlowMatchEulerDiscreteScheduler
|
| 39 |
print("[startup] importing QwenImageEditPlusPipeline...", flush=True)
|
|
|
|
| 316 |
with open("static/run_preprocess.js") as _f:
|
| 317 |
run_preprocess_js = _f.read()
|
| 318 |
|
| 319 |
+
with open("static/mode_toggle.js") as _f:
|
| 320 |
+
mode_toggle_js = _f.read()
|
| 321 |
+
|
| 322 |
with open("static/negative_prompt.txt") as _f:
|
| 323 |
negative_prompt = _f.read().strip()
|
| 324 |
|
|
|
|
| 362 |
|
| 363 |
seed = _resolve_seed(seed, randomize_seed)
|
| 364 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 365 |
+
width, height = update_dimensions_on_upload(pil_images[0], max_dim_for_mode(mode))
|
|
|
|
| 366 |
print(f"[infer] input={pil_images[0].size}, output={width}x{height}, seed={seed}")
|
| 367 |
|
| 368 |
# Per-step callback: syncs the GPU then records a CUDA event so elapsed_time()
|
|
|
|
| 435 |
|
| 436 |
demo.load(fn=None, js=gallery_js)
|
| 437 |
demo.load(fn=None, js=wire_outputs_js)
|
| 438 |
+
demo.load(fn=None, js=mode_toggle_js)
|
| 439 |
|
| 440 |
run_btn.click(
|
| 441 |
fn=infer,
|
static/mode_toggle.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
window.__selectedMode = 'fast';
|
| 2 |
+
window.__setMode = function(m) {
|
| 3 |
+
window.__selectedMode = m;
|
| 4 |
+
var fast = document.getElementById('mode-btn-fast');
|
| 5 |
+
var hd = document.getElementById('mode-btn-hd');
|
| 6 |
+
if (fast) fast.classList.toggle('mode-btn-active', m === 'fast');
|
| 7 |
+
if (hd) hd.classList.toggle('mode-btn-active', m === 'high_detail');
|
| 8 |
+
};
|
templates/app.html
CHANGED
|
@@ -179,12 +179,3 @@
|
|
| 179 |
</details>
|
| 180 |
|
| 181 |
</div>
|
| 182 |
-
|
| 183 |
-
<script>
|
| 184 |
-
window.__selectedMode = 'fast';
|
| 185 |
-
window.__setMode = function(m) {{
|
| 186 |
-
window.__selectedMode = m;
|
| 187 |
-
document.getElementById('mode-btn-fast').classList.toggle('mode-btn-active', m === 'fast');
|
| 188 |
-
document.getElementById('mode-btn-hd').classList.toggle('mode-btn-active', m === 'high_detail');
|
| 189 |
-
}};
|
| 190 |
-
</script>
|
|
|
|
| 179 |
</details>
|
| 180 |
|
| 181 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|