mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
Merge pull request #587 from JashoBell/Base
Basic documentation for custom_code.py template
This commit is contained in:
commit
8ff6f09320
@ -13,18 +13,37 @@ class Script:
|
|||||||
args_from = None
|
args_from = None
|
||||||
args_to = None
|
args_to = None
|
||||||
|
|
||||||
|
# The title of the script. This is what will be displayed in the dropdown menu.
|
||||||
def title(self):
|
def title(self):
|
||||||
raise NotImplementedError()
|
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):
|
def ui(self, is_img2img):
|
||||||
pass
|
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):
|
def show(self, is_img2img):
|
||||||
return True
|
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):
|
def run(self, *args):
|
||||||
raise NotImplementedError()
|
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):
|
def describe(self):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ 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
|
||||||
|
|
||||||
|
|
||||||
class Script(scripts.Script):
|
class Script(scripts.Script):
|
||||||
|
|
||||||
def title(self):
|
def title(self):
|
||||||
return "Custom code"
|
return "Custom code"
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ class Script(scripts.Script):
|
|||||||
|
|
||||||
return [code]
|
return [code]
|
||||||
|
|
||||||
|
|
||||||
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 +38,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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user