fix API always using -1 as seed

This commit is contained in:
AUTOMATIC1111 2023-08-14 10:43:18 +03:00
parent f3b96d4998
commit 353c876172
5 changed files with 16 additions and 6 deletions

View File

@ -330,6 +330,7 @@ class Api:
with self.queue_lock:
with closing(StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, **args)) as p:
p.is_api = True
p.scripts = script_runner
p.outpath_grids = opts.outdir_txt2img_grids
p.outpath_samples = opts.outdir_txt2img_samples
@ -390,6 +391,7 @@ class Api:
with self.queue_lock:
with closing(StableDiffusionProcessingImg2Img(sd_model=shared.sd_model, **args)) as p:
p.init_images = [decode_base64_to_image(x) for x in init_images]
p.is_api = True
p.scripts = script_runner
p.outpath_grids = opts.outdir_img2img_grids
p.outpath_samples = opts.outdir_img2img_samples

View File

@ -194,6 +194,8 @@ class StableDiffusionProcessing:
sd_vae_name: str = field(default=None, init=False)
sd_vae_hash: str = field(default=None, init=False)
is_api: bool = field(default=False, init=False)
def __post_init__(self):
if self.sampler_index is not None:
print("sampler_index argument for StableDiffusionProcessing does not do anything; use sampler_name", file=sys.stderr)
@ -258,7 +260,7 @@ class StableDiffusionProcessing:
def setup_scripts(self):
self.scripts_setup_complete = True
self.scripts.setup_scrips(self)
self.scripts.setup_scrips(self, is_ui=not self.is_api)
def comment(self, text):
self.comments[text] = 1

View File

@ -5,7 +5,7 @@ from modules.ui_common import create_refresh_button
from modules.ui_components import InputAccordion
class ScriptRefiner(scripts.Script):
class ScriptRefiner(scripts.ScriptBuiltinUI):
section = "accordions"
create_group = False

View File

@ -7,7 +7,7 @@ from modules.shared import cmd_opts
from modules.ui_components import ToolButton
class ScriptSeed(scripts.ScriptBuiltin):
class ScriptSeed(scripts.ScriptBuiltinUI):
section = "seed"
create_group = False

View File

@ -68,6 +68,9 @@ class Script:
on_after_component_elem_id = None
"""list of callbacks to be called after a component with an elem_id is created"""
setup_for_ui_only = False
"""If true, the script setup will only be run in Gradio UI, not in API"""
def title(self):
"""this function should return the title of the script. This is what will be displayed in the dropdown menu."""
@ -258,7 +261,6 @@ class Script:
self.on_after_component_elem_id.append((elem_id, callback))
def describe(self):
"""unused"""
return ""
@ -280,7 +282,8 @@ class Script:
pass
class ScriptBuiltin(Script):
class ScriptBuiltinUI(Script):
setup_for_ui_only = True
def elem_id(self, item_id):
"""helper function to generate id for a HTML element, constructs final id out of tab and user-supplied item_id"""
@ -728,8 +731,11 @@ class ScriptRunner:
except Exception:
errors.report(f"Error running before_hr: {script.filename}", exc_info=True)
def setup_scrips(self, p):
def setup_scrips(self, p, *, is_ui=True):
for script in self.alwayson_scripts:
if not is_ui and script.setup_for_ui_only:
continue
try:
script_args = p.script_args[script.args_from:script.args_to]
script.setup(p, *script_args)