From 2711e32c2e69473c570bd5c20b82087b90a45a6f Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 18 Apr 2023 09:32:26 -0400 Subject: [PATCH] add script/extension priorty --- TODO.md | 8 ++++ extensions-builtin/ScuNET/.priority | 1 + extensions-builtin/sd-extension-system-info | 2 +- modules/extensions.py | 8 +++- modules/scripts.py | 47 +++++++++++---------- webui.py | 1 + 6 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 extensions-builtin/ScuNET/.priority diff --git a/TODO.md b/TODO.md index ddf91cde2..6db7b5426 100644 --- a/TODO.md +++ b/TODO.md @@ -69,6 +69,13 @@ Complete: - +## Models + +StabilityAI is working on new stuff... + +- SD XL +- SD ReImagined + ## Integration Tech that can be integrated as part of the core workflow... @@ -87,3 +94,4 @@ Tech that can be integrated as part of the core workflow... - force unload `xformers` when not used, improves compatibility with AMD/M1 - add `styles.csv` to UI settings to allow customizing path +- add `--disable-queue` to cmd flags that disables Gradio queues and forces it to use HTTP instead of WebSockets diff --git a/extensions-builtin/ScuNET/.priority b/extensions-builtin/ScuNET/.priority new file mode 100644 index 000000000..3ad5abd03 --- /dev/null +++ b/extensions-builtin/ScuNET/.priority @@ -0,0 +1 @@ +99 diff --git a/extensions-builtin/sd-extension-system-info b/extensions-builtin/sd-extension-system-info index f7be53474..5e108ce2d 160000 --- a/extensions-builtin/sd-extension-system-info +++ b/extensions-builtin/sd-extension-system-info @@ -1 +1 @@ -Subproject commit f7be53474b01b8c7dace642179ae38b587a7ac2b +Subproject commit 5e108ce2dd20c7721e05170483d33890508d7f78 diff --git a/modules/extensions.py b/modules/extensions.py index df5007ff0..9efc56b8f 100644 --- a/modules/extensions.py +++ b/modules/extensions.py @@ -67,7 +67,13 @@ class Extension: res = [] for filename in sorted(os.listdir(dirpath)): - res.append(scripts.ScriptFile(self.path, filename, os.path.join(dirpath, filename))) + priority = '50' + if os.path.isfile(os.path.join(dirpath, "..", ".priority")): + with open(os.path.join(dirpath, "..", ".priority"), "r", encoding="utf-8") as f: + priority = str(f.read().strip()) + _fn, ext = os.path.splitext(filename) + if ext == '.py': + res.append(scripts.ScriptFile(self.path, filename, os.path.join(dirpath, filename), priority)) res = [x for x in res if os.path.splitext(x.path)[1].lower() == extension and os.path.isfile(x.path)] diff --git a/modules/scripts.py b/modules/scripts.py index 2606ff267..9fc9fa143 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -179,7 +179,7 @@ def basedir(): return current_basedir -ScriptFile = namedtuple("ScriptFile", ["basedir", "filename", "path"]) +ScriptFile = namedtuple("ScriptFile", ["basedir", "filename", "path", "priority"]) scripts_data = [] postprocessing_scripts_data = [] @@ -189,10 +189,16 @@ ScriptClassData = namedtuple("ScriptClassData", ["script_class", "path", "basedi def list_scripts(scriptdirname, extension): scripts_list = [] - basedir = os.path.join(paths.script_path, scriptdirname) - if os.path.exists(basedir): - for filename in sorted(os.listdir(basedir)): - scripts_list.append(ScriptFile(paths.script_path, filename, os.path.join(basedir, filename))) + base = os.path.join(paths.script_path, scriptdirname) + if os.path.exists(base): + priority = '50' + if os.path.isfile(os.path.join(base, "..", ".priority")): + with open(os.path.join(base, "..", ".priority"), "r", encoding="utf-8") as f: + priority = str(f.read().strip()) + for filename in sorted(os.listdir(base)): + _fn, ext = os.path.splitext(filename) + if ext == '.py': + scripts_list.append(ScriptFile(paths.script_path, filename, os.path.join(base, filename), priority)) for ext in extensions.active(): scripts_list += ext.list_files(scriptdirname, extension) @@ -219,7 +225,7 @@ def list_files_with_name(filename): def load_scripts(): - global current_basedir + global current_basedir # pylint: disable=global-statement scripts_data.clear() postprocessing_scripts_data.clear() script_callbacks.clear_callbacks() @@ -229,7 +235,7 @@ def load_scripts(): syspath = sys.path def register_scripts_from_module(module): - for key, script_class in module.__dict__.items(): + for _key, script_class in module.__dict__.items(): if type(script_class) != type: continue @@ -238,19 +244,16 @@ def load_scripts(): elif issubclass(script_class, scripts_postprocessing.ScriptPostprocessing): postprocessing_scripts_data.append(ScriptClassData(script_class, scriptfile.path, scriptfile.basedir, module)) - alpha_sort = sorted(scripts_list, key=lambda item: item.path.lower()) - for scriptfile in alpha_sort: + priority_sort = sorted(scripts_list, key=lambda item: item.priority + item.path.lower(), reverse=False) + for scriptfile in priority_sort: try: if scriptfile.basedir != paths.script_path: sys.path = [scriptfile.basedir] + sys.path current_basedir = scriptfile.basedir script_module = script_loading.load_module(scriptfile.path) register_scripts_from_module(script_module) - except Exception as e: - errors.display(e, f'loading script: {scriptfile.filename}') - - + errors.display(e, f'Loading script: {scriptfile.filename}') finally: sys.path = syspath current_basedir = paths.script_path @@ -261,7 +264,7 @@ def wrap_call(func, filename, funcname, *args, default=None, **kwargs): res = func(*args, **kwargs) return res except Exception as e: - errors.display(e, f'calling script: {filename}/{funcname}') + errors.display(e, f'Calling script: {filename}/{funcname}') return default @@ -406,7 +409,7 @@ class ScriptRunner: script_args = p.script_args[script.args_from:script.args_to] script.process(p, *script_args) except Exception as e: - errors.display(e, f'running script process: {script.filename}') + errors.display(e, f'Running script process: {script.filename}') def before_process_batch(self, p, **kwargs): for script in self.alwayson_scripts: @@ -414,7 +417,7 @@ class ScriptRunner: script_args = p.script_args[script.args_from:script.args_to] script.before_process_batch(p, *script_args, **kwargs) except Exception as e: - errors.display(e, f'running script before process batch: {script.filename}') + errors.display(e, f'Running script before process batch: {script.filename}') def process_batch(self, p, **kwargs): for script in self.alwayson_scripts: @@ -422,7 +425,7 @@ class ScriptRunner: script_args = p.script_args[script.args_from:script.args_to] script.process_batch(p, *script_args, **kwargs) except Exception as e: - errors.display(e, f'running script process batch: {script.filename}') + errors.display(e, f'Running script process batch: {script.filename}') def postprocess(self, p, processed): for script in self.alwayson_scripts: @@ -430,7 +433,7 @@ class ScriptRunner: script_args = p.script_args[script.args_from:script.args_to] script.postprocess(p, processed, *script_args) except Exception as e: - errors.display(e, f'running script postprocess: {script.filename}') + errors.display(e, f'Running script postprocess: {script.filename}') def postprocess_batch(self, p, images, **kwargs): for script in self.alwayson_scripts: @@ -438,7 +441,7 @@ class ScriptRunner: script_args = p.script_args[script.args_from:script.args_to] script.postprocess_batch(p, *script_args, images=images, **kwargs) except Exception as e: - errors.display(e, f'running script before postprocess batch: {script.filename}') + errors.display(e, f'Running script before postprocess batch: {script.filename}') def postprocess_image(self, p, pp: PostprocessImageArgs): for script in self.alwayson_scripts: @@ -446,21 +449,21 @@ class ScriptRunner: script_args = p.script_args[script.args_from:script.args_to] script.postprocess_image(p, pp, *script_args) except Exception as e: - errors.display(e, f'running script postprocess image: {script.filename}') + errors.display(e, f'Running script postprocess image: {script.filename}') def before_component(self, component, **kwargs): for script in self.scripts: try: script.before_component(component, **kwargs) except Exception as e: - errors.display(e, f'running script before component: {script.filename}') + errors.display(e, f'Running script before component: {script.filename}') def after_component(self, component, **kwargs): for script in self.scripts: try: script.after_component(component, **kwargs) except Exception as e: - errors.display(e, f'running script after component: {script.filename}') + errors.display(e, f'Running script after component: {script.filename}') def reload_sources(self, cache): for si, script in list(enumerate(self.scripts)): diff --git a/webui.py b/webui.py index 9576c822e..c512cf093 100644 --- a/webui.py +++ b/webui.py @@ -162,6 +162,7 @@ def start_ui(): startup_timer.record("ui") if cmd_opts.disable_queue: print('Server queues disabled') + else: shared.demo.queue(16) gradio_auth_creds = []