Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
08744040
Unverified
Commit
08744040
authored
Nov 01, 2022
by
AUTOMATIC1111
Committed by
GitHub
Nov 01, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3982 from MaikoTan/on-started-callback
feat: add app started callback
parents
40b3a7e8
081df45d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
script_callbacks.py
modules/script_callbacks.py
+17
-0
webui.py
webui.py
+3
-0
No files found.
modules/script_callbacks.py
View file @
08744040
...
...
@@ -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"""
...
...
webui.py
View file @
08744040
...
...
@@ -23,6 +23,7 @@ import modules.sd_hijack
import
modules.sd_models
import
modules.shared
as
shared
import
modules.txt2img
import
modules.script_callbacks
import
modules.ui
from
modules
import
devices
...
...
@@ -140,6 +141,8 @@ def webui():
if
launch_api
:
create_api
(
app
)
modules
.
script_callbacks
.
app_started_callback
(
demo
,
app
)
wait_on_server
(
demo
)
sd_samplers
.
set_samplers
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment