fix controlnet causing crash. enhance script compatability
parent
1ce405cc51
commit
3e448e4fcc
|
|
@ -289,44 +289,38 @@ class Script(scripts.Script):
|
||||||
Script.initialize(initial_payload=p)
|
Script.initialize(initial_payload=p)
|
||||||
|
|
||||||
# strip scripts that aren't yet supported and warn user
|
# strip scripts that aren't yet supported and warn user
|
||||||
controlnet = None
|
packed_script_args: List[dict] = [] # list of api formatted per-script argument objects
|
||||||
arg = 0
|
|
||||||
while arg < len(p.script_args) - 1:
|
|
||||||
try:
|
|
||||||
json.dumps(p.script_args[arg])
|
|
||||||
except Exception:
|
|
||||||
|
|
||||||
# find which script owns the offending arguments and fix if supported
|
|
||||||
script_args_upper = None # the upper index of the offending scripts args so that we can skip the rest
|
|
||||||
for script in p.scripts.scripts:
|
for script in p.scripts.scripts:
|
||||||
|
if script.alwayson is not True:
|
||||||
|
continue
|
||||||
title = script.title()
|
title = script.title()
|
||||||
|
|
||||||
# check for supported scripts
|
# check for supported scripts
|
||||||
if title == "ControlNet" and script.alwayson is True:
|
if title == "ControlNet":
|
||||||
# grab all controlnet units
|
# grab all controlnet units
|
||||||
cn_units = []
|
cn_units = []
|
||||||
for cn_arg in range(script.args_from, script.args_to + 1):
|
cn_args = p.script_args[script.args_from:script.args_to]
|
||||||
if isinstance(p.script_args[cn_arg], type(p.script_args[arg])):
|
for cn_arg in cn_args:
|
||||||
cn_units.append(p.script_args[cn_arg])
|
if type(cn_arg).__name__ == "UiControlNetUnit":
|
||||||
|
cn_units.append(cn_arg)
|
||||||
logger.debug(f"Detected {len(cn_units)} controlnet unit(s)")
|
logger.debug(f"Detected {len(cn_units)} controlnet unit(s)")
|
||||||
|
|
||||||
# get api formatted controlnet
|
# get api formatted controlnet
|
||||||
controlnet: dict = pack_control_net(cn_units)
|
packed_script_args.append(pack_control_net(cn_units))
|
||||||
|
|
||||||
# ensure we don't do this more than once
|
|
||||||
script_args_upper = script.args_to
|
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
script_serial = {
|
||||||
|
script.name: {'args': []}
|
||||||
|
}
|
||||||
|
|
||||||
# clean unsupported scripts
|
this_args = p.script_args[script.args_from:script.args_to]
|
||||||
if script.args_from <= arg <= script.args_to:
|
this_args = json.dumps(this_args, default=lambda k: '<not serializable>')
|
||||||
logger.warn(f"Distributed does not yet support '{title}'")
|
script_serial[script.name]['args'] = this_args
|
||||||
sanitized_script_args = p.script_args[:arg] + p.script_args[arg + 1:]
|
|
||||||
p.script_args = sanitized_script_args
|
|
||||||
|
|
||||||
if script_args_upper is not None:
|
packed_script_args.append(script_serial)
|
||||||
arg = script_args_upper
|
logger.warning(f"Distributed doesn't officially support '{title}'")
|
||||||
|
|
||||||
arg += 1
|
|
||||||
|
|
||||||
# encapsulating the request object within a txt2imgreq object is deprecated and no longer works
|
# encapsulating the request object within a txt2imgreq object is deprecated and no longer works
|
||||||
# see test/basic_features/txt2img_test.py for an example
|
# see test/basic_features/txt2img_test.py for an example
|
||||||
|
|
@ -335,8 +329,9 @@ class Script(scripts.Script):
|
||||||
payload['scripts'] = None
|
payload['scripts'] = None
|
||||||
del payload['script_args']
|
del payload['script_args']
|
||||||
|
|
||||||
if controlnet is not None:
|
payload['alwayson_scripts'] = {}
|
||||||
payload['alwayson_scripts'] = controlnet
|
for packed in packed_script_args:
|
||||||
|
payload['alwayson_scripts'].update(packed)
|
||||||
|
|
||||||
# TODO api for some reason returns 200 even if something failed to be set.
|
# TODO api for some reason returns 200 even if something failed to be set.
|
||||||
# for now we may have to make redundant GET requests to check if actually successful...
|
# for now we may have to make redundant GET requests to check if actually successful...
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue