mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
add flag use mime for batches
This commit is contained in:
parent
221ac0b9ab
commit
06c528ac1c
@ -125,3 +125,4 @@ parser.add_argument("--skip-load-model-at-start", action='store_true', help="if
|
|||||||
parser.add_argument("--unix-filenames-sanitization", action='store_true', help="allow any symbols except '/' in filenames. May conflict with your browser and file system")
|
parser.add_argument("--unix-filenames-sanitization", action='store_true', help="allow any symbols except '/' in filenames. May conflict with your browser and file system")
|
||||||
parser.add_argument("--filenames-max-length", type=int, default=128, help='maximal length of filenames of saved images. If you override it, it can conflict with your file system')
|
parser.add_argument("--filenames-max-length", type=int, default=128, help='maximal length of filenames of saved images. If you override it, it can conflict with your file system')
|
||||||
parser.add_argument("--no-prompt-history", action='store_true', help="disable read prompt from last generation feature; settings this argument will not create '--data_path/params.txt' file")
|
parser.add_argument("--no-prompt-history", action='store_true', help="disable read prompt from last generation feature; settings this argument will not create '--data_path/params.txt' file")
|
||||||
|
parser.add_argument("--use-mime-file-filtering-for-batch-from-dir", action='store_true', help="allows passing images with no or with incorrect extension in batch from directory")
|
||||||
|
@ -22,7 +22,7 @@ def process_batch(p, input, output_dir, inpaint_mask_dir, args, to_scale=False,
|
|||||||
processing.fix_seed(p)
|
processing.fix_seed(p)
|
||||||
|
|
||||||
if isinstance(input, str):
|
if isinstance(input, str):
|
||||||
batch_images = list(shared.walk_files(input, allowed_extensions=(".png", ".jpg", ".jpeg", ".webp", ".tif", ".tiff")))
|
batch_images = list(shared.walk_image_files(input))
|
||||||
else:
|
else:
|
||||||
batch_images = [os.path.abspath(x.name) for x in input]
|
batch_images = [os.path.abspath(x.name) for x in input]
|
||||||
|
|
||||||
|
@ -300,16 +300,14 @@ def requirements_met(requirements_file):
|
|||||||
package = m.group(1).strip()
|
package = m.group(1).strip()
|
||||||
version_required = (m.group(2) or "").strip()
|
version_required = (m.group(2) or "").strip()
|
||||||
|
|
||||||
if version_required == "":
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
version_installed = importlib.metadata.version(package)
|
version_installed = importlib.metadata.version(package)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if packaging.version.parse(version_required) != packaging.version.parse(version_installed):
|
if version_required != "":
|
||||||
return False
|
if packaging.version.parse(version_required) != packaging.version.parse(version_installed):
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir,
|
|||||||
assert not shared.cmd_opts.hide_ui_dir_config, '--hide-ui-dir-config option must be disabled'
|
assert not shared.cmd_opts.hide_ui_dir_config, '--hide-ui-dir-config option must be disabled'
|
||||||
assert input_dir, 'input directory not selected'
|
assert input_dir, 'input directory not selected'
|
||||||
|
|
||||||
image_list = shared.listfiles(input_dir)
|
image_list = shared.walk_image_files(input_dir)
|
||||||
for filename in image_list:
|
for filename in image_list:
|
||||||
yield filename, filename
|
yield filename, filename
|
||||||
else:
|
else:
|
||||||
|
@ -82,6 +82,7 @@ listfiles = util.listfiles
|
|||||||
html_path = util.html_path
|
html_path = util.html_path
|
||||||
html = util.html
|
html = util.html
|
||||||
walk_files = util.walk_files
|
walk_files = util.walk_files
|
||||||
|
walk_image_files = util.walk_image_files
|
||||||
ldm_print = util.ldm_print
|
ldm_print = util.ldm_print
|
||||||
|
|
||||||
reload_gradio_theme = shared_gradio_themes.reload_gradio_theme
|
reload_gradio_theme = shared_gradio_themes.reload_gradio_theme
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import filetype
|
||||||
|
|
||||||
from modules import shared
|
from modules import shared
|
||||||
from modules.paths_internal import script_path, cwd
|
from modules.paths_internal import script_path, cwd
|
||||||
@ -28,7 +29,7 @@ def html(filename):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def walk_files(path, allowed_extensions=None):
|
def walk_files(path, allowed_extensions=None, allowed_mime=None):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -40,15 +41,36 @@ def walk_files(path, allowed_extensions=None):
|
|||||||
|
|
||||||
for root, _, files in items:
|
for root, _, files in items:
|
||||||
for filename in sorted(files, key=natural_sort_key):
|
for filename in sorted(files, key=natural_sort_key):
|
||||||
if allowed_extensions is not None:
|
filepath = os.path.join(root, filename)
|
||||||
_, ext = os.path.splitext(filename)
|
|
||||||
if ext.lower() not in allowed_extensions:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not shared.opts.list_hidden_files and ("/." in root or "\\." in root):
|
if not shared.opts.list_hidden_files and ("/." in root or "\\." in root):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield os.path.join(root, filename)
|
if allowed_extensions or allowed_mime:
|
||||||
|
file_allowed = False
|
||||||
|
|
||||||
|
if allowed_extensions is not None:
|
||||||
|
_, ext = os.path.splitext(filename)
|
||||||
|
if ext.lower() in allowed_extensions:
|
||||||
|
file_allowed = True
|
||||||
|
|
||||||
|
if allowed_mime is not None:
|
||||||
|
if filetype.guess(filepath).mime.startswith(allowed_mime):
|
||||||
|
file_allowed = True
|
||||||
|
else:
|
||||||
|
file_allowed = True
|
||||||
|
|
||||||
|
if not file_allowed:
|
||||||
|
continue
|
||||||
|
|
||||||
|
yield filepath
|
||||||
|
|
||||||
|
|
||||||
|
def walk_image_files(path):
|
||||||
|
if shared.cmd_opts.use_mime_file_filtering_for_batch_from_dir:
|
||||||
|
return walk_files(path, allowed_mime='image/')
|
||||||
|
else:
|
||||||
|
return walk_files(path, allowed_extensions=(".png", ".jpg", ".jpeg", ".webp", ".tif", ".tiff"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ldm_print(*args, **kwargs):
|
def ldm_print(*args, **kwargs):
|
||||||
|
@ -30,4 +30,5 @@ torch
|
|||||||
torchdiffeq
|
torchdiffeq
|
||||||
torchsde
|
torchsde
|
||||||
transformers==4.30.2
|
transformers==4.30.2
|
||||||
pillow-avif-plugin==1.4.3
|
pillow-avif-plugin==1.4.3
|
||||||
|
filetype
|
||||||
|
@ -30,3 +30,4 @@ torchsde==0.2.6
|
|||||||
transformers==4.30.2
|
transformers==4.30.2
|
||||||
httpx==0.24.1
|
httpx==0.24.1
|
||||||
pillow-avif-plugin==1.4.3
|
pillow-avif-plugin==1.4.3
|
||||||
|
filetype
|
||||||
|
Loading…
Reference in New Issue
Block a user