From 33c22929e4f0965862e4957cc6ba4d99d4324515 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Mon, 1 Jul 2024 22:08:52 +0200 Subject: [PATCH] feat: add preset option for default_inpaint_engine_version, revert previous overwrite_step changes add handling with state to allow overrides with inpaint_mode preset setting (currently disabled) --- modules/config.py | 5 +++-- modules/meta_parser.py | 14 ++++++++++++++ presets/anime.json | 1 - presets/default.json | 1 - presets/lcm.json | 1 - presets/playground_v2.5.json | 3 +-- presets/pony_v6.json | 4 ++-- presets/realistic.json | 1 - presets/sai.json | 1 - webui.py | 17 ++++++++++------- 10 files changed, 30 insertions(+), 18 deletions(-) diff --git a/modules/config.py b/modules/config.py index cbc919ec..9c5272f5 100644 --- a/modules/config.py +++ b/modules/config.py @@ -533,7 +533,7 @@ example_inpaint_prompts = [[x] for x in example_inpaint_prompts] config_dict["default_loras"] = default_loras = default_loras[:default_max_lora_number] + [[True, 'None', 1.0] for _ in range(default_max_lora_number - len(default_loras))] -# mapping config to meta parameter +# mapping config to meta parameter possible_preset_keys = { "default_model": "base_model", "default_refiner": "refiner_model", @@ -562,7 +562,8 @@ possible_preset_keys = { "lora_downloads": "lora_downloads", "vae_downloads": "vae_downloads", "default_vae": "vae", - "default_inpaint_method": "inpaint_method" + # "default_inpaint_method": "inpaint_method", # disabled so inpaint mode doesn't refresh after every preset change + "default_inpaint_engine_version": "inpaint_engine_version", } REWRITE_PRESET = False diff --git a/modules/meta_parser.py b/modules/meta_parser.py index e5ba765f..628ec402 100644 --- a/modules/meta_parser.py +++ b/modules/meta_parser.py @@ -49,6 +49,7 @@ def load_parameter_button_click(raw_metadata: dict | str, is_generating: bool): get_str('scheduler', 'Scheduler', loaded_parameter_dict, results) get_str('vae', 'VAE', loaded_parameter_dict, results) get_seed('seed', 'Seed', loaded_parameter_dict, results) + get_inpaint_engine_version('inpaint_engine_version', 'Inpaint Engine Version', loaded_parameter_dict, results) get_inpaint_method('inpaint_method', 'Inpaint Mode', loaded_parameter_dict, results) if is_generating: @@ -161,6 +162,19 @@ def get_seed(key: str, fallback: str | None, source_dict: dict, results: list, d results.append(gr.update()) +def get_inpaint_engine_version(key: str, fallback: str | None, source_dict: dict, results: list, default=None) -> str | None: + try: + h = source_dict.get(key, source_dict.get(fallback, default)) + assert isinstance(h, str) and h in modules.flags.inpaint_engine_versions + results.append(h) + results.append(h) + return h + except: + results.append(gr.update()) + results.append('empty') + return None + + def get_inpaint_method(key: str, fallback: str | None, source_dict: dict, results: list, default=None) -> str | None: try: h = source_dict.get(key, source_dict.get(fallback, default)) diff --git a/presets/anime.json b/presets/anime.json index 7bcaad89..debfeb84 100644 --- a/presets/anime.json +++ b/presets/anime.json @@ -43,7 +43,6 @@ ], "default_aspect_ratio": "896*1152", "default_overwrite_step": -1, - "default_overwrite_switch": -1, "checkpoint_downloads": { "animaPencilXL_v310.safetensors": "https://huggingface.co/mashb1t/fav_models/resolve/main/fav/animaPencilXL_v310.safetensors" }, diff --git a/presets/default.json b/presets/default.json index 0a1ad863..e9aa2b62 100644 --- a/presets/default.json +++ b/presets/default.json @@ -43,7 +43,6 @@ ], "default_aspect_ratio": "1152*896", "default_overwrite_step": -1, - "default_overwrite_switch": -1, "checkpoint_downloads": { "juggernautXL_v8Rundiffusion.safetensors": "https://huggingface.co/lllyasviel/fav_models/resolve/main/fav/juggernautXL_v8Rundiffusion.safetensors" }, diff --git a/presets/lcm.json b/presets/lcm.json index cca37956..441cbdc8 100644 --- a/presets/lcm.json +++ b/presets/lcm.json @@ -43,7 +43,6 @@ ], "default_aspect_ratio": "1152*896", "default_overwrite_step": -1, - "default_overwrite_switch": -1, "checkpoint_downloads": { "juggernautXL_v8Rundiffusion.safetensors": "https://huggingface.co/lllyasviel/fav_models/resolve/main/fav/juggernautXL_v8Rundiffusion.safetensors" }, diff --git a/presets/playground_v2.5.json b/presets/playground_v2.5.json index 34fa29b6..ac28c260 100644 --- a/presets/playground_v2.5.json +++ b/presets/playground_v2.5.json @@ -41,8 +41,7 @@ ], "default_aspect_ratio": "1024*1024", "default_overwrite_step": -1, - "default_overwrite_switch": -1, - "default_inpaint_method": "Improve Detail (face, hand, eyes, etc.)", + "default_inpaint_engine_version": "None", "checkpoint_downloads": { "playground-v2.5-1024px-aesthetic.fp16.safetensors": "https://huggingface.co/mashb1t/fav_models/resolve/main/fav/playground-v2.5-1024px-aesthetic.fp16.safetensors" }, diff --git a/presets/pony_v6.json b/presets/pony_v6.json index b5230f89..549d7c52 100644 --- a/presets/pony_v6.json +++ b/presets/pony_v6.json @@ -1,7 +1,7 @@ { "default_model": "ponyDiffusionV6XL.safetensors", "default_refiner": "None", - "default_refiner_switch": 1, + "default_refiner_switch": 0.5, "default_vae": "ponyDiffusionV6XL_vae.safetensors", "default_loras": [ [ @@ -42,7 +42,7 @@ ], "default_aspect_ratio": "896*1152", "default_overwrite_step": -1, - "default_overwrite_switch": 999, + "default_inpaint_engine_version": "None", "checkpoint_downloads": { "ponyDiffusionV6XL.safetensors": "https://huggingface.co/mashb1t/fav_models/resolve/main/fav/ponyDiffusionV6XL.safetensors" }, diff --git a/presets/realistic.json b/presets/realistic.json index 33d66702..f2d4773f 100644 --- a/presets/realistic.json +++ b/presets/realistic.json @@ -43,7 +43,6 @@ ], "default_aspect_ratio": "896*1152", "default_overwrite_step": -1, - "default_overwrite_switch": -1, "checkpoint_downloads": { "realisticStockPhoto_v20.safetensors": "https://huggingface.co/lllyasviel/fav_models/resolve/main/fav/realisticStockPhoto_v20.safetensors" }, diff --git a/presets/sai.json b/presets/sai.json index 9bfed082..21146311 100644 --- a/presets/sai.json +++ b/presets/sai.json @@ -42,7 +42,6 @@ ], "default_aspect_ratio": "1152*896", "default_overwrite_step": -1, - "default_overwrite_switch": -1, "checkpoint_downloads": { "sd_xl_base_1.0_0.9vae.safetensors": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors", "sd_xl_refiner_1.0_0.9vae.safetensors": "https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0_0.9vae.safetensors" diff --git a/webui.py b/webui.py index d8e5ffe4..6fd1da7b 100644 --- a/webui.py +++ b/webui.py @@ -100,6 +100,7 @@ shared.gradio_root = gr.Blocks(title=title).queue() with shared.gradio_root: currentTask = gr.State(worker.AsyncTask(args=[])) + inpaint_engine_state = gr.State('empty') with gr.Row(): with gr.Column(scale=2): with gr.Row(): @@ -589,8 +590,8 @@ with shared.gradio_root: overwrite_width, overwrite_height, guidance_scale, sharpness, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, refiner_swap_method, adaptive_cfg, clip_skip, base_model, refiner_model, refiner_switch, sampler_name, scheduler_name, vae_name, - seed_random, image_seed, inpaint_mode, generate_button, load_parameter_button - ] + freeu_ctrls + lora_ctrls + seed_random, image_seed, inpaint_engine, inpaint_engine_state, inpaint_mode, + generate_button, load_parameter_button] + freeu_ctrls + lora_ctrls if not args_manager.args.disable_preset_selection: def preset_selection_change(preset, is_generating): @@ -632,7 +633,7 @@ with shared.gradio_root: queue=False, show_progress=False) \ .then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False) - def inpaint_mode_change(mode): + def inpaint_mode_change(mode, inpaint_engine_version): assert mode in modules.flags.inpaint_options # inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, @@ -645,28 +646,30 @@ with shared.gradio_root: gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts), False, 'None', 0.5, 0.0 ] + if inpaint_engine_version == 'empty': + inpaint_engine_version = modules.config.default_inpaint_engine_version if mode == modules.flags.inpaint_option_modify: return [ gr.update(visible=True), gr.update(visible=False, value=[]), gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts), - True, modules.config.default_inpaint_engine_version, 1.0, 0.0 + True, inpaint_engine_version, 1.0, 0.0 ] return [ gr.update(visible=False, value=''), gr.update(visible=True), gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts), - False, modules.config.default_inpaint_engine_version, 1.0, 0.618 + False, inpaint_engine_version, 1.0, 0.618 ] - inpaint_mode.change(inpaint_mode_change, inputs=inpaint_mode, outputs=[ + inpaint_mode.change(inpaint_mode_change, inputs=[inpaint_mode, inpaint_engine_state], outputs=[ inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field ], show_progress=False, queue=False) # load configured default_inpaint_method - shared.gradio_root.load(inpaint_mode_change, inputs=inpaint_mode, outputs=[ + shared.gradio_root.load(inpaint_mode_change, inputs=[inpaint_mode, inpaint_engine_state], outputs=[ inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field