Spaces:
Build error
Build error
Upload tagger.py
Browse files
tagger.py
CHANGED
|
@@ -49,6 +49,18 @@ DANBOORU_TO_E621_RATING_MAP = {
|
|
| 49 |
}
|
| 50 |
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def load_dict_from_csv(filename):
|
| 53 |
with open(filename, 'r', encoding="utf-8") as f:
|
| 54 |
lines = f.readlines()
|
|
@@ -227,20 +239,19 @@ def convert_tags_to_ja(input_prompt: str = ""):
|
|
| 227 |
return ", ".join(out_tags)
|
| 228 |
|
| 229 |
|
| 230 |
-
|
| 231 |
-
def to_list(s):
|
| 232 |
-
return [x.strip() for x in s.split(",") if not s == ""]
|
| 233 |
-
|
| 234 |
-
def list_sub(a, b):
|
| 235 |
-
return [e for e in a if e not in b]
|
| 236 |
-
|
| 237 |
-
def list_uniq(l):
|
| 238 |
-
return sorted(set(l), key=l.index)
|
| 239 |
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
prompts = to_list(prompt)
|
| 245 |
neg_prompts = to_list(neg_prompt)
|
| 246 |
|
|
@@ -250,12 +261,16 @@ def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "Non
|
|
| 250 |
last_empty_p = [""] if not prompts and type != "None" else []
|
| 251 |
last_empty_np = [""] if not neg_prompts and type != "None" else []
|
| 252 |
|
| 253 |
-
if type == "
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
prompt = ", ".join(list_uniq(prompts) + last_empty_p)
|
| 261 |
neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
|
|
@@ -263,6 +278,43 @@ def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "Non
|
|
| 263 |
return prompt, neg_prompt
|
| 264 |
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
tag_group_dict = load_dict_from_csv('tag_group.csv')
|
| 267 |
|
| 268 |
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
|
| 52 |
+
def to_list(s):
|
| 53 |
+
return [x.strip() for x in s.split(",") if not s == ""]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def list_sub(a, b):
|
| 57 |
+
return [e for e in a if e not in b]
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def list_uniq(l):
|
| 61 |
+
return sorted(set(l), key=l.index)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
def load_dict_from_csv(filename):
|
| 65 |
with open(filename, 'r', encoding="utf-8") as f:
|
| 66 |
lines = f.readlines()
|
|
|
|
| 239 |
return ", ".join(out_tags)
|
| 240 |
|
| 241 |
|
| 242 |
+
enable_auto_recom_prompt = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
+
|
| 245 |
+
animagine_ps = to_list("anime artwork, anime style, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
|
| 246 |
+
animagine_nps = to_list("lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]")
|
| 247 |
+
pony_ps = to_list("source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres")
|
| 248 |
+
pony_nps = to_list("source_pony, source_furry, source_cartoon, score_6, score_5, score_4, busty, ugly face, mutated hands, low res, blurry face, black and white, the simpsons, overwatch, apex legends")
|
| 249 |
+
other_ps = to_list("anime artwork, anime style, vibrant, studio anime, highly detailed, cinematic photo, 35mm photograph, film, bokeh, professional, 4k, highly detailed")
|
| 250 |
+
other_nps = to_list("photo, deformed, black and white, realism, disfigured, low contrast, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly")
|
| 251 |
+
default_ps = to_list("score_9, score_8_up, score_7_up, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
|
| 252 |
+
default_nps = to_list("score_6, score_5, score_4, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]")
|
| 253 |
+
def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "None"):
|
| 254 |
+
global enable_auto_recom_prompt
|
| 255 |
prompts = to_list(prompt)
|
| 256 |
neg_prompts = to_list(neg_prompt)
|
| 257 |
|
|
|
|
| 261 |
last_empty_p = [""] if not prompts and type != "None" else []
|
| 262 |
last_empty_np = [""] if not neg_prompts and type != "None" else []
|
| 263 |
|
| 264 |
+
if type == "Auto":
|
| 265 |
+
enable_auto_recom_prompt = True
|
| 266 |
+
else:
|
| 267 |
+
enable_auto_recom_prompt = False
|
| 268 |
+
if type == "Animagine":
|
| 269 |
+
prompts = prompts + animagine_ps
|
| 270 |
+
neg_prompts = neg_prompts + animagine_nps
|
| 271 |
+
elif type == "Pony":
|
| 272 |
+
prompts = prompts + pony_ps
|
| 273 |
+
neg_prompts = neg_prompts + pony_nps
|
| 274 |
|
| 275 |
prompt = ", ".join(list_uniq(prompts) + last_empty_p)
|
| 276 |
neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
|
|
|
|
| 278 |
return prompt, neg_prompt
|
| 279 |
|
| 280 |
|
| 281 |
+
def load_model_prompt_dict():
|
| 282 |
+
import json
|
| 283 |
+
dict = {}
|
| 284 |
+
try:
|
| 285 |
+
with open('model_dict.json', encoding='utf-8') as f:
|
| 286 |
+
dict = json.load(f)
|
| 287 |
+
except Exception:
|
| 288 |
+
pass
|
| 289 |
+
return dict
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
model_prompt_dict = load_model_prompt_dict()
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def insert_model_recom_prompt(prompt: str = "", neg_prompt: str = "", model_name: str = "None"):
|
| 296 |
+
if not model_name or not enable_auto_recom_prompt: return prompt, neg_prompt
|
| 297 |
+
prompts = to_list(prompt)
|
| 298 |
+
neg_prompts = to_list(neg_prompt)
|
| 299 |
+
prompts = list_sub(prompts, animagine_ps + pony_ps + other_ps)
|
| 300 |
+
neg_prompts = list_sub(neg_prompts, animagine_nps + pony_nps + other_nps)
|
| 301 |
+
last_empty_p = [""] if not prompts and type != "None" else []
|
| 302 |
+
last_empty_np = [""] if not neg_prompts and type != "None" else []
|
| 303 |
+
ps = []
|
| 304 |
+
nps = []
|
| 305 |
+
if model_name in model_prompt_dict.keys():
|
| 306 |
+
ps = to_list(model_prompt_dict[model_name]["prompt"])
|
| 307 |
+
nps = to_list(model_prompt_dict[model_name]["negative_prompt"])
|
| 308 |
+
else:
|
| 309 |
+
ps = default_ps
|
| 310 |
+
nps = default_nps
|
| 311 |
+
prompts = prompts + ps
|
| 312 |
+
neg_prompts = neg_prompts + nps
|
| 313 |
+
prompt = ", ".join(list_uniq(prompts) + last_empty_p)
|
| 314 |
+
neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
|
| 315 |
+
return prompt, neg_prompt
|
| 316 |
+
|
| 317 |
+
|
| 318 |
tag_group_dict = load_dict_from_csv('tag_group.csv')
|
| 319 |
|
| 320 |
|