diff options
author | AUTOMATIC <16777216c@gmail.com> | 2023-01-03 15:38:21 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2023-01-03 15:38:21 +0000 |
commit | 2d5a5076bb2a0c05cc27d75a1bcadab7f32a46d0 (patch) | |
tree | 165ffb66d455c06ef1ffae8f2a41390ca10b3004 | |
parent | e9fb9bb0c25f59109a816fc53c385bed58965c24 (diff) | |
download | stable-diffusion-webui-gfx803-2d5a5076bb2a0c05cc27d75a1bcadab7f32a46d0.tar.gz stable-diffusion-webui-gfx803-2d5a5076bb2a0c05cc27d75a1bcadab7f32a46d0.tar.bz2 stable-diffusion-webui-gfx803-2d5a5076bb2a0c05cc27d75a1bcadab7f32a46d0.zip |
Make it so that upscalers are not repeated when restarting UI.
-rw-r--r-- | modules/modelloader.py | 20 | ||||
-rw-r--r-- | webui.py | 14 |
2 files changed, 27 insertions, 7 deletions
diff --git a/modules/modelloader.py b/modules/modelloader.py index e647f6fa..6a1a7ac8 100644 --- a/modules/modelloader.py +++ b/modules/modelloader.py @@ -123,6 +123,23 @@ def move_files(src_path: str, dest_path: str, ext_filter: str = None): pass +builtin_upscaler_classes = [] +forbidden_upscaler_classes = set() + + +def list_builtin_upscalers(): + load_upscalers() + + builtin_upscaler_classes.clear() + builtin_upscaler_classes.extend(Upscaler.__subclasses__()) + + +def forbid_loaded_nonbuiltin_upscalers(): + for cls in Upscaler.__subclasses__(): + if cls not in builtin_upscaler_classes: + forbidden_upscaler_classes.add(cls) + + def load_upscalers(): # We can only do this 'magic' method to dynamically load upscalers if they are referenced, # so we'll try to import any _model.py files before looking in __subclasses__ @@ -139,6 +156,9 @@ def load_upscalers(): datas = [] commandline_options = vars(shared.cmd_opts) for cls in Upscaler.__subclasses__(): + if cls in forbidden_upscaler_classes: + continue + name = cls.__name__ cmd_name = f"{name.lower().replace('upscaler', '')}_models_path" scaler = cls(commandline_options.get(cmd_name, None)) @@ -1,4 +1,5 @@ import os
+import sys
import threading
import time
import importlib
@@ -55,8 +56,8 @@ def initialize(): gfpgan.setup_model(cmd_opts.gfpgan_models_path)
shared.face_restorers.append(modules.face_restoration.FaceRestoration())
+ modelloader.list_builtin_upscalers()
modules.scripts.load_scripts()
-
modelloader.load_upscalers()
modules.sd_vae.refresh_vae_list()
@@ -169,23 +170,22 @@ def webui(): modules.script_callbacks.app_started_callback(shared.demo, app)
wait_on_server(shared.demo)
+ print('Restarting UI...')
sd_samplers.set_samplers()
- print('Reloading extensions')
extensions.list_extensions()
localization.list_localizations(cmd_opts.localizations_dir)
- print('Reloading custom scripts')
+ modelloader.forbid_loaded_nonbuiltin_upscalers()
modules.scripts.reload_scripts()
modelloader.load_upscalers()
- print('Reloading modules: modules.ui')
- importlib.reload(modules.ui)
- print('Refreshing Model List')
+ for module in [module for name, module in sys.modules.items() if name.startswith("modules.ui")]:
+ importlib.reload(module)
+
modules.sd_models.list_models()
- print('Restarting Gradio')
if __name__ == "__main__":
|