diff --git a/sd_dynamic_prompts/dynamic_prompting.py b/sd_dynamic_prompts/dynamic_prompting.py index f8367425..5f029982 100644 --- a/sd_dynamic_prompts/dynamic_prompting.py +++ b/sd_dynamic_prompts/dynamic_prompting.py @@ -12,7 +12,7 @@ from dynamicprompts.generators.promptgenerator import GeneratorException from dynamicprompts.parser.parse import ParserConfig from dynamicprompts.wildcards import WildcardManager -from modules.processing import fix_seed +from modules.processing import fix_seed, create_infotext from modules.shared import opts from sd_dynamic_prompts import __version__, callbacks @@ -517,10 +517,22 @@ def process( if opts.dp_write_raw_template: params = p.extra_generation_params - if original_prompt: - params["Template"] = original_prompt - if original_negative_prompt: - params["Negative Template"] = original_negative_prompt + + first_time_only = params.get("Dynamic Prompts") is None + + params["Dynamic Prompts"] = { + "use_fixed_seed": use_fixed_seed, + "unlink_seed_from_prompt": unlink_seed_from_prompt, + "enable_jinja_templates": enable_jinja_templates, + } + + if first_time_only: + def _lazy_params(k1: str, v1, v2): + if k1 not in params and v1 != v2: + params[k1] = v1 + + _lazy_params("Template", original_prompt, all_prompts[0]) + _lazy_params("Negative Template", original_negative_prompt, all_negative_prompts[0]) p.all_prompts = all_prompts p.all_negative_prompts = all_negative_prompts @@ -545,5 +557,54 @@ def process( original_negative_prompt, ) + def process_batch(selfself, p, *args, **kwargs): + batch_number = kwargs.get('batch_number') + prompts = kwargs.get('prompts') + + def _lazy_params(params, k1: str, v1, k2: str): + v2 = params.get(k2) + if v2 is not None and v1 != v2: + params[k1] = v1 + + _lazy_params(p.extra_generation_params, "Template Generated", prompts[0], "Template") + _lazy_params(p.extra_generation_params, "Negative Template Generated", p.all_negative_prompts[batch_number], "Negative Template") + + p.extra_generation_params["Template Seeds"] = kwargs.get('seeds') + p.extra_generation_params["Template Seeds Sub"] = kwargs.get('subseeds') + + def postprocess( + self, + p, + res, + *args, + **kwargs + ): + index_of_first_image = res.index_of_first_image + infotexts = res.infotexts + + if index_of_first_image != 0: + images = res.images + + grid = images[index_of_first_image-1] + + def _lazy_params(params, k1: str, v1: list, k2: str): + v2 = params.get(k2) + if v2 is not None and v1[0] != v2: + params[k1] = v1 + + res.extra_generation_params.pop("Template Generated", None) + res.extra_generation_params.pop("Negative Template Generated", None) + + _lazy_params(res.extra_generation_params, "Template Generated Grid", res.all_prompts, "Template") + _lazy_params(res.extra_generation_params, "Negative Template Generated Grid", res.all_negative_prompts, + "Negative Template") + + text = create_infotext(p, res.all_prompts, res.all_seeds, res.all_subseeds, use_main_prompt=True, + all_negative_prompts=res.all_negative_prompts) + grid.info["parameters"] = text + + infotexts.pop(index_of_first_image-1) + infotexts.insert(index_of_first_image-1, text) + callbacks.register_settings() # Settings need to be registered early, see #754. diff --git a/sd_dynamic_prompts/wildcards_tab.py b/sd_dynamic_prompts/wildcards_tab.py index 105928ea..68f278f2 100644 --- a/sd_dynamic_prompts/wildcards_tab.py +++ b/sd_dynamic_prompts/wildcards_tab.py @@ -74,17 +74,12 @@ def on_ui_tabs():
  • Use the wildcard in your script by typing the name of the file or copying the text from the Wildcards file text box.
  • You can also add your own wildcard files to the {wildcard_manager.path} folder.
  • + """ with gr.Blocks() as wildcards_tab: with gr.Row(): with gr.Column(): - gr.Textbox( - placeholder="Search in wildcard names...", - elem_id=make_element_id("wildcard-search"), - label="", - ) - gr.HTML("Loading...", elem_id=make_element_id("wildcard-tree")) with gr.Accordion("Help", open=False): gr.HTML(help_html) with gr.Accordion("Collection actions", open=False): @@ -111,6 +106,12 @@ def on_ui_tabs(): "Delete all wildcards", elem_id=make_element_id("wildcard-delete-tree-button"), ) + gr.Textbox( + placeholder="Search in wildcard names...", + elem_id=make_element_id("wildcard-search"), + label="", + ) + gr.HTML("Loading...", elem_id=make_element_id("wildcard-tree")) with gr.Column(): gr.Textbox( "", @@ -127,7 +128,7 @@ def on_ui_tabs(): ) save_button = gr.Button( "Save wildcards", - scale=1, + # scale=1, elem_id=make_element_id("wildcard-save-button"), ) @@ -180,7 +181,6 @@ def on_ui_tabs(): inputs=[overwrite_checkbox, collection_dropdown], outputs=[server_to_client_message_textbox], ) - return ((wildcards_tab, "Wildcards Manager", "sddp-wildcard-manager"),)