diff options
author | Sihan Wang <31711261+shwang95@users.noreply.github.com> | 2022-11-02 06:09:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 06:09:33 +0000 |
commit | 5c864be010b42373e51eac4c6869d561adca4202 (patch) | |
tree | 1de5f558ab056bc766ac51d3612356f0de52b1f8 /modules/scripts.py | |
parent | 7bd8581e461623932ffbd5762ee931ee51f798db (diff) | |
parent | 65522ff157e4be4095a99421da04ecb0749824ac (diff) | |
download | stable-diffusion-webui-gfx803-5c864be010b42373e51eac4c6869d561adca4202.tar.gz stable-diffusion-webui-gfx803-5c864be010b42373e51eac4c6869d561adca4202.tar.bz2 stable-diffusion-webui-gfx803-5c864be010b42373e51eac4c6869d561adca4202.zip |
Merge branch 'AUTOMATIC1111:master' into master
Diffstat (limited to 'modules/scripts.py')
-rw-r--r-- | modules/scripts.py | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/modules/scripts.py b/modules/scripts.py index 9323af3e..533db45c 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -7,7 +7,7 @@ import modules.ui as ui import gradio as gr
from modules.processing import StableDiffusionProcessing
-from modules import shared, paths, script_callbacks
+from modules import shared, paths, script_callbacks, extensions
AlwaysVisible = object()
@@ -64,7 +64,16 @@ class Script: def process(self, p, *args):
"""
This function is called before processing begins for AlwaysVisible scripts.
- scripts. You can modify the processing object (p) here, inject hooks, etc.
+ You can modify the processing object (p) here, inject hooks, etc.
+ args contains all values returned by components from ui()
+ """
+
+ pass
+
+ def postprocess(self, p, processed, *args):
+ """
+ This function is called after processing ends for AlwaysVisible scripts.
+ args contains all values returned by components from ui()
"""
pass
@@ -98,17 +107,8 @@ def list_scripts(scriptdirname, extension): for filename in sorted(os.listdir(basedir)):
scripts_list.append(ScriptFile(paths.script_path, filename, os.path.join(basedir, filename)))
- extdir = os.path.join(paths.script_path, "extensions")
- if os.path.exists(extdir):
- for dirname in sorted(os.listdir(extdir)):
- dirpath = os.path.join(extdir, dirname)
- scriptdirpath = os.path.join(dirpath, scriptdirname)
-
- if not os.path.isdir(scriptdirpath):
- continue
-
- for filename in sorted(os.listdir(scriptdirpath)):
- scripts_list.append(ScriptFile(dirpath, filename, os.path.join(scriptdirpath, filename)))
+ for ext in extensions.active():
+ scripts_list += ext.list_files(scriptdirname, extension)
scripts_list = [x for x in scripts_list if os.path.splitext(x.path)[1].lower() == extension and os.path.isfile(x.path)]
@@ -118,11 +118,7 @@ def list_scripts(scriptdirname, extension): def list_files_with_name(filename):
res = []
- dirs = [paths.script_path]
-
- extdir = os.path.join(paths.script_path, "extensions")
- if os.path.exists(extdir):
- dirs += [os.path.join(extdir, d) for d in sorted(os.listdir(extdir))]
+ dirs = [paths.script_path] + [ext.path for ext in extensions.active()]
for dirpath in dirs:
if not os.path.isdir(dirpath):
@@ -236,7 +232,7 @@ class ScriptRunner: with gr.Group():
create_script_ui(script, inputs, inputs_alwayson)
- dropdown = gr.Dropdown(label="Script", choices=["None"] + self.titles, value="None", type="index")
+ dropdown = gr.Dropdown(label="Script", elem_id="script_list", choices=["None"] + self.titles, value="None", type="index")
dropdown.save_to_config = True
inputs[0] = dropdown
@@ -289,13 +285,22 @@ class ScriptRunner: return processed
- def run_alwayson_scripts(self, p):
+ def process(self, p):
for script in self.alwayson_scripts:
try:
script_args = p.script_args[script.args_from:script.args_to]
script.process(p, *script_args)
except Exception:
- print(f"Error running alwayson script: {script.filename}", file=sys.stderr)
+ print(f"Error running process: {script.filename}", file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
+
+ def postprocess(self, p, processed):
+ for script in self.alwayson_scripts:
+ try:
+ script_args = p.script_args[script.args_from:script.args_to]
+ script.postprocess(p, processed, *script_args)
+ except Exception:
+ print(f"Error running postprocess: {script.filename}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
def reload_sources(self, cache):
|