mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-02-09 09:29:57 +00:00
Improve options management (#2078)
- `/sdapi/v1/options` GET now calls `get_config()` from **sysinfo** module, instead of from its own version of the function. - Defined a new, flexible and more robust `set_config()` function in **sysinfo** module, which: - obsoletes redundant code - skips updating values that are unchanged - has flexible args for both API and UI use - `/sdapi/v1/options` POST and `override_settings` now use the new `set_config()` function. `set_config()` could possibly obsolete additional functions, but I'm not going to get into that just yet. - Options for `forge_additional_modules` can now be provided either as the file path, or just the module name. - Most importantly, `refresh_model_loading_parameters()` is now only called ONCE per request, and **only** if necessary. - It is now much easier to call `shared.opts.save()` as needed
This commit is contained in:
@@ -239,28 +239,35 @@ def refresh_model_loading_parameters():
|
||||
return
|
||||
|
||||
|
||||
def checkpoint_change(ckpt_name, refresh_params=True):
|
||||
def checkpoint_change(ckpt_name:str, save=True, refresh=True):
|
||||
shared.opts.set('sd_model_checkpoint', ckpt_name)
|
||||
shared.opts.save(shared.config_filename)
|
||||
|
||||
if refresh_params:
|
||||
if save:
|
||||
shared.opts.save(shared.config_filename)
|
||||
if refresh:
|
||||
refresh_model_loading_parameters()
|
||||
return
|
||||
|
||||
|
||||
def modules_change(module_names, refresh_params=True):
|
||||
def modules_change(module_values:list, save=True, refresh=True) -> bool:
|
||||
""" module values may be provided as file paths or as simply the module names """
|
||||
modules = []
|
||||
|
||||
for n in module_names:
|
||||
if n in module_list:
|
||||
modules.append(module_list[n])
|
||||
for v in module_values:
|
||||
module_name = os.path.basename(v) # If the input is a filepath, extract the file name
|
||||
if module_name in module_list:
|
||||
modules.append(module_list[module_name])
|
||||
|
||||
# skip further processing if value unchanged
|
||||
if modules == shared.opts.data.get('forge_additional_modules'):
|
||||
return False
|
||||
|
||||
shared.opts.set('forge_additional_modules', modules)
|
||||
shared.opts.save(shared.config_filename)
|
||||
|
||||
if refresh_params:
|
||||
if save:
|
||||
shared.opts.save(shared.config_filename)
|
||||
if refresh:
|
||||
refresh_model_loading_parameters()
|
||||
return
|
||||
return True
|
||||
|
||||
|
||||
def get_a1111_ui_component(tab, label):
|
||||
|
||||
Reference in New Issue
Block a user