Support recursive.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from tagger.interrogator import Interrogator, WaifuDiffusionInterrogator
|
||||
from tagger.interrogator import Interrogator
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
@@ -32,6 +32,10 @@ parser.add_argument(
|
||||
'--rawtag',
|
||||
action='store_true',
|
||||
help='Use the raw output of the model')
|
||||
parser.add_argument(
|
||||
'--recursive',
|
||||
action='store_true',
|
||||
help='Enable recursive file search')
|
||||
parser.add_argument(
|
||||
'--model',
|
||||
default='wd14-convnextv2.v1',
|
||||
@@ -56,17 +60,24 @@ def image_interrogate(image_path: Path):
|
||||
return Interrogator.postprocess_tags(result[1], threshold=args.threshold)
|
||||
return Interrogator.postprocess_tags(result[1], threshold=args.threshold, escape_tag=True, replace_underscore=True)
|
||||
|
||||
def explore_files(folder_path: Path):
|
||||
"""
|
||||
Explore files by folder path
|
||||
"""
|
||||
for path in folder_path.iterdir():
|
||||
if path.is_file() and path.suffix in ['.png', '.jpg', '.jpeg', '.webp']:
|
||||
yield path
|
||||
elif args.recursive and path.is_dir():
|
||||
yield from explore_files(path)
|
||||
|
||||
if args.dir:
|
||||
d = Path(args.dir)
|
||||
for f in d.iterdir():
|
||||
if not f.is_file() or f.suffix not in ['.png', '.jpg', '.jpeg', '.webp']:
|
||||
continue
|
||||
root_path = Path(args.dir)
|
||||
for file_path in explore_files(root_path):
|
||||
image_path = Path(file_path)
|
||||
caption_path = image_path.parent / f'{file_path.stem}{args.ext}'
|
||||
|
||||
image_path = Path(f)
|
||||
caption_path = image_path.parent / f'{f.stem}{args.ext}'
|
||||
|
||||
if caption_path.is_file() and not args.overwrite:
|
||||
# skip if file exists
|
||||
if caption_path.is_file() and not args.overwrite:
|
||||
# skip if caption exists
|
||||
print('skip:', image_path)
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user