baqu2213 commited on
Commit
4eae981
β€’
1 Parent(s): 9db79e9

Upload 2 files

Browse files
Danbooru Prompt Selector/TEST/prompt_selector_auto_1208_testv6.exe CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e359edfa85abd142301b02cc3ebcc59d1040f2effeeb0443b02f6ccae56ccf88
3
- size 81784429
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e4593d4f9fc5c8aaf0b3e291f874f76e1718d6c83cdfaca02dcc77d7e6e98e4
3
+ size 84497981
Danbooru Prompt Selector/TEST/prompt_selector_auto_1208_testv6.py CHANGED
@@ -148,13 +148,14 @@ def generate(width, height, positive, negative, button):
148
  with open(f"error_log.txt", "a") as file:
149
  file.write(error_message)
150
 
151
- global access_token
152
  while (running_flag):
153
  time.sleep(1)
154
  try:
155
  running_flag = True
156
  tprint("Running : NAI request received")
157
- zipped_bytes = generate_image(access_token, positive, "nai-diffusion-3", "generate", params)
 
158
  d = Path(f"output_NAI/{start_time}/txt2img")
159
  d.mkdir(parents=True, exist_ok=True)
160
  zipped = zipfile.ZipFile(io.BytesIO(zipped_bytes))
@@ -170,15 +171,23 @@ def generate(width, height, positive, negative, button):
170
  globals()['tk_image'] = None
171
  tk_image = ImageTk.PhotoImage(i_resized)
172
  image_label.config(image=tk_image)
 
173
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
174
  output_file_path = "output_image.jpg"
175
  i.save(output_file_path)
 
176
  except Exception as e:
177
  #text_output.insert(tk.END, f"Error: {e}", fg='red')
178
- log_error(e, "path_to_output_folder")
179
  time.sleep(random.uniform(1.0, 2.5))
 
 
 
180
  button.config(state=tk.NORMAL)
181
 
 
 
 
182
  running_flag = False
183
  last_generation_seed = params['seed']
184
  entry_seed_value.set(last_generation_seed)
@@ -480,6 +489,24 @@ def random_function():
480
  if " (" in keyword:
481
  temp_first_keywords.append(keyword)
482
  random_row_keywords.remove(keyword)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
 
484
  #last_selected_row_keywords =boy_keywords + girl_keywords[:0] + random_row_keywords
485
  #print("3 :", temp_first_keywords)
@@ -558,6 +585,11 @@ def turbo_stop(button):
558
  tprint("Stopping pipelines ... ")
559
 
560
  def exit_program():
 
 
 
 
 
561
  window.destroy()
562
 
563
  def save_settings():
@@ -843,11 +875,23 @@ def NAI_generation(width, height, button):
843
  global access_token_multi, NAI_width, NAI_height
844
  global button_stop, running_flag
845
 
 
 
 
 
 
 
846
  pretest = text_output.get("1.0", tk.END).split(', ')
847
  if (turbo_var.get() == 1):
848
  if ( 'sex' not in pretest or '1girl' not in pretest or '1boy' not in pretest):
849
- tprint('ν˜„μž¬ λΆ€μŠ€νŠΈ κΈ°λŠ₯은 1girl, 1boy, sex 세가지 ν‚€μ›Œλ“œκ°€ μžˆμ–΄μ•Ό λ™μž‘ν•©λ‹ˆλ‹€.')
850
- return
 
 
 
 
 
 
851
 
852
  if(rand_resolution_var.get() == 1):
853
  resolutions = ["1024 x 1024", "960 x 1088", "896 x 1152", "832 x 1216", "1088 x 960", "1152 x 896", "1216 x 832"]
@@ -866,14 +910,24 @@ def Auto_login_check():
866
  if os.path.exists('token.txt'):
867
  with open('token.txt', 'r', encoding='utf-8') as f:
868
  tokens = f.readlines()
869
- if(tokens[0]): access_token = tokens[0].strip()
870
- if(access_token): button_setting.config(state='disabled')
 
 
 
 
 
 
 
871
  if(access_token): button_generate.config(state='normal')
872
 
873
  def NAI_generation_normal(width, height, button):
874
  button.config(state=tk.DISABLED)
875
  positive = text_output.get("1.0", tk.END)
876
  negative = negative_text.get("1.0", "end-1c").strip()
 
 
 
877
  thread = threading.Thread(target=generate, args=(width, height, positive, negative, button))
878
  thread.start()
879
 
@@ -882,7 +936,6 @@ def NAI_generation_turbo(width, height, button):
882
  button.config(state=tk.DISABLED)
883
  positive = text_output.get("1.0", tk.END)
884
  negative = negative_text.get("1.0", "end-1c").strip()
885
-
886
 
887
  def SELECT(positive):
888
  lines = positive[:25]
@@ -1064,6 +1117,9 @@ def NAI_generation_turbo(width, height, button):
1064
  sleep2 = sleep1 + random.uniform(13.5,19.5)
1065
  sleep3 = sleep2 + random.uniform(13.5,19.5)
1066
 
 
 
 
1067
  thread_init = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive, negative, button, 0, 0))
1068
  thread_init.start()
1069
  thread0 = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive0, negative, button, 1, sleep0))
@@ -1149,7 +1205,7 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1149
 
1150
  return new_image
1151
 
1152
- def insert_queue(i, _number):
1153
  global image_queue, temp_clipboard_image
1154
  while len(image_queue) < 4: image_queue.append(None)
1155
  if _number <= 4:
@@ -1165,17 +1221,23 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1165
  globals()['tk_image'] = None
1166
  tk_image = ImageTk.PhotoImage(i_resized)
1167
  image_label.config(image=tk_image)
 
1168
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
1169
  if all(img is not None for img in image_queue):
1170
  time.sleep(5)
1171
  merged_image = merge_images(image_queue)
1172
  temp_clipboard_image = merged_image.copy()
1173
  if merged_image is not None:
 
 
 
 
1174
  i_resized = resize_and_fill(merged_image)
1175
  if 'tk_image' in globals():
1176
  globals()['tk_image'] = None
1177
  tk_image = ImageTk.PhotoImage(i_resized)
1178
  image_label.config(image=tk_image)
 
1179
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
1180
  output_file_path = "output_image.jpg"
1181
  merged_image.save(output_file_path)
@@ -1223,7 +1285,8 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1223
  print('containing : ',pipe_number)
1224
 
1225
  running_flag = True
1226
- tprint("Running : request received, pipeline :",pipe_number)
 
1227
  try:
1228
  zipped_bytes = generate_image(tb_access_token, positive, "nai-diffusion-3", "generate", params)
1229
  if(pipe_number != 0):
@@ -1237,13 +1300,14 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1237
  (d / f"{turbo_count:05}_{pipe_number}.png" ).write_bytes(image_bytes)
1238
  i = Image.open(io.BytesIO(image_bytes))
1239
  i = ImageOps.exif_transpose(i).convert("RGB")
 
1240
  if(pipe_number != 0):
1241
  if temp_clipboard_image is not None:
1242
  temp_clipboard_image.close()
1243
  if(pipe_number == 1 and len(image_queue) < 4): image_queue.clear()
1244
  temp_clipboard_image = i
1245
- insert_queue(i, pipe_number)
1246
- tprint("image inserted, pipe number : ",pipe_number)
1247
  else:
1248
  if temp_clipboard_image is not None:
1249
  temp_clipboard_image.close()
@@ -1253,12 +1317,16 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1253
  globals()['tk_image'] = None
1254
  tk_image = ImageTk.PhotoImage(i_resized)
1255
  image_label.config(image=tk_image)
 
1256
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
1257
  except Exception as e:
1258
  #text_output.insert(tk.END, f"Error: {e}", fg='red')
1259
- log_error(e, "path_to_output_folder")
 
 
 
1260
  time.sleep(random.uniform(3.0, 9.0))
1261
- insert_queue(temp_clipboard_image, pipe_number)
1262
 
1263
  task_finished += 1 #터보 κΈ°λŠ₯의 μ•ˆμ „μž₯μΉ˜μž…λ‹ˆλ‹€.
1264
 
@@ -1269,6 +1337,9 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1269
  last_generation_seed = params['seed']
1270
  entry_seed_value.set(last_generation_seed)
1271
 
 
 
 
1272
  stopped = False
1273
  if (turbo_stop_bit):
1274
  time.sleep(1.5)
@@ -1276,7 +1347,7 @@ def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive,
1276
  button.config(state=tk.NORMAL)
1277
  stopped = True
1278
  if (pipe_number != 4):
1279
- tprint("Stopped : request stopped before assign pipeline :",pipe_number+1)
1280
 
1281
  if pipe_number == 4 and mac_var.get():
1282
  wait_limit = 0
@@ -1596,7 +1667,6 @@ def apply_wildcard(artist_text, character_text, window):
1596
 
1597
  window.destroy()
1598
 
1599
-
1600
  def load_wildcard(text_widget, window, _type):
1601
  global artist_wildcard_saved, character_wildcard_saved
1602
  window.iconify()
@@ -1643,13 +1713,236 @@ def get_random_keyword(req_keyword):
1643
 
1644
  def tprint(*args):
1645
  ctext = ""
 
1646
  for t in args:
1647
- ctext += str(t)
1648
- running_state.config(text=ctext)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1649
 
1650
  def on_hold_seed_button_click():
1651
  global last_generation_seed
1652
- last_generation_seed = entry_seed_value.get() # entry_seed_valueμ—μ„œ 값을 가져와 last_generation_seed에 μ €μž₯
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1653
 
1654
  start_time = datetime.now().strftime('%Y%m%d_%H%M')
1655
  thread_controller = False
@@ -1684,6 +1977,8 @@ image_queue = []
1684
  last_generation_seed = random.randint(0,9999999999)
1685
  turbo_stop_bit = False
1686
  task_finished = 0
 
 
1687
 
1688
  whitelist = wlist.whitelist
1689
  bag_of_tags = tagbag.bag_of_tags
@@ -1802,16 +2097,12 @@ button_stop.grid(row=0, column=5, sticky='ew')
1802
  button_stop.config(state='disabled')
1803
 
1804
  # "μ„€μ •" λ²„νŠΌ
1805
- button_setting = tk.Button(button_frame, text="NAI 둜그인 μ„€μ •", command=lambda: NAI_setting(button_setting, button_generate))
1806
  button_setting.grid(row=0, column=6, sticky='ew')
1807
 
1808
- # "터보" λ²„νŠΌ
1809
- #button_turbo = tk.Button(button_frame, text="터보", command=lambda: NAI_setting_multi(button_turbo))
1810
- #button_turbo.grid(row=0, column=7, sticky='ew')
1811
-
1812
  # 'μžλ™ν™”'와 '터보on'을 포함할 μ„œλΈŒ ν”„λ ˆμž„ 생성
1813
  sub_frame = tk.Frame(button_frame)
1814
- sub_frame.grid(row=0, column=8, sticky='ns') # μ„œλΈŒ ν”„λ ˆμž„μ„ μ—΄ 8에 배치
1815
 
1816
  # 'μžλ™ν™”' μ²΄ν¬λ°•μŠ€λ₯Ό μ„œλΈŒ ν”„λ ˆμž„μ— 배치
1817
  mac_var = tk.IntVar()
@@ -1823,6 +2114,10 @@ turbo_var = tk.IntVar()
1823
  turbo_button = tk.Checkbutton(sub_frame, text="터보on", variable=turbo_var)
1824
  turbo_button.grid(row=1, column=0, sticky='ew') # 두 번째 행에 배치
1825
 
 
 
 
 
1826
  # ν…μŠ€νŠΈ 및 κ³ μ • ν”„λ‘¬ν”„νŠΈ λ„€κ±°ν‹°λΈŒ λ“± ν”„λ‘¬ν”„νŠΈ μ°½
1827
  text_frame = tk.Frame(left_frame)
1828
  text_frame.grid(row=6, column=0, padx=5, pady=5, sticky='w')
@@ -1991,6 +2286,10 @@ resolution3_frame.columnconfigure(2, weight=1)
1991
 
1992
  running_state = tk.Label(resolution3_frame, text="state : idle")
1993
  running_state.grid(row = 0, column= 0, sticky='w')
 
 
 
 
1994
  entry_rescale_value = tk.StringVar()
1995
  entry_rescale_label = tk.Label(resolution3_frame, text=" Prompt Guidance Rescale : ", justify=tk.LEFT)
1996
  entry_rescale_label.grid(row=0, column=1, sticky='e')
@@ -2016,6 +2315,9 @@ hold_seed_button.grid(row=0, column=2, sticky='ew')
2016
  btn_add_low_freq = tk.Button(right_frame_area16, text="이미지λ₯Ό ν΄λ¦½λ³΄λ“œμ— 볡사", fg="blue", command=copy_image_to_clipboard)
2017
  btn_add_low_freq.grid(row=0, column=3, padx=5, pady=5, sticky='ew')
2018
 
 
 
 
2019
  # ν•˜μ–€μƒ‰ 이미지 생성
2020
  white_image = Image.new('RGB', (_size, _size), 'white')
2021
  white_photo = ImageTk.PhotoImage(white_image)
@@ -2034,4 +2336,5 @@ listener_thread.start()
2034
 
2035
  Auto_login_check()
2036
 
 
2037
  window.mainloop()
 
148
  with open(f"error_log.txt", "a") as file:
149
  file.write(error_message)
150
 
151
+ global access_token, access_token_multi, error_count, multi_token_enable
152
  while (running_flag):
153
  time.sleep(1)
154
  try:
155
  running_flag = True
156
  tprint("Running : NAI request received")
157
+ if not (multi_token_enable): zipped_bytes = generate_image(access_token, positive, "nai-diffusion-3", "generate", params)
158
+ else: zipped_bytes = generate_image(access_token_multi, positive, "nai-diffusion-3", "generate", params)
159
  d = Path(f"output_NAI/{start_time}/txt2img")
160
  d.mkdir(parents=True, exist_ok=True)
161
  zipped = zipfile.ZipFile(io.BytesIO(zipped_bytes))
 
171
  globals()['tk_image'] = None
172
  tk_image = ImageTk.PhotoImage(i_resized)
173
  image_label.config(image=tk_image)
174
+ image_label.original_image = i.copy()
175
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
176
  output_file_path = "output_image.jpg"
177
  i.save(output_file_path)
178
+ error_count = 0
179
  except Exception as e:
180
  #text_output.insert(tk.END, f"Error: {e}", fg='red')
181
+ log_error(zipped_bytes.decode('utf-8')[2:-2], "path_to_output_folder")
182
  time.sleep(random.uniform(1.0, 2.5))
183
+ error_count += 1
184
+ if error_count > 5:
185
+ mac_var.set(0)
186
  button.config(state=tk.NORMAL)
187
 
188
+ global delay_offset
189
+ time.sleep(delay_offset)
190
+
191
  running_flag = False
192
  last_generation_seed = params['seed']
193
  entry_seed_value.set(last_generation_seed)
 
489
  if " (" in keyword:
490
  temp_first_keywords.append(keyword)
491
  random_row_keywords.remove(keyword)
492
+ # νƒ€μœ¨ κ°œμ„  ν”„λ‘¬ν”„νŠΈ
493
+ valid_keywords = []
494
+ for keyword in temp_first_keywords:
495
+ if "(" in keyword and "(artist)" not in keyword and "(style)" not in keyword:
496
+ start = keyword.find("(") + 1
497
+ end = keyword.find(")")
498
+ if start < end and keyword[start:end] in current_deep_search_keywords:
499
+ valid_keywords.append(keyword)
500
+ for keyword in valid_keywords:
501
+ if keyword in temp_first_keywords:
502
+ temp_first_keywords.remove(keyword)
503
+ girl_index = next((i for i, k in enumerate(temp_first_keywords) if 'girl' in k), None)
504
+ if girl_index is not None:
505
+ for keyword in valid_keywords:
506
+ temp_first_keywords.insert(girl_index + 1, keyword)
507
+ girl_index += 1
508
+ # κ²°κ³Ό 좜λ ₯
509
+ print(temp_first_keywords)
510
 
511
  #last_selected_row_keywords =boy_keywords + girl_keywords[:0] + random_row_keywords
512
  #print("3 :", temp_first_keywords)
 
585
  tprint("Stopping pipelines ... ")
586
 
587
  def exit_program():
588
+ global stop_event, auto_thread
589
+ if stop_event is not None:
590
+ stop_event.set()
591
+ if auto_thread is not None and auto_thread.is_alive():
592
+ auto_thread.join() # μŠ€λ ˆλ“œκ°€ μ’…λ£Œλ  λ•ŒκΉŒμ§€ κΈ°λ‹€λ¦Ό
593
  window.destroy()
594
 
595
  def save_settings():
 
875
  global access_token_multi, NAI_width, NAI_height
876
  global button_stop, running_flag
877
 
878
+ def run_function():
879
+ time.sleep(1)
880
+ random_function()
881
+ time.sleep(2)
882
+ window.event_generate(GENERATE_EVENT, when="tail")
883
+
884
  pretest = text_output.get("1.0", tk.END).split(', ')
885
  if (turbo_var.get() == 1):
886
  if ( 'sex' not in pretest or '1girl' not in pretest or '1boy' not in pretest):
887
+ tprint('λΆ€μŠ€νŠΈ κΈ°λŠ₯은 1girl, 1boy, sex 세가지 ν‚€μ›Œλ“œκ°€ μžˆμ–΄μ•Ό λ™μž‘ν•©λ‹ˆλ‹€.','color=red')
888
+ if not mac_var.get():
889
+ button.config(state='normal')
890
+ return
891
+ else:
892
+ thread = threading.Thread(target=run_function)
893
+ thread.start()
894
+ return
895
 
896
  if(rand_resolution_var.get() == 1):
897
  resolutions = ["1024 x 1024", "960 x 1088", "896 x 1152", "832 x 1216", "1088 x 960", "1152 x 896", "1216 x 832"]
 
910
  if os.path.exists('token.txt'):
911
  with open('token.txt', 'r', encoding='utf-8') as f:
912
  tokens = f.readlines()
913
+ if(tokens[0]):
914
+ access_token = tokens[0].strip()
915
+ tprint("1 Account automatically loaded : ",access_token[-5:])
916
+ try:
917
+ if(len(tokens)>=2):
918
+ access_token_multi = tokens[1].strip()
919
+ tprint("2 Account automatically loaded : ",access_token[-5:]+", "+access_token_multi[-5:])
920
+ except:
921
+ access_token_multi = None
922
  if(access_token): button_generate.config(state='normal')
923
 
924
  def NAI_generation_normal(width, height, button):
925
  button.config(state=tk.DISABLED)
926
  positive = text_output.get("1.0", tk.END)
927
  negative = negative_text.get("1.0", "end-1c").strip()
928
+ global auto_count_left_flag, auto_count_left
929
+ if(auto_count_left_flag and auto_count_left > 0):
930
+ auto_count_left -= 1
931
  thread = threading.Thread(target=generate, args=(width, height, positive, negative, button))
932
  thread.start()
933
 
 
936
  button.config(state=tk.DISABLED)
937
  positive = text_output.get("1.0", tk.END)
938
  negative = negative_text.get("1.0", "end-1c").strip()
 
939
 
940
  def SELECT(positive):
941
  lines = positive[:25]
 
1117
  sleep2 = sleep1 + random.uniform(13.5,19.5)
1118
  sleep3 = sleep2 + random.uniform(13.5,19.5)
1119
 
1120
+ global auto_count_left_flag, auto_count_left, turbo_stop_bit
1121
+ if(auto_count_left_flag and auto_count_left > 0):
1122
+ auto_count_left -= 5
1123
  thread_init = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive, negative, button, 0, 0))
1124
  thread_init.start()
1125
  thread0 = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive0, negative, button, 1, sleep0))
 
1205
 
1206
  return new_image
1207
 
1208
+ def insert_queue(i, _number, turbo_count):
1209
  global image_queue, temp_clipboard_image
1210
  while len(image_queue) < 4: image_queue.append(None)
1211
  if _number <= 4:
 
1221
  globals()['tk_image'] = None
1222
  tk_image = ImageTk.PhotoImage(i_resized)
1223
  image_label.config(image=tk_image)
1224
+ image_label.original_image = i.copy()
1225
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
1226
  if all(img is not None for img in image_queue):
1227
  time.sleep(5)
1228
  merged_image = merge_images(image_queue)
1229
  temp_clipboard_image = merged_image.copy()
1230
  if merged_image is not None:
1231
+ output_directory = Path(f"output_NAI/{start_time}/turbo/grid")
1232
+ output_directory.mkdir(parents=True, exist_ok=True)
1233
+ file_path = output_directory / f"{turbo_count:05}.png"
1234
+ merged_image.save(file_path)
1235
  i_resized = resize_and_fill(merged_image)
1236
  if 'tk_image' in globals():
1237
  globals()['tk_image'] = None
1238
  tk_image = ImageTk.PhotoImage(i_resized)
1239
  image_label.config(image=tk_image)
1240
+ image_label.original_image = i_resized.copy()
1241
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
1242
  output_file_path = "output_image.jpg"
1243
  merged_image.save(output_file_path)
 
1285
  print('containing : ',pipe_number)
1286
 
1287
  running_flag = True
1288
+ tprint("Running : request received, pipeline : "+str(pipe_number))
1289
+ global error_count
1290
  try:
1291
  zipped_bytes = generate_image(tb_access_token, positive, "nai-diffusion-3", "generate", params)
1292
  if(pipe_number != 0):
 
1300
  (d / f"{turbo_count:05}_{pipe_number}.png" ).write_bytes(image_bytes)
1301
  i = Image.open(io.BytesIO(image_bytes))
1302
  i = ImageOps.exif_transpose(i).convert("RGB")
1303
+ error_count = 0
1304
  if(pipe_number != 0):
1305
  if temp_clipboard_image is not None:
1306
  temp_clipboard_image.close()
1307
  if(pipe_number == 1 and len(image_queue) < 4): image_queue.clear()
1308
  temp_clipboard_image = i
1309
+ insert_queue(i, pipe_number, turbo_count)
1310
+ tprint("image inserted, pipe number : "+str(pipe_number))
1311
  else:
1312
  if temp_clipboard_image is not None:
1313
  temp_clipboard_image.close()
 
1317
  globals()['tk_image'] = None
1318
  tk_image = ImageTk.PhotoImage(i_resized)
1319
  image_label.config(image=tk_image)
1320
+ image_label.original_image = i.copy()
1321
  image_label.image = tk_image # μ°Έμ‘° μœ μ§€
1322
  except Exception as e:
1323
  #text_output.insert(tk.END, f"Error: {e}", fg='red')
1324
+ log_error(zipped_bytes.decode('utf-8')[2:-2], "path_to_output_folder")
1325
+ error_count += 1
1326
+ if error_count > 5:
1327
+ mac_var.set(0)
1328
  time.sleep(random.uniform(3.0, 9.0))
1329
+ insert_queue(temp_clipboard_image, pipe_number, turbo_count)
1330
 
1331
  task_finished += 1 #터보 κΈ°λŠ₯의 μ•ˆμ „μž₯μΉ˜μž…λ‹ˆλ‹€.
1332
 
 
1337
  last_generation_seed = params['seed']
1338
  entry_seed_value.set(last_generation_seed)
1339
 
1340
+ global delay_offset
1341
+ time.sleep(delay_offset)
1342
+
1343
  stopped = False
1344
  if (turbo_stop_bit):
1345
  time.sleep(1.5)
 
1347
  button.config(state=tk.NORMAL)
1348
  stopped = True
1349
  if (pipe_number != 4):
1350
+ tprint("Stopped : request stopped before assign pipeline :"+str(pipe_number+1))
1351
 
1352
  if pipe_number == 4 and mac_var.get():
1353
  wait_limit = 0
 
1667
 
1668
  window.destroy()
1669
 
 
1670
  def load_wildcard(text_widget, window, _type):
1671
  global artist_wildcard_saved, character_wildcard_saved
1672
  window.iconify()
 
1713
 
1714
  def tprint(*args):
1715
  ctext = ""
1716
+ color = None
1717
  for t in args:
1718
+ if(type(t) is str and 'color=' in t):
1719
+ color = t[6:]
1720
+ else:
1721
+ ctext += str(t)
1722
+ if not color: running_state.config(text=ctext, fg='black')
1723
+ else: running_state.config(text=ctext, fg='red')
1724
+
1725
+
1726
+ def show_automation_option():
1727
+ global auto_thread, stop_event
1728
+ top = tk.Toplevel(window)
1729
+ top.title("Automation Stop Condition")
1730
+
1731
+ global var, timer_label, timer_entry, count_label, count_entry
1732
+ var = tk.StringVar(value="unlimited")
1733
+
1734
+ def show_option():
1735
+ if var.get() == 'timer':
1736
+ timer_label.grid(row=4, column=0)
1737
+ timer_entry.grid(row=4, column=1)
1738
+ count_label.grid_forget()
1739
+ count_entry.grid_forget()
1740
+ elif var.get() == 'count':
1741
+ count_label.grid(row=4, column=0)
1742
+ count_entry.grid(row=4, column=1)
1743
+ timer_label.grid_forget()
1744
+ timer_entry.grid_forget()
1745
+ else:
1746
+ timer_label.grid_forget()
1747
+ timer_entry.grid_forget()
1748
+ count_label.grid_forget()
1749
+ count_entry.grid_forget()
1750
+
1751
+ label_time = tk.Label(top, text="이미지 생성당 μ§€μ—°μ‹œκ°„ μΆ”κ°€ (초)")
1752
+ label_time.grid(row=0, column=0, columnspan=3)
1753
+
1754
+ delay_entry = tk.Entry(top)
1755
+ delay_entry.grid(row=1, column=0, columnspan=3)
1756
+
1757
+ label = tk.Label(top, text="μžλ™ν™” μ’…λ£Œ 쑰건")
1758
+ label.grid(row=2, column=0, columnspan=3)
1759
+
1760
+ radio1 = tk.Radiobutton(top, text="λ¬΄μ œν•œ", variable=var, value="unlimited", command=show_option)
1761
+ radio1.grid(row=3, column=0)
1762
+
1763
+ radio2 = tk.Radiobutton(top, text="타이머", variable=var, value="timer", command=show_option)
1764
+ radio2.grid(row=3, column=1)
1765
+
1766
+ radio3 = tk.Radiobutton(top, text="생성 카운트", variable=var, value="count", command=show_option)
1767
+ radio3.grid(row=3, column=2)
1768
+
1769
+ timer_label = tk.Label(top, text="μžλ™ν™” λ™μž‘ μ‹œκ°„(λΆ„) :")
1770
+ timer_entry = tk.Entry(top)
1771
+
1772
+ count_label = tk.Label(top, text="μžλ™ 생성 횟수:")
1773
+ count_entry = tk.Entry(top)
1774
+
1775
+ # "A.μ„€μ •" μ°½μ—μ„œ λ²„νŠΌ 클릭 이벀트 처리
1776
+ def on_apply(top):
1777
+ global auto_time_left_flag, auto_time_left, auto_count_left_flag, auto_count_left, delay_offset, delay_offset_label
1778
+
1779
+ selected_option = var.get()
1780
+ if delay_entry.get():
1781
+ try:
1782
+ delay_offset = round(float(delay_entry.get()), 1)
1783
+ delay_offset_label.config(text="Dealy offset : "+str(delay_offset))
1784
+ except ValueError as e:
1785
+ print(e)
1786
+ delay_offset = 0
1787
+ else:
1788
+ delay_offset = 0
1789
+ delay_offset_label.config(text="")
1790
+ if selected_option == "timer":
1791
+ auto_time_left_flag = True
1792
+ auto_count_left_flag = False
1793
+ try:
1794
+ # μ—”νŠΈλ¦¬μ—μ„œ μž…λ ₯된 μ‹œκ°„μ„ λΆ„ λ‹¨μœ„μ—μ„œ 초 λ‹¨μœ„λ‘œ λ³€ν™˜
1795
+ auto_time_left = int(timer_entry.get()) * 60
1796
+ except ValueError:
1797
+ # 잘λͺ»λœ μž…λ ₯ 처리
1798
+ print("Invalid input for timer. Please enter a number.")
1799
+ return
1800
+ elif selected_option == "count":
1801
+ auto_count_left_flag = True
1802
+ auto_time_left_flag = False
1803
+ try:
1804
+ auto_count_left = int(count_entry.get())
1805
+ except ValueError:
1806
+ # 잘λͺ»λœ μž…λ ₯ 처리
1807
+ print("Invalid input for count. Please enter a number.")
1808
+ return
1809
+ else:
1810
+ auto_time_left_flag = False
1811
+ auto_count_left_flag = False
1812
+ stop_auto_thread() # 이전 μŠ€λ ˆλ“œ μ’…λ£Œ
1813
+ start_auto_thread() # μƒˆ μŠ€λ ˆλ“œ μ‹œμž‘
1814
+ mac_var.set(1)
1815
+ top.destroy()
1816
+
1817
+ apply_button = tk.Button(top, text="적용", command=lambda: on_apply(top))
1818
+ stop_button = tk.Button(top, text="쀑단", command=on_stop)
1819
+ close_button = tk.Button(top, text="λ‹«κΈ°", command=top.destroy)
1820
+
1821
+ apply_button.grid(row=5, column=0, pady=5)
1822
+ stop_button.grid(row=5, column=1, pady=5)
1823
+ close_button.grid(row=5, column=2, pady=5)
1824
+
1825
+ def auto_time_thread(stop_event):
1826
+ global auto_time_left, auto_time_left_flag
1827
+
1828
+ def seconds_to_hms(seconds):
1829
+ h = seconds // 3600
1830
+ m = (seconds % 3600) // 60
1831
+ s = seconds % 60
1832
+ return f"{h:02d}:{m:02d}:{s:02d}"
1833
+
1834
+ def update_label_for_time_finished():
1835
+ automation_state.config(text="μ§€μ •ν•œ μ‹œκ°„μ΄ λͺ¨λ‘ μ†Œμ§„λ˜μ–΄ μžλ™ν™”κ°€ μ’…λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
1836
+ auto_time_left_flag = False
1837
+ mac_var.set(0)
1838
+
1839
+ while not stop_event.is_set() and auto_time_left > 0:
1840
+ time.sleep(1)
1841
+ auto_time_left -= 1
1842
+ remaining_time = seconds_to_hms(auto_time_left)
1843
+ window.after(0, lambda: automation_state.config(text=f"μžλ™ν™” λ‚¨μ€μ‹œκ°„ : {remaining_time}"))
1844
+
1845
+ if auto_time_left <= 0:
1846
+ window.after(0, update_label_for_time_finished)
1847
+
1848
+ if stop_event.is_set():
1849
+ window.after(0, lambda: automation_state.config(text="Conditional automation not set (A.μ„€μ •)"))
1850
+ auto_time_left_flag = False
1851
+
1852
+ def auto_count_thread(stop_event):
1853
+ global auto_count_left, auto_count_left_flag
1854
+
1855
+ def update_label_for_count_finished():
1856
+ mac_var.set(0) # μžλ™ν™” μ’…λ£Œ 쑰건 μΆ©μ‘±
1857
+ auto_count_left_flag = False
1858
+ automation_state.config(text="μ§€μ •ν•œ νšŸμˆ˜κ°€ λͺ¨λ‘ μ†Œμ§„λ˜μ–΄ μžλ™ν™”κ°€ μ’…λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.")
1859
+
1860
+ while not stop_event.is_set():
1861
+ time.sleep(1) # 주기적으둜 확인
1862
+ window.after(0, lambda: automation_state.config(text=f"μžλ™ν™” λ‚¨μ€νšŸμˆ˜ : {auto_count_left}"))
1863
+ if auto_count_left <= 0:
1864
+ window.after(0, update_label_for_count_finished)
1865
+ break # 루프 νƒˆμΆœ
1866
+ if stop_event.is_set():
1867
+ window.after(0, lambda: automation_state.config(text="Conditional automation not set (A.μ„€μ •)"))
1868
+ mac_var.set(0)
1869
+ auto_count_left_flag = False
1870
+
1871
+ # μŠ€λ ˆλ“œ μ‹œμž‘ 및 μ’…λ£Œ ν•¨μˆ˜
1872
+ def start_auto_thread():
1873
+ global auto_thread, stop_event
1874
+ stop_event = threading.Event()
1875
+ auto_thread = None
1876
+
1877
+ if auto_time_left_flag:
1878
+ auto_thread = threading.Thread(target=auto_time_thread, args=(stop_event,))
1879
+ elif auto_count_left_flag:
1880
+ auto_thread = threading.Thread(target=auto_count_thread, args=(stop_event,))
1881
+
1882
+ if auto_thread is not None:
1883
+ auto_thread.start()
1884
+
1885
+ def stop_auto_thread():
1886
+ global stop_event, auto_thread
1887
+ if stop_event is not None:
1888
+ stop_event.set()
1889
+ #if auto_thread is not None and auto_thread.is_alive():
1890
+ # auto_thread.join()
1891
+
1892
+ def on_stop():
1893
+ global auto_thread, stop_event
1894
+ stop_auto_thread() # μŠ€λ ˆλ“œ μ’…λ£Œ
1895
 
1896
  def on_hold_seed_button_click():
1897
  global last_generation_seed
1898
+ last_generation_seed = entry_seed_value.get()
1899
+
1900
+ def update_fullscreen_image(new_window, new_image_label):
1901
+ last_updated_image = None
1902
+ while True:
1903
+ time.sleep(1)
1904
+ if not new_window.winfo_exists():
1905
+ break
1906
+ try:
1907
+ current_image = getattr(image_label, 'original_image', None)
1908
+ if current_image and current_image != last_updated_image:
1909
+ resized_image = resize_image_to_fit(current_image, new_window.winfo_height())
1910
+ tk_image = ImageTk.PhotoImage(resized_image)
1911
+ new_window.after(0, lambda img=tk_image: new_image_label.config(image=img))
1912
+ new_image_label.image = tk_image
1913
+ last_updated_image = current_image
1914
+ except ValueError:
1915
+ print(ValueError)
1916
+
1917
+ def show_fullscreen_image():
1918
+ new_window = tk.Toplevel()
1919
+ new_window.attributes('-fullscreen', True)
1920
+ new_window.configure(bg='black')
1921
+
1922
+ new_image_label = tk.Label(new_window, relief='solid', borderwidth=1, bg='black')
1923
+ new_image_label.pack(expand=True, fill='both')
1924
+ new_window.bind("<Escape>", lambda e: new_window.destroy())
1925
+
1926
+ update_thread = threading.Thread(target=update_fullscreen_image, args=(new_window, new_image_label))
1927
+ update_thread.daemon = True
1928
+ update_thread.start()
1929
+
1930
+ def resize_image_to_fit(image, target_height):
1931
+ original_width, original_height = image.size
1932
+
1933
+ ratio = target_height / float(original_height)
1934
+ new_width = int(original_width * ratio)
1935
+
1936
+ resized_image = image.resize((new_width, target_height), Image.Resampling.LANCZOS)
1937
+ return resized_image
1938
+
1939
+ auto_time_left_flag = False
1940
+ auto_time_left = 0
1941
+ auto_count_left_flag = False
1942
+ auto_count_left = 0
1943
+ stop_event = None
1944
+ auto_thread = None
1945
+ delay_offset = 0
1946
 
1947
  start_time = datetime.now().strftime('%Y%m%d_%H%M')
1948
  thread_controller = False
 
1977
  last_generation_seed = random.randint(0,9999999999)
1978
  turbo_stop_bit = False
1979
  task_finished = 0
1980
+ error_count = 0
1981
+ multi_token_enable = False
1982
 
1983
  whitelist = wlist.whitelist
1984
  bag_of_tags = tagbag.bag_of_tags
 
2097
  button_stop.config(state='disabled')
2098
 
2099
  # "μ„€μ •" λ²„νŠΌ
2100
+ button_setting = tk.Button(button_frame, text="NAI μ„€μ •", command=lambda: NAI_setting(button_setting, button_generate))
2101
  button_setting.grid(row=0, column=6, sticky='ew')
2102
 
 
 
 
 
2103
  # 'μžλ™ν™”'와 '터보on'을 포함할 μ„œλΈŒ ν”„λ ˆμž„ 생성
2104
  sub_frame = tk.Frame(button_frame)
2105
+ sub_frame.grid(row=0, column=7, sticky='ns') # μ„œλΈŒ ν”„λ ˆμž„μ„ μ—΄ 8에 배치
2106
 
2107
  # 'μžλ™ν™”' μ²΄ν¬λ°•μŠ€λ₯Ό μ„œλΈŒ ν”„λ ˆμž„μ— 배치
2108
  mac_var = tk.IntVar()
 
2114
  turbo_button = tk.Checkbutton(sub_frame, text="터보on", variable=turbo_var)
2115
  turbo_button.grid(row=1, column=0, sticky='ew') # 두 번째 행에 배치
2116
 
2117
+ # "A.μ„€μ •" λ²„νŠΌ
2118
+ button_auto_setting = tk.Button(button_frame, text="A.μ„€μ •", command=show_automation_option)
2119
+ button_auto_setting.grid(row=0, column=8, sticky='ew')
2120
+
2121
  # ν…μŠ€νŠΈ 및 κ³ μ • ν”„λ‘¬ν”„νŠΈ λ„€κ±°ν‹°λΈŒ λ“± ν”„λ‘¬ν”„νŠΈ μ°½
2122
  text_frame = tk.Frame(left_frame)
2123
  text_frame.grid(row=6, column=0, padx=5, pady=5, sticky='w')
 
2286
 
2287
  running_state = tk.Label(resolution3_frame, text="state : idle")
2288
  running_state.grid(row = 0, column= 0, sticky='w')
2289
+ automation_state = tk.Label(resolution3_frame, text="Conditional automation not set (A.μ„€μ •)")
2290
+ automation_state.grid(row = 1, column= 0, sticky='w')
2291
+ delay_offset_label = tk.Label(resolution3_frame, text="Dealy offset : "+str(delay_offset))
2292
+ delay_offset_label.grid(row = 1, column= 1, sticky='e')
2293
  entry_rescale_value = tk.StringVar()
2294
  entry_rescale_label = tk.Label(resolution3_frame, text=" Prompt Guidance Rescale : ", justify=tk.LEFT)
2295
  entry_rescale_label.grid(row=0, column=1, sticky='e')
 
2315
  btn_add_low_freq = tk.Button(right_frame_area16, text="이미지λ₯Ό ν΄λ¦½λ³΄λ“œμ— 볡사", fg="blue", command=copy_image_to_clipboard)
2316
  btn_add_low_freq.grid(row=0, column=3, padx=5, pady=5, sticky='ew')
2317
 
2318
+ show_fullscreen_btn = tk.Button(right_frame_area16, text="전체화면 보기 (ESC둜 λ‹«κΈ°)", command=show_fullscreen_image)
2319
+ show_fullscreen_btn.grid(row=0, column=4, padx=5, pady=5, sticky='ew')
2320
+
2321
  # ν•˜μ–€μƒ‰ 이미지 생성
2322
  white_image = Image.new('RGB', (_size, _size), 'white')
2323
  white_photo = ImageTk.PhotoImage(white_image)
 
2336
 
2337
  Auto_login_check()
2338
 
2339
+ window.protocol("WM_DELETE_WINDOW", exit_program)
2340
  window.mainloop()