mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-09 06:45:09 +00:00
change option to append_tags, minor update
This commit is contained in:
@@ -169,31 +169,26 @@ def main(args):
|
|||||||
|
|
||||||
tag_text = ", ".join(combined_tags)
|
tag_text = ", ".join(combined_tags)
|
||||||
|
|
||||||
if args.append_captions:
|
if args.append_tags:
|
||||||
# Check if file exists
|
# Check if file exists
|
||||||
if os.path.exists(caption_file):
|
if os.path.exists(caption_file):
|
||||||
|
|
||||||
with open(caption_file, "rt", encoding="utf-8") as f:
|
with open(caption_file, "rt", encoding="utf-8") as f:
|
||||||
|
|
||||||
# Read file and remove new lines
|
# Read file and remove new lines
|
||||||
existing_content = f.read().strip("\n") # Remove newlines
|
existing_content = f.read().strip("\n") # Remove newlines
|
||||||
|
|
||||||
# Split the content into tags and store them in a list
|
# Split the content into tags and store them in a list
|
||||||
existing_tags = [tag.strip() for tag in existing_content.split(",") if tag.strip()]
|
existing_tags = [tag.strip() for tag in existing_content.split(",") if tag.strip()]
|
||||||
|
|
||||||
# Check and remove repeating tags in tag_text
|
# Check and remove repeating tags in tag_text
|
||||||
tag_text = ", ".join([tag for tag in combined_tags if tag not in existing_tags])
|
new_tags = [tag for tag in combined_tags if tag not in existing_tags]
|
||||||
|
|
||||||
# If the file has content, prepend a comma to tag_text
|
|
||||||
if existing_content.strip() and tag_text:
|
|
||||||
tag_text = ", ".join(existing_tags) + ", " + tag_text
|
|
||||||
|
|
||||||
|
# Create new tag_text
|
||||||
|
tag_text = ", ".join(existing_tags + new_tags)
|
||||||
|
|
||||||
with open(caption_file, "wt", encoding="utf-8") as f:
|
with open(caption_file, "wt", encoding="utf-8") as f:
|
||||||
f.write(tag_text + "\n")
|
f.write(tag_text + "\n")
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print(
|
print(f"\n{image_path}:\n Character tags: {character_tag_text}\n General tags: {general_tag_text}")
|
||||||
f"\n{image_path}:\n Character tags: {character_tag_text}\n General tags: {general_tag_text}")
|
|
||||||
|
|
||||||
# 読み込みの高速化のためにDataLoaderを使うオプション
|
# 読み込みの高速化のためにDataLoaderを使うオプション
|
||||||
if args.max_data_loader_n_workers is not None:
|
if args.max_data_loader_n_workers is not None:
|
||||||
@@ -305,12 +300,12 @@ def setup_parser() -> argparse.ArgumentParser:
|
|||||||
default="",
|
default="",
|
||||||
help="comma-separated list of undesired tags to remove from the output / 出力から除外したいタグのカンマ区切りのリスト",
|
help="comma-separated list of undesired tags to remove from the output / 出力から除外したいタグのカンマ区切りのリスト",
|
||||||
)
|
)
|
||||||
parser.add_argument("--frequency_tags", action="store_true",
|
parser.add_argument("--frequency_tags", action="store_true", help="Show frequency of tags for images / 画像ごとのタグの出現頻度を表示する")
|
||||||
help="Show frequency of tags for images / 画像ごとのタグの出現頻度を表示する")
|
parser.add_argument("--append_tags", action="store_true", help="Append captions instead of overwriting / 上書きではなくキャプションを追記する")
|
||||||
parser.add_argument("--append_captions", action="store_true", help="Append captions instead of overwriting")
|
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = setup_parser()
|
parser = setup_parser()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user