baqu2213 commited on
Commit
aeffc0b
โ€ข
1 Parent(s): c9d6165

Upload 2 files

Browse files
Danbooru Prompt Selector/TEST2024/NAIA_0226_testv1.exe CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2949964cb601d2a79a2f014d8e6c8a39b2cbffd9fa0ef2c75cf6c17e8a77875d
3
- size 889007554
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e00b723e2afa2e1872f92151972d293d69d7a60a2227c46af3bd2d27bcf92874
3
+ size 889014231
Danbooru Prompt Selector/TEST2024/NAIA_0226_testv1.py CHANGED
@@ -48,7 +48,7 @@ class Data:
48
  questionable_word = list(remove_result_qe.keyword_counts.keys())
49
  self.qe_word = nsfw_word + questionable_word
50
  """
51
- dataset/clothes_list.txt written by JioChoi
52
  https://github.com/JioChoi/NAI-Prompt-Randomizer/blob/main/dataset/clothes_list.txt
53
  """
54
  self.attire_list = tagbag.clothes_list
@@ -1980,14 +1980,25 @@ class App(customtkinter.CTk, TkinterDnD.DnDWrapper):
1980
  fdf.loc[fdf['id'] == idx, 'deleted'] = 'deleted'
1981
 
1982
  # DataFrame์—์„œ ํŠน์ • ํ–‰ ์‚ญ์ œ
1983
- fdf.drop(fdf[fdf['id'] == idx].index, inplace=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1984
 
1985
- # ๋ณ€๊ฒฝ๋œ DataFrame์„ parquet ํŒŒ์ผ๋กœ ์ €์žฅ
1986
- fdf.to_parquet("favorite_prompt.parquet", engine='pyarrow')
1987
-
1988
- # ์ด๋ฏธ์ง€ ํŒŒ์ผ ์‚ญ์ œ
1989
- delete_image(image_path)
1990
-
1991
  update_ui_with_dataframe(current_page, favorite_window, headers_width, my_font)
1992
 
1993
  # ์‚ญ์ œ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์‹คํ–‰๋  ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
@@ -4431,7 +4442,7 @@ class App(customtkinter.CTk, TkinterDnD.DnDWrapper):
4431
  def _img2img(self):
4432
  global iimg, img2img_window, inpaint_mode
4433
 
4434
- def instant_image_generation(self, current_lookup):
4435
  try:
4436
  img2img_window.attributes('-topmost', False)
4437
  except:
@@ -4537,48 +4548,53 @@ class App(customtkinter.CTk, TkinterDnD.DnDWrapper):
4537
  "steps": steps if steps <= 50 else 50,
4538
  "image": send_image
4539
  }
 
 
 
 
4540
  if not inpaint_check:
4541
  gen_request["strength"] = round(self.i2i_value, 2)
4542
  gen_request["noise"] = 0
4543
  if gen_request["type"] == "inpaint":
4544
  gen_request["mask"] = mask_to_base64(create_and_save_mask_image())
4545
  gen_request["add_original_image"] = True if overlay_original_image_var.get()==1 else False
 
4546
  def run_generation():
4547
- if gen_request["png_rule"] == "count":
4548
- self.generation_count += 1
4549
- gen_request["count"] =self.generation_count
4550
- self.state_label.configure(text ="state : img2img ์š”์ฒญ๋จ ", text_color = "#FFFF97")
4551
- result_image, result_prompt, result_seed, info, filename = NAIA_generation.generate(gen_request)
4552
- self.state_label.configure(text ="state : img2img ์š”์ฒญ ๋ฐ˜ํ™˜๋จ", text_color = "#DCE4EE")
4553
- self.get_anlas()
4554
- i2i_generate_button.configure(state="normal")
4555
- if info:
4556
- temp = info.get('Comment', '')
4557
- temp = temp[temp.find("prompt")+10:temp.find("skip_cfg_below_sigma")-3].replace('"','')
 
 
 
 
 
 
 
 
 
 
4558
  else:
4559
- temp = result_prompt
4560
- self.image_label_report.configure(state="normal")
4561
- self.image_label_report.delete("0.0", "end")
4562
- self.image_label_report.configure(text_color="#DCE4EE")
4563
- self.image_label_report.insert("0.0", temp)
4564
- self.image_label_report.configure(state="disabled")
4565
- if result_image:
4566
- if app.state() != 'zoomed':
4567
- instant_result_image = customtkinter.CTkImage(result_image, size=(620,620))
4568
  else:
4569
- current_image = Image.open(filename)
4570
- original_width, original_height = current_image.size
4571
- max_size = app.winfo_screenheight()-100
4572
- if original_width > max_size or original_height > max_size:
4573
- new_image = Image.new("RGB", (max_size, max_size), "black")
4574
- new_image.paste(current_image, ((max_size - original_width) // 2, (max_size - original_height) // 2))
4575
- instant_result_image = customtkinter.CTkImage(new_image, size=(max_size, max_size))
4576
- else:
4577
- instant_result_image = customtkinter.CTkImage(current_image, size=(max_size, max_size))
4578
- self.image_label.configure(image=instant_result_image)
4579
- img_label_result.grid(row=0, column=1)
4580
- img_label_result.configure(image=customtkinter.CTkImage(result_image, size=(576, 576)))
4581
- set_image_to_queue(result_image, result_prompt, str(result_seed), filename)
4582
  generation_thread = threading.Thread(target=run_generation, daemon=True)
4583
  generation_thread.start()
4584
 
@@ -4886,6 +4902,9 @@ class App(customtkinter.CTk, TkinterDnD.DnDWrapper):
4886
  def seed_button_event():
4887
  self.i2i_seed_hold_check = True if request_upper_size_seed_hold.get() == 1 else False
4888
 
 
 
 
4889
  request_upper_size_seed_hold_var = customtkinter.IntVar(value=i2i_seed_hold_check)
4890
  request_upper_size_seed_hold = customtkinter.CTkCheckBox(i2i_generate_frame, text="์‹œ๋“œ๊ณ ์ • Step : ", font=my_font, variable=request_upper_size_seed_hold_var, command=seed_button_event)
4891
  request_upper_size_seed_hold.grid(row=1, column=0, padx=5, pady=5, sticky="nsew")
@@ -4893,8 +4912,58 @@ class App(customtkinter.CTk, TkinterDnD.DnDWrapper):
4893
  request_upper_size_steps = customtkinter.StringVar(value="28")
4894
  request_upper_size_steps_entry = customtkinter.CTkEntry(i2i_generate_frame, font=my_font, textvariable=request_upper_size_steps, width=60)
4895
  request_upper_size_steps_entry.grid(row=1, column=1,padx=5, pady=5, sticky="nsew")
4896
- i2i_generate_button = customtkinter.CTkButton(i2i_generate_frame, text="Request I2I", font=large_font, command=lambda: instant_image_generation(self, current_lookup))
4897
  i2i_generate_button.grid(row = 1, column= 2, pady=5, sticky="n" )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4898
 
4899
  def instant_img2img(self):
4900
  current_lookup = self.image_queue[self.current_window].copy()
@@ -5173,13 +5242,8 @@ class App(customtkinter.CTk, TkinterDnD.DnDWrapper):
5173
 
5174
  import_image_reference = customtkinter.CTkButton(import_window, font=customtkinter.CTkFont('Pretendard', 14), text="Vibe Transfer", command=lambda: set_image_reference(import_image_reference))
5175
  import_image_reference.grid(row=1, column=0, padx=5, pady=5, sticky="nsew")
 
5176
 
5177
-
5178
-
5179
-
5180
-
5181
-
5182
-
5183
  def extract_keywords_from_image(image):
5184
  if image.info and image.info.get('dpi') is None:
5185
  result = image.info.get('Comment', '')
 
48
  questionable_word = list(remove_result_qe.keyword_counts.keys())
49
  self.qe_word = nsfw_word + questionable_word
50
  """
51
+ dataset/clothes_list.txt, characteristic_list.txt written by JioChoi
52
  https://github.com/JioChoi/NAI-Prompt-Randomizer/blob/main/dataset/clothes_list.txt
53
  """
54
  self.attire_list = tagbag.clothes_list
 
1980
  fdf.loc[fdf['id'] == idx, 'deleted'] = 'deleted'
1981
 
1982
  # DataFrame์—์„œ ํŠน์ • ํ–‰ ์‚ญ์ œ
1983
+ row_indices = fdf.index[fdf['id'] == idx].tolist()
1984
+ sdf = pd.read_parquet("favorite_prompt.parquet", engine='pyarrow')
1985
+ try:
1986
+ if row_indices:
1987
+ fdf.drop(index=row_indices, inplace=True)
1988
+ # ๋ณ€๊ฒฝ๋œ DataFrame์„ parquet ํŒŒ์ผ๋กœ ์ €์žฅ
1989
+ fdf.to_parquet("favorite_prompt.parquet", engine='pyarrow')
1990
+ # ์ด๋ฏธ์ง€ ํŒŒ์ผ ์‚ญ์ œ
1991
+ delete_image(image_path)
1992
+ except:
1993
+ sdf.to_parquet("favorite_prompt.parquet", engine='pyarrow')
1994
+ self.image_label_report.configure(state="normal")
1995
+ self.image_label_report.delete("0.0", "end")
1996
+ self.image_label_report.insert("0.0", "<ExceptionAlert> parquet ์ฒ˜๋ฆฌ ์‹คํŒจ๋กœ ์ฐฝ์ด ๋‹ซํ˜”์Šต๋‹ˆ๋‹ค. ์ •๊ธฐ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐฑ์—… ํ•ด ์ฃผ์„ธ์š”.")
1997
+ self.image_label_report.configure(text_color="#FFFF97")
1998
+ self.image_label_report.configure(state="disabled")
1999
+ favorite_search_close()
2000
+ return
2001
 
 
 
 
 
 
 
2002
  update_ui_with_dataframe(current_page, favorite_window, headers_width, my_font)
2003
 
2004
  # ์‚ญ์ œ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์‹คํ–‰๋  ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
 
4442
  def _img2img(self):
4443
  global iimg, img2img_window, inpaint_mode
4444
 
4445
+ def instant_image_generation(self, current_lookup, i2irf=None):
4446
  try:
4447
  img2img_window.attributes('-topmost', False)
4448
  except:
 
4548
  "steps": steps if steps <= 50 else 50,
4549
  "image": send_image
4550
  }
4551
+ if i2irf and i2irf["image_reference"]:
4552
+ gen_request["reference_image"] = i2irf["image_reference_string"]
4553
+ gen_request["reference_information_extracted"] = round(i2irf["ie"], 2)
4554
+ gen_request["reference_strength"] = round(i2irf["irs"], 2)
4555
  if not inpaint_check:
4556
  gen_request["strength"] = round(self.i2i_value, 2)
4557
  gen_request["noise"] = 0
4558
  if gen_request["type"] == "inpaint":
4559
  gen_request["mask"] = mask_to_base64(create_and_save_mask_image())
4560
  gen_request["add_original_image"] = True if overlay_original_image_var.get()==1 else False
4561
+
4562
  def run_generation():
4563
+ if gen_request["png_rule"] == "count":
4564
+ self.generation_count += 1
4565
+ gen_request["count"] =self.generation_count
4566
+ self.state_label.configure(text ="state : img2img ์š”์ฒญ๋จ ", text_color = "#FFFF97")
4567
+ result_image, result_prompt, result_seed, info, filename = NAIA_generation.generate(gen_request)
4568
+ self.state_label.configure(text ="state : img2img ์š”์ฒญ ๋ฐ˜ํ™˜๋จ", text_color = "#DCE4EE")
4569
+ self.get_anlas()
4570
+ i2i_generate_button.configure(state="normal")
4571
+ if info:
4572
+ temp = info.get('Comment', '')
4573
+ temp = temp[temp.find("prompt")+10:temp.find("skip_cfg_below_sigma")-3].replace('"','')
4574
+ else:
4575
+ temp = result_prompt
4576
+ self.image_label_report.configure(state="normal")
4577
+ self.image_label_report.delete("0.0", "end")
4578
+ self.image_label_report.configure(text_color="#DCE4EE")
4579
+ self.image_label_report.insert("0.0", temp)
4580
+ self.image_label_report.configure(state="disabled")
4581
+ if result_image:
4582
+ if app.state() != 'zoomed':
4583
+ instant_result_image = customtkinter.CTkImage(result_image, size=(620,620))
4584
  else:
4585
+ current_image = Image.open(filename)
4586
+ original_width, original_height = current_image.size
4587
+ max_size = app.winfo_screenheight()-100
4588
+ if original_width > max_size or original_height > max_size:
4589
+ new_image = Image.new("RGB", (max_size, max_size), "black")
4590
+ new_image.paste(current_image, ((max_size - original_width) // 2, (max_size - original_height) // 2))
4591
+ instant_result_image = customtkinter.CTkImage(new_image, size=(max_size, max_size))
 
 
4592
  else:
4593
+ instant_result_image = customtkinter.CTkImage(current_image, size=(max_size, max_size))
4594
+ self.image_label.configure(image=instant_result_image)
4595
+ img_label_result.grid(row=0, column=1)
4596
+ img_label_result.configure(image=customtkinter.CTkImage(result_image, size=(576, 576)))
4597
+ set_image_to_queue(result_image, result_prompt, str(result_seed), filename)
 
 
 
 
 
 
 
 
4598
  generation_thread = threading.Thread(target=run_generation, daemon=True)
4599
  generation_thread.start()
4600
 
 
4902
  def seed_button_event():
4903
  self.i2i_seed_hold_check = True if request_upper_size_seed_hold.get() == 1 else False
4904
 
4905
+ #๊ธฐ๋Šฅ ์ถ”๊ฐ€ : i2i_reference์— ๋Œ€์‘
4906
+ i2irf = {"image_reference" : None, "image_reference_string" : None, "image_reference_tk" : None, "image_id" : None, "ie" : 1, "irs" : 0.6}
4907
+
4908
  request_upper_size_seed_hold_var = customtkinter.IntVar(value=i2i_seed_hold_check)
4909
  request_upper_size_seed_hold = customtkinter.CTkCheckBox(i2i_generate_frame, text="์‹œ๋“œ๊ณ ์ • Step : ", font=my_font, variable=request_upper_size_seed_hold_var, command=seed_button_event)
4910
  request_upper_size_seed_hold.grid(row=1, column=0, padx=5, pady=5, sticky="nsew")
 
4912
  request_upper_size_steps = customtkinter.StringVar(value="28")
4913
  request_upper_size_steps_entry = customtkinter.CTkEntry(i2i_generate_frame, font=my_font, textvariable=request_upper_size_steps, width=60)
4914
  request_upper_size_steps_entry.grid(row=1, column=1,padx=5, pady=5, sticky="nsew")
4915
+ i2i_generate_button = customtkinter.CTkButton(i2i_generate_frame, text="Request I2I", font=large_font, command=lambda: instant_image_generation(self, current_lookup, i2irf))
4916
  i2i_generate_button.grid(row = 1, column= 2, pady=5, sticky="n" )
4917
+
4918
+ def i2i_set_image_reference():
4919
+ filepath = filedialog.askopenfilename(title="Open Image", filetypes=[("Image files", "*.png;*.jpg;*.webp"), ("All files", "*.*")])
4920
+ if filepath:
4921
+ i2irf["image_reference"] = Image.open(filepath)
4922
+ i2irf["image_reference_string"] = NAIA_generation.image_to_base64(i2irf["image_reference"])
4923
+ enhancer = ImageEnhance.Brightness(i2irf["image_reference"])
4924
+ darker_image = enhancer.enhance(0.5)
4925
+ i2irf["image_reference_tk"] = ImageTk.PhotoImage(darker_image.resize((486, 468) if self.winfo_screenheight() < 1152 else (600, 468), Image.Resampling.LANCZOS))
4926
+ i2irf["image_id"] = image_reference_canvas.create_image(0, 0, image=i2irf["image_reference_tk"], anchor='nw')
4927
+ image_reference_strength.set(0.6)
4928
+ information_extracted.set(1)
4929
+ image_reference_frame.grid(row=2, column=0, columnspan=4, sticky="nsew")
4930
+ i2i_offset_input_label2.configure(text="*์ธํŽ˜์ธํŠธ ๊ธฐ๋Šฅ์€ Vibe Transfer์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")
4931
+
4932
+ i2i_vibe_import = customtkinter.CTkButton(i2i_generate_frame, font=my_font, width=40, text="(+) Vibe", fg_color="grey10", hover_color="grey", command=i2i_set_image_reference)
4933
+ i2i_vibe_import.grid(row = 1, column=3, pady=5, sticky="n")
4934
+
4935
+ def slider_event_IRS(value):
4936
+ image_reference_strength_label.configure(text=f"Reference Strength : {value:.2f}")
4937
+ i2irf["irs"] = value
4938
+
4939
+ def slider_event_IE(value):
4940
+ information_extracted_label.configure(text=f"Information Extracted : {value:.2f}")
4941
+ i2irf["ie"] = value
4942
+
4943
+ def i2i_rem_image_reference(i2irf):
4944
+ if i2irf["image_reference"]:
4945
+ i2irf = {"image_reference" : None, "image_reference_string" : None, "image_reference_tk" : None, "image_id" : None, "ie" : 1, "irs" : 0.6}
4946
+ image_reference_frame.grid_forget()
4947
+ image_reference_canvas.delete(i2irf["image_id"])
4948
+ i2irf["image_id"] = None
4949
+
4950
+ image_reference_frame = customtkinter.CTkFrame(i2i_generate_frame)
4951
+ image_reference_canvas = customtkinter.CTkCanvas(image_reference_frame, width=600, height=200,bg="#333333", highlightthickness = 1, highlightbackground = 'grey10')
4952
+ image_reference_canvas.grid(row=0, column=0, columnspan=4, padx=5, pady=5, sticky="n")
4953
+ image_reference_strength_label = customtkinter.CTkLabel(image_reference_canvas, font=v_large_font, text_color='white', text=f"Reference Strength : 0.6", fg_color='transparent', width=190)
4954
+ information_extracted_label = customtkinter.CTkLabel(image_reference_canvas, font=v_large_font, text_color='white', text=f"Information Extracted : 1", fg_color='transparent', width=190)
4955
+ image_reference_strength = customtkinter.CTkSlider(image_reference_canvas, from_=0.01, to=1.00, number_of_steps=100, command=slider_event_IRS, button_color='grey', button_hover_color='grey10', height=20, progress_color='transparent')
4956
+ information_extracted = customtkinter.CTkSlider(image_reference_canvas, from_=0.01, to=1.00, number_of_steps=100, command=slider_event_IE, button_color='grey', button_hover_color='grey10', height=20, progress_color='transparent')
4957
+ exit_reference_mode = customtkinter.CTkButton(image_reference_canvas, text="Vibe Transfer ํ•ด์ œ", font=my_font, command=lambda: i2i_rem_image_reference(i2irf), fg_color='grey10', hover_color='grey', corner_radius=0)
4958
+ if self.winfo_screenheight() >= 1152:
4959
+ irc_xpos = [130, 130, 420, 420, 280]
4960
+ else:
4961
+ irc_xpos = [110, 110, 370, 370, 240]
4962
+ image_reference_canvas.create_window(irc_xpos[0], 120, window=image_reference_strength_label)
4963
+ image_reference_canvas.create_window(irc_xpos[1], 70, window=information_extracted_label)
4964
+ image_reference_canvas.create_window(irc_xpos[2], 120, window=image_reference_strength)
4965
+ image_reference_canvas.create_window(irc_xpos[3], 70, window=information_extracted)
4966
+ image_reference_canvas.create_window(irc_xpos[4], 170, window=exit_reference_mode)
4967
 
4968
  def instant_img2img(self):
4969
  current_lookup = self.image_queue[self.current_window].copy()
 
5242
 
5243
  import_image_reference = customtkinter.CTkButton(import_window, font=customtkinter.CTkFont('Pretendard', 14), text="Vibe Transfer", command=lambda: set_image_reference(import_image_reference))
5244
  import_image_reference.grid(row=1, column=0, padx=5, pady=5, sticky="nsew")
5245
+ img2img_window.after(1500, lambda: img2img_window.attributes('-topmost', False))
5246
 
 
 
 
 
 
 
5247
  def extract_keywords_from_image(image):
5248
  if image.info and image.info.get('dpi') is None:
5249
  result = image.info.get('Comment', '')