From 2bcada4755b665f5cd62b9b4a663b37ee9b66709 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 1 Jun 2024 07:31:00 -0400 Subject: [PATCH] fix restore variation seed for txt2img and img2img --- CHANGELOG.md | 3 ++- modules/processing.py | 1 - modules/ui_common.py | 24 +++++++++++++++--------- modules/ui_img2img.py | 2 +- modules/ui_sections.py | 2 +- modules/ui_txt2img.py | 2 +- wiki | 2 +- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beecb380e..ee35c2b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Change Log for SD.Next -## Update for 2024-05-30 +## Update for 2024-06-01 - fix textual inversion loading - fix gallery mtime display - fix extra network scrollable area when using modernui - fix control prompts list handling - fix variation seed with hires pass +- fix restore variation seed and strength - workaround for scale-by when using modernui - lock torch-directml version - improve xformers installer diff --git a/modules/processing.py b/modules/processing.py index 8a44d9477..b9a9f2edc 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -239,7 +239,6 @@ def process_init(p: StableDiffusionProcessing): if reset_prompts: p.all_prompts, p.all_negative_prompts = shared.prompt_styles.apply_styles_to_prompts(p.all_prompts, p.all_negative_prompts, p.styles, p.all_seeds) - def process_images_inner(p: StableDiffusionProcessing) -> Processed: """this is the main loop that both txt2img and img2img use; it calls func_init once inside all the scopes and func_sample once per batch""" if type(p.prompt) == list: diff --git a/modules/ui_common.py b/modules/ui_common.py index 1b8aea378..ec1d7f505 100644 --- a/modules/ui_common.py +++ b/modules/ui_common.py @@ -348,31 +348,37 @@ def create_override_inputs(tab): # pylint: disable=unused-argument return override_settings -def connect_reuse_seed(seed: gr.Number, reuse_seed: gr.Button, generation_info: gr.Textbox, is_subseed): +def connect_reuse_seed(seed: gr.Number, reuse_seed: gr.Button, generation_info: gr.Textbox, is_subseed, subseed_strength=None): """ Connects a 'reuse (sub)seed' button's click event so that it copies last used (sub)seed value from generation info the to the seed field. If copying subseed and subseed strength was 0, i.e. no variation seed was used, it copies the normal seed value instead.""" def copy_seed(gen_info_string: str, index: int): - res = -1 + restore_seed = -1 + restore_strength = -1 try: gen_info = json.loads(gen_info_string) shared.log.debug(f'Reuse: info={gen_info}') index -= gen_info.get('index_of_first_image', 0) index = int(index) - - if is_subseed and gen_info.get('subseed_strength', 0) > 0: + if is_subseed: all_subseeds = gen_info.get('all_subseeds', [-1]) - res = all_subseeds[index if 0 <= index < len(all_subseeds) else 0] + restore_seed = all_subseeds[index if 0 <= index < len(all_subseeds) else 0] + restore_strength = gen_info.get('subseed_strength', 0) else: all_seeds = gen_info.get('all_seeds', [-1]) - res = all_seeds[index if 0 <= index < len(all_seeds) else 0] + restore_seed = all_seeds[index if 0 <= index < len(all_seeds) else 0] except json.decoder.JSONDecodeError: if gen_info_string != '': shared.log.error(f"Error parsing JSON generation info: {gen_info_string}") - return [res, gr_show(False)] - + if is_subseed is not None: + return [restore_seed, gr_show(False), restore_strength] + else: + return [restore_seed, gr_show(False)] dummy_component = gr.Number(visible=False, value=0) - reuse_seed.click(fn=copy_seed, _js="(x, y) => [x, selected_gallery_index()]", show_progress=False, inputs=[generation_info, dummy_component], outputs=[seed, dummy_component]) + if subseed_strength is None: + reuse_seed.click(fn=copy_seed, _js="(x, y) => [x, selected_gallery_index()]", show_progress=False, inputs=[generation_info, dummy_component], outputs=[seed, dummy_component]) + else: + reuse_seed.click(fn=copy_seed, _js="(x, y) => [x, selected_gallery_index()]", show_progress=False, inputs=[generation_info, dummy_component], outputs=[seed, dummy_component, subseed_strength]) def update_token_counter(text, steps): diff --git a/modules/ui_img2img.py b/modules/ui_img2img.py index c8d82358a..09d0c5022 100644 --- a/modules/ui_img2img.py +++ b/modules/ui_img2img.py @@ -157,7 +157,7 @@ def create_ui(): img2img_gallery, img2img_generation_info, img2img_html_info, _img2img_html_info_formatted, img2img_html_log = ui_common.create_output_panel("img2img", prompt=img2img_prompt) ui_common.connect_reuse_seed(seed, reuse_seed, img2img_generation_info, is_subseed=False) - ui_common.connect_reuse_seed(subseed, reuse_subseed, img2img_generation_info, is_subseed=True) + ui_common.connect_reuse_seed(subseed, reuse_subseed, img2img_generation_info, is_subseed=True, subseed_strength=subseed_strength) img2img_prompt_img.change(fn=modules.images.image_data, inputs=[img2img_prompt_img], outputs=[img2img_prompt, img2img_prompt_img]) dummy_component1 = gr.Textbox(visible=False, value='dummy') diff --git a/modules/ui_sections.py b/modules/ui_sections.py index 724d9487f..b6082e839 100644 --- a/modules/ui_sections.py +++ b/modules/ui_sections.py @@ -136,7 +136,7 @@ def create_seed_inputs(tab, reuse_visible=True): with gr.Row(visible=False): seed_resize_from_w = gr.Slider(minimum=0, maximum=4096, step=8, label="Resize seed from width", value=0, elem_id=f"{tab}_seed_resize_from_w") seed_resize_from_h = gr.Slider(minimum=0, maximum=4096, step=8, label="Resize seed from height", value=0, elem_id=f"{tab}_seed_resize_from_h") - random_seed.click(fn=lambda: [-1, -1], show_progress=False, inputs=[], outputs=[seed, subseed]) + random_seed.click(fn=lambda: -1, show_progress=False, inputs=[], outputs=[seed]) random_subseed.click(fn=lambda: -1, show_progress=False, inputs=[], outputs=[subseed]) return seed, reuse_seed, subseed, reuse_subseed, subseed_strength, seed_resize_from_h, seed_resize_from_w diff --git a/modules/ui_txt2img.py b/modules/ui_txt2img.py index ab6545b8c..27d93fb7b 100644 --- a/modules/ui_txt2img.py +++ b/modules/ui_txt2img.py @@ -56,7 +56,7 @@ def create_ui(): txt2img_gallery, txt2img_generation_info, txt2img_html_info, _txt2img_html_info_formatted, txt2img_html_log = ui_common.create_output_panel("txt2img", preview=True, prompt=txt2img_prompt) ui_common.connect_reuse_seed(seed, reuse_seed, txt2img_generation_info, is_subseed=False) - ui_common.connect_reuse_seed(subseed, reuse_subseed, txt2img_generation_info, is_subseed=True) + ui_common.connect_reuse_seed(subseed, reuse_subseed, txt2img_generation_info, is_subseed=True, subseed_strength=subseed_strength) dummy_component = gr.Textbox(visible=False, value='dummy') txt2img_args = [ diff --git a/wiki b/wiki index 04cfbf213..b308811ab 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 04cfbf2132c6d5f5e5f5e5667934694e7dd36dd3 +Subproject commit b308811ab96e6eec771155c59bb295bebb6740df