Skip to content

Commit 6f26ef3

Browse files
committed
feat: add Checkbox "Use different CFG scale" to UI
1 parent 2ffb3d7 commit 6f26ef3

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

javascript/hires_fix.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,24 @@ function onCalcResolutionHires(enable, width, height, hr_scale, hr_resize_x, hr_
1616

1717
return [enable, width, height, hr_scale, hr_resize_x, hr_resize_y];
1818
}
19+
20+
function toggleUseDifferentHRCFGScale(enabled, cfg_scale, ditilled_cfg_scale) {
21+
if (enabled) {
22+
return [
23+
{ interactive: enabled, __type__: "update" },
24+
{ interactive: enabled, __type__: "update" },
25+
];
26+
}
27+
28+
return [
29+
{ interactive: enabled, value: ditilled_cfg_scale, __type__: "update" },
30+
{ interactive: enabled, value: cfg_scale, __type__: "update" },
31+
];
32+
}
33+
34+
function syncHRCFGScale(enabled, value) {
35+
if (enabled) {
36+
return { __type__: "update" };
37+
}
38+
return { value: value, __type__: "update" };
39+
}

modules/ui.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,25 @@ def create_ui():
489489
cfg_scale = gr.Slider(minimum=1.0, maximum=30.0, step=0.1, label='CFG Scale', value=7.0, elem_id="txt2img_cfg_scale")
490490
cfg_scale.change(lambda x: gr.update(interactive=(x != 1)), inputs=[cfg_scale], outputs=[toprow.negative_prompt], queue=False, show_progress=False)
491491

492+
hr_use_different_cfg.change(
493+
fn=None,
494+
_js="toggleUseDifferentHRCFGScale",
495+
inputs=[hr_use_different_cfg, distilled_cfg_scale, cfg_scale],
496+
outputs=[hr_distilled_cfg, hr_cfg],
497+
)
498+
distilled_cfg_scale.change(
499+
fn=None,
500+
_js="syncHRCFGScale",
501+
inputs=[hr_use_different_cfg, distilled_cfg_scale],
502+
outputs=[hr_distilled_cfg],
503+
)
504+
cfg_scale.change(
505+
fn=None,
506+
_js="syncHRCFGScale",
507+
inputs=[hr_use_different_cfg, cfg_scale],
508+
outputs=[hr_cfg],
509+
)
510+
492511
elif category == "checkboxes":
493512
with FormRow(elem_classes="checkboxes-row", variant="compact"):
494513
restore_faces = gr.Checkbox(label='Restore faces', value=False, visible=len(shared.face_restorers) > 1, elem_id="txt2img_restore_faces")
@@ -540,8 +559,9 @@ def create_ui():
540559
_js="monitorThisParam('tab_txt2img', 'modules.txt2img.txt2img', 'hr_resize_y')")
541560

542561
with FormRow(elem_id="txt2img_hires_fix_row_cfg", variant="compact"):
543-
hr_distilled_cfg = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label="Hires Distilled CFG Scale", value=3.5, elem_id="txt2img_hr_distilled_cfg")
544-
hr_cfg = gr.Slider(minimum=1.0, maximum=30.0, step=0.1, label="Hires CFG Scale", value=7.0, elem_id="txt2img_hr_cfg")
562+
hr_distilled_cfg = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label="Hires Distilled CFG Scale", value=3.5, elem_id="txt2img_hr_distilled_cfg", interactive=False)
563+
hr_cfg = gr.Slider(minimum=1.0, maximum=30.0, step=0.1, label="Hires CFG Scale", value=7.0, elem_id="txt2img_hr_cfg", interactive=False)
564+
hr_use_different_cfg = gr.Checkbox(label="Use different CFG scale", value=False, elem_id="txt2img_hr_use_different_cfg")
545565

546566
with FormRow(elem_id="txt2img_hires_fix_row3", variant="compact", visible=shared.opts.hires_fix_show_sampler) as hr_checkpoint_container:
547567
hr_checkpoint_name = gr.Dropdown(label='Hires Checkpoint', elem_id="hr_checkpoint", choices=["Use same checkpoint"], value="Use same checkpoint", scale=2, multiselect=False)

0 commit comments

Comments
 (0)