Skip to content

Commit 6166575

Browse files
update tag gen/captioner
1 parent e968de7 commit 6166575

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

hakubooru/caption.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from random import shuffle
2+
13
from hakubooru.metainfo import (
24
meta_keywords_black_list,
35
special_tags,
@@ -48,23 +50,35 @@ def extract_special_tags(tag_list: list[Tag]) -> tuple[list[str], list[str]]:
4850

4951
def make_caption(
5052
post: Post,
53+
shuffle_each: bool = False,
5154
tag_word_sep: str = " ",
5255
tag_seperator: str = ", ",
5356
keep_seperator: str = "|||",
5457
processor=[year_tag, rating_tag, quality_tag],
5558
) -> str:
5659
special_tag_list, general_tag_list = extract_special_tags(post.tag_list_general)
60+
character_tag_list = post.tag_list_character
61+
copyright_tag_list = post.tag_list_copyright
62+
artists_tag_list = post.tag_list_artist
63+
meta_tag_list = [tag for tag in post.tag_list_meta if meta_tags_filter(tag)]
64+
65+
if shuffle_each:
66+
shuffle(special_tag_list)
67+
shuffle(general_tag_list)
68+
shuffle(character_tag_list)
69+
shuffle(copyright_tag_list)
70+
shuffle(artists_tag_list)
71+
shuffle(meta_tag_list)
72+
5773
special_tag_list = tag_str_list(special_tag_list, tag_word_sep)
5874
general_tag_list = tag_str_list(general_tag_list, tag_word_sep)
59-
character_tag_list = tag_str_list(post.tag_list_character, tag_word_sep)
60-
copyright_tag_list = tag_str_list(post.tag_list_copyright, tag_word_sep)
75+
character_tag_list = tag_str_list(character_tag_list, tag_word_sep)
76+
copyright_tag_list = tag_str_list(copyright_tag_list, tag_word_sep)
6177
artists_tag_list = tag_str_list(
62-
[tag for tag in post.tag_list_artist if tags_filter(tag, ["banned"])],
78+
[tag for tag in artists_tag_list if tags_filter(tag, ["banned"])],
6379
tag_word_sep,
6480
)
65-
meta_tag_list = tag_str_list(
66-
[tag for tag in post.tag_list_meta if meta_tags_filter(tag)], tag_word_sep
67-
)
81+
meta_tag_list = tag_str_list(meta_tag_list)
6882

6983
keep_tags = (
7084
special_tag_list + character_tag_list + copyright_tag_list + artists_tag_list
@@ -101,11 +115,13 @@ def caption(self, post: Post, img: bytes) -> str:
101115
class KohakuCaptioner(BaseCaptioner):
102116
def __init__(
103117
self,
118+
shuffle_each=False,
104119
tag_word_sep=" ",
105120
tag_seperator=", ",
106121
keep_seperator="|||",
107122
processors=[year_tag, rating_tag, quality_tag_new],
108123
):
124+
self.shuffle_each = shuffle_each
109125
self.processors = processors
110126
self.tag_word_sep = tag_word_sep
111127
self.tag_seperator = tag_seperator
@@ -114,6 +130,7 @@ def __init__(
114130
def caption(self, post: Post, img: bytes) -> str:
115131
return make_caption(
116132
post,
133+
self.shuffle_each,
117134
self.tag_word_sep,
118135
self.tag_seperator,
119136
self.keep_seperator,

hakubooru/tag_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def quality_tag_new(
8181
general_tags: list[str],
8282
percentile_map: dict[str, dict[int, int]] = fav_count_percentile_full,
8383
) -> tuple[list[str], list[str]]:
84-
if post.id > 7100000:
84+
if post.id > 7500000:
8585
# Don't add quality tag for posts which are new.
8686
return keep_tags, general_tags
8787
rating = post.rating

0 commit comments

Comments
 (0)