1
+ from random import shuffle
2
+
1
3
from hakubooru .metainfo import (
2
4
meta_keywords_black_list ,
3
5
special_tags ,
@@ -48,23 +50,35 @@ def extract_special_tags(tag_list: list[Tag]) -> tuple[list[str], list[str]]:
48
50
49
51
def make_caption (
50
52
post : Post ,
53
+ shuffle_each : bool = False ,
51
54
tag_word_sep : str = " " ,
52
55
tag_seperator : str = ", " ,
53
56
keep_seperator : str = "|||" ,
54
57
processor = [year_tag , rating_tag , quality_tag ],
55
58
) -> str :
56
59
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
+
57
73
special_tag_list = tag_str_list (special_tag_list , tag_word_sep )
58
74
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 )
61
77
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" ])],
63
79
tag_word_sep ,
64
80
)
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 )
68
82
69
83
keep_tags = (
70
84
special_tag_list + character_tag_list + copyright_tag_list + artists_tag_list
@@ -101,11 +115,13 @@ def caption(self, post: Post, img: bytes) -> str:
101
115
class KohakuCaptioner (BaseCaptioner ):
102
116
def __init__ (
103
117
self ,
118
+ shuffle_each = False ,
104
119
tag_word_sep = " " ,
105
120
tag_seperator = ", " ,
106
121
keep_seperator = "|||" ,
107
122
processors = [year_tag , rating_tag , quality_tag_new ],
108
123
):
124
+ self .shuffle_each = shuffle_each
109
125
self .processors = processors
110
126
self .tag_word_sep = tag_word_sep
111
127
self .tag_seperator = tag_seperator
@@ -114,6 +130,7 @@ def __init__(
114
130
def caption (self , post : Post , img : bytes ) -> str :
115
131
return make_caption (
116
132
post ,
133
+ self .shuffle_each ,
117
134
self .tag_word_sep ,
118
135
self .tag_seperator ,
119
136
self .keep_seperator ,
0 commit comments