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
8ff6f093
Unverified
Commit
8ff6f093
authored
Sep 17, 2022
by
AUTOMATIC1111
Committed by
GitHub
Sep 17, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #587 from JashoBell/Base
Basic documentation for custom_code.py template
parents
23a0ec04
98a6644b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
scripts.py
modules/scripts.py
+19
-0
custom_code.py
scripts/custom_code.py
+4
-2
No files found.
modules/scripts.py
View file @
8ff6f093
...
...
@@ -13,18 +13,37 @@ class Script:
args_from
=
None
args_to
=
None
# The title of the script. This is what will be displayed in the dropdown menu.
def
title
(
self
):
raise
NotImplementedError
()
# How the script is displayed in the UI. See https://gradio.app/docs/#components
# for the different UI components you can use and how to create them.
# Most UI components 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
):
pass
# Determines when the script should be shown in the dropdown menu via the
# returned value. As an example:
# 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
):
return
True
# This is where the additional processing is implemented. The parameters include
# self, the model object "p" (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
,
*
args
):
raise
NotImplementedError
()
# The description method is currently unused.
# To add a description that appears when hovering over the title, amend the "titles"
# dict in script.js to include the script title (returned by title) as a key, and
# your description as the value.
def
describe
(
self
):
return
""
...
...
scripts/custom_code.py
View file @
8ff6f093
...
...
@@ -4,8 +4,8 @@ import gradio as gr
from
modules.processing
import
Processed
from
modules.shared
import
opts
,
cmd_opts
,
state
class
Script
(
scripts
.
Script
):
def
title
(
self
):
return
"Custom code"
...
...
@@ -18,6 +18,7 @@ class Script(scripts.Script):
return
[
code
]
def
run
(
self
,
p
,
code
):
assert
cmd_opts
.
allow_code
,
'--allow-code option must be enabled'
...
...
@@ -38,3 +39,4 @@ class Script(scripts.Script):
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