Commit ·
ca50d09
1
Parent(s): a532114
Add 2K/4K resolution selector to Advanced Settings
Browse files- Add `_resolve_output_dimensions` helper to encapsulate max_dim parsing
- Wire `max_output_dim` hidden Gradio Textbox (defaults to MAX_OUTPUT_DIM) through infer
- Add res-btn toggle group in Advanced Settings panel (HTML + CSS)
- Track selection in `window.__setResolution` / `window.__selectedMaxDim` (gallery.js)
- Pass selected resolution through run_preprocess.js to the backend
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Files changed (5)
262 unmodified lines26326426526626726829 unmodified lines29829930030130230330422 unmodified lines32732832933033133233353 unmodified lines3873883893903913929 unmodified lines402403404405406407408262 unmodified linesreturn random.randint(0, MAX_SEED) if randomize_seed else seeddef _spawn_log(pil_images, result_image, prompt, seed, steps, guidance_scale,width, height, duration, success, error=""):threading.Thread(29 unmodified lines# ── Gradio blocks ──────────────────────────────────────────────────────────────@spaces.GPUdef infer(images_b64_json, prompt, seed, randomize_seed, guidance_scale, steps, progress=gr.Progress(track_tqdm=True)):_cuda_ok = torch.cuda.is_available()timer = _InferTimer(_cuda_ok)t0 = time.perf_counter()22 unmodified linesseed = _resolve_seed(seed, randomize_seed)generator = torch.Generator(device=device).manual_seed(seed)width, height = update_dimensions_on_upload(pil_images[0])print(f"[infer] input={pil_images[0].size}, output={width}x{height}, seed={seed}")# Per-step callback: syncs the GPU then records a CUDA event so elapsed_time()53 unmodified linesrandomize_seed = gr.Checkbox(value=True, elem_id="gradio-randomize", elem_classes="hidden-input", container=False)guidance_scale = gr.Slider(minimum=1.0, maximum=10.0, step=0.1, value=1.0, elem_id="gradio-guidance", elem_classes="hidden-input", container=False)steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, elem_id="gradio-steps", elem_classes="hidden-input", container=False)result = gr.Image(elem_id="gradio-result", elem_classes="hidden-input", container=False, format="png")example_idx = gr.Textbox(value="", elem_id="example-idx-input", elem_classes="hidden-input", container=False)9 unmodified linesrun_btn.click(fn=infer,inputs=[hidden_images_b64, prompt, seed, randomize_seed, guidance_scale, steps],outputs=[result, seed],js=run_preprocess_js,)262 unmodified lines26326426526626726826927027127227329 unmodified lines30330430530630730830922 unmodified lines33233333433533633733853 unmodified lines3923933943953963973989 unmodified lines408409410411412413414262 unmodified linesreturn random.randint(0, MAX_SEED) if randomize_seed else seeddef _resolve_output_dimensions(image: Image.Image, max_output_dim) -> tuple:max_dim = int(max_output_dim) if str(max_output_dim).strip() else MAX_OUTPUT_DIMreturn compute_output_dimensions(*image.size, max_dim=max_dim)def _spawn_log(pil_images, result_image, prompt, seed, steps, guidance_scale,width, height, duration, success, error=""):threading.Thread(29 unmodified lines# ── Gradio blocks ──────────────────────────────────────────────────────────────@spaces.GPUdef infer(images_b64_json, prompt, seed, randomize_seed, guidance_scale, steps, max_output_dim, progress=gr.Progress(track_tqdm=True)):_cuda_ok = torch.cuda.is_available()timer = _InferTimer(_cuda_ok)t0 = time.perf_counter()22 unmodified linesseed = _resolve_seed(seed, randomize_seed)generator = torch.Generator(device=device).manual_seed(seed)width, height = _resolve_output_dimensions(pil_images[0], max_output_dim)print(f"[infer] input={pil_images[0].size}, output={width}x{height}, seed={seed}")# Per-step callback: syncs the GPU then records a CUDA event so elapsed_time()53 unmodified linesrandomize_seed = gr.Checkbox(value=True, elem_id="gradio-randomize", elem_classes="hidden-input", container=False)guidance_scale = gr.Slider(minimum=1.0, maximum=10.0, step=0.1, value=1.0, elem_id="gradio-guidance", elem_classes="hidden-input", container=False)steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, elem_id="gradio-steps", elem_classes="hidden-input", container=False)max_output_dim = gr.Textbox(value=str(MAX_OUTPUT_DIM), elem_id="gradio-max-output-dim", elem_classes="hidden-input", container=False)result = gr.Image(elem_id="gradio-result", elem_classes="hidden-input", container=False, format="png")example_idx = gr.Textbox(value="", elem_id="example-idx-input", elem_classes="hidden-input", container=False)9 unmodified linesrun_btn.click(fn=infer,inputs=[hidden_images_b64, prompt, seed, randomize_seed, guidance_scale, steps, max_output_dim],outputs=[result, seed],js=run_preprocess_js,)
300 unmodified lines301302303304305306300 unmodified lines.checkbox-row{display:flex;align-items:center;gap:8px;font-size:13px;color:#a1a1aa}.checkbox-row input[type="checkbox"]{accent-color:#ff0080;width:16px;height:16px;cursor:pointer}.checkbox-row label{color:#a1a1aa;font-size:13px;cursor:pointer}.app-statusbar{background:#280018;border-top:1px solid #4d0030;padding:6px 20px;300 unmodified lines301302303304305306307308309310311312313314315316300 unmodified lines.checkbox-row{display:flex;align-items:center;gap:8px;font-size:13px;color:#a1a1aa}.checkbox-row input[type="checkbox"]{accent-color:#ff0080;width:16px;height:16px;cursor:pointer}.checkbox-row label{color:#a1a1aa;font-size:13px;cursor:pointer}.res-row{display:flex;align-items:center;gap:10px;min-height:28px}.res-row label{font-size:13px;font-weight:500;color:#a1a1aa;min-width:72px;flex-shrink:0}.res-btn-group{display:flex;gap:4px}.res-btn{padding:4px 16px;font-size:12px;font-weight:600;border-radius:6px;cursor:pointer;border:1px solid #4d0030;background:transparent;color:#71717a;font-family:'Inter',sans-serif;transition:all .15s;}.res-btn.active{background:rgba(255,0,128,.2);border-color:rgba(255,0,128,.5);color:#ff4da6}.res-btn:hover:not(.active){background:rgba(255,0,128,.1);border-color:rgba(255,0,128,.3);color:#a1a1aa}.app-statusbar{background:#280018;border-top:1px solid #4d0030;padding:6px 20px;
281 unmodified lines282283284285286287281 unmodified linesif (runBtnEl) runBtnEl.addEventListener('click', () => window.__clickGradioRunBtn());renderGallery();updateCounts();}281 unmodified lines282283284285286287288289290291292293294281 unmodified linesif (runBtnEl) runBtnEl.addEventListener('click', () => window.__clickGradioRunBtn());window.__selectedMaxDim = 2048;window.__setResolution = function(dim, btn) {window.__selectedMaxDim = dim;document.querySelectorAll('.res-btn').forEach(b => b.classList.remove('active'));if (btn) btn.classList.add('active');};renderGallery();updateCounts();}
12345678(imgs, p, s, rs, gs, st) => {const images = window.__uploadedImages || [];const b64Array = images.map(img => img.b64);const imgsJson = JSON.stringify(b64Array);const promptEl = document.getElementById('custom-prompt-input');const promptVal = promptEl ? promptEl.value : p;return [imgsJson, promptVal, s, rs, gs, st];}123456789(imgs, p, s, rs, gs, st, mod) => {const images = window.__uploadedImages || [];const b64Array = images.map(img => img.b64);const imgsJson = JSON.stringify(b64Array);const promptEl = document.getElementById('custom-prompt-input');const promptVal = promptEl ? promptEl.value : p;const maxDim = String(window.__selectedMaxDim || 2048);return [imgsJson, promptVal, s, rs, gs, st, maxDim];}
122 unmodified lines123124125126127128122 unmodified lines<div class="settings-group"><div class="settings-group-title">Advanced Settings</div><div class="settings-group-body"><div class="slider-row"><label>Seed</label><input type="range" id="custom-seed" min="0" max="2147483647" step="1" value="0">122 unmodified lines123124125126127128129130131132133134135122 unmodified lines<div class="settings-group"><div class="settings-group-title">Advanced Settings</div><div class="settings-group-body"><div class="res-row"><label>Resolution</label><div class="res-btn-group"><button type="button" class="res-btn active" onclick="window.__setResolution(2048, this)">2K</button><button type="button" class="res-btn" onclick="window.__setResolution(4096, this)">4K</button></div></div><div class="slider-row"><label>Seed</label><input type="range" id="custom-seed" min="0" max="2147483647" step="1" value="0">
app.py+9-3
static/app.css+10
static/gallery.js+7
static/run_preprocess.js+3-2
templates/app.html+7