2024-03-10 19:07:51 +08:00
|
|
|
import html
|
2023-08-09 15:25:35 +08:00
|
|
|
import sys
|
|
|
|
|
2024-03-10 19:07:51 +08:00
|
|
|
from modules import script_callbacks, scripts, ui_components
|
|
|
|
from modules.options import OptionHTML, OptionInfo
|
2023-08-09 15:25:35 +08:00
|
|
|
from modules.shared_cmd_options import cmd_opts
|
2023-01-27 04:29:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
def realesrgan_models_names():
|
|
|
|
import modules.realesrgan_model
|
|
|
|
return [x.name for x in modules.realesrgan_model.get_realesrgan_models(None)]
|
|
|
|
|
2023-01-27 16:28:12 +08:00
|
|
|
|
2024-01-19 07:10:02 +08:00
|
|
|
def dat_models_names():
|
|
|
|
import modules.dat_model
|
|
|
|
return [x.name for x in modules.dat_model.get_dat_models(None)]
|
|
|
|
|
|
|
|
|
2023-01-27 04:29:27 +08:00
|
|
|
def postprocessing_scripts():
|
|
|
|
import modules.scripts
|
|
|
|
|
2023-01-27 16:28:12 +08:00
|
|
|
return modules.scripts.scripts_postproc.scripts
|
|
|
|
|
|
|
|
|
|
|
|
def sd_vae_items():
|
|
|
|
import modules.sd_vae
|
|
|
|
|
|
|
|
return ["Automatic", "None"] + list(modules.sd_vae.vae_dict)
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_vae_list():
|
|
|
|
import modules.sd_vae
|
|
|
|
|
2023-02-19 17:23:40 +08:00
|
|
|
modules.sd_vae.refresh_vae_list()
|
2023-05-19 03:48:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
def cross_attention_optimizations():
|
|
|
|
import modules.sd_hijack
|
|
|
|
|
|
|
|
return ["Automatic"] + [x.title() for x in modules.sd_hijack.optimizers] + ["None"]
|
|
|
|
|
|
|
|
|
2023-05-27 20:47:33 +08:00
|
|
|
def sd_unet_items():
|
|
|
|
import modules.sd_unet
|
|
|
|
|
|
|
|
return ["Automatic"] + [x.label for x in modules.sd_unet.unet_options] + ["None"]
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_unet_list():
|
|
|
|
import modules.sd_unet
|
|
|
|
|
|
|
|
modules.sd_unet.list_unets()
|
|
|
|
|
2023-06-01 01:31:17 +08:00
|
|
|
|
2023-09-08 09:00:27 +08:00
|
|
|
def list_checkpoint_tiles(use_short=False):
|
2023-08-09 15:25:35 +08:00
|
|
|
import modules.sd_models
|
2023-09-08 09:00:27 +08:00
|
|
|
return modules.sd_models.checkpoint_tiles(use_short)
|
2023-08-09 15:25:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
def refresh_checkpoints():
|
|
|
|
import modules.sd_models
|
|
|
|
return modules.sd_models.list_models()
|
|
|
|
|
|
|
|
|
|
|
|
def list_samplers():
|
|
|
|
import modules.sd_samplers
|
|
|
|
return modules.sd_samplers.all_samplers
|
|
|
|
|
|
|
|
|
|
|
|
def reload_hypernetworks():
|
|
|
|
from modules.hypernetworks import hypernetwork
|
|
|
|
from modules import shared
|
|
|
|
|
|
|
|
shared.hypernetworks = hypernetwork.list_hypernetworks(cmd_opts.hypernetwork_dir)
|
|
|
|
|
|
|
|
|
2023-12-02 13:33:28 +08:00
|
|
|
def get_infotext_names():
|
2024-01-01 22:25:30 +08:00
|
|
|
from modules import infotext_utils, shared
|
2023-12-02 13:33:28 +08:00
|
|
|
res = {}
|
|
|
|
|
|
|
|
for info in shared.opts.data_labels.values():
|
|
|
|
if info.infotext:
|
|
|
|
res[info.infotext] = 1
|
|
|
|
|
2024-01-01 22:25:30 +08:00
|
|
|
for tab_data in infotext_utils.paste_fields.values():
|
2023-12-02 13:33:28 +08:00
|
|
|
for _, name in tab_data.get("fields") or []:
|
|
|
|
if isinstance(name, str):
|
|
|
|
res[name] = 1
|
|
|
|
|
|
|
|
return list(res)
|
|
|
|
|
|
|
|
|
2023-06-01 01:31:17 +08:00
|
|
|
ui_reorder_categories_builtin_items = [
|
2023-11-06 00:19:55 +08:00
|
|
|
"prompt",
|
|
|
|
"image",
|
2023-06-01 01:31:17 +08:00
|
|
|
"inpaint",
|
|
|
|
"sampler",
|
2023-08-12 17:39:59 +08:00
|
|
|
"accordions",
|
2023-06-01 01:31:17 +08:00
|
|
|
"checkboxes",
|
|
|
|
"dimensions",
|
|
|
|
"cfg",
|
2023-08-12 22:46:13 +08:00
|
|
|
"denoising",
|
2023-06-01 01:31:17 +08:00
|
|
|
"seed",
|
|
|
|
"batch",
|
|
|
|
"override_settings",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def ui_reorder_categories():
|
2023-06-01 03:40:09 +08:00
|
|
|
from modules import scripts
|
|
|
|
|
2023-06-01 01:31:17 +08:00
|
|
|
yield from ui_reorder_categories_builtin_items
|
2023-06-01 03:40:09 +08:00
|
|
|
|
|
|
|
sections = {}
|
|
|
|
for script in scripts.scripts_txt2img.scripts + scripts.scripts_img2img.scripts:
|
2023-08-12 17:39:59 +08:00
|
|
|
if isinstance(script.section, str) and script.section not in ui_reorder_categories_builtin_items:
|
2023-06-01 03:40:09 +08:00
|
|
|
sections[script.section] = 1
|
|
|
|
|
|
|
|
yield from sections
|
|
|
|
|
2023-06-01 01:31:17 +08:00
|
|
|
yield "scripts"
|
2023-08-09 15:25:35 +08:00
|
|
|
|
|
|
|
|
2024-03-10 19:07:51 +08:00
|
|
|
def callbacks_order_settings():
|
|
|
|
options = {
|
|
|
|
"sd_vae_explanation": OptionHTML("""
|
|
|
|
For categories below, callbacks added to dropdowns happen before others, in order listed.
|
|
|
|
"""),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
callback_options = {}
|
|
|
|
|
|
|
|
for category, _ in script_callbacks.enumerate_callbacks():
|
|
|
|
callback_options[category] = script_callbacks.ordered_callbacks(category, enable_user_sort=False)
|
|
|
|
|
|
|
|
for method_name in scripts.scripts_txt2img.callback_names:
|
|
|
|
callback_options["script_" + method_name] = scripts.scripts_txt2img.create_ordered_callbacks_list(method_name, enable_user_sort=False)
|
|
|
|
|
|
|
|
for method_name in scripts.scripts_img2img.callback_names:
|
|
|
|
callbacks = callback_options.get("script_" + method_name, [])
|
|
|
|
|
|
|
|
for addition in scripts.scripts_img2img.create_ordered_callbacks_list(method_name, enable_user_sort=False):
|
|
|
|
if any(x.name == addition.name for x in callbacks):
|
|
|
|
continue
|
|
|
|
|
|
|
|
callbacks.append(addition)
|
|
|
|
|
|
|
|
callback_options["script_" + method_name] = callbacks
|
|
|
|
|
|
|
|
for category, callbacks in callback_options.items():
|
|
|
|
if not callbacks:
|
|
|
|
continue
|
|
|
|
|
|
|
|
option_info = OptionInfo([], f"{category} callback priority", ui_components.DropdownMulti, {"choices": [x.name for x in callbacks]})
|
|
|
|
option_info.needs_restart()
|
|
|
|
option_info.html("<div class='info'>Default order: <ol>" + "".join(f"<li>{html.escape(x.name)}</li>\n" for x in callbacks) + "</ol></div>")
|
|
|
|
options['prioritized_callbacks_' + category] = option_info
|
|
|
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
|
2023-08-09 15:25:35 +08:00
|
|
|
class Shared(sys.modules[__name__].__class__):
|
|
|
|
"""
|
|
|
|
this class is here to provide sd_model field as a property, so that it can be created and loaded on demand rather than
|
|
|
|
at program startup.
|
|
|
|
"""
|
|
|
|
|
|
|
|
sd_model_val = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sd_model(self):
|
|
|
|
import modules.sd_models
|
|
|
|
|
|
|
|
return modules.sd_models.model_data.get_sd_model()
|
|
|
|
|
|
|
|
@sd_model.setter
|
|
|
|
def sd_model(self, value):
|
|
|
|
import modules.sd_models
|
|
|
|
|
|
|
|
modules.sd_models.model_data.set_sd_model(value)
|
|
|
|
|
|
|
|
|
|
|
|
sys.modules['modules.shared'].__class__ = Shared
|