|
@@ -6,7 +6,7 @@ import numpy as np
|
|
from PIL import Image, ImageOps, ImageFilter, ImageEnhance, UnidentifiedImageError
|
|
from PIL import Image, ImageOps, ImageFilter, ImageEnhance, UnidentifiedImageError
|
|
import gradio as gr
|
|
import gradio as gr
|
|
|
|
|
|
-from modules import images as imgutil
|
|
|
|
|
|
+from modules import images
|
|
from modules.infotext_utils import create_override_settings_dict, parse_generation_parameters
|
|
from modules.infotext_utils import create_override_settings_dict, parse_generation_parameters
|
|
from modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images
|
|
from modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images
|
|
from modules.shared import opts, state
|
|
from modules.shared import opts, state
|
|
@@ -21,7 +21,7 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
|
|
output_dir = output_dir.strip()
|
|
output_dir = output_dir.strip()
|
|
processing.fix_seed(p)
|
|
processing.fix_seed(p)
|
|
|
|
|
|
- images = list(shared.walk_files(input_dir, allowed_extensions=(".png", ".jpg", ".jpeg", ".webp", ".tif", ".tiff")))
|
|
|
|
|
|
+ batch_images = list(shared.walk_files(input_dir, allowed_extensions=(".png", ".jpg", ".jpeg", ".webp", ".tif", ".tiff")))
|
|
|
|
|
|
is_inpaint_batch = False
|
|
is_inpaint_batch = False
|
|
if inpaint_mask_dir:
|
|
if inpaint_mask_dir:
|
|
@@ -31,9 +31,9 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
|
|
if is_inpaint_batch:
|
|
if is_inpaint_batch:
|
|
print(f"\nInpaint batch is enabled. {len(inpaint_masks)} masks found.")
|
|
print(f"\nInpaint batch is enabled. {len(inpaint_masks)} masks found.")
|
|
|
|
|
|
- print(f"Will process {len(images)} images, creating {p.n_iter * p.batch_size} new images for each.")
|
|
|
|
|
|
+ print(f"Will process {len(batch_images)} images, creating {p.n_iter * p.batch_size} new images for each.")
|
|
|
|
|
|
- state.job_count = len(images) * p.n_iter
|
|
|
|
|
|
+ state.job_count = len(batch_images) * p.n_iter
|
|
|
|
|
|
# extract "default" params to use in case getting png info fails
|
|
# extract "default" params to use in case getting png info fails
|
|
prompt = p.prompt
|
|
prompt = p.prompt
|
|
@@ -46,8 +46,8 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
|
|
sd_model_checkpoint_override = get_closet_checkpoint_match(override_settings.get("sd_model_checkpoint", None))
|
|
sd_model_checkpoint_override = get_closet_checkpoint_match(override_settings.get("sd_model_checkpoint", None))
|
|
batch_results = None
|
|
batch_results = None
|
|
discard_further_results = False
|
|
discard_further_results = False
|
|
- for i, image in enumerate(images):
|
|
|
|
- state.job = f"{i+1} out of {len(images)}"
|
|
|
|
|
|
+ for i, image in enumerate(batch_images):
|
|
|
|
+ state.job = f"{i+1} out of {len(batch_images)}"
|
|
if state.skipped:
|
|
if state.skipped:
|
|
state.skipped = False
|
|
state.skipped = False
|
|
|
|
|
|
@@ -55,7 +55,7 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
|
|
break
|
|
break
|
|
|
|
|
|
try:
|
|
try:
|
|
- img = Image.open(image)
|
|
|
|
|
|
+ img = images.read(image)
|
|
except UnidentifiedImageError as e:
|
|
except UnidentifiedImageError as e:
|
|
print(e)
|
|
print(e)
|
|
continue
|
|
continue
|
|
@@ -86,7 +86,7 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
|
|
# otherwise user has many masks with the same name but different extensions
|
|
# otherwise user has many masks with the same name but different extensions
|
|
mask_image_path = masks_found[0]
|
|
mask_image_path = masks_found[0]
|
|
|
|
|
|
- mask_image = Image.open(mask_image_path)
|
|
|
|
|
|
+ mask_image = images.read(mask_image_path)
|
|
p.image_mask = mask_image
|
|
p.image_mask = mask_image
|
|
|
|
|
|
if use_png_info:
|
|
if use_png_info:
|
|
@@ -94,8 +94,8 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
|
|
info_img = img
|
|
info_img = img
|
|
if png_info_dir:
|
|
if png_info_dir:
|
|
info_img_path = os.path.join(png_info_dir, os.path.basename(image))
|
|
info_img_path = os.path.join(png_info_dir, os.path.basename(image))
|
|
- info_img = Image.open(info_img_path)
|
|
|
|
- geninfo, _ = imgutil.read_info_from_image(info_img)
|
|
|
|
|
|
+ info_img = images.read(info_img_path)
|
|
|
|
+ geninfo, _ = images.read_info_from_image(info_img)
|
|
parsed_parameters = parse_generation_parameters(geninfo)
|
|
parsed_parameters = parse_generation_parameters(geninfo)
|
|
parsed_parameters = {k: v for k, v in parsed_parameters.items() if k in (png_info_props or {})}
|
|
parsed_parameters = {k: v for k, v in parsed_parameters.items() if k in (png_info_props or {})}
|
|
except Exception:
|
|
except Exception:
|
|
@@ -175,9 +175,8 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s
|
|
image = None
|
|
image = None
|
|
mask = None
|
|
mask = None
|
|
|
|
|
|
- # Use the EXIF orientation of photos taken by smartphones.
|
|
|
|
- if image is not None:
|
|
|
|
- image = ImageOps.exif_transpose(image)
|
|
|
|
|
|
+ image = images.fix_image(image)
|
|
|
|
+ mask = images.fix_image(mask)
|
|
|
|
|
|
if selected_scale_tab == 1 and not is_batch:
|
|
if selected_scale_tab == 1 and not is_batch:
|
|
assert image, "Can't scale by because no image is selected"
|
|
assert image, "Can't scale by because no image is selected"
|