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
5a797a56
Commit
5a797a56
authored
Sep 16, 2022
by
JashoBell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic explanation for custom_code.py template
parent
b153ebe3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
custom_code.py
scripts/custom_code.py
+21
-2
No files found.
scripts/custom_code.py
View file @
5a797a56
...
@@ -4,20 +4,38 @@ import gradio as gr
...
@@ -4,20 +4,38 @@ import gradio as gr
from
modules.processing
import
Processed
from
modules.processing
import
Processed
from
modules.shared
import
opts
,
cmd_opts
,
state
from
modules.shared
import
opts
,
cmd_opts
,
state
# An example custom script that allows you to make modifications to how the model object is handled.
# These scripts appear in the lower-left dropdown menu on the txt2img and img2img tabs.
class
Script
(
scripts
.
Script
):
class
Script
(
scripts
.
Script
):
# The title of the script. This is what will be displayed in the dropdown menu.
def
title
(
self
):
def
title
(
self
):
return
"Custom code"
return
"Custom code"
# Determines when the script should be shown in the dropdown menu via the returned value.
# is_img2img is True if the current tab is img2img, and False if it is txt2img. Thus, return
# is_img2img to only show the script on the img2img tab.
def
show
(
self
,
is_img2img
):
def
show
(
self
,
is_img2img
):
return
cmd_opts
.
allow_code
return
cmd_opts
.
allow_code
# How the script's is displayed in the UI. See https://gradio.app/docs/#components
# for the different elements you can use and how to specify them.
# Each UI element can return a value, such as a boolean for a checkbox.
# The returned values are passed to the run method as parameters.
def
ui
(
self
,
is_img2img
):
def
ui
(
self
,
is_img2img
):
code
=
gr
.
Textbox
(
label
=
"Python code"
,
visible
=
False
,
lines
=
1
)
code
=
gr
.
Textbox
(
label
=
"Python code"
,
visible
=
False
,
lines
=
1
)
return
[
code
]
return
[
code
]
# This is where the additional processing is implemented. The parameters include self, the
# model object (a StableDiffusionProcessing class, see processing.py), and the parameters
# returned by the ui method.
# Custom functions can be defined here, and additional libraries can be imported to be used
# in processing. The return value should be a Processed object, which is what is returned
# by the process_images method.
def
run
(
self
,
p
,
code
):
def
run
(
self
,
p
,
code
):
assert
cmd_opts
.
allow_code
,
'--allow-code option must be enabled'
assert
cmd_opts
.
allow_code
,
'--allow-code option must be enabled'
...
@@ -37,4 +55,5 @@ class Script(scripts.Script):
...
@@ -37,4 +55,5 @@ class Script(scripts.Script):
exec
(
compiled
,
module
.
__dict__
)
exec
(
compiled
,
module
.
__dict__
)
return
Processed
(
p
,
*
display_result_data
)
return
Processed
(
p
,
*
display_result_data
)
\ No newline at end of file
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