aboutsummaryrefslogtreecommitdiffstats
path: root/modules/script_callbacks.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2022-11-01 10:47:47 +0000
committerGitHub <noreply@github.com>2022-11-01 10:47:47 +0000
commit087440404030fe4f704f3a568a35c86fb1b69259 (patch)
tree3d3c00ffe1d6301c61baa98dc354a7bb179f14ce /modules/script_callbacks.py
parent40b3a7e8a55091a5e9a0d28011b6e1cbb016e4ce (diff)
parent081df45da47feadfb055552c0ad5c6e6ecdd9f28 (diff)
downloadstable-diffusion-webui-gfx803-087440404030fe4f704f3a568a35c86fb1b69259.tar.gz
stable-diffusion-webui-gfx803-087440404030fe4f704f3a568a35c86fb1b69259.tar.bz2
stable-diffusion-webui-gfx803-087440404030fe4f704f3a568a35c86fb1b69259.zip
Merge pull request #3982 from MaikoTan/on-started-callback
feat: add app started callback
Diffstat (limited to 'modules/script_callbacks.py')
-rw-r--r--modules/script_callbacks.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/script_callbacks.py b/modules/script_callbacks.py
index 6ea58d61..d8aa6f00 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:
@@ -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"""