diff options
author | Bruno Seoane <brunoseoaneamarillo@gmail.com> | 2022-11-01 15:06:10 +0000 |
---|---|---|
committer | Bruno Seoane <brunoseoaneamarillo@gmail.com> | 2022-11-01 15:06:10 +0000 |
commit | 31db25ecc8d9c3996e7bac00cc616ee12557b7d3 (patch) | |
tree | a2126c45535b989a7954ff30e142d73d1848cb0a /modules/script_callbacks.py | |
parent | 952ff32a5ffe7495721272a3443714b93c267ca9 (diff) | |
parent | 458cca03915ba437ac65a2087965f3885e6022bc (diff) | |
download | stable-diffusion-webui-gfx803-31db25ecc8d9c3996e7bac00cc616ee12557b7d3.tar.gz stable-diffusion-webui-gfx803-31db25ecc8d9c3996e7bac00cc616ee12557b7d3.tar.bz2 stable-diffusion-webui-gfx803-31db25ecc8d9c3996e7bac00cc616ee12557b7d3.zip |
Merge branch 'master' of https://github.com/AUTOMATIC1111/stable-diffusion-webui
Diffstat (limited to 'modules/script_callbacks.py')
-rw-r--r-- | modules/script_callbacks.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/modules/script_callbacks.py b/modules/script_callbacks.py index 6ea58d61..ce264690 100644 --- a/modules/script_callbacks.py +++ b/modules/script_callbacks.py @@ -3,6 +3,8 @@ import traceback from collections import namedtuple
import inspect
+from fastapi import FastAPI
+from gradio import Blocks
def report_exception(c, job):
print(f"Error executing callback {job} for {c.script}", file=sys.stderr)
@@ -25,6 +27,7 @@ class ImageSaveParams: ScriptCallback = namedtuple("ScriptCallback", ["script", "callback"])
+callbacks_app_started = []
callbacks_model_loaded = []
callbacks_ui_tabs = []
callbacks_ui_settings = []
@@ -40,6 +43,14 @@ def clear_callbacks(): callbacks_image_saved.clear()
+def app_started_callback(demo: Blocks, app: FastAPI):
+ for c in callbacks_app_started:
+ try:
+ c.callback(demo, app)
+ except Exception:
+ report_exception(c, 'app_started_callback')
+
+
def model_loaded_callback(sd_model):
for c in callbacks_model_loaded:
try:
@@ -69,7 +80,7 @@ def ui_settings_callback(): def before_image_saved_callback(params: ImageSaveParams):
- for c in callbacks_image_saved:
+ for c in callbacks_before_image_saved:
try:
c.callback(params)
except Exception:
@@ -91,6 +102,12 @@ def add_callback(callbacks, fun): callbacks.append(ScriptCallback(filename, fun))
+def on_app_started(callback):
+ """register a function to be called when the webui started, the gradio `Block` component and
+ fastapi `FastAPI` object are passed as the arguments"""
+ add_callback(callbacks_app_started, callback)
+
+
def on_model_loaded(callback):
"""register a function to be called when the stable diffusion model is created; the model is
passed as an argument"""
|