improve api scripts resiliency

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2024-11-21 10:17:44 -05:00
parent 9f65f8b8c3
commit a5c8bb57c7
7 changed files with 74 additions and 10 deletions
+6 -4
View File
@@ -116,12 +116,13 @@ class APIGenerate():
p.script_args = tuple(script_args) # Need to pass args as tuple here
processed = process_images(p)
shared.state.end(api=False)
if processed.images is None or len(processed.images) == 0:
if processed is None or processed.images is None or len(processed.images) == 0:
b64images = []
else:
b64images = list(map(helpers.encode_pil_to_base64, processed.images)) if send_images else []
self.sanitize_b64(txt2imgreq)
return models.ResTxt2Img(images=b64images, parameters=vars(txt2imgreq), info=processed.js())
info = processed.js() if processed else ''
return models.ResTxt2Img(images=b64images, parameters=vars(txt2imgreq), info=info)
def post_img2img(self, img2imgreq: models.ReqImg2Img):
self.prepare_face_module(img2imgreq)
@@ -165,7 +166,7 @@ class APIGenerate():
p.script_args = tuple(script_args) # Need to pass args as tuple here
processed = process_images(p)
shared.state.end(api=False)
if processed.images is None or len(processed.images) == 0:
if processed is None or processed.images is None or len(processed.images) == 0:
b64images = []
else:
b64images = list(map(helpers.encode_pil_to_base64, processed.images)) if send_images else []
@@ -173,4 +174,5 @@ class APIGenerate():
img2imgreq.init_images = None
img2imgreq.mask = None
self.sanitize_b64(img2imgreq)
return models.ResImg2Img(images=b64images, parameters=vars(img2imgreq), info=processed.js())
info = processed.js() if processed else ''
return models.ResImg2Img(images=b64images, parameters=vars(img2imgreq), info=info)
+2 -1
View File
@@ -81,7 +81,8 @@ def init_script_args(p, request, default_script_args, selectable_scripts, select
script_args = default_script_args.copy()
# position 0 in script_arg is the idx+1 of the selectable script that is going to be run when using scripts.scripts_*2img.run()
if selectable_scripts:
script_args[selectable_scripts.args_from:selectable_scripts.args_to] = request.script_args
for idx in range(len(request.script_args)):
script_args[selectable_scripts.args_from + idx] = request.script_args[idx]
script_args[0] = selectable_script_idx + 1
# Now check for always on scripts
if request.alwayson_scripts and (len(request.alwayson_scripts) > 0):