From 9390049288115dfc8bebc47e872bd55bc52febea Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 1 Jul 2023 10:08:57 -0400 Subject: [PATCH] extra options in filename pattern --- installer.py | 2 ++ modules/images.py | 54 +++++++++++++++++++++++------------------------ modules/shared.py | 4 ++-- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/installer.py b/installer.py index c48d28fbb..4e9a3b805 100644 --- a/installer.py +++ b/installer.py @@ -191,6 +191,8 @@ def git(arg: str, folder: str = None, ignore: bool = False): if args.skip_git: return '' git_cmd = os.environ.get('GIT', "git") + if git_cmd != "git": + git_cmd = os.path.abspath(git_cmd) result = subprocess.run(f'"{git_cmd}" {arg}', check=False, shell=True, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=folder or '.') txt = result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stderr) > 0: diff --git a/modules/images.py b/modules/images.py index b7ab28ebc..d5f0b5970 100644 --- a/modules/images.py +++ b/modules/images.py @@ -4,6 +4,7 @@ import re import os import math import json +import uuid import string import hashlib import queue @@ -61,37 +62,25 @@ Grid = namedtuple("Grid", ["tiles", "tile_w", "tile_h", "image_w", "image_h", "o def split_grid(image, tile_w=512, tile_h=512, overlap=64): w = image.width h = image.height - non_overlap_width = tile_w - overlap non_overlap_height = tile_h - overlap - cols = math.ceil((w - overlap) / non_overlap_width) rows = math.ceil((h - overlap) / non_overlap_height) - dx = (w - tile_w) / (cols - 1) if cols > 1 else 0 dy = (h - tile_h) / (rows - 1) if rows > 1 else 0 - grid = Grid([], tile_w, tile_h, w, h, overlap) for row in range(rows): row_images = [] - y = int(row * dy) - if y + tile_h >= h: y = h - tile_h - for col in range(cols): x = int(col * dx) - if x + tile_w >= w: x = w - tile_w - tile = image.crop((x, y, x + tile_w, y + tile_h)) - row_images.append([x, tile_w, tile]) - grid.tiles.append([y, tile_h, row_images]) - return grid @@ -103,7 +92,6 @@ def combine_grid(grid): mask_w = make_mask_image(np.arange(grid.overlap, dtype=np.float32).reshape((1, grid.overlap)).repeat(grid.tile_h, axis=0)) mask_h = make_mask_image(np.arange(grid.overlap, dtype=np.float32).reshape((grid.overlap, 1)).repeat(grid.image_w, axis=1)) - combined_image = Image.new("RGB", (grid.image_w, grid.image_h)) for y, h, row in grid.tiles: combined_row = Image.new("RGB", (grid.image_w, h)) @@ -111,17 +99,13 @@ def combine_grid(grid): if x == 0: combined_row.paste(tile, (0, 0)) continue - combined_row.paste(tile.crop((0, 0, grid.overlap, h)), (x, 0), mask=mask_w) combined_row.paste(tile.crop((grid.overlap, 0, w, h)), (x + grid.overlap, 0)) - if y == 0: combined_image.paste(combined_row, (0, 0)) continue - combined_image.paste(combined_row.crop((0, 0, combined_row.width, grid.overlap)), (0, y), mask=mask_h) combined_image.paste(combined_row.crop((0, grid.overlap, combined_row.width, h)), (0, y + grid.overlap)) - return combined_image @@ -298,6 +282,8 @@ def sanitize_filename_part(text, replace_spaces=True): class FilenameGenerator: replacements = { + 'uuid': lambda self: str(uuid.uuid4()), + 'image_hash': lambda self: self.image_hash(), 'seed': lambda self: self.seed if self.seed is not None else '', 'steps': lambda self: self.p and self.p.steps, 'cfg': lambda self: self.p and self.p.cfg_scale, @@ -307,6 +293,7 @@ class FilenameGenerator: 'sampler': lambda self: self.p and sanitize_filename_part(self.p.sampler_name, replace_spaces=False), 'model_hash': lambda self: getattr(self.p, "sd_model_hash", shared.sd_model.sd_model_hash), 'model_name': lambda self: sanitize_filename_part(shared.sd_model.sd_checkpoint_info.model_name, replace_spaces=False), + 'model': lambda self: sanitize_filename_part(shared.sd_model.sd_checkpoint_info.name_for_extra, replace_spaces=False), 'model_shortname': lambda self: sanitize_filename_part(shared.sd_model.sd_checkpoint_info.name_for_extra, replace_spaces=False), 'date': lambda self: datetime.datetime.now().strftime('%Y-%m-%d'), 'datetime': lambda self, *args: self.datetime(*args), # accepts formats: [datetime], [datetime], [datetime