Support saving last model of inpainting webui
parent
1bb082803c
commit
1a20d073f8
53
ia_config.py
53
ia_config.py
|
|
@ -54,19 +54,26 @@ def setup_ia_config_ini():
|
|||
if os.path.isfile(IAConfig.PATHS.INI):
|
||||
ia_config_ini.read(IAConfig.PATHS.INI, encoding="utf-8")
|
||||
|
||||
changed = False
|
||||
for key, ids_info in ia_config.ids_dict.items():
|
||||
if not ia_config_ini.has_option(IAConfig.SECTIONS.DEFAULT, key):
|
||||
if len(ids_info["list"]) > ids_info["index"]:
|
||||
ia_config_ini[IAConfig.SECTIONS.DEFAULT][key] = ids_info["list"][ids_info["index"]]
|
||||
changed = True
|
||||
else:
|
||||
if len(ids_info["list"]) > ids_info["index"] and ia_config_ini[IAConfig.SECTIONS.DEFAULT][key] != ids_info["list"][ids_info["index"]]:
|
||||
ia_config_ini[IAConfig.SECTIONS.DEFAULT][key] = ids_info["list"][ids_info["index"]]
|
||||
changed = True
|
||||
|
||||
with open(IAConfig.PATHS.INI, "w", encoding="utf-8") as f:
|
||||
ia_config_ini.write(f)
|
||||
if changed:
|
||||
with open(IAConfig.PATHS.INI, "w", encoding="utf-8") as f:
|
||||
ia_config_ini.write(f)
|
||||
|
||||
|
||||
def get_ia_config(key, section=IAConfig.SECTIONS.DEFAULT):
|
||||
setup_ia_config_ini()
|
||||
|
||||
ia_config_ini = configparser.ConfigParser()
|
||||
ia_config_ini = configparser.ConfigParser(defaults={})
|
||||
ia_config_ini.read(IAConfig.PATHS.INI, encoding="utf-8")
|
||||
|
||||
if ia_config_ini.has_option(section, key):
|
||||
|
|
@ -82,29 +89,32 @@ def get_ia_config(key, section=IAConfig.SECTIONS.DEFAULT):
|
|||
def get_ia_config_index(key, section=IAConfig.SECTIONS.DEFAULT):
|
||||
value = get_ia_config(key, section)
|
||||
|
||||
ids_dict = ia_config.ids_dict
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if key in ia_config.ids_dict.keys():
|
||||
ids_info = ia_config.ids_dict[key]
|
||||
idx = ids_info["list"].index(value) if value in ids_info["list"] else ids_info["index"]
|
||||
|
||||
return idx
|
||||
|
||||
return None
|
||||
if key in ids_dict.keys():
|
||||
ids_info = ids_dict[key]
|
||||
return ids_info["index"]
|
||||
else:
|
||||
return 0
|
||||
else:
|
||||
if key in ids_dict.keys():
|
||||
ids_info = ids_dict[key]
|
||||
return ids_info["list"].index(value) if value in ids_info["list"] else ids_info["index"]
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def set_ia_config(key, value, section=IAConfig.SECTIONS.DEFAULT):
|
||||
setup_ia_config_ini()
|
||||
|
||||
ia_config_ini = configparser.ConfigParser()
|
||||
ia_config_ini = configparser.ConfigParser(defaults={})
|
||||
ia_config_ini.read(IAConfig.PATHS.INI, encoding="utf-8")
|
||||
|
||||
if ia_config_ini.has_option(section, key) and ia_config_ini[section][key] == value:
|
||||
return
|
||||
|
||||
if section != IAConfig.SECTIONS.DEFAULT and not ia_config_ini.has_section(section):
|
||||
ia_config_ini[section] = {}
|
||||
else:
|
||||
if ia_config_ini.has_option(section, key) and ia_config_ini[section][key] == value:
|
||||
return
|
||||
|
||||
try:
|
||||
ia_config_ini[section][key] = value
|
||||
|
|
@ -120,13 +130,12 @@ def set_ia_config(key, value, section=IAConfig.SECTIONS.DEFAULT):
|
|||
with open(IAConfig.PATHS.WEBUI_CONFIG, "r", encoding="utf-8") as f:
|
||||
webui_config = json.load(f)
|
||||
|
||||
if key in ia_config.webui_keys.keys():
|
||||
webui_key = ia_config.webui_keys[key]
|
||||
if webui_key in webui_config.keys():
|
||||
webui_config[webui_key] = value
|
||||
webui_keys = ia_config.webui_keys
|
||||
if key in webui_keys.keys() and webui_keys[key] in webui_config.keys():
|
||||
webui_config[webui_keys[key]] = value
|
||||
|
||||
with open(IAConfig.PATHS.WEBUI_CONFIG, "w", encoding="utf-8") as f:
|
||||
json.dump(webui_config, f, indent=4)
|
||||
with open(IAConfig.PATHS.WEBUI_CONFIG, "w", encoding="utf-8") as f:
|
||||
json.dump(webui_config, f, indent=4)
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -719,6 +719,8 @@ def run_webui_inpaint(input_image, sel_mask,
|
|||
yield ret_image
|
||||
return
|
||||
|
||||
set_ia_config(IAConfig.KEYS.INP_WEBUI_MODEL_ID, webui_model_id, IAConfig.SECTIONS.USER)
|
||||
|
||||
save_mask_image(mask_image, webui_save_mask_chk)
|
||||
|
||||
info = get_closet_checkpoint_match(webui_model_id)
|
||||
|
|
@ -793,10 +795,8 @@ def on_ui_tabs():
|
|||
sampler_names = get_sampler_names()
|
||||
sam_model_ids = get_sam_model_ids()
|
||||
sam_model_index = get_ia_config_index(IAConfig.KEYS.SAM_MODEL_ID, IAConfig.SECTIONS.USER)
|
||||
sam_model_index = sam_model_index if sam_model_index is not None else 1
|
||||
inp_model_ids = get_inp_model_ids()
|
||||
inp_model_index = get_ia_config_index(IAConfig.KEYS.INP_MODEL_ID, IAConfig.SECTIONS.USER)
|
||||
inp_model_index = inp_model_index if inp_model_index is not None else 0
|
||||
cleaner_model_ids = get_cleaner_model_ids()
|
||||
padding_mode_names = get_padding_mode_names()
|
||||
sam_dict["cnet"] = find_controlnet()
|
||||
|
|
@ -828,6 +828,7 @@ def on_ui_tabs():
|
|||
webui_model_ids = get_inp_webui_model_ids()
|
||||
if len(webui_model_ids) > 0:
|
||||
webui_inpaint_enabled = True
|
||||
webui_model_index = get_ia_config_index(IAConfig.KEYS.INP_WEBUI_MODEL_ID, IAConfig.SECTIONS.USER)
|
||||
|
||||
if samplers_for_img2img is not None and len(samplers_for_img2img) > 0:
|
||||
webui_sampler_ids = [sampler.name for sampler in samplers_for_img2img]
|
||||
|
|
@ -979,7 +980,7 @@ def on_ui_tabs():
|
|||
with gr.Row():
|
||||
with gr.Column():
|
||||
webui_model_id = gr.Dropdown(label="Inpainting Model ID webui", elem_id="webui_model_id",
|
||||
choices=webui_model_ids, value=webui_model_ids[0], show_label=True)
|
||||
choices=webui_model_ids, value=webui_model_ids[webui_model_index], show_label=True)
|
||||
with gr.Column():
|
||||
with gr.Row():
|
||||
webui_inpaint_btn = gr.Button("Run Inpainting", elem_id="webui_inpaint_btn", variant="primary")
|
||||
|
|
|
|||
Loading…
Reference in New Issue