error handling

This commit is contained in:
Vladimir Mandic
2024-02-13 09:17:01 -05:00
parent f5c1cb1bae
commit 1bcaa77dc5
7 changed files with 12 additions and 6 deletions
+2
View File
@@ -98,6 +98,8 @@ class Unit(): # mashup of gradio controls and mapping to actual implementation c
self.adain_weight = c4
def upload_image(image_file):
if image_file is None:
return gr.update(value=None)
try:
self.process.override = Image.open(image_file.name)
self.override = self.process.override
+2 -2
View File
@@ -241,7 +241,7 @@ def resize_image(resize_mode, im, width, height, upscaler_name=None, output_type
def resize(im, w, h):
if upscaler_name is None or upscaler_name == "None" or im.mode == 'L':
return im.resize((w, h), resample=Image.Resampling.LANCZOS)
return im.resize((w, h), resample=Image.Resampling.LANCZOS) # force for mask
scale = max(w / im.width, h / im.height)
if scale > 1.0:
upscalers = [x for x in shared.sd_upscalers if x.name == upscaler_name]
@@ -254,7 +254,7 @@ def resize_image(resize_mode, im, width, height, upscaler_name=None, output_type
im = latent(im, w, h, upscaler)
else:
shared.log.warning(f"Resize upscaler: invalid={upscaler_name} fallback={upscaler.name}")
if im.width != w or im.height != h:
if im.width != w or im.height != h: # probably downsample after upscaler created larger image
im = im.resize((w, h), resample=Image.Resampling.LANCZOS)
return im
+2 -2
View File
@@ -54,7 +54,7 @@ def get_crop_region(mask, pad=0):
int(min(x2, w)),
int(min(y2, h)),
)
debug(f'Mask crop: mask={mask.shape} region={crop_region} pad={pad}')
debug(f'Mask crop: mask={w, h} region={crop_region} pad={pad}')
return crop_region
@@ -99,7 +99,7 @@ def expand_crop_region(crop_region, processing_width, processing_height, image_w
int(x2),
int(y2),
)
debug(f'Mask expand: region={crop_expand} processing={processing_width}x{processing_height} image={image_width}x{image_height}')
debug(f'Mask expand: image={image_width, image_height} processing={processing_width, processing_height} region={crop_expand}')
return crop_expand
+2 -2
View File
@@ -361,10 +361,10 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
crop_region = masking.expand_crop_region(crop_region, self.width, self.height, mask.width, mask.height)
x1, y1, x2, y2 = crop_region
crop_mask = mask.crop(crop_region)
self.image_mask = images.resize_image(2, crop_mask, self.width, self.height)
self.image_mask = images.resize_image(resize_mode=2, im=crop_mask, width=self.width, height=self.height)
self.paste_to = (x1, y1, x2-x1, y2-y1)
else: # full image inpaint
self.image_mask = images.resize_image(self.resize_mode, self.image_mask, self.width, self.height)
self.image_mask = images.resize_image(resize_mode=self.resize_mode, im=self.image_mask, width=self.width, height=self.height)
np_mask = np.array(self.image_mask)
np_mask = np.clip((np_mask.astype(np.float32)) * 2, 0, 255).astype(np.uint8)
self.mask_for_overlay = Image.fromarray(np_mask)
+2
View File
@@ -440,6 +440,8 @@ class ScriptRunner:
script.group = group
def select_script(script_index):
if script_index is None:
return [gr.update(visible=False) for script in self.selectable_scripts]
selected_script = self.selectable_scripts[script_index - 1] if script_index > 0 else None
return [gr.update(visible=selected_script == s) for s in self.selectable_scripts]
+1
View File
@@ -67,6 +67,7 @@ def interrogate_booru():
def display_units(num_units):
num_units = num_units or 1
return (num_units * [gr.update(visible=True)]) + ((max_units - num_units) * [gr.update(visible=False)])
+1
View File
@@ -36,6 +36,7 @@ class Script(scripts.Script):
return init_images
def display_units(self, num_units):
num_units = num_units or 1
return (num_units * [gr.update(visible=True)]) + ((MAX_ADAPTERS - num_units) * [gr.update(visible=False)])
def ui(self, _is_img2img):