baqu2213 commited on
Commit
ec48d92
โ€ข
1 Parent(s): 27f82b9

Upload prompt_selector_auto_1215_testv9.py

Browse files
Danbooru Prompt Selector/TEST2024/prompt_selector_auto_1215_testv9.py CHANGED
@@ -226,7 +226,7 @@ def generate(width, height, positive, negative, button):
226
  mac_var.set(0)
227
  button.config(state=tk.NORMAL)
228
 
229
- global delay_offset
230
  time.sleep(delay_offset)
231
 
232
  running_flag = False
@@ -235,6 +235,8 @@ def generate(width, height, positive, negative, button):
235
 
236
  if mac_var.get() and not running_flag:
237
  random_function()
 
 
238
  time.sleep(random.uniform(5.1, 8.5))
239
  button.config(state=tk.DISABLED)
240
  window.event_generate(GENERATE_EVENT, when="tail")
@@ -353,7 +355,7 @@ def rearrange_keywords_boys_girls(keywords):
353
 
354
  def random_function():
355
  global last_deep_search_keywords, cached_rows, last_selected_row_keywords, top_100_keywords, previous_artist, top_100_counts
356
- global current_wildcard_character, current_wildcard_artist
357
  global previous_wildcard_artist, previous_wildcard_character, character_keys, copyright_keys
358
  current_deep_search_keywords = entry_deep_search.get().strip()
359
  auto_hide_keywords = entry_auto_hide.get().split(',')
@@ -487,14 +489,47 @@ def random_function():
487
  else:
488
  formatted_artist_random_keyword = f"์ž‘๊ฐ€ ํ‚ค์›Œ๋“œ๊ฐ€ ์—†์Œ!!"
489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  if cached_rows:
491
  if toggle_prompt_var.get() and last_selected_row_keywords:
492
- random_row_keywords = [keyword.strip() for keyword in text_output.get("1.0", "end-1c").split(',')]
493
- random_row_keywords = [keyword.strip() for keyword in text_output.get("1.0", "end-1c").split(',')]
494
- #random_row_keywords[-1].strip()
495
- #if random_row_keywords[0]=='': random_row_keywords = last_selected_row_keywords
 
 
 
 
496
  text_output.delete('1.0', tk.END)
497
  else:
 
498
  if (safe_search_var.get()):
499
  for i in range(100):
500
  random_index = random.randint(0, len(cached_rows) - 1)
@@ -514,12 +549,38 @@ def random_function():
514
  random_row_keywords = [keyword.strip() for keyword in random_row[0].split(',')]
515
  last_selected_row_keywords = random_row_keywords.copy()
516
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
517
  if(entry_fixed_prompt.get()):
518
  entry_text_keywords = entry_fixed_prompt.get()
519
  if(',' not in entry_text_keywords[-2:]): entry_text_keywords += ','
520
- entry_text_keywords = entry_text_keywords.split(',')
521
  entry_text_keywords = [kw.strip() for kw in entry_text_keywords if kw.strip()]
522
 
 
 
 
 
 
 
 
 
523
  temp_first_keywords = []
524
  #print("1 :", temp_first_keywords)
525
 
@@ -644,11 +705,12 @@ def random_function():
644
  temp_first_keywords.append(keyword)
645
  random_row_keywords.remove(keyword)
646
 
647
- t_temp = []
648
- for keyword in temp_first_keywords:
649
- t_temp.append(keyword.strip())
650
- t_temp = list(OrderedDict.fromkeys(t_temp))
651
- temp_first_keywords = list(t_temp)
 
652
 
653
  #last_selected_row_keywords =boy_keywords + girl_keywords[:0] + random_row_keywords
654
  #print("3 :", temp_first_keywords)
@@ -674,10 +736,19 @@ def random_function():
674
  random_row_keywords.remove(pattern)
675
 
676
  if entry_fixed_prompt_after.get():
677
- entry_after_text = [keyword.strip() for keyword in entry_fixed_prompt_after.get().split(',')]
678
- for at_kw in entry_after_text:
679
- if at_kw not in random_row_keywords and at_kw not in random_row_keywords:
680
- random_row_keywords.append(at_kw)
 
 
 
 
 
 
 
 
 
681
 
682
  rm_copyright = []
683
  if(rm_copyright_var.get()):
@@ -726,7 +797,18 @@ def random_function():
726
  random_row_keywords.remove(keyword)
727
  random_row_keywords.insert(found_index,"artist:"+keyword)
728
 
 
 
 
 
 
 
729
  random_row_keywords = rearrange_keywords_boys_girls(random_row_keywords)
 
 
 
 
 
730
  #print(random_row_keywords)
731
  text_output.insert(tk.END, f"{', '.join(random_row_keywords)}")
732
  if auto_copy_var.get():
@@ -993,6 +1075,159 @@ def character_search_thread():
993
  search_thread = threading.Thread(target=character_search, daemon=True)
994
  search_thread.start()
995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
996
  def character_search():
997
  def on_search():
998
  # ๊ฒ€์ƒ‰ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
@@ -1125,7 +1360,9 @@ def character_search():
1125
 
1126
  # left_frame ๋‚ด๋ถ€ ๊ตฌ์„ฑ
1127
  search_label = tk.Label(left_frame, text="๊ฒ€์ƒ‰ ํ•˜๋ ค๋Š” ์บ๋ฆญํ„ฐ:")
1128
- search_label.grid(row=0, column=0, padx=10, pady=5, sticky="ew")
 
 
1129
  search_entry = tk.Entry(left_frame, width=35)
1130
  search_entry.grid(row=1, column=0, padx=10, pady=5, sticky="ew")
1131
  search_entry.bind("<KeyRelease>", on_key_release)
@@ -1930,14 +2167,27 @@ def open_wildcard_setting():
1930
  character_text_content = '\n'.join(character_wildcard_saved)
1931
  character_text.insert('1.0', character_text_content)
1932
 
 
 
 
 
 
 
1933
  # ๋ฒ„ํŠผ๋“ค
1934
  buttons_frame = tk.Frame(wildcard_window)
1935
- buttons_frame.grid(row=4, column=0, columnspan=2)
1936
 
1937
- text_label = tk.Label(wildcard_window, text="wildcard ๋ฌธ๋ฒ•(์ž‘๊ฐ€):\noffset:wildcard1 150:null (helloworld)\noffset:wildcard2 100:none (goodbye)\n์—†์œผ๋ฉด 100: ์œผ๋กœ ๊ฐ„์ฃผ\noffset/offset ์ดํ•ฉ: wildcard ํ™•๋ฅ ")
1938
- text_label.grid(row=5, column=0,sticky='ew')
1939
- text_label2 = tk.Label(wildcard_window, text="wildcard ๋ฌธ๋ฒ•(์บ๋ฆญ):\n200:{{arona (blue archive)}}, blue hair, blue eyes, hair over one eye, ...\n150:{{nahida (genshin impact)}}, green eyes, pointy ears, ...\n...")
1940
- text_label2.grid(row=6, column=0,sticky='ew')
 
 
 
 
 
 
 
1941
 
1942
  load_button = tk.Button(buttons_frame, text="์™€์ผ๋“œ์นด๋“œ ํƒ‘์žฌ", command=lambda: apply_wildcard(artist_text, character_text, wildcard_window))
1943
  load_button.pack(side=tk.LEFT, padx=10)
@@ -2259,6 +2509,71 @@ def resize_image_to_fit(image, target_height):
2259
  resized_image = image.resize((new_width, target_height), Image.Resampling.LANCZOS)
2260
  return resized_image
2261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2262
  auto_time_left_flag = False
2263
  auto_time_left = 0
2264
  auto_count_left_flag = False
@@ -2266,6 +2581,8 @@ auto_count_left = 0
2266
  stop_event = None
2267
  auto_thread = None
2268
  delay_offset = 0
 
 
2269
 
2270
  start_time = datetime.now().strftime('%Y%m%d_%H%M')
2271
  thread_controller = False
@@ -2302,6 +2619,7 @@ turbo_stop_bit = False
2302
  task_finished = 0
2303
  error_count = 0
2304
  multi_token_enable = False
 
2305
 
2306
  whitelist = wlist.whitelist
2307
  bag_of_tags = tagbag.bag_of_tags
@@ -2572,6 +2890,10 @@ NSFW_assert_var = tk.IntVar()
2572
  NSFW_assert_label = tk.Checkbutton(checkbox_frame, text="NSFW Only", variable=NSFW_assert_var)
2573
  NSFW_assert_label.grid(row=2, column=1, pady=5, sticky='ew')
2574
 
 
 
 
 
2575
  window.bind('<Control-Return>', on_ctrl_enter)
2576
  window.bind('<Shift-Return>', on_shift_enter)
2577
 
@@ -2677,5 +2999,7 @@ image_label.image = white_photo
2677
 
2678
  Auto_login_check()
2679
 
 
 
2680
  window.protocol("WM_DELETE_WINDOW", exit_program)
2681
  window.mainloop()
 
226
  mac_var.set(0)
227
  button.config(state=tk.NORMAL)
228
 
229
+ global delay_offset,cached_rows
230
  time.sleep(delay_offset)
231
 
232
  running_flag = False
 
235
 
236
  if mac_var.get() and not running_flag:
237
  random_function()
238
+ if len(cached_rows) == 0:
239
+ mac_var.set(0)
240
  time.sleep(random.uniform(5.1, 8.5))
241
  button.config(state=tk.DISABLED)
242
  window.event_generate(GENERATE_EVENT, when="tail")
 
355
 
356
  def random_function():
357
  global last_deep_search_keywords, cached_rows, last_selected_row_keywords, top_100_keywords, previous_artist, top_100_counts
358
+ global current_wildcard_character, current_wildcard_artist, wildcard_used_fixed_prompt
359
  global previous_wildcard_artist, previous_wildcard_character, character_keys, copyright_keys
360
  current_deep_search_keywords = entry_deep_search.get().strip()
361
  auto_hide_keywords = entry_auto_hide.get().split(',')
 
489
  else:
490
  formatted_artist_random_keyword = f"์ž‘๊ฐ€ ํ‚ค์›Œ๋“œ๊ฐ€ ์—†์Œ!!"
491
 
492
+ def custom_split(text):
493
+ keywords = []
494
+ temp_keyword = ""
495
+ inside_angle_brackets = False
496
+
497
+ for char in text:
498
+ if char == '<':
499
+ inside_angle_brackets = True
500
+ temp_keyword += char
501
+ elif char == '>' and inside_angle_brackets:
502
+ temp_keyword += char
503
+ keywords.append(temp_keyword.strip())
504
+ temp_keyword = ""
505
+ inside_angle_brackets = False
506
+ elif inside_angle_brackets:
507
+ temp_keyword += char
508
+ elif char == ',':
509
+ if temp_keyword:
510
+ keywords.append(temp_keyword.strip())
511
+ temp_keyword = ""
512
+ else:
513
+ temp_keyword += char
514
+
515
+ if temp_keyword:
516
+ keywords.append(temp_keyword.strip())
517
+
518
+ return keywords
519
+
520
  if cached_rows:
521
  if toggle_prompt_var.get() and last_selected_row_keywords:
522
+ random_row_keywords = custom_split(text_output.get("1.0", "end-1c"))
523
+ processed_elements = set()
524
+ if wildcard_used_fixed_prompt:
525
+ for element in wildcard_used_fixed_prompt:
526
+ split_elements = element.split(',')
527
+ processed_elements.update([e.strip() for e in split_elements])
528
+ wildcard_used_fixed_prompt = list(processed_elements)
529
+ random_row_keywords = [keyword for keyword in random_row_keywords if keyword not in wildcard_used_fixed_prompt]
530
  text_output.delete('1.0', tk.END)
531
  else:
532
+ wildcard_used_fixed_prompt.clear()
533
  if (safe_search_var.get()):
534
  for i in range(100):
535
  random_index = random.randint(0, len(cached_rows) - 1)
 
549
  random_row_keywords = [keyword.strip() for keyword in random_row[0].split(',')]
550
  last_selected_row_keywords = random_row_keywords.copy()
551
 
552
+ def get_wildcard(input_str):
553
+ global wildcard_dict, wildcards_dir
554
+ print(input_str)
555
+ if '/' in input_str:
556
+ folder, filename = input_str.split('/', 1)
557
+ file_path = os.path.join(wildcards_dir, folder, filename + '.txt')
558
+ if folder in wildcard_dict and filename + ".txt" in wildcard_dict[folder] and os.path.exists(file_path):
559
+ with open(file_path, 'r') as file:
560
+ lines = file.readlines()
561
+ return random.choice(lines).strip() if lines else ' '
562
+ else:
563
+ file_path = os.path.join(wildcards_dir, input_str + ".txt")
564
+ if input_str + ".txt" in wildcard_dict['none'] and os.path.exists(file_path):
565
+ with open(file_path, 'r') as file:
566
+ lines = file.readlines()
567
+ return random.choice(lines).strip() if lines else ' '
568
+ return ' '
569
+
570
  if(entry_fixed_prompt.get()):
571
  entry_text_keywords = entry_fixed_prompt.get()
572
  if(',' not in entry_text_keywords[-2:]): entry_text_keywords += ','
573
+ entry_text_keywords = custom_split(entry_text_keywords)
574
  entry_text_keywords = [kw.strip() for kw in entry_text_keywords if kw.strip()]
575
 
576
+ for i, keyword in enumerate(entry_text_keywords):
577
+ if keyword.startswith('<') and keyword.endswith('>'):
578
+ vbar_check = keyword.strip('<>').strip() # '<', '>' ์ œ๊ฑฐ
579
+ if '|' in vbar_check:
580
+ choices = vbar_check.split('|') # '|'๋ฅผ ๊ธฐ์ค€์œผ๋กœ split
581
+ entry_text_keywords[i] = random.choice(choices)
582
+ wildcard_used_fixed_prompt.append(entry_text_keywords[i])
583
+
584
  temp_first_keywords = []
585
  #print("1 :", temp_first_keywords)
586
 
 
705
  temp_first_keywords.append(keyword)
706
  random_row_keywords.remove(keyword)
707
 
708
+ if not (any(keyword.startswith('<') and keyword.endswith('>') for keyword in temp_first_keywords)):
709
+ t_temp = []
710
+ for keyword in temp_first_keywords:
711
+ t_temp.append(keyword.strip())
712
+ t_temp = list(OrderedDict.fromkeys(t_temp))
713
+ temp_first_keywords = list(t_temp)
714
 
715
  #last_selected_row_keywords =boy_keywords + girl_keywords[:0] + random_row_keywords
716
  #print("3 :", temp_first_keywords)
 
736
  random_row_keywords.remove(pattern)
737
 
738
  if entry_fixed_prompt_after.get():
739
+ entry_after_text = custom_split(entry_fixed_prompt_after.get())
740
+
741
+ for i, keyword in enumerate(entry_after_text):
742
+ if keyword.startswith('<') and keyword.endswith('>'):
743
+ vbar_check = keyword.strip('<>').strip() # '<', '>' ์ œ๊ฑฐ
744
+ if '|' in vbar_check:
745
+ choices = vbar_check.split('|') # '|'๋ฅผ ๊ธฐ์ค€์œผ๋กœ split
746
+ entry_after_text[i] = random.choice(choices)
747
+ wildcard_used_fixed_prompt.append(entry_after_text[i])
748
+
749
+ for at_kw in entry_after_text:
750
+ if at_kw not in random_row_keywords and at_kw not in random_row_keywords:
751
+ random_row_keywords.append(at_kw)
752
 
753
  rm_copyright = []
754
  if(rm_copyright_var.get()):
 
797
  random_row_keywords.remove(keyword)
798
  random_row_keywords.insert(found_index,"artist:"+keyword)
799
 
800
+ for i, keyword in enumerate(random_row_keywords):
801
+ if keyword.startswith('<') and keyword.endswith('>'):
802
+ input_str = keyword.strip('<>').strip() # '<', '>' ์ œ๊ฑฐ
803
+ random_row_keywords[i] = get_wildcard(input_str) # get_wildcard ํ•จ์ˆ˜ ํ˜ธ์ถœ ๋ฐ ๋Œ€์ฒด
804
+ wildcard_used_fixed_prompt.append(random_row_keywords[i])
805
+
806
  random_row_keywords = rearrange_keywords_boys_girls(random_row_keywords)
807
+
808
+ if '' in random_row_keywords:
809
+ random_row_keywords.remove('')
810
+ if ' ' in random_row_keywords:
811
+ random_row_keywords.remove(' ')
812
  #print(random_row_keywords)
813
  text_output.insert(tk.END, f"{', '.join(random_row_keywords)}")
814
  if auto_copy_var.get():
 
1075
  search_thread = threading.Thread(target=character_search, daemon=True)
1076
  search_thread.start()
1077
 
1078
+ def copyright_search_thread():
1079
+ search_thread = threading.Thread(target=copyright_search, daemon=True)
1080
+ search_thread.start()
1081
+
1082
+ def copyright_search():
1083
+ pass
1084
+ def on_search():
1085
+ # ๊ฒ€์ƒ‰ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
1086
+ selected_indices = listbox.curselection()
1087
+ if not selected_indices: # If there is no selection
1088
+ print("No selection made.")
1089
+ return
1090
+
1091
+ # Assuming the first selected index (single selection mode)
1092
+ selected_index = selected_indices[0]
1093
+ # Get the keyword from the listbox, split by '-', and trim whitespace
1094
+ keyword_with_count = listbox.get(selected_index).strip()
1095
+ keyword = keyword_with_count.split('-')[0].strip()
1096
+
1097
+ # Call the analyze function with the selected keyword
1098
+ print(f"Analyzing keyword: {keyword}")
1099
+ character, cosplay = analyze_keywords_in_data('csdataset.parquet', keyword)
1100
+ #character_prompt.delete('1.0', tk.END)
1101
+ #character_prompt.insert(tk.END, f"{', '.join(character)}")
1102
+ #cosplay_prompt.delete('1.0', tk.END)
1103
+ #cosplay_prompt.insert(tk.END, f"{', '.join(cosplay)}")
1104
+
1105
+ def on_key_release(event):
1106
+ # Get the current search keyword
1107
+ search_keyword = search_entry.get()
1108
+ # Update the listbox with matching keywords
1109
+ update_listbox(search_keyword)
1110
+
1111
+ def analyze_keywords_in_data(parquet_file, keyword):
1112
+ # Parquet ํŒŒ์ผ ์ฝ๊ธฐ
1113
+ df = pd.read_parquet(parquet_file)
1114
+
1115
+ bag_of_tags = ['penis', 'character name', 'upper body', 'full body', 'artist name', 'male focus', 'open mouth', 'mature male', 'muscular', 'muscular male', 'closed mouth','closed eyes','1girl', '1boy', '1other', 'white background', 'solo', 'breasts', 'simple background', 'smile', 'looking at viewer', 'flat chest', 'small breasts', 'medium breasts', 'large breasts', 'huge breasts','aqua eyes', 'black eyes', 'blue eyes', 'brown eyes', 'green eyes', 'grey eyes', 'orange eyes', 'purple eyes', 'pink eyes', 'red eyes', 'white eyes', 'yellow eyes', 'amber eyes', 'heterochromia', 'multicolored eyes', 'aqua pupils', 'blue pupils', 'brown pupils', 'green pupils', 'grey pupils', 'orange pupils', 'pink pupils', 'purple pupils', 'red pupils', 'white pupils', 'yellow pupils', 'pointy ears', 'long pointy ears', 'aqua hair', 'black hair', 'blonde hair', 'blue hair', 'light blue hair', 'dark blue hair', 'brown hair', 'light brown hair', 'green hair', 'dark green hair', 'light green hair', 'grey hair', 'orange hair', 'pink hair', 'purple hair', 'light purple hair', 'red hair', 'white hair', 'multicolored hair', 'colored inner hair', 'colored tips', 'roots (hair)', 'gradient hair', 'print hair', 'rainbow hair', 'split-color hair', 'spotted hair', 'streaked hair', 'two-tone hair', 'very short hair', 'short hair', 'medium hair', 'long hair', 'very long hair', 'absurdly long hair', 'big hair', 'bald', 'bald girl', 'bob cut', 'inverted bob', 'bowl cut', 'buzz cut', 'chonmage', 'crew cut', 'flattop', 'okappa', 'pixie cut', 'undercut', 'flipped hair', 'wolf cut', 'cornrows', 'dreadlocks', 'hime cut', 'mullet', 'bow-shaped hair', 'braid', 'braided bangs', 'front braid', 'side braid', 'french braid', 'crown braid', 'single braid', 'multiple braids', 'twin braids', 'low twin braids', 'tri braids', 'quad braids', 'flower-shaped hair', 'hair bun', 'braided bun', 'single hair bun', 'double bun', 'cone hair bun', 'doughnut hair bun', 'heart hair bun', 'triple bun', 'cone hair bun', 'hair rings', 'single hair ring', 'half updo', 'one side up', 'two side up', 'low-braided long hair', 'low-tied long hair', 'mizura', 'multi-tied hair', 'nihongami', 'ponytail', 'folded ponytail', 'front ponytail', 'high ponytail', 'short ponytail', 'side ponytail', 'split ponytail', 'star-shaped hair', 'topknot', 'twintails', 'low twintails', 'short twintails', 'uneven twintails', 'tri tails', 'quad tails', 'quin tails', 'twisted hair', 'afro', 'huge afro', 'beehive hairdo', 'crested hair', 'pompadour', 'quiff', 'shouten pegasus mix mori', 'curly hair', 'drill hair', 'twin drills', 'tri drills', 'hair flaps', 'messy hair', 'pointy hair', 'ringlets', 'spiked hair', 'straight hair', 'wavy hair', 'bangs', 'arched bangs', 'asymmetrical bangs', 'bangs pinned back', 'blunt bangs', 'crossed bangs', 'diagonal bangs', 'dyed bangs', 'fanged bangs', 'hair over eyes', 'hair over one eye', 'long bangs', 'parted bangs', 'curtained hair', 'ribbon bangs', 'short bangs', 'swept bangs', 'hair between eyes', 'hair intakes', 'single hair intake', 'sidelocks', 'asymmetrical sidelocks', 'drill sidelocks', 'low-tied sidelocks', 'sidelocks tied back', 'single sidelock', 'ahoge', 'heart ahoge', 'huge ahoge', 'antenna hair', 'heart antenna hair', 'comb over', 'hair pulled back', 'hair slicked back', 'mohawk', 'oseledets', 'lone nape hair', 'hair bikini', 'hair censor', 'hair in own mouth', 'hair over breasts', 'hair over one breast', 'hair over crotch', 'hair over shoulder', 'hair scarf', 'alternate hairstyle', 'hair down', 'hair up', 'asymmetrical hair', 'sidecut', 'blunt ends', 'dark skin', 'dark-skinned female', 'pale skin', 'sun tatoo', 'black skin', 'blue skin', 'green skin', 'grey skin', 'orange skin', 'pink skin', 'purple skin', 'red skin', 'white skin', 'yellow skin', 'colored skin', 'multiple tails', 'demon tail', 'dragon tail', 'ghost tail', 'pikachu tail', 'snake head tail', 'fiery tail', 'bear tail', 'rabbit tail', 'cat tail', 'cow tail', 'deer tail', 'dog tail', 'ermine tail', 'fox tail', 'horse tail', 'leopard tail', 'lion tail', 'monkey tail', 'mouse tail', 'pig tail', 'sheep tail', 'squirrel tail', 'tiger tail', 'wolf tail', 'crocodilian tail', 'fish tail', 'scorpion tail', 'snake tail', 'tadpole tail']
1116
+ mini_bag_of_tags = ['penis', 'character name', 'upper body', 'full body', 'artist name', 'male focus', 'open mouth', 'mature male', 'muscular', 'muscular male', 'closed mouth','closed eyes','1girl', '1boy', '1other', 'white background', 'solo', 'breasts', 'simple background', 'smile', 'looking at viewer']
1117
+ # 'character' ์—ด์—์„œ keyword์— ํ•ด๋‹นํ•˜๋Š” ํ–‰๋งŒ ํ•„ํ„ฐ๋ง
1118
+ filtered_df = df[df['character'] == keyword]
1119
+ filtered_df = filtered_df[~filtered_df['character'].str.contains(',', na=False)]
1120
+ if filtered_df.empty:
1121
+ filtered_df = df[df['character'].str.contains(keyword, na=False, regex=False)]
1122
+ filtered_df = filtered_df[~(filtered_df['rating'] == 'e')]
1123
+ print(len(filtered_df))
1124
+ # keyword:count ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ ์ง‘๊ณ„ํ•  ๋”•์…”๋„ˆ๋ฆฌ ์ƒ์„ฑ
1125
+ keyword_count_dict = {}
1126
+
1127
+ # ๊ฐ ํ–‰์˜ 'general' ์—ด ์ฒ˜๋ฆฌ
1128
+ for general in filtered_df['general']:
1129
+ # ๋ฌธ์ž์—ด ๋ถ„ํ• 
1130
+ tags = [tag.strip() for tag in general.split(',')]
1131
+
1132
+ # ๋”•์…”๋„ˆ๋ฆฌ์— ๊ฐ ํƒœ๊ทธ์˜ count ์ถ”๊ฐ€
1133
+ for tag in tags:
1134
+ keyword_count_dict[tag] = keyword_count_dict.get(tag, 0) + 1
1135
+
1136
+ # ํŠน์ • ํ‚ค์›Œ๋“œ ์ œ์™ธ
1137
+ exclude_keywords = bag_of_tags
1138
+ keyword_count_dict1 = keyword_count_dict.copy()
1139
+ keyword_count_dict1 = {k: v for k, v in keyword_count_dict1.items() if k not in mini_bag_of_tags}
1140
+ keyword_count_dict = {k: v for k, v in keyword_count_dict.items() if k not in exclude_keywords}
1141
+
1142
+ # ๊ฐ€์žฅ ๋†’์€ count ๊ฐ’ ์ฐพ๊ธฐ
1143
+ highest_count = max(keyword_count_dict.values()) if keyword_count_dict else 0
1144
+ highest_count1 = max(keyword_count_dict1.values()) if keyword_count_dict1 else 0
1145
+
1146
+ if(len(filtered_df)) < 10:
1147
+ weight = 0.6
1148
+ elif(len(filtered_df)) < 30:
1149
+ weight = 0.5
1150
+ elif(len(filtered_df)) < 80:
1151
+ weight = 0.45
1152
+ elif(len(filtered_df)) < 160:
1153
+ weight = 0.35
1154
+ elif(len(filtered_df)) < 280:
1155
+ weight = 0.3
1156
+ else:
1157
+ weight = 0.2
1158
+
1159
+ result_list = []
1160
+ result_list1 = []
1161
+ # count๊ฐ€ highest_count*0.4 ์ด์ƒ์ธ ํ‚ค์›Œ๋“œ ์ถœ๋ ฅ
1162
+ for k, v in keyword_count_dict.items():
1163
+ if '|' in k: continue
1164
+ if v >= highest_count * weight:
1165
+ result_list.append(k)
1166
+
1167
+ for k, v in keyword_count_dict1.items():
1168
+ if '|' in k: continue
1169
+ if v >= highest_count1 * weight:
1170
+ result_list1.append(k)
1171
+
1172
+ result_list1.insert(0, keyword)
1173
+ result_list.insert(0, "["+keyword+" (cosplay)]")
1174
+ return result_list1, result_list
1175
+
1176
+ def update_listbox(search_keyword):
1177
+ # Clear the listbox
1178
+ listbox.delete(0, tk.END)
1179
+
1180
+ # Check if the search keyword is not empty
1181
+ if search_keyword:
1182
+ # Find matching keywords in the dictionary
1183
+ # Sort them by count in descending order
1184
+ matching_keywords = sorted(
1185
+ ((k, v) for k, v in cd.character_dictionary.items() if search_keyword.lower() in k.lower()),
1186
+ key=lambda item: item[1],
1187
+ reverse=True
1188
+ )
1189
+
1190
+ # Insert the matching keywords into the listbox
1191
+ for keyword, count in matching_keywords:
1192
+ listbox.insert(tk.END, f"{keyword} - {count}")
1193
+ else:
1194
+ # Sort all keywords by count in descending order
1195
+ all_keywords = sorted(cd.character_dictionary.items(), key=lambda item: item[1], reverse=True)
1196
+ for keyword, count in all_keywords:
1197
+ listbox.insert(tk.END, f"{keyword} - {count}")
1198
+
1199
+ # ๋ฉ”์ธ ์œˆ๋„์šฐ ์ƒ์„ฑ
1200
+ ch_search_window = tk.Toplevel(window)
1201
+ ch_search_window.title("์บ๋ฆญํ„ฐ ๊ฒ€์ƒ‰")
1202
+
1203
+ # ํ”„๋ ˆ์ž„ ์ƒ์„ฑ (left, center, right)
1204
+ left_frame = tk.Frame(ch_search_window)
1205
+ center_frame = tk.Frame(ch_search_window)
1206
+ right_frame = tk.Frame(ch_search_window)
1207
+
1208
+ # ํ”„๋ ˆ์ž„ ๋ฐฐ์น˜
1209
+ left_frame.grid(row=0, column=0, sticky="nsew")
1210
+ center_frame.grid(row=0, column=1, sticky="ns")
1211
+ right_frame.grid(row=0, column=2, sticky="nsew")
1212
+
1213
+ # left_frame ๋‚ด๋ถ€ ๊ตฌ์„ฑ
1214
+ search_label = tk.Label(left_frame, text="๊ฒ€์ƒ‰ ํ•˜๋ ค๋Š” ์บ๋ฆญํ„ฐ:")
1215
+ search_label.grid(row=0, column=0, padx=10, pady=5, sticky="w")
1216
+ copyright_search_button = tk.Button(center_frame, text="์ž‘ํ’ˆ๋ช… ๊ฒ€์ƒ‰", command=copyright_search_thread)
1217
+ copyright_search_button.grid(row=0, column=0, padx=10, pady=5, sticky="e")
1218
+ search_entry = tk.Entry(left_frame, width=35)
1219
+ search_entry.grid(row=1, column=0, padx=10, pady=5, sticky="ew")
1220
+ search_entry.bind("<KeyRelease>", on_key_release)
1221
+
1222
+ result_label = tk.Label(left_frame, text="๋งค์นญ ์บ๋ฆญํ„ฐ:")
1223
+ result_label.grid(row=2, column=0, padx=10, pady=5, sticky="ew")
1224
+ listbox = tk.Listbox(left_frame)
1225
+ listbox.grid(row=3, column=0, padx=10, pady=5, sticky="nsew")
1226
+
1227
+ # center_frame ๋‚ด๋ถ€ ๊ตฌ์„ฑ
1228
+ search_button = tk.Button(center_frame, text="๊ฒ€์ƒ‰", command=on_search)
1229
+ search_button.grid(row=2, column=0, rowspan=4, padx=10, pady=175)
1230
+
1231
  def character_search():
1232
  def on_search():
1233
  # ๊ฒ€์ƒ‰ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
 
1360
 
1361
  # left_frame ๋‚ด๋ถ€ ๊ตฌ์„ฑ
1362
  search_label = tk.Label(left_frame, text="๊ฒ€์ƒ‰ ํ•˜๋ ค๋Š” ์บ๋ฆญํ„ฐ:")
1363
+ search_label.grid(row=0, column=0, padx=10, pady=5, sticky="w")
1364
+ copyright_search_button = tk.Button(center_frame, text="์ž‘ํ’ˆ๋ช… ๊ฒ€์ƒ‰", command=copyright_search_thread)
1365
+ copyright_search_button.grid(row=0, column=0, padx=10, pady=5, sticky="e")
1366
  search_entry = tk.Entry(left_frame, width=35)
1367
  search_entry.grid(row=1, column=0, padx=10, pady=5, sticky="ew")
1368
  search_entry.bind("<KeyRelease>", on_key_release)
 
2167
  character_text_content = '\n'.join(character_wildcard_saved)
2168
  character_text.insert('1.0', character_text_content)
2169
 
2170
+ # ์ „์—ญ ์™€์ผ๋“œ์นด๋“œ
2171
+ wildcard_label = tk.Label(wildcard_window, text="๊ธ€๋กœ๋ฒŒ ์™€์ผ๋“œ์นด๋“œ")
2172
+ wildcard_label.grid(row=4, column=0, columnspan=2)
2173
+ wildcard_text = tk.Text(wildcard_window, height=7, width=60)
2174
+ wildcard_text.grid(row=5, column=0, columnspan=2)
2175
+
2176
  # ๋ฒ„ํŠผ๋“ค
2177
  buttons_frame = tk.Frame(wildcard_window)
2178
+ buttons_frame.grid(row=6, column=0, columnspan=2)
2179
 
2180
+ def reactivate_wildcards():
2181
+ global wildcard_dict
2182
+ activate_wildcards()
2183
+ pretty_string = ""
2184
+ for key, value in wildcard_dict.items():
2185
+ pretty_string += f"{key}: {value}\n"
2186
+ wildcard_text.delete('1.0', tk.END)
2187
+ wildcard_text.insert('1.0', pretty_string)
2188
+
2189
+ wildcard_button = tk.Button(buttons_frame, text="์ „์—ญ ์™€์ผ๋“œ์นด๋“œ ๊ฐฑ์‹ ", command=reactivate_wildcards)
2190
+ wildcard_button.pack(side=tk.LEFT, padx=10)
2191
 
2192
  load_button = tk.Button(buttons_frame, text="์™€์ผ๋“œ์นด๋“œ ํƒ‘์žฌ", command=lambda: apply_wildcard(artist_text, character_text, wildcard_window))
2193
  load_button.pack(side=tk.LEFT, padx=10)
 
2509
  resized_image = image.resize((new_width, target_height), Image.Resampling.LANCZOS)
2510
  return resized_image
2511
 
2512
+ def open_instant_row():
2513
+ # ์ƒˆ ์ฐฝ์„ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
2514
+ def load_to_cache():
2515
+ # instant_row_text ์œ„์ ฏ์—์„œ ํ…์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.
2516
+ text_data = instant_row_text.get("1.0", tk.END)
2517
+ # ํ…์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š๋‹ค๋ฉด ์ฒ˜๋ฆฌ
2518
+ if text_data.strip():
2519
+ # global ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•จ์ˆ˜ ๋ฐ–์˜ cached_rows ๋ณ€์ˆ˜๋ฅผ ์ˆ˜์ •
2520
+ global cached_rows, last_deep_search_keywords,last_generation_seed
2521
+ cached_rows.clear() # cached_rows๋ฅผ ๋น„์šด๋‹ค
2522
+ # ์ค„๋ฐ”๊ฟˆ ๋ฌธ์ž๋กœ ํ…์ŠคํŠธ๋ฅผ ๋ถ„ํ• ํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋กœ ๋งŒ๋“ ๋‹ค
2523
+ used_list = []
2524
+ for line in text_data.strip().split('\n'):
2525
+ if line not in used_list:
2526
+ used_list.append(line)
2527
+ temp_line = [line, 0]
2528
+ cached_rows.append(temp_line)
2529
+ print("Cached rows updated!") # ์ฝ˜์†”์— ์ƒํƒœ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ
2530
+ last_deep_search_keywords = cached_rows[0][0][:3]
2531
+ entry_deep_search.delete(0, tk.END)
2532
+ entry_deep_search.insert(tk.END, cached_rows[0][0][:3])
2533
+ last_generation_seed = random.randint(0,9999999999)
2534
+ hold_seed_var.set(1)
2535
+ mac_var.set(1)
2536
+ random_function()
2537
+ window.event_generate(GENERATE_EVENT, when="tail")
2538
+
2539
+ # ์ƒˆ๋กœ์šด TopLevel ์œˆ๋„์šฐ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
2540
+ new_window = tk.Toplevel()
2541
+ new_window.title("Instant Row")
2542
+
2543
+ # Text ์œ„์ ฏ์„ ์ƒ์„ฑํ•œ๋‹ค.
2544
+ instant_row_text = tk.Text(new_window, width=40, height=10)
2545
+ instant_row_text.pack(padx=10, pady=10)
2546
+
2547
+ # 'ํƒ‘์žฌ' ๋ฒ„ํŠผ์„ ์ƒ์„ฑํ•˜๊ณ , load_to_cache ํ•จ์ˆ˜๋ฅผ command๋กœ ์„ค์ •ํ•œ๋‹ค.
2548
+ load_button = tk.Button(new_window, text='ํƒ‘์žฌ', command=load_to_cache)
2549
+ load_button.pack(padx=10, pady=10)
2550
+
2551
+ def activate_wildcards():
2552
+ global wildcard_dict, wildcards_dir
2553
+ wildcards_dir = os.path.join(os.getcwd(), 'wildcards')
2554
+
2555
+ # wildcards ํด๋”๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ์—†์œผ๋ฉด ์ƒ์„ฑ
2556
+ if not os.path.exists(wildcards_dir):
2557
+ os.makedirs(wildcards_dir)
2558
+
2559
+ # wildcard_dict ๋”•์…”๋„ˆ๋ฆฌ ์ดˆ๊ธฐํ™”
2560
+ wildcard_dict = {'none': []}
2561
+
2562
+ # wildcards ํด๋” ๋‚ด์˜ ํŒŒ์ผ ๋ฐ ํด๋”๋ช… ํš๋“
2563
+ for item in os.listdir(wildcards_dir):
2564
+ item_path = os.path.join(wildcards_dir, item)
2565
+ # ํŒŒ์ผ์ธ ๊ฒฝ์šฐ
2566
+ if os.path.isfile(item_path) and item.endswith('.txt'):
2567
+ wildcard_dict['none'].append(item)
2568
+ # ํด๋”์ธ ๊ฒฝ์šฐ
2569
+ elif os.path.isdir(item_path):
2570
+ wildcard_dict[item] = []
2571
+ # ํ•ด๋‹น ํด๋” ๋‚ด์˜ ํŒŒ์ผ๋“ค์„ ๏ฟฝ๏ฟฝ๏ฟฝ์ƒ‰
2572
+ for subitem in os.listdir(item_path):
2573
+ subitem_path = os.path.join(item_path, subitem)
2574
+ if os.path.isfile(subitem_path) and subitem.endswith('.txt'):
2575
+ wildcard_dict[item].append(subitem)
2576
+
2577
  auto_time_left_flag = False
2578
  auto_time_left = 0
2579
  auto_count_left_flag = False
 
2581
  stop_event = None
2582
  auto_thread = None
2583
  delay_offset = 0
2584
+ wildcard_dict = None
2585
+ wildcards_dir = ""
2586
 
2587
  start_time = datetime.now().strftime('%Y%m%d_%H%M')
2588
  thread_controller = False
 
2619
  task_finished = 0
2620
  error_count = 0
2621
  multi_token_enable = False
2622
+ wildcard_used_fixed_prompt = []
2623
 
2624
  whitelist = wlist.whitelist
2625
  bag_of_tags = tagbag.bag_of_tags
 
2890
  NSFW_assert_label = tk.Checkbutton(checkbox_frame, text="NSFW Only", variable=NSFW_assert_var)
2891
  NSFW_assert_label.grid(row=2, column=1, pady=5, sticky='ew')
2892
 
2893
+ # Instant rows
2894
+ instant_button = tk.Button(checkbox_frame, text="Instant row", command=open_instant_row) #output_file_path
2895
+ instant_button.grid(row=2, column=3, sticky='ew')
2896
+
2897
  window.bind('<Control-Return>', on_ctrl_enter)
2898
  window.bind('<Shift-Return>', on_shift_enter)
2899
 
 
2999
 
3000
  Auto_login_check()
3001
 
3002
+ activate_wildcards()
3003
+
3004
  window.protocol("WM_DELETE_WINDOW", exit_program)
3005
  window.mainloop()