diff --git a/modules/control/unit.py b/modules/control/unit.py index f07b70529..777b1532c 100644 --- a/modules/control/unit.py +++ b/modules/control/unit.py @@ -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 diff --git a/modules/images.py b/modules/images.py index 77a458623..d91f06b94 100644 --- a/modules/images.py +++ b/modules/images.py @@ -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 diff --git a/modules/masking.py b/modules/masking.py index 964f61c8f..a2c183ede 100644 --- a/modules/masking.py +++ b/modules/masking.py @@ -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 diff --git a/modules/processing_class.py b/modules/processing_class.py index ee9d044e8..5cfb50cb2 100644 --- a/modules/processing_class.py +++ b/modules/processing_class.py @@ -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) diff --git a/modules/scripts.py b/modules/scripts.py index ce6d44a6c..9d82c8efe 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -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] diff --git a/modules/ui_control_helpers.py b/modules/ui_control_helpers.py index 507fab614..416607913 100644 --- a/modules/ui_control_helpers.py +++ b/modules/ui_control_helpers.py @@ -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)]) diff --git a/scripts/ipadapter.py b/scripts/ipadapter.py index ebe273654..5447eefd0 100644 --- a/scripts/ipadapter.py +++ b/scripts/ipadapter.py @@ -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):