Merge branch 'dev' into pytorch-210

This commit is contained in:
Hameer Abbasi
2023-10-12 07:36:31 +02:00
committed by GitHub
18 changed files with 131 additions and 136 deletions
+6 -3
View File
@@ -1,9 +1,8 @@
# Change Log for SD.Next
## Update for 2023-10-09
## Update for 2023-10-11
- Final strech of the DEV branch before merge to master
- Requires pending `diffusers==0.22.0`
- Final strech of the DEV branch before merge to master: requires pending `diffusers==0.22.0`
This is a major release, with many changes and new functionality...
@@ -173,6 +172,10 @@ or even free speedups and quality improvements (regardless of which workflows yo
new option *settings -> inference -> batch mode*
when using img2img process batch, process multiple images in batch in parallel
thanks @Symbiomatrix
- **NSFW**
- install extension: [NudeNet](https://github.com/vladmandic/sd-extension-nudenet)
body part detection, image metadata, advanced censoring, etc...
more in the extension notes
- **General**
- **Startup**
- all main CLI parameters can now be set as environment variable as well
+1
View File
@@ -23,6 +23,7 @@ Stuff to be added, in no particular order...
- Rename repo: **automatic** -> **sdnext**
- New Minor
- Prompt padding for positive/negative
- PyTorch / XLA
- New Major
- Profile manager (for `config.json` and `ui-config.json`)
- Multi-user support
Binary file not shown.
+5 -1
View File
@@ -959,10 +959,14 @@ def git_reset():
log.warning('Running GIT reset')
global quick_allowed # pylint: disable=global-statement
quick_allowed = False
git('merge --abort')
git('add .')
git('stash')
git('merge --abort', folder=None, ignore=True)
git('fetch --all')
git('reset --hard origin/master')
git('checkout master')
git('submodule update --init --recursive')
git('submodule sync --recursive')
log.info('GIT reset complete')
+1 -1
View File
@@ -77,7 +77,7 @@ button.custom-button{ border-radius: var(--button-large-radius); padding: var(--
#txt2img_generate_line2 > button, #img2img_generate_line2 > button, #extras_generate_box > button, #txt2img_tools > button, #img2img_tools > button { height: 2em; line-height: 0; font-size: var(--input-text-size);
min-width: unset; display: block !important; margin-left: 0.4em; margin-right: 0.4em; }
#txt2img_prompt, #txt2img_neg_prompt, #img2img_prompt, #img2img_neg_prompt { display: contents; }
.interrogate-col{ min-width: 0 !important; max-width: fit-content; gap: 0.5em; }
.interrogate-col{ min-width: 0 !important; max-width: fit-content; margin-right: var(--spacing-xxl); }
.interrogate-col > button{ flex: 1; }
#sampler_selection_img2img { margin-top: 1em; }
#txtimg_hr_finalres{ min-height: 0 !important; }
+76 -105
View File
@@ -9,6 +9,7 @@ import string
import hashlib
import queue
import threading
from pathlib import Path
from collections import namedtuple
import pytz
import numpy as np
@@ -266,58 +267,47 @@ def resize_image(resize_mode, im, width, height, upscaler_name=None, output_type
return res
invalid_filename_chars = '<>:"/\\|?*\n'
invalid_filename_prefix = ' '
invalid_filename_postfix = ' .'
re_nonletters = re.compile(r'[\s' + string.punctuation + ']+')
re_pattern = re.compile(r"(.*?)(?:\[([^\[\]]+)\]|$)")
re_pattern_arg = re.compile(r"(.*)<([^>]*)>$")
max_filename_part_length = 128
re_attention = re.compile(r'[\(*\[*](\w+)(:\d+(\.\d+))?[\)*\]*]|')
re_network = re.compile(r'\<\w+:(\w+)(:\d+(\.\d+))?\>|')
re_brackets = re.compile(r'[\([{})\]]')
NOTHING = object()
def sanitize_filename_part(text, replace_spaces=True):
if text is None:
return None
text = os.path.basename(text)
if replace_spaces:
text = text.replace(' ', '_')
text = text.replace('#', '_')
text = text.translate({ord(x): '_' for x in invalid_filename_chars})
text = text.lstrip(invalid_filename_prefix)[:max_filename_part_length]
text = text.rstrip(invalid_filename_postfix)
return text
class FilenameGenerator:
replacements = {
'width': lambda self: self.image.width,
'height': lambda self: self.image.height,
'batch_number': lambda self: self.batch_number,
'iter_number': lambda self: self.iter_number,
'cfg': lambda self: self.p and self.p.cfg_scale,
'clip_skip': lambda self: self.p and self.p.clip_skip,
'num': lambda self: NOTHING if self.p.n_iter == 1 and self.p.batch_size == 1 else self.p.iteration * self.p.batch_size + self.p.batch_index + 1,
'generation_number': lambda self: NOTHING if self.p.n_iter == 1 and self.p.batch_size == 1 else self.p.iteration * self.p.batch_size + self.p.batch_index + 1,
'date': lambda self: datetime.datetime.now().strftime('%Y-%m-%d'),
'datetime': lambda self, *args: self.datetime(*args), # accepts formats: [datetime], [datetime<Format>], [datetime<Format><Time Zone>]
'denoising': lambda self: self.p.denoising_strength if self.p and self.p.denoising_strength else NOTHING,
'generation_number': lambda self: NOTHING if self.p.n_iter == 1 and self.p.batch_size == 1 else self.p.iteration * self.p.batch_size + self.p.batch_index + 1,
'hasprompt': lambda self, *args: self.hasprompt(*args), # accepts formats:[hasprompt<prompt1|default><prompt2>..]
'height': lambda self: self.image.height,
'hash': lambda self: self.image_hash(),
'image_hash': lambda self: self.image_hash(),
'timestamp': lambda self: getattr(self.p, "job_timestamp", shared.state.job_timestamp),
'job_timestamp': lambda self: getattr(self.p, "job_timestamp", shared.state.job_timestamp),
'model': lambda self: sanitize_filename_part(shared.sd_model.sd_checkpoint_info.title, replace_spaces=False),
'model_shortname': lambda self: sanitize_filename_part(shared.sd_model.sd_checkpoint_info.name, replace_spaces=False),
'model': lambda self: shared.sd_model.sd_checkpoint_info.title,
'model_shortname': lambda self: shared.sd_model.sd_checkpoint_info.name,
'model_name': lambda self: shared.sd_model.sd_checkpoint_info.name,
'model_hash': lambda self: shared.sd_model.sd_checkpoint_info.shorthash,
'model_name': lambda self: sanitize_filename_part(shared.sd_model.sd_checkpoint_info.name, replace_spaces=False),
'prompt_hash': lambda self: hashlib.sha256(self.prompt.encode()).hexdigest()[0:8],
'prompt': lambda self: self.prompt,
'prompt_no_styles': lambda self: self.prompt_no_style(),
'prompt_spaces': lambda self: sanitize_filename_part(self.prompt, replace_spaces=False),
'prompt_words': lambda self: self.prompt_words(),
'prompt': lambda self: sanitize_filename_part(self.prompt),
'sampler': lambda self: self.p and sanitize_filename_part(self.p.sampler_name, replace_spaces=False),
'seed': lambda self: self.seed if self.seed is not None else '',
'prompt_hash': lambda self: hashlib.sha256(self.prompt.encode()).hexdigest()[0:8],
'sampler': lambda self: self.p and self.p.sampler_name,
'seed': lambda self: str(self.seed) if self.seed is not None else '',
'steps': lambda self: self.p and self.p.steps,
'styles': lambda self: self.p and sanitize_filename_part(", ".join([style for style in self.p.styles if not style == "None"]) or "None", replace_spaces=False),
'styles': lambda self: self.p and ", ".join([style for style in self.p.styles if not style == "None"]) or "None",
'uuid': lambda self: str(uuid.uuid4()),
'width': lambda self: self.image.width,
}
default_time_format = '%Y%m%d%H%M%S'
@@ -347,7 +337,7 @@ class FilenameGenerator:
outres = f'{outres}{expected}'
else:
outres = outres if default == "" else f'{outres}{default}'
return sanitize_filename_part(outres)
return outres
def image_hash(self):
if self.image is None:
@@ -360,6 +350,14 @@ class FilenameGenerator:
shorthash = hashlib.sha256(img_str).hexdigest()[0:8]
return shorthash
def prompt_words(self):
no_attention = re_attention.sub(r'\1', self.prompt)
no_network = re_network.sub(r'\1', no_attention)
no_brackets = re_brackets.sub('', no_network)
words = [x for x in re_nonletters.split(no_brackets or "") if len(x) > 0]
prompt = " ".join(words[0:shared.opts.directories_max_prompt_words])
return prompt
def prompt_no_style(self):
if self.p is None or self.prompt is None:
return None
@@ -367,13 +365,9 @@ class FilenameGenerator:
for style in shared.prompt_styles.get_style_prompts(self.p.styles):
if len(style) > 0:
for part in style.split("{prompt}"):
prompt_no_style = prompt_no_style.replace(part, "").replace(", ,", ",").strip().strip(',')
prompt_no_style = prompt_no_style.replace(style, "").strip().strip(',').strip()
return sanitize_filename_part(prompt_no_style, replace_spaces=False)
def prompt_words(self):
words = [x for x in re_nonletters.split(self.prompt or "") if len(x) > 0]
return sanitize_filename_part(" ".join(words[0:shared.opts.directories_max_prompt_words]), replace_spaces=False)
prompt_no_style = prompt_no_style.replace(part, "").replace(", ,", ",")
prompt_no_style = prompt_no_style.replace(style, "")
return prompt_no_style
def datetime(self, *args):
time_datetime = datetime.datetime.now()
@@ -387,7 +381,23 @@ class FilenameGenerator:
formatted_time = time_zone_time.strftime(time_format)
except (ValueError, TypeError):
formatted_time = time_zone_time.strftime(self.default_time_format)
return sanitize_filename_part(formatted_time, replace_spaces=False)
return formatted_time
def sanitize(self, filename):
invalid_chars = '#<>:;"/\\|?*\n\t\r'
invalid_prefix = ''
invalid_suffix = '.'
parts = Path(filename).parts
for part in parts:
part = part.translate({ord(x): '_' for x in invalid_chars})
part = part.lstrip(invalid_prefix)
part = part.rstrip(invalid_suffix)
fn = Path(*parts)
max_length = os.statvfs(__file__).f_namemax if hasattr(os, 'statvfs') else 128
fn, ext = os.path.splitext(fn)
fn = fn[:max_length-max(4, len(ext))] + ext
# shared.log.debug(f'Filename sanitize: input={filename} parts={parts} output={fn}')
return fn
def apply(self, x):
res = ''
@@ -409,16 +419,14 @@ class FilenameGenerator:
replacement = fun(self, *pattern_args)
except Exception as e:
replacement = None
errors.display(e, 'filename pattern')
shared.log.error(f'Filename apply pattern: {e}')
if replacement == NOTHING:
continue
elif replacement is not None:
res += text + str(replacement)
res += text + str(replacement).replace('/', '-').replace('\\', '-')
continue
else:
res += text + f'[{pattern}]' # reinsert unknown pattern
res += f'{text}'
res = res.split('?')[0].strip('-').strip()
return res
@@ -430,6 +438,8 @@ def get_next_sequence_number(path, basename):
if basename != '':
basename = f"{basename}-"
prefix_length = len(basename)
if not os.path.isdir(path):
return 0
for p in os.listdir(path):
if p.startswith(basename):
parts = os.path.splitext(p[prefix_length:])[0].split('-') # splits the filename (removing the basename first if one is defined, so the sequence number is always the first element)
@@ -443,7 +453,7 @@ def get_next_sequence_number(path, basename):
def atomically_save_image():
Image.MAX_IMAGE_PIXELS = None # disable check in Pillow and rely on check below to allow large custom image sizes
while True:
image, filename, extension, params, exifinfo, txt_fullfn = save_queue.get()
image, filename, extension, params, exifinfo, filename_txt = save_queue.get()
fn = filename + extension
filename = filename.strip()
if extension[0] != '.': # add dot if missing
@@ -488,11 +498,11 @@ def atomically_save_image():
# additional metadata saved in files
if shared.opts.save_txt and len(exifinfo) > 0:
try:
with open(txt_fullfn, "w", encoding="utf8") as file:
with open(filename_txt, "w", encoding="utf8") as file:
file.write(f"{exifinfo}\n")
shared.log.debug(f'Saving: text="{txt_fullfn}"')
shared.log.debug(f'Saving: text="{filename_txt}"')
except Exception as e:
shared.log.warning(f'Image description save failed: {txt_fullfn} {e}')
shared.log.warning(f'Image description save failed: {filename_txt} {e}')
with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file:
file.write(exifinfo)
if shared.opts.save_log_fn != '' and len(exifinfo) > 0:
@@ -512,37 +522,7 @@ save_thread = threading.Thread(target=atomically_save_image, daemon=True)
save_thread.start()
def save_image(image, path, basename, seed=None, prompt=None, extension='jpg', info=None, short_filename=False, no_prompt=False, grid=False, pnginfo_section_name='parameters', p=None, existing_info=None, forced_filename=None, suffix="", save_to_dirs=None):
"""Save an image.
Args:
image (`PIL.Image`):
The image to be saved.
path (`str`):
The directory to save the image. Note, the option `save_to_dirs` will make the image to be saved into a sub directory.
basename (`str`):
The base filename which will be applied to `filename pattern`.
seed, prompt, short_filename,
extension (`str`):
Image file extension, default is `jpg`.
pngsectionname (`str`):
Specify the name of the section which `info` will be saved in.
info (`str` or `PngImagePlugin.iTXt`):
PNG info chunks.
existing_info (`dict`):
Additional PNG info. `existing_info == {pngsectionname: info, ...}`
no_prompt:
TODO I don't know its meaning.
p (`StableDiffusionProcessing`)
forced_filename (`str`):
If specified, `basename` and filename pattern will be ignored.
save_to_dirs (bool):
If true, the image will be saved into a subdirectory of `path`.
Returns: (fullfn, txt_fullfn)
fullfn (`str`):
The full path of the saved imaged.
txt_fullfn (`str` or None):
If a text file is saved for this image, this will be its full path. Otherwise None.
"""
def save_image(image, path, basename, seed=None, prompt=None, extension='jpg', info=None, short_filename=False, no_prompt=False, grid=False, pnginfo_section_name='parameters', p=None, existing_info=None, forced_filename=None, suffix="", save_to_dirs=None): # pylint: disable=unused-argument
if image is None:
shared.log.warning('Image is none')
return None, None
@@ -551,12 +531,9 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='jpg', i
if path is None or len(path) == 0: # set default path to avoid errors when functions are triggered manually or via api and param is not set
path = shared.opts.outdir_save
namegen = FilenameGenerator(p, seed, prompt, image, grid=grid)
if save_to_dirs is None:
save_to_dirs = (grid and shared.opts.grid_save_to_dirs) or (not grid and shared.opts.save_to_dirs and not no_prompt)
if save_to_dirs:
dirname = namegen.apply(shared.opts.directories_filename_pattern or "[prompt_words]").lstrip(' ').rstrip('\\ /')
if shared.opts.save_to_dirs:
dirname = namegen.apply(shared.opts.directories_filename_pattern or "[prompt_words]")
path = os.path.join(path, dirname)
os.makedirs(path, exist_ok=True)
if forced_filename is None:
if short_filename or seed is None:
file_decoration = ""
@@ -564,46 +541,40 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='jpg', i
file_decoration = shared.opts.samples_filename_pattern
else:
file_decoration = "[seq]-[prompt_words]"
file_decoration = namegen.apply(file_decoration).strip(' ').strip('-')
if len(file_decoration) == 0:
file_decoration = namegen.apply('[seq]').strip(' ').strip('-')
file_decoration = namegen.apply(file_decoration)
file_decoration += suffix
if shared.opts.save_images_add_number:
if '[seq]' not in file_decoration:
file_decoration = f"[seq]-{file_decoration}"
basecount = get_next_sequence_number(path, basename)
fullfn = None
filename = None
for i in range(9999):
seq = f"{basecount + i:05}" if basename == '' else f"{basename}-{basecount + i:04}"
fullfn = os.path.join(path, f"{file_decoration.replace('[seq]', seq)}.{extension}")
if not os.path.exists(fullfn):
filename = os.path.join(path, f"{file_decoration.replace('[seq]', seq)}.{extension}")
if not os.path.exists(filename):
break
else:
if basename == '':
fullfn = os.path.join(path, f"{file_decoration}.{extension}")
else:
fullfn = os.path.join(path, f"{basename}-{file_decoration}.{extension}")
filename = os.path.join(path, f"{file_decoration}.{extension}") if basename == '' else os.path.join(path, f"{basename}-{file_decoration}.{extension}")
else:
fullfn = os.path.join(path, f"{forced_filename}.{extension}")
filename = os.path.join(path, f"{forced_filename}.{extension}")
pnginfo = existing_info or {}
if info is not None:
pnginfo[pnginfo_section_name] = info
params = script_callbacks.ImageSaveParams(image, p, fullfn, pnginfo)
params = script_callbacks.ImageSaveParams(image, p, filename, pnginfo)
script_callbacks.before_image_saved_callback(params)
exifinfo = params.pnginfo.get('UserComment', '')
exifinfo = (exifinfo + ', ' if len(exifinfo) > 0 else '') + params.pnginfo.get(pnginfo_section_name, '')
filename, extension = os.path.splitext(params.filename)
if hasattr(os, 'statvfs'):
max_name_len = os.statvfs(path).f_namemax
filename = filename[:max_name_len - max(4, len(extension))]
params.filename = filename + extension
txt_fullfn = f"{filename}.txt" if shared.opts.save_txt and len(exifinfo) > 0 else None
save_queue.put((params.image, filename, extension, params, exifinfo, txt_fullfn)) # actual save is executed in a thread that polls data from queue
filename = namegen.sanitize(params.filename)
dirname = os.path.dirname(filename)
os.makedirs(dirname, exist_ok=True)
filename, extension = os.path.splitext(filename)
filename_txt = f"{filename}.txt" if shared.opts.save_txt and len(exifinfo) > 0 else None
save_queue.put((params.image, filename, extension, params, exifinfo, filename_txt)) # actual save is executed in a thread that polls data from queue
save_queue.join()
params.image.already_saved_as = params.filename
script_callbacks.image_saved_callback(params)
return params.filename, txt_fullfn
return params.filename, filename_txt
def safe_decode_string(s: bytes):
+4 -2
View File
@@ -169,6 +169,7 @@ class StableDiffusionProcessing:
self.s_tmax = float('inf') # not representable as a standard ui option
self.comments = {}
self.is_api = False
self.resize_mode: int = 0
shared.opts.data['clip_skip'] = clip_skip
@property
@@ -901,7 +902,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
output_images.insert(0, grid)
index_of_first_image = 1
if shared.opts.grid_save:
images.save_image(grid, p.outpath_grids, "", p.all_seeds[0], p.all_prompts[0], shared.opts.grid_format, info=infotext(-1), short_filename=not shared.opts.grid_extended_filename, p=p, grid=True, suffix="-grid") # main save grid
images.save_image(grid, p.outpath_grids, "", p.all_seeds[0], p.all_prompts[0], shared.opts.grid_format, info=infotext(-1), p=p, grid=True, suffix="-grid") # main save grid
if not p.disable_extra_networks:
modules.extra_networks.deactivate(p, extra_network_data)
@@ -1000,6 +1001,7 @@ class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):
shared.state.job_count = self.n_iter
shared.state.job_count = shared.state.job_count * 2
shared.state.processing_has_refined_job_count = True
hypertile_set(self, hr=True)
shared.log.debug(f'Init hires: upscaler="{self.hr_upscaler}" sampler="{self.latent_sampler}" resize={self.hr_resize_x}x{self.hr_resize_y} upscale={self.hr_upscale_to_x}x{self.hr_upscale_to_y}')
def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts):
@@ -1178,7 +1180,7 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
self.init_img_width = img.width # pylint: disable=attribute-defined-outside-init
self.init_img_height = img.height # pylint: disable=attribute-defined-outside-init
if shared.opts.save_init_img:
images.save_image(img, path=shared.opts.outdir_init_images, basename=None, forced_filename=self.init_img_hash, save_to_dirs=False, suffix="-init-image")
images.save_image(img, path=shared.opts.outdir_init_images, basename=None, forced_filename=self.init_img_hash, suffix="-init-image")
image = images.flatten(img, shared.opts.img2img_background_color)
if crop_region is None and self.resize_mode != 4:
image = images.resize_image(self.resize_mode, image, self.width, self.height)
+6
View File
@@ -12,6 +12,7 @@ import modules.sd_models as sd_models
import modules.sd_vae as sd_vae
import modules.taesd.sd_vae_taesd as sd_vae_taesd
import modules.images as images
import modules.errors as errors
from modules.processing import StableDiffusionProcessing
import modules.prompt_parser_diffusers as prompt_parser_diffusers
from modules.sd_hijack_hypertile import hypertile_set
@@ -28,6 +29,9 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
if p.init_images[0].width != tgt_width or p.init_images[0].height != tgt_height:
shared.log.debug(f'Resizing init images: original={p.init_images[0].width}x{p.init_images[0].height} target={tgt_width}x{tgt_height}')
p.init_images = [images.resize_image(1, image, tgt_width, tgt_height, upscaler_name=None) for image in p.init_images]
p.height = tgt_height
p.width = tgt_width
hypertile_set(p)
if p.mask is not None:
p.mask = images.resize_image(1, p.mask, tgt_width, tgt_height, upscaler_name=None)
if p.mask_for_overlay is not None:
@@ -373,6 +377,8 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
except ValueError as e:
shared.state.interrupted = True
shared.log.error(f'Processing: {e}')
if shared.cmd_opts.debug:
errors.display(e, 'Processing')
if hasattr(shared.sd_model, 'embedding_db') and len(shared.sd_model.embedding_db.embeddings_used) > 0:
p.extra_generation_params['Embeddings'] = ', '.join(shared.sd_model.embedding_db.embeddings_used)
+5 -2
View File
@@ -324,8 +324,11 @@ def parse_prompt_attention(text):
whitespace = ' '
def multiply_range(start_position, multiplier):
for p in range(start_position, len(res)):
res[p][1] *= multiplier
try:
for p in range(start_position, len(res)):
res[p][1] *= multiplier
except Exception as e:
log(f'Prompt parser: {e}')
for m in re_attention.finditer(text):
text = m.group(0)
+8 -3
View File
@@ -43,19 +43,24 @@ def parse_list(x: list[int], /) -> str:
@contextmanager
def split_attention(layer: nn.Module, tile_size: int=256, min_tile_size: int=256, swap_size: int=1, depth: int=0):
# hijacks AttnBlock from ldm and attention from diffusers
global reset_needed # pylint: disable=global-statement
ar = height / width # Aspect ratio
reset_needed = True
nhs = possible_tile_sizes(height, tile_size, min_tile_size, swap_size) # possible sub-grids that fit into the image
nws = possible_tile_sizes(width, tile_size, min_tile_size, swap_size)
# random sub-grid indices # TODO remove randomness. seed?
make_ns = lambda: (nhs[random.randint(0, len(nhs) - 1)], nws[random.randint(0, len(nws) - 1)]) # pylint: disable=unnecessary-lambda-assignment
def reset_nhs():
nonlocal nhs
nonlocal nws, make_ns, ar
ar = height / width # Aspect ratio
nhs = possible_tile_sizes(height, tile_size, min_tile_size, swap_size)
make_ns = lambda: (nhs[random.randint(0, len(nhs) - 1)], nws[random.randint(0, len(nws) - 1)]) # pylint: disable=unnecessary-lambda-assignment
def reset_nws():
nonlocal nws
nonlocal nws, make_ns, ar
ar = height / width # Aspect ratio
nws = possible_tile_sizes(width, tile_size, min_tile_size, swap_size)
make_ns = lambda: (nhs[random.randint(0, len(nhs) - 1)], nws[random.randint(0, len(nws) - 1)]) # pylint: disable=unnecessary-lambda-assignment
def self_attn_forward(forward: Callable) -> Callable:
@wraps(forward)
+3 -3
View File
@@ -553,7 +553,7 @@ options_templates.update(options_section(('saving-paths', "Image Naming & Paths"
"outdir_sep_dirs": OptionInfo("<h2>Directories</h2>", "", gr.HTML),
"save_to_dirs": OptionInfo(False, "Save images to a subdirectory"),
"use_save_to_dirs_for_ui": OptionInfo(False, "Save images to a subdirectory when using Save button"),
"use_save_to_dirs_for_ui": OptionInfo(False, "Save images to a subdirectory when using Save button", gr.Checkbox, {"visible": False}),
"directories_filename_pattern": OptionInfo("[date]", "Directory name pattern", component_args=hide_dirs),
"directories_max_prompt_words": OptionInfo(8, "Max prompt words for [prompt_words] pattern", gr.Slider, {"minimum": 1, "maximum": 99, "step": 1, **hide_dirs}),
"outdir_samples": OptionInfo("", "Output directory for images", component_args=hide_dirs, folder=True),
@@ -564,8 +564,8 @@ options_templates.update(options_section(('saving-paths', "Image Naming & Paths"
"outdir_init_images": OptionInfo("outputs/init-images", "Directory for saving init images when using img2img", component_args=hide_dirs, folder=True),
"outdir_sep_grids": OptionInfo("<h2>Grids</h2>", "", gr.HTML),
"grid_extended_filename": OptionInfo(True, "Add extended info (seed, prompt) to filename when saving grid"),
"grid_save_to_dirs": OptionInfo(False, "Save grids to a subdirectory"),
"grid_extended_filename": OptionInfo(True, "Add extended info (seed, prompt) to filename when saving grid", gr.Checkbox, {"visible": False}),
"grid_save_to_dirs": OptionInfo(False, "Save grids to a subdirectory", gr.Checkbox, {"visible": False}),
"outdir_grids": OptionInfo("", "Output directory for grids", component_args=hide_dirs, folder=True),
"outdir_txt2img_grids": OptionInfo("outputs/grids", 'Output directory for txt2img grids', component_args=hide_dirs, folder=True),
"outdir_img2img_grids": OptionInfo("outputs/grids", 'Output directory for img2img grids', component_args=hide_dirs, folder=True),
+6 -6
View File
@@ -115,11 +115,11 @@ def save_files(js_data, images, html_info, index):
filenames.append(os.path.basename(fullfn))
fullfns.append(fullfn)
destination = shared.opts.outdir_save
if shared.opts.use_save_to_dirs_for_ui:
namegen = modules.images.FilenameGenerator(p, seed=p.all_seeds[i], prompt=p.all_prompts[i], image=None) # pylint: disable=no-member
dirname = namegen.apply(shared.opts.directories_filename_pattern or "[prompt_words]").lstrip(' ').rstrip('\\ /')
destination = os.path.join(destination, dirname)
os.makedirs(destination, exist_ok = True)
namegen = modules.images.FilenameGenerator(p, seed=p.all_seeds[i], prompt=p.all_prompts[i], image=None) # pylint: disable=no-member
dirname = namegen.apply(shared.opts.directories_filename_pattern or "[prompt_words]").lstrip(' ').rstrip('\\ /')
destination = os.path.join(destination, dirname)
destination = namegen.sanitize(destination)
os.makedirs(destination, exist_ok = True)
shutil.copy(fullfn, destination)
shared.log.info(f'Copying image: file="{fullfn}" folder="{destination}"')
tgt_filename = os.path.join(destination, os.path.basename(fullfn))
@@ -127,7 +127,7 @@ def save_files(js_data, images, html_info, index):
else:
image = image_from_url_text(filedata)
info = p.infotexts[i + 1] if len(p.infotexts) > len(p.all_seeds) else p.infotexts[i] # infotexts may be offset by 1 because the first image is the grid
fullfn, txt_fullfn = modules.images.save_image(image, shared.opts.outdir_save, "", seed=p.all_seeds[i], prompt=p.all_prompts[i], info=info, extension=shared.opts.samples_format, grid=is_grid, p=p, save_to_dirs=shared.opts.use_save_to_dirs_for_ui)
fullfn, txt_fullfn = modules.images.save_image(image, shared.opts.outdir_save, "", seed=p.all_seeds[i], prompt=p.all_prompts[i], info=info, extension=shared.opts.samples_format, grid=is_grid, p=p)
if fullfn is None:
continue
filename = os.path.relpath(fullfn, shared.opts.outdir_save)
+3 -3
View File
@@ -245,8 +245,8 @@ def create_ui():
data = []
def civit_search_model(name, tag, model_type):
types = 'LORA' if model_type == 'LoRA' else 'Checkpoint'
url = f'https://civitai.com/api/v1/models?limit=25&types={types}&Sort=Newest'
# types = 'LORA' if model_type == 'LoRA' else 'Checkpoint'
url = 'https://civitai.com/api/v1/models?limit=25&&Sort=Newest'
if name is not None and len(name) > 0:
url += f'&query={name}'
if tag is not None and len(tag) > 0:
@@ -261,7 +261,7 @@ def create_ui():
data1 = []
for model in data:
found = 0
if model_type == 'LoRA' and model['type'] == 'LORA':
if model_type == 'LoRA' and model['type'] in ['LORA', 'LoCon']:
found += 1
for variant in model['modelVersions']:
if model_type == 'SD 1.5':
+1 -1
View File
@@ -51,7 +51,7 @@ accelerate==0.20.3
opencv-python-headless==4.7.0.72
diffusers==0.21.4
einops==0.4.1
gradio==3.44.4
gradio==3.43.2
huggingface_hub==0.17.1
numexpr==2.8.4
numpy==1.24.4
+1 -1
View File
@@ -128,7 +128,7 @@ class Script(scripts.Script):
if len(history) > 1:
grid = images.image_grid(history, rows=1)
if opts.grid_save:
images.save_image(grid, p.outpath_grids, "grid", initial_seed, p.prompt, opts.grid_format, info=info, short_filename=not opts.grid_extended_filename, grid=True, p=p)
images.save_image(grid, p.outpath_grids, "grid", initial_seed, p.prompt, opts.grid_format, info=info, grid=True, p=p)
if opts.return_grid:
grids.append(grid)
+3 -3
View File
@@ -69,7 +69,7 @@ def get_matched_noise(_np_src_image, np_mask_rgb, noise_q=1, color_variation=0.0
height = _np_src_image.shape[1]
num_channels = _np_src_image.shape[2]
_np_src_image[:] * (1. - np_mask_rgb)
_np_src_image[:] * (1. - np_mask_rgb) # pylint: disable=pointless-statement
np_mask_grey = np.sum(np_mask_rgb, axis=2) / 3.
img_mask = np_mask_grey > 1e-6
ref_mask = np_mask_grey < 1e-3
@@ -136,7 +136,7 @@ class Script(scripts.Script):
return [info, pixels, mask_blur, direction, noise_q, color_variation]
def run(self, p, _, pixels, mask_blur, direction, noise_q, color_variation):
def run(self, p, _, pixels, mask_blur, direction, noise_q, color_variation): # pylint: disable=arguments-differ
initial_seed_and_info = [None, None]
process_width = p.width
@@ -274,6 +274,6 @@ class Script(scripts.Script):
images.save_image(img, p.outpath_samples, "", res.seed, p.prompt, opts.samples_format, info=res.info, p=p)
if opts.grid_save and len(all_processed_images) > 1:
images.save_image(combined_grid_image, p.outpath_grids, "grid", res.seed, p.prompt, opts.samples_format, info=res.info, short_filename=not opts.grid_extended_filename, grid=True, p=p)
images.save_image(combined_grid_image, p.outpath_grids, "grid", res.seed, p.prompt, opts.samples_format, info=res.info, grid=True, p=p)
return res
+1 -1
View File
@@ -118,7 +118,7 @@ class Script(scripts.Script):
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)
return [checkbox_iterate, checkbox_iterate_batch, prompt_txt]
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_txt: str):
def run(self, p, checkbox_iterate, checkbox_iterate_batch, prompt_txt: str): # pylint: disable=arguments-differ
lines = [x.strip() for x in prompt_txt.splitlines()]
lines = [x for x in lines if len(x) > 0]