From 333cc6db508780b70af2c6ab09b087cb78fa74a2 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sun, 30 Jun 2024 20:19:18 +0200 Subject: [PATCH] feat: add config default_inpaint_method, reload on start and preset change --- modules/config.py | 9 ++++++++- modules/meta_parser.py | 12 ++++++++++++ presets/pony_v6.json | 1 + webui.py | 14 +++++++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/modules/config.py b/modules/config.py index bc9744e6..f7fc7e04 100644 --- a/modules/config.py +++ b/modules/config.py @@ -466,6 +466,12 @@ default_inpaint_engine_version = get_config_item_or_set_default( validator=lambda x: x in modules.flags.inpaint_engine_versions, expected_type=str ) +default_inpaint_method = get_config_item_or_set_default( + key='default_inpaint_method', + default_value=modules.flags.inpaint_option_default, + validator=lambda x: x in modules.flags.inpaint_options, + expected_type=str +) default_cfg_tsnr = get_config_item_or_set_default( key='default_cfg_tsnr', default_value=7.0, @@ -553,7 +559,8 @@ possible_preset_keys = { "checkpoint_downloads": "checkpoint_downloads", "embeddings_downloads": "embeddings_downloads", "lora_downloads": "lora_downloads", - "default_vae": "vae" + "default_vae": "vae", + "default_inpaint_method": "inpaint_method" } REWRITE_PRESET = False diff --git a/modules/meta_parser.py b/modules/meta_parser.py index ff930cc0..e5ba765f 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_method('inpaint_method', 'Inpaint Mode', loaded_parameter_dict, results) if is_generating: results.append(gr.update()) @@ -160,6 +161,17 @@ def get_seed(key: str, fallback: str | None, source_dict: dict, results: list, d results.append(gr.update()) +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)) + assert isinstance(h, str) and h in modules.flags.inpaint_options + results.append(h) + return h + except: + results.append(gr.update()) + return None + + def get_adm_guidance(key: str, fallback: str | None, source_dict: dict, results: list, default=None): try: h = source_dict.get(key, source_dict.get(fallback, default)) diff --git a/presets/pony_v6.json b/presets/pony_v6.json index f28064b8..8a3a962a 100644 --- a/presets/pony_v6.json +++ b/presets/pony_v6.json @@ -42,6 +42,7 @@ ], "default_aspect_ratio": "896*1152", "default_overwrite_step": -1, + "default_inpaint_method": "Improve Detail (face, hand, eyes, etc.)", "checkpoint_downloads": { "ponyDiffusionV6XL.safetensors": "https://huggingface.co/mashb1t/fav_models/resolve/main/fav/ponyDiffusionV6XL.safetensors" }, diff --git a/webui.py b/webui.py index fa98387c..d8e5ffe4 100644 --- a/webui.py +++ b/webui.py @@ -207,7 +207,7 @@ with shared.gradio_root: with gr.Row(): inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False) outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction') - inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method') + inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.config.default_inpaint_method, label='Method') example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False) gr.HTML('* Powered by Fooocus Inpaint Engine \U0001F4D4 Document') example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False) @@ -589,7 +589,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, generate_button, load_parameter_button] + freeu_ctrls + lora_ctrls + seed_random, image_seed, 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): @@ -658,7 +659,14 @@ with shared.gradio_root: False, modules.config.default_inpaint_engine_version, 1.0, 0.618 ] - inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[ + inpaint_mode.change(inpaint_mode_change, inputs=inpaint_mode, 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=[ inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field