mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
improve api scripts resiliency
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -86,7 +86,11 @@ def load_prompt_file(file):
|
||||
if file is None:
|
||||
return None, gr.update(), gr.update(lines=7)
|
||||
else:
|
||||
lines = [x.strip() for x in file.decode('utf8', errors='ignore').split("\n")]
|
||||
try:
|
||||
lines = [x.strip() for x in file.decode('utf8', errors='ignore').split("\n")]
|
||||
except Exception as e:
|
||||
log.error(f"Prompt file: {e}")
|
||||
lines = ''
|
||||
return None, "\n".join(lines), gr.update(lines=7)
|
||||
|
||||
|
||||
@@ -100,7 +104,7 @@ class Script(scripts.Script):
|
||||
with gr.Row():
|
||||
checkbox_iterate = gr.Checkbox(label="Iterate seed per line", value=False, elem_id=self.elem_id("checkbox_iterate"))
|
||||
checkbox_iterate_batch = gr.Checkbox(label="Use same seed", value=False, elem_id=self.elem_id("checkbox_iterate_batch"))
|
||||
prompt_txt = gr.Textbox(label="Prompts", lines=2, elem_id=self.elem_id("prompt_txt"))
|
||||
prompt_txt = gr.Textbox(label="Prompts", lines=2, elem_id=self.elem_id("prompt_txt"), value='')
|
||||
file = gr.File(label="Upload prompts", type='binary', elem_id=self.elem_id("file"))
|
||||
file.change(fn=load_prompt_file, inputs=[file], outputs=[file, prompt_txt, prompt_txt], show_progress=False)
|
||||
prompt_txt.change(lambda tb: gr.update(lines=7) if ("\n" in tb) else gr.update(lines=2), inputs=[prompt_txt], outputs=[prompt_txt], show_progress=False)
|
||||
|
||||
@@ -114,7 +114,7 @@ class Script(scripts.Script):
|
||||
): # pylint: disable=arguments-differ, unused-argument
|
||||
images = []
|
||||
try:
|
||||
if len(gallery) == 0:
|
||||
if gallery is None or isinstance(gallery, str) or len(gallery) == 0:
|
||||
from modules.api.api import decode_base64_to_image
|
||||
images = getattr(p, 'pulid_images', uploaded_images)
|
||||
images = [decode_base64_to_image(image) if isinstance(image, str) else image for image in images]
|
||||
@@ -127,6 +127,12 @@ class Script(scripts.Script):
|
||||
if len(images) == 0:
|
||||
shared.log.error('PuLID: no images')
|
||||
return None
|
||||
try:
|
||||
images = [self.pulid.resize(image, 1024) for image in images]
|
||||
except Exception as e:
|
||||
shared.log.error(f'PuLID: failed to resize images: {e}')
|
||||
return None
|
||||
|
||||
supported_model_list = ['sdxl']
|
||||
if shared.sd_model_type not in supported_model_list:
|
||||
shared.log.error(f'PuLID: class={shared.sd_model.__class__.__name__} model={shared.sd_model_type} required={supported_model_list}')
|
||||
@@ -190,7 +196,6 @@ class Script(scripts.Script):
|
||||
self.pulid.attention.NUM_ZERO = zero
|
||||
self.pulid.attention.ORTHO = ortho == 'v1'
|
||||
self.pulid.attention.ORTHO_v2 = ortho == 'v2'
|
||||
images = [self.pulid.resize(image, 1024) for image in images]
|
||||
shared.sd_model.debug_img_list = []
|
||||
|
||||
# get id embedding used for attention
|
||||
|
||||
Reference in New Issue
Block a user