From 6f409deedfdbe5c9903a1707480e08462c60e3e0 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 24 Sep 2025 12:33:57 -0400 Subject: [PATCH] ui separate guidance and detail sections Signed-off-by: Vladimir Mandic --- extensions-builtin/sdnext-modernui | 2 +- modules/control/run.py | 4 ++-- modules/processing_class.py | 16 ++++++++-------- modules/processing_diffusers.py | 4 ++-- modules/ui_control.py | 3 ++- modules/ui_img2img.py | 5 +++-- modules/ui_sections.py | 26 ++++++++++++-------------- modules/ui_txt2img.py | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/extensions-builtin/sdnext-modernui b/extensions-builtin/sdnext-modernui index 049386fd9..a445b6b09 160000 --- a/extensions-builtin/sdnext-modernui +++ b/extensions-builtin/sdnext-modernui @@ -1 +1 @@ -Subproject commit 049386fd9d5c2d9b30cc9136be1e1bcda13d81c6 +Subproject commit a445b6b09f3974f95d410f19575200109e1a8b83 diff --git a/modules/control/run.py b/modules/control/run.py index 6d1b885b7..586958a49 100644 --- a/modules/control/run.py +++ b/modules/control/run.py @@ -396,9 +396,9 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg # hires/refine defined outside of main init vae_scale_factor = sd_vae.get_vae_scale_factor() if p.enable_hr and (p.hr_resize_x == 0 or p.hr_resize_y == 0): - p.hr_upscale_to_x, p.hr_upscale_to_y = vae_scale_factor * int(p.width_before * p.hr_scale / vae_scale_factor), vae_scale_factor * int(p.height_before * p.hr_scale / vae_scale_factor) + p.hr_upscale_to_x, p.hr_upscale_to_y = int(vae_scale_factor * int(p.width_before * p.hr_scale / vae_scale_factor)), int(vae_scale_factor * int(p.height_before * p.hr_scale / vae_scale_factor)) elif p.enable_hr and (p.hr_upscale_to_x == 0 or p.hr_upscale_to_y == 0): - p.hr_upscale_to_x, p.hr_upscale_to_y = 8 * int(p.hr_resize_x / vae_scale_factor), vae_scale_factor * int(p.hr_resize_y / vae_scale_factor) + p.hr_upscale_to_x, p.hr_upscale_to_y = 8 * int(p.hr_resize_x / vae_scale_factor), int(vae_scale_factor * int(p.hr_resize_y / vae_scale_factor)) global p_extra_args # pylint: disable=global-statement for k, v in p_extra_args.items(): diff --git a/modules/processing_class.py b/modules/processing_class.py index 7ea9c2eab..d0d634cfa 100644 --- a/modules/processing_class.py +++ b/modules/processing_class.py @@ -445,14 +445,14 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing): self.hr_upscale_to_y = int(self.height * scale) else: if self.hr_resize_y == 0: - self.hr_upscale_to_x = self.hr_resize_x - self.hr_upscale_to_y = self.hr_resize_x * self.height // self.width + self.hr_upscale_to_x = int(self.hr_resize_x) + self.hr_upscale_to_y = int(self.hr_resize_x * self.height // self.width) elif self.hr_resize_x == 0: - self.hr_upscale_to_x = self.hr_resize_y * self.width // self.height - self.hr_upscale_to_y = self.hr_resize_y + self.hr_upscale_to_x = int(self.hr_resize_y * self.width // self.height) + self.hr_upscale_to_y = int(self.hr_resize_y) elif self.hr_resize_x > 0 and self.hr_resize_y > 0: - self.hr_upscale_to_x = self.hr_resize_x - self.hr_upscale_to_y = self.hr_resize_y + self.hr_upscale_to_x = int(self.hr_resize_x) + self.hr_upscale_to_y = int(self.hr_resize_y) shared.log.debug(f'Init hires: upscaler="{self.hr_upscaler}" sampler="{self.hr_sampler_name}" resize={self.hr_resize_x}x{self.hr_resize_y} upscale={self.hr_upscale_to_x}x{self.hr_upscale_to_y}') @@ -572,9 +572,9 @@ class StableDiffusionProcessingControl(StableDiffusionProcessingImg2Img): self.hr_force = force if use_scale: vae_scale_factor = sd_vae.get_vae_scale_factor() - self.hr_upscale_to_x, self.hr_upscale_to_y = vae_scale_factor * int(self.width * scale / vae_scale_factor), vae_scale_factor * int(self.height * scale / vae_scale_factor) + self.hr_upscale_to_x, self.hr_upscale_to_y = int(vae_scale_factor * int(self.width * scale / vae_scale_factor)), int(vae_scale_factor * int(self.height * scale / vae_scale_factor)) else: - self.hr_upscale_to_x, self.hr_upscale_to_y = self.hr_resize_x, self.hr_resize_y + self.hr_upscale_to_x, self.hr_upscale_to_y = int(self.hr_resize_x), int(self.hr_resize_y) def switch_class(p: StableDiffusionProcessing, new_class: type, dct: dict = None): diff --git a/modules/processing_diffusers.py b/modules/processing_diffusers.py index 75f74a11b..6453516c0 100644 --- a/modules/processing_diffusers.py +++ b/modules/processing_diffusers.py @@ -238,8 +238,8 @@ def process_hires(p: processing.StableDiffusionProcessing, output): p.hr_upscaler = p.resize_name p.hr_resize_mode = p.resize_mode p.hr_resize_context = p.resize_context - p.hr_upscale_to_x = p.width * p.hr_scale if p.hr_resize_x == 0 else p.hr_resize_x - p.hr_upscale_to_y = p.height * p.hr_scale if p.hr_resize_y == 0 else p.hr_resize_y + p.hr_upscale_to_x = int(p.width * p.hr_scale) if p.hr_resize_x == 0 else p.hr_resize_x + p.hr_upscale_to_y = int(p.height * p.hr_scale) if p.hr_resize_y == 0 else p.hr_resize_y # hires runs on original pipeline if hasattr(shared.sd_model, 'restore_pipeline') and (shared.sd_model.restore_pipeline is not None) and (not shared.opts.control_hires): diff --git a/modules/ui_control.py b/modules/ui_control.py index b75842aee..0fe361aa2 100644 --- a/modules/ui_control.py +++ b/modules/ui_control.py @@ -163,7 +163,8 @@ def create_ui(_blocks: gr.Blocks=None): mask_controls = masking.create_segment_ui() - vae_type, tiling, hidiffusion, cfg_scale, clip_skip, image_cfg_scale, guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_sections.create_advanced_inputs('control') + cfg_scale, image_cfg_scale, guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_sections.create_guidance_inputs('control') + vae_type, tiling, hidiffusion, clip_skip = ui_sections.create_advanced_inputs('control') hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio = ui_sections.create_correction_inputs('control') with gr.Accordion(open=False, label="Video", elem_id="control_video", elem_classes=["small-accordion"]): diff --git a/modules/ui_img2img.py b/modules/ui_img2img.py index d08999c8c..7e7db44cb 100644 --- a/modules/ui_img2img.py +++ b/modules/ui_img2img.py @@ -132,9 +132,10 @@ def create_ui(): denoising_strength = gr.Slider(minimum=0.00, maximum=0.99, step=0.01, label='Denoising strength', value=0.30, elem_id="img2img_denoising_strength") refiner_start = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Denoise start', value=0.0, elem_id="img2img_refiner_start") - vae_type, tiling, hidiffusion, cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_sections.create_advanced_inputs('img2img') + cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_sections.create_guidance_inputs('img2img') + vae_type, tiling, hidiffusion, clip_skip = ui_sections.create_advanced_inputs('img2img') hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio = ui_sections.create_correction_inputs('img2img') - enable_hr, hr_sampler_index, hr_denoising_strength, hr_resize_mode, hr_resize_context, hr_upscaler, hr_force, hr_second_pass_steps, hr_scale, hr_resize_x, hr_resize_y, refiner_steps, hr_refiner_start, refiner_prompt, refiner_negative = ui_sections.create_hires_inputs('txt2img') + enable_hr, hr_sampler_index, hr_denoising_strength, hr_resize_mode, hr_resize_context, hr_upscaler, hr_force, hr_second_pass_steps, hr_scale, hr_resize_x, hr_resize_y, refiner_steps, hr_refiner_start, refiner_prompt, refiner_negative = ui_sections.create_hires_inputs('img2img') detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution = shared.yolo.ui('img2img') # with gr.Group(elem_id="inpaint_controls", visible=False) as inpaint_controls: diff --git a/modules/ui_sections.py b/modules/ui_sections.py index 07ce95b3c..829c502bd 100644 --- a/modules/ui_sections.py +++ b/modules/ui_sections.py @@ -146,26 +146,24 @@ def create_video_inputs(tab:str, show_always:bool=False): return video_type, video_duration, video_loop, video_pad, video_interpolate -def create_cfg_inputs(tab): - with gr.Row(elem_id=f"{tab}_cfg_row", elem_classes=['flexbox']): - cfg_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label='Guidance scale', value=6.0, elem_id=f"{tab}_cfg_scale") - cfg_end = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='Guidance end', value=1.0, elem_id=f"{tab}_cfg_end") - return cfg_scale, cfg_end - - -def create_advanced_inputs(tab, base=True): - with gr.Accordion(open=False, label="Advanced", elem_id=f"{tab}_advanced", elem_classes=["small-accordion"]): +def create_guidance_inputs(tab): + with gr.Accordion(open=False, label="Guidance", elem_id=f"{tab}_guidance", elem_classes=["small-accordion"]): with gr.Group(): - if base: - cfg_scale, cfg_end = create_cfg_inputs(tab) - else: - cfg_scale, cfg_end = None, None + with gr.Row(elem_id=f"{tab}_cfg_row", elem_classes=['flexbox']): + cfg_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label='Guidance scale', value=6.0, elem_id=f"{tab}_cfg_scale") + cfg_end = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='Guidance end', value=1.0, elem_id=f"{tab}_cfg_end") with gr.Row(): image_cfg_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.1, label='Refine guidance', value=6.0, elem_id=f"{tab}_image_cfg_scale") diffusers_guidance_rescale = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Rescale guidance', value=0.0, elem_id=f"{tab}_image_cfg_rescale") with gr.Row(): diffusers_pag_scale = gr.Slider(minimum=0.0, maximum=30.0, step=0.05, label='Attention guidance', value=0.0, elem_id=f"{tab}_pag_scale") diffusers_pag_adaptive = gr.Slider(minimum=0.0, maximum=1.0, step=0.05, label='Adaptive scaling', value=0.5, elem_id=f"{tab}_pag_adaptive") + return cfg_scale, image_cfg_scale, diffusers_guidance_rescale, diffusers_pag_scale, diffusers_pag_adaptive, cfg_end + + +def create_advanced_inputs(tab): + with gr.Accordion(open=False, label="Advanced", elem_id=f"{tab}_advanced", elem_classes=["small-accordion"]): + with gr.Group(): with gr.Row(): clip_skip = gr.Slider(label='CLiP skip', value=1, minimum=0, maximum=12, step=0.1, elem_id=f"{tab}_clip_skip", interactive=shared.opts.clip_skip_enabled) with gr.Row(elem_id=f"{tab}_vae_options"): @@ -173,7 +171,7 @@ def create_advanced_inputs(tab, base=True): with gr.Row(elem_id=f"{tab}_advanced_options"): tiling = gr.Checkbox(label='Texture tiling', value=False, elem_id=f"{tab}_tiling") hidiffusion = gr.Checkbox(label='HiDiffusion', value=False, elem_id=f"{tab}_hidiffusion") - return vae_type, tiling, hidiffusion, cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, diffusers_pag_scale, diffusers_pag_adaptive, cfg_end + return vae_type, tiling, hidiffusion, clip_skip def create_correction_inputs(tab): diff --git a/modules/ui_txt2img.py b/modules/ui_txt2img.py index a7efadba1..0fae0c606 100644 --- a/modules/ui_txt2img.py +++ b/modules/ui_txt2img.py @@ -27,14 +27,14 @@ def create_ui(): width, height = ui_sections.create_resolution_inputs('txt2img') batch_count, batch_size = ui_sections.create_batch_inputs('txt2img', accordion=False) - cfg_scale, cfg_end = ui_sections.create_cfg_inputs('txt2img') steps, sampler_index = ui_sections.create_sampler_and_steps_selection(None, "txt2img") with gr.Group(elem_classes="settings-accordion"): with gr.Accordion(open=False, label="Samplers", elem_classes=["small-accordion"], elem_id="txt2img_sampler_group"): ui_sections.create_sampler_options('txt2img') seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w = ui_sections.create_seed_inputs('txt2img') - vae_type, tiling, hidiffusion, _cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, _cfg_end = ui_sections.create_advanced_inputs('txt2img', base=False) + cfg_scale, image_cfg_scale, diffusers_guidance_rescale, pag_scale, pag_adaptive, cfg_end = ui_sections.create_guidance_inputs('txt2img') + vae_type, tiling, hidiffusion, clip_skip = ui_sections.create_advanced_inputs('txt2img') hdr_mode, hdr_brightness, hdr_color, hdr_sharpen, hdr_clamp, hdr_boundary, hdr_threshold, hdr_maximize, hdr_max_center, hdr_max_boundary, hdr_color_picker, hdr_tint_ratio = ui_sections.create_correction_inputs('txt2img') enable_hr, hr_sampler_index, denoising_strength, hr_resize_mode, hr_resize_context, hr_upscaler, hr_force, hr_second_pass_steps, hr_scale, hr_resize_x, hr_resize_y, refiner_steps, refiner_start, refiner_prompt, refiner_negative = ui_sections.create_hires_inputs('txt2img') detailer_enabled, detailer_prompt, detailer_negative, detailer_steps, detailer_strength, detailer_resolution = shared.yolo.ui('txt2img')