fix restore variation seed for txt2img and img2img

This commit is contained in:
Vladimir Mandic
2024-06-01 07:31:00 -04:00
parent fdb5e240c6
commit 2bcada4755
7 changed files with 21 additions and 15 deletions
+2 -1
View File
@@ -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
-1
View File
@@ -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:
+15 -9
View File
@@ -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):
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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 = [
+1 -1
Submodule wiki updated: 04cfbf2132...b308811ab9