Upload 2 files
Browse filesFiles changed (3)
85 unmodified lines86878885 unmodified linesDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST/prompt_selector_auto_1201_TEST.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST/prompt_selector_auto_1202_testv2.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_auto_1202.exe filter=lfs diff=lfs merge=lfs -text85 unmodified lines8687888985 unmodified linesDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST/prompt_selector_auto_1201_TEST.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST/prompt_selector_auto_1202_testv2.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/prompt_selector_auto_1202.exe filter=lfs diff=lfs merge=lfs -textDanbooru[[:space:]]Prompt[[:space:]]Selector/TEST/prompt_selector_auto_1204_test.exe filter=lfs diff=lfs merge=lfs -text
123version https://git-lfs.github.com/spec/v1oid sha256:3a97ae84373ad6ca331bf57901bd204a3e26aa991e7d659d44260cdac4402937size 8178268712345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898import tkinter as tkimport tkinter.ttk as ttkfrom tkinter import filedialogimport osimport csvimport randomimport timefrom collections import Counterimport reimport astimport pyautoguiimport threadingfrom pynput import keyboardfrom base64 import urlsafe_b64encodefrom hashlib import blake2bimport argon2import requestsimport jsonfrom os import environ as envimport zipfileimport iofrom pathlib import Pathfrom datetime import datetimeimport numpy as npfrom PIL import Image, ImageOps, ImageDraw, ImageFont,ImageTkfrom IPython.display import displayimport win32clipboardfrom io import BytesIOfrom datetime import datetimeimport arti_list, tagbag, wlist
BASE_URL="https://api.novelai.net"
def argon_hash(email: str, password: str, size: int, domain: str) -> str: pre_salt = f"{password[:6]}{email}{domain}" # salt blake = blake2b(digest_size=16) blake.update(pre_salt.encode()) salt = blake.digest() raw = argon2.low_level.hash_secret_raw( password.encode(), salt, 2, int(2000000 / 1024), 1, size, argon2.low_level.Type.ID, ) hashed = urlsafe_b64encode(raw).decode() return hashed
def login(key) -> str: response = requests.post(f"{BASE_URL}/user/login", json={ "key": key }) # catch any errors return response.json()["accessToken"]
def get_access_key(email: str, password: str) -> str: return argon_hash(email, password, 64, "novelai_data_access_key")[:64]
def get_max_size(): global window width = window.winfo_screenheight() return 768 if width < 1440 else 1024
def generate_image(access_token, prompt, model, action, parameters): data = { "input": prompt, "model": model, "action": action, "parameters": parameters, }
response = requests.post(f"{BASE_URL}/ai/generate-image", json=data, headers={ "Authorization": f"Bearer {access_token}" }) # catch any errors return response.content
def generate(width, height, positive, negative, button): global temp_clipboard_image global current_sampler global NAI_width, NAI_height global running_flag try: scale = float(entry_CFG_value.get()) except: scale = 5.0 if scale > 7.0: scale = 7.0 elif scale < 4.0: scale = 4.0 else: scale = round(scale, 1)
try: scale2 = float(entry_rescale_value.get()) except: scale2 = 0 if scale2 > 1.00: scale = 1.00 elif scale2 < 0.0: scale = 0.00 else: scale2 = round(scale2, 2)
params = { "legacy": False, "quality_toggle": False, "width": width, "height": height, "n_samples": 1, "seed": random.randint(0,9999999999), "extra_noise_seed": random.randint(0,9999999999), "sampler": current_sampler, "steps": 28, "scale": scale, "uncond_scale": 1.0, "negative_prompt": negative_text.get("1.0", "end-1c").strip(), "sm" : sema_button_var.get(), "sm_dyn" : dyn_button_var.get(), "decrisper": False, "controlnet_strength": 1.0, "add_original_image": False, "cfg_rescale": scale2, "noise_schedule": "native", }
def resize_and_fill(image, max_size=None): if max_size is None: max_size = get_max_size() original_width, original_height = image.size if original_width > max_size or original_height > max_size: # ๋น์จ์ ์ ์งํ๋ฉด์ ํฌ๊ธฐ ์กฐ์ image.thumbnail((max_size, max_size))
# ์ ์ด๋ฏธ์ง ํฌ๊ธฐ ๊ณ์ฐ width, height = image.size new_image = Image.new("RGB", (max_size, max_size), "black") new_image.paste(image, ((max_size - width) // 2, (max_size - height) // 2)) return new_image else: return image
def log_error(e, output_file_path="output_file_path"): # ํ์ฌ ์๊ฐ์ ์ป์ต๋๋ค current_time = datetime.now().strftime("%m/%d %H:%M:%S")
# ์๋ฌ ๋ก๊ทธ ๋ฉ์์ง error_message = f"#### Error occured at {current_time} ####\nError: {e}\n############################################\n"
# ์ง์ ๋ ์ถ๋ ฅ ํด๋์ error_log.txt ํ์ผ์ ์ฐ๊ธฐ with open(f"error_log.txt", "a") as file: file.write(error_message)
global access_token try: tprint("Running : NAI request received") zipped_bytes = generate_image(access_token, positive, "nai-diffusion-3", "generate", params) d = Path("output_NAI") d.mkdir(exist_ok=True) zipped = zipfile.ZipFile(io.BytesIO(zipped_bytes)) image_bytes = zipped.read(zipped.infolist()[0]) (d / f"{datetime.now().strftime('%Y%m%d_%H%M%S')}.png" ).write_bytes(image_bytes) i = Image.open(io.BytesIO(image_bytes)) i = ImageOps.exif_transpose(i).convert("RGB") if temp_clipboard_image is not None: temp_clipboard_image.close() temp_clipboard_image = i i_resized = resize_and_fill(i) if 'tk_image' in globals(): globals()['tk_image'] = None tk_image = ImageTk.PhotoImage(i_resized) image_label.config(image=tk_image) image_label.image = tk_image # ์ฐธ์กฐ ์ ์ง output_file_path = "output_image.jpg" i.save(output_file_path) except Exception as e: #text_output.insert(tk.END, f"Error: {e}", fg='red') log_error(e, "path_to_output_folder") if mac_var.get(): time.sleep(random.uniform(3.0, 9.0)) button.config(state=tk.DISABLED) window.event_generate(GENERATE_EVENT, when="tail") else: time.sleep(random.uniform(1.0, 2.5)) button.config(state=tk.NORMAL) running_flag = False
if mac_var.get() and not running_flag: random_function() time.sleep(random.uniform(5.1, 8.5)) button.config(state=tk.DISABLED) window.event_generate(GENERATE_EVENT, when="tail") else: time.sleep(random.uniform(1.0, 2.5)) button.config(state=tk.NORMAL) running_flag = False tprint('state : idle')
def filter_csv(input_file, output_file, _search_strings): output_directory = os.getcwd() output_file = os.path.join(output_directory, output_file) search_strings = [s.strip() for s in _search_strings.split(',')] with open(input_file, 'r', newline='', encoding='utf-8') as f_in, \ open(output_file, 'w', newline='', encoding='utf-8') as f_out: reader = csv.reader(f_in) writer = csv.writer(f_out) writer_count = 0 for row in reader: if all(search_str in value for search_str in search_strings for value in row): writer.writerow(row) writer_count += 1 return writer_count
def open_file(): initial_dir = os.getcwd() filepath = filedialog.askopenfilename( initialdir=initial_dir, filetypes=[("CSV Files", "*.csv")] ) if filepath: entry_file_path.delete(0, tk.END) entry_file_path.insert(0, filepath)
def search(): global total_rows, cached_rows # cached_rows๋ฅผ global๋ก ์ ์ธ input_file = entry_file_path.get() keywords = entry_keyword.get()
output_file = 'txt2img_temp_prompt.csv' writer_count = filter_csv(input_file, output_file, keywords) total_rows = writer_count total_rows_count_label.config(text=f".csv ๋ด ํ๋กฌํํธ ํ: {writer_count}", fg="blue") text_output.insert(tk.END, f"์ด {writer_count}๊ฐ์ ๋ฌธ์์ด์ด ๊ฒ์๋์ด ์ ์ฅ๋์์ต๋๋ค.\n") # ๊ฒ์ ํ cached_rows ์ด๊ธฐํ cached_rows = [] def exclude(): global total_rows, cached_rows # cached_rows๋ฅผ global๋ก ์ ์ธ input_file = entry_file_path.get() keywords = entry_keyword.get() output_file = 'txt2img_temp_prompt.csv' keyword_label.config(text="๊ฒ์ํ ํค์๋: ")
output_directory = os.getcwd() output_file = os.path.join(output_directory, output_file) search_strings = [s.strip() for s in keywords.split(',')] with open(input_file, 'r', newline='', encoding='utf-8') as f_in, \ open(output_file, 'w', newline='', encoding='utf-8') as f_out: reader = csv.reader(f_in) writer = csv.writer(f_out) writer_count = 0 for row in reader: if not any(search_str in value for search_str in search_strings for value in row): writer.writerow(row) writer_count += 1 total_rows = writer_count total_rows_count_label.config(text=f".csv ๋ด ํ๋กฌํํธ ํ: {writer_count}", fg="red") text_output.insert(tk.END, f"์ด {writer_count}๊ฐ์ ๋ฌธ์์ด์ด ๊ฒ์๋์ด ์ ์ฅ๋์์ต๋๋ค.\n") # ์ ์ธ ํ cached_rows ์ด๊ธฐํ cached_rows = []
def copy_image_to_clipboard(): global temp_clipboard_image image = temp_clipboard_image output = BytesIO() image.convert('RGB').save(output, format='BMP') data = output.getvalue()[14:] # BMP ํ์ผ ํค๋ ์ ๊ฑฐ output.close()
win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data) win32clipboard.CloseClipboard()
def reset(): cached_rows = None entry_file_path.delete(0, tk.END) entry_keyword.delete(0, tk.END) entry_deep_search.delete(0, tk.END) text_output.delete('1.0', tk.END)
def random_function(): global last_deep_search_keywords, cached_rows, last_selected_row_keywords, top_100_keywords, previous_artist, top_100_counts current_deep_search_keywords = entry_deep_search.get().strip() auto_hide_keywords = entry_auto_hide.get().split(',') auto_hide_keywords = [keyword.strip() for keyword in auto_hide_keywords if keyword.strip()] current_artist = None
curly_brackets_keywords = re.findall(r'\{([^}]+)\}', current_deep_search_keywords) # ๊ฐ ๋ธ๋ํท ๋ด ํค์๋ ๊ทธ๋ฃน์ ์ฒ๋ฆฌํ์ฌ ์๋ฒฝ ์ผ์น ํค์๋์ ์ผ๋ฐ ํค์๋๋ฅผ ๊ตฌ๋ถ processed_keywords = [] for group in curly_brackets_keywords: perfect_match_group = [kw[1:].strip() for kw in group.split('|') if kw.startswith('*')] regular_group = [kw.strip() for kw in group.split('|') if not kw.startswith('*')] processed_keywords.append((perfect_match_group, regular_group))
modified_deep_search_keywords = re.sub(r'\{[^}]+\}', '', current_deep_search_keywords)
# ๋จ์ ํค์๋๋ค์ ์ผํ๋ก ๋ถ๋ฆฌํ์ฌ ์ฒ๋ฆฌ remaining_keywords = [kw.strip() for kw in modified_deep_search_keywords.split(',') if kw.strip()] perfect_match_keywords = [kw[1:].strip() for kw in remaining_keywords if kw.startswith('*')] # exclude_keywords์ include_keywords ์ ์ exclude_keywords = [kw[1:].strip() for kw in remaining_keywords if kw.startswith('~') and not kw[1:].startswith('*')] include_keywords = [kw for kw in remaining_keywords if not kw.startswith('~') and not kw.startswith('*')]
if current_deep_search_keywords != last_deep_search_keywords or not cached_rows: entry_auto_hide.delete(0, tk.END) entry_auto_hide.insert(tk.END, 'monochrome, doujin cover, bad source, censored, bar censor, photoshop (medium)') with open('txt2img_temp_prompt.csv', 'r', newline='', encoding='utf-8') as f: reader = csv.reader(f) rows = [] for row in reader: if all(re.search(r'(?:^|, )' + re.escape(kw) + r'(?:,|$)', ', '.join(row)) for kw in perfect_match_keywords) \ and not any(exclude in cell for exclude in exclude_keywords for cell in row) \ and all(include in cell for include in include_keywords for cell in row): # '{}' ์์ ํค์๋ ์ฒ๋ฆฌ if all(any(re.search(r'(?:^|, )' + re.escape(kw) + r'(?:,|$)', ', '.join(cell)) for kw in perfect_group) or any(kw in cell for kw in regular_group) for perfect_group, regular_group in processed_keywords for cell in row): rows.append(row) cached_rows = rows
last_deep_search_keywords = current_deep_search_keywords if not toggle_prompt_var.get(): text_output.delete('1.0', tk.END) if random_artist_var.get(): if(not entry_fixed_prompt.get()): entry_fixed_prompt.insert(tk.END,'1girl')
if not os.path.exists("counting_result.txt"): keyword_counts = analyze_cached_rows(cached_rows) excluded_keywords = set(whitelist[:2974]) with open("counting_result.txt", "w") as file: for keyword, count in sorted(keyword_counts.items(), key=lambda item: item[1], reverse=True): if keyword not in excluded_keywords and keyword in afilter_30000: file.write(f"{keyword}: {count}\n") with open("counting_result.txt", "r") as file: lines = file.readlines() top_100_data = [ (line.split(":")[0].strip(), int(line.split(":")[1].strip())) for line in lines[:3000] if line.split(":")[0].strip() in afilter_30000[:8528] ] top_100_keywords, top_100_counts = zip(*top_100_data) if top_100_data else ([], []) elif (not top_100_keywords): with open("counting_result.txt", "r") as file: lines = file.readlines() top_100_data = [ (line.split(":")[0].strip(), int(line.split(":")[1].strip())) for line in lines[:3000] if line.split(":")[0].strip() in afilter_30000[:8528] ] top_100_keywords, top_100_counts = zip(*top_100_data) if top_100_data else ([], [])
formatted_artist_random_keyword = [] if top_100_keywords: temp_keyword = [] temp_keyword += top_100_keywords whatthefuck = random.random() if(whatthefuck > 0.9): for i in range(4): random_keyword = random.choice(temp_keyword) temp_keyword.remove(random_keyword) if(i == 0): formatted_artist_random_keyword = "{{{artist:"+random_keyword+"}}}" if(i == 1): formatted_artist_random_keyword += ",{artist:"+random_keyword+"}" if(i == 2): formatted_artist_random_keyword += ",artist:"+random_keyword if(i == 3): formatted_artist_random_keyword += ",[[artist:"+random_keyword+"]]" elif(whatthefuck > 0.7): for i in range(3): random_keyword = random.choice(temp_keyword) temp_keyword.remove(random_keyword) if(i == 0): formatted_artist_random_keyword = "{{{artist:"+random_keyword+"}}}" if(i == 1): formatted_artist_random_keyword += ",{artist:"+random_keyword+"}" if(i == 2): formatted_artist_random_keyword += ",[[artist:"+random_keyword+"]]" elif(whatthefuck > 0.45): for i in range(2): random_keyword = random.choice(temp_keyword) temp_keyword.remove(random_keyword) if(i == 0): formatted_artist_random_keyword = "{{{artist:"+random_keyword+"}}}" if(i == 2): formatted_artist_random_keyword += ",[[artist:"+random_keyword+"]]" else: random_keyword = random.choice(temp_keyword) temp_keyword.remove(random_keyword) formatted_artist_random_keyword = "{{artist:"+random_keyword+"}}" current_artist = formatted_artist_random_keyword if not top_100_keywords: random_artist_var.set(0) else: formatted_artist_random_keyword = f"์๊ฐ ํค์๋๊ฐ ์์!!"
if cached_rows: if toggle_prompt_var.get() and last_selected_row_keywords: random_row_keywords = text_output.get("1.0", "end-1c").split(',') #random_row_keywords[-1].strip() if random_row_keywords[0]=='': random_row_keywords = last_selected_row_keywords text_output.delete('1.0', tk.END) else: random_index = random.randint(0, len(cached_rows) - 1) random_row = cached_rows.pop(random_index) random_row_keywords = [keyword.strip() for keyword in random_row[0].split(',')] last_selected_row_keywords = random_row_keywords
if(entry_fixed_prompt.get()): entry_text_keywords = entry_fixed_prompt.get() if(',' not in entry_text_keywords[-2:]): entry_text_keywords += ',' entry_text_keywords = entry_text_keywords.split(',') entry_text_keywords = [kw.strip() for kw in entry_text_keywords if kw.strip()]
temp_first_keywords = [] #print("1 :", temp_first_keywords)
# entry_text_keywords์ ๋ชจ๋ ํค์๋๋ฅผ temp_first_keywords์ ์ถ๊ฐ for et_kw in entry_text_keywords: if ('boy' in et_kw or 'girl' in et_kw) or (' '+et_kw not in random_row_keywords and ' '+et_kw not in random_row_keywords): temp_first_keywords.append(et_kw)
# 'boy' ํค์๋ ์ฒ๋ฆฌ boy_keywords = [kw for kw in random_row_keywords if 'boy' in kw and len(kw) <= 7]
# 'girl' ํค์๋ ์ฒ๋ฆฌ ๋ฐ ์์น ์กฐ์ girl_keywords = [] if 'girl' in entry_text_keywords[0] and len(entry_text_keywords[0]) <= 7: girl_keywords = [kw for kw in random_row_keywords if 'girl' in kw and len(kw) <= 7]
# random_row_keywords์์ boy์ girl ํค์๋ ์ ๊ฑฐ for kw in boy_keywords + girl_keywords: if kw in random_row_keywords: random_row_keywords.remove(kw)
for kw in temp_first_keywords: if kw in random_row_keywords: random_row_keywords.remove(kw)
# temp_first_keywords์ boy์ girl ํค์๋๋ฅผ ์ ์ ํ ์์น์ ์ถ๊ฐ if(girl_keywords and 'girl' in temp_first_keywords[0]): temp_first_keywords.pop(0) #print(wildcard_var.get()) if(wildcard_var2.get() == 1): temp_len = len(girl_keywords) girl_keywords.append(get_random_keyword('character')) if(wildcard_var.get() == 1): if(wildcard_var2.get() == 1): girl_keywords.insert(temp_len+1,get_random_keyword('artist')) else: girl_keywords.append(get_random_keyword('artist')) temp_first_keywords = boy_keywords + girl_keywords + temp_first_keywords #print("2 :", temp_first_keywords)
if remove_artist_var.get(): for keyword in random_row_keywords: if keyword in afilter_30000: random_row_keywords.remove(keyword) temp_rm = [] if rm_characteristic_var.get(): for keyword in random_row_keywords: if keyword in bag_of_tags or "(" in keyword: random_row_keywords.remove(keyword) temp_rm.append(keyword) for keyword in random_row_keywords: if "(" in keyword: random_row_keywords.remove(keyword) temp_rm.append(keyword) #print('removed : ',temp_rm)
for keyword in random_row_keywords[:]: # ๋ณต์ฌ๋ณธ์ ์ํํ์ฌ ์๋ณธ ๋ฆฌ์คํธ๋ฅผ ์์ if " (" in keyword: temp_first_keywords.append(keyword) random_row_keywords.remove(keyword) else: if not random_row_keywords: random_row_keywords = last_selected_row_keywords temp_first_keywords = [] for keyword in random_row_keywords[:]: # ๋ณต์ฌ๋ณธ์ ์ํํ์ฌ ์๋ณธ ๋ฆฌ์คํธ๋ฅผ ์์ if " (" in keyword: temp_first_keywords.append(keyword) random_row_keywords.remove(keyword)
last_selected_row_keywords = random_row_keywords #print("3 :", temp_first_keywords) if random_artist_var.get(): temp_first_keywords.append(formatted_artist_random_keyword) #print("4 :", temp_first_keywords) if (previous_artist and previous_artist in temp_first_keywords): temp_first_keywords.remove(previous_artist) if (current_artist is (not None)): for i in range (len(current_artist)): previous_artist += current_artist[i] random_row_keywords = temp_first_keywords + random_row_keywords #print("5 :", random_row_keywords) elif toggle_prompt_var.get(): random_row_keywords = temp_first_keywords + random_row_keywords else: random_row_keywords = temp_first_keywords + random_row_keywords patterns = [r'\b{}\b'.format(re.escape(keyword)) for keyword in auto_hide_keywords]
for pattern in patterns: random_row_keywords = [re.sub(pattern + '(, )?', '', keyword) for keyword in random_row_keywords] random_row_keywords = [re.sub('(?<=, )' + pattern, '', keyword) for keyword in random_row_keywords]
if entry_fixed_prompt_after.get(): entry_after_text = entry_fixed_prompt_after.get().strip().split(',') for at_kw in entry_after_text: if at_kw not in random_row_keywords and ' '+at_kw not in random_row_keywords: random_row_keywords.append(at_kw)
random_row_keywords = [keyword.strip(', ') for keyword in random_row_keywords] random_row_keywords = [keyword for keyword in random_row_keywords if keyword] #print(random_row_keywords) text_output.insert(tk.END, f"{', '.join(random_row_keywords)}") if auto_copy_var.get(): copy_to_clipboard() else: text_output.insert(tk.END, "๊ฒ์ ์กฐ๊ฑด์ ๋ง๋ ๋ฐ์ดํฐ๊ฐ ์๊ฑฐ๋ CSV ํ์ผ์ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.\n")
cached_rows_count_label.config(text=f"์ฌ์ธต๊ฒ์ ํ๋กฌํํธ ํ: {len(cached_rows)}")
def add_low_frequency_keywords(): global keyword_counts, most_common_count keyword_counts = analyze_cached_rows(cached_rows) if not keyword_counts: # keyword_counts๊ฐ ๋น์ด์๋ ๊ฒฝ์ฐ ํจ์๋ฅผ ๋น ์ ธ๋์ต๋๋ค. return
# ๊ฐ์ฅ ํํ ํค์๋์ ๋น๋์๋ฅผ ๊ฐ์ ธ์ต๋๋ค. most_common_count = keyword_counts.most_common(1)[0][1]
# ์กฐ๊ฑด์ ๋ง๋ ํค์๋๋ค์ ์ฐพ์ต๋๋ค. low_freq_keywords = [keyword for keyword, count in keyword_counts.items() if keyword not in last_deep_search_keywords and keyword not in whitelist and count / most_common_count <= 0.05]
# ์๋ ์จ๊น ํค์๋ ์
๋ ฅ์ฐฝ์ ์
๋ฐ์ดํธํฉ๋๋ค. existing_keywords = entry_auto_hide.get().split(',') existing_keywords = [keyword.strip() for keyword in existing_keywords if keyword.strip()] # ๊ณต๋ฐฑ ์ ๊ฑฐ ๋ฐ ๋น ๋ฌธ์์ด ์ ๊ฑฐ
# ๊ธฐ์กด ํค์๋์ ์๋ก์ด ์ ๋น๋ ํค์๋๋ฅผ ์ถ๊ฐํฉ๋๋ค. updated_keywords = existing_keywords + low_freq_keywords unique_keywords = list(set(updated_keywords)) # ์ค๋ณต ์ ๊ฑฐ for keyword in unique_keywords: if(keyword in afilter_30000): unique_keywords.remove(keyword) entry_auto_hide.delete(0, tk.END) entry_auto_hide.insert(0, ', '.join(unique_keywords))
def copy_to_clipboard(): window.clipboard_clear() entry_text = entry_fixed_prompt.get() if(',' not in entry_text and entry_text): entry_text += ',' combined_text = text_output.get("1.0", tk.END) window.clipboard_append(combined_text)
def exit_program(): window.destroy()
def save_settings(): global NAI_ID with open('app_settings.txt', 'w', encoding='utf-8') as f: #1 if(len(entry_file_path.get()) > 4): f.write(entry_file_path.get() + '\n') else: f.write(" "+'\n') if(len(entry_keyword.get()) > 3): #2 f.write(entry_keyword.get() + '\n') else: f.write(" "+'\n') if(len(entry_deep_search.get()) > 3): #3 f.write(entry_deep_search.get() + '\n') else: f.write(" "+'\n') if(len(entry_fixed_prompt.get()) > 4): #4 f.write(entry_fixed_prompt.get() + '\n') else: f.write(" "+'\n') if(len(entry_fixed_prompt_after.get()) > 4): #5 f.write(entry_fixed_prompt_after.get() + '\n') else: f.write(" "+'\n') if(len(entry_auto_hide.get()) > 3): #6 f.write(entry_auto_hide.get() + '\n') else: f.write(" "+'\n') if(len(negative_text.get("1.0", tk.END)) > 4): #7 f.write(negative_text.get("1.0", tk.END)) else: f.write(" "+'\n') if(NAI_ID): f.write(NAI_ID + '\n' ) #ํญ์ ๋ง์ง๋ง์ ์ค๋๋ก ๊ธฐ์ต #8
def load_settings(): NAI_ID = "" if os.path.exists('app_settings.txt'): with open('app_settings.txt', 'r', encoding='utf-8') as f: settings = f.readlines() entry_file_path.insert(0, settings[0].strip()) entry_keyword.insert(0, settings[1].strip()) entry_deep_search.insert(0, settings[2].strip()) entry_fixed_prompt.insert(0, settings[3].strip()) entry_fixed_prompt_after.insert(0, settings[4].strip()) entry_auto_hide.insert(0, settings[5].strip()) if(len(settings)>=7): negative_text.insert(tk.END, settings[6].strip()) if(len(settings)>=8): NAI_ID = settings[7].strip() #ํญ์ ๋ง์ง๋ง์ ์ค๋๋ก ๊ธฐ์ต return NAI_ID
def open_prompt_window(): # ์ ์ฐฝ ์์ฑ prompt_window = tk.Toplevel(window) prompt_title = f"{entry_keyword.get()}+{last_deep_search_keywords}" if last_deep_search_keywords else "์ถ์ฒ ํ๋กฌํํธ" prompt_window.title(prompt_title)
# ์ฒซ ๋ฒ์งธ Text Output Box ์ค์ text_output1 = tk.Text(prompt_window, height=10, width=50) text_output1.pack(padx=10, pady=10)
# ๊ตต์ ๊ธ์จ ์คํ์ผ ํ๊ทธ๋ฅผ ์ค์ ํฉ๋๋ค. text_output1.tag_configure('bold', font=('Arial', 10, 'bold'))
# ๋ ๋ฒ์งธ Text Output Box ์ค์ text_output2 = tk.Text(prompt_window, height=10, width=50) text_output2.pack(padx=10, pady=10) # ์ธ ๋ฒ์งธ Text Output Box ์ค์ text_output3 = tk.Text(prompt_window, height=10, width=50) text_output3.pack(padx=10, pady=10)
# cached_rows ๋ถ์ keyword_counts = analyze_cached_rows(cached_rows)
# ๊ฐ์ฅ ๋์ count ๊ฐ์ ๊ฐ์ ธ์ต๋๋ค. most_common_count = keyword_counts.most_common(1)[0][1] if keyword_counts else 0
# text_output1์ ๊ฐ์ฅ ํํ ํค์๋๋ฅผ ์ถ๋ ฅํ๊ณ , ์กฐ๊ฑด์ ๋ฐ๋ผ ๊ตต๊ฒ ํ์ํฉ๋๋ค. for keyword, count in keyword_counts.most_common(50): if count / most_common_count >= 0.5: # count๊ฐ ๊ฐ์ฅ ๋์ ํค์๋ ๋๋น 60% ์ด์์ธ ๊ฒฝ์ฐ text_output1.insert(tk.END, f"{keyword}, ", 'bold') else: text_output1.insert(tk.END, f"{keyword}, ")
# text_output2์ ๋ชจ๋ ํค์๋์ ๋น๋์ ์ถ๋ ฅ for keyword, count in keyword_counts.most_common(200): text_output2.insert(tk.END, f"{keyword}: {count}, ")
excluded_keywords = set(whitelist[:2974]) artist_count = 0 with open("counting_result.txt", "w") as file: for keyword, count in sorted(keyword_counts.items(), key=lambda item: item[1], reverse=True): if keyword not in excluded_keywords and keyword in afilter_30000: file.write(f"{keyword}: {count}\n") if(artist_count < 150): text_output3.insert(tk.END, f"{keyword}: {count}, ") artist_count += 1
# ๋ซ๊ธฐ ๋ฒํผ ์ค์ close_button = tk.Button(prompt_window, text="๋ซ๊ธฐ", command=prompt_window.destroy) close_button.pack(pady=10)
def analyze_cached_rows(cached_rows): global top_100_keywords top_100_keywords = [] counts = Counter() for row in cached_rows: substrings = [substring.strip() for value in row for substring in value.split(',') if substring.strip()] counts.update(substrings) return counts
def exit_program(): save_settings() window.destroy()
def on_ctrl_enter(event): random_function()
def on_shift_enter(event): random_function() copy_to_clipboard()
def export_csv(): source_file = os.path.join(os.getcwd(), 'txt2img_temp_prompt.csv') if not os.path.exists(source_file): print("์์ค ํ์ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค.") return
# ๊ธฐ๋ณธ ํ์ผ ์ด๋ฆ์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํค์๋๋ก ์ค์ default_filename = f"{entry_keyword.get()}.csv" if entry_keyword.get() else "exported.csv" file_types = [('CSV ํ์ผ', '*.csv')] dest_file = filedialog.asksaveasfilename(defaultextension='.csv', filetypes=file_types, initialfile=default_filename)
if dest_file: # ์ฌ์ฉ์๊ฐ ํ์ผ ์ด๋ฆ์ ์ ํํ์ ๊ฒฝ์ฐ import shutil shutil.copy(source_file, dest_file) print(f"ํ์ผ์ด ์ ์ฅ๋์์ต๋๋ค: {dest_file}")
def export_csv_search():
if not cached_rows: print("๋น์ด์๋ ํ๋กฌํํธํ.") return
# ๊ธฐ๋ณธ ํ์ผ ์ด๋ฆ์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํค์๋๋ก ์ค์ default_filename = f"{entry_keyword.get()}.csv" if entry_keyword.get() else "exported.csv" file_types = [('CSV ํ์ผ', '*.csv')] dest_file = filedialog.asksaveasfilename(defaultextension='.csv', filetypes=file_types, initialfile=default_filename)
if dest_file: # ์ฌ์ฉ์๊ฐ ํ์ผ ์์น๋ฅผ ์ ํํ๋ค๋ฉด with open(dest_file, 'w', newline='', encoding='utf-8') as file: writer = csv.writer(file) for row in cached_rows: writer.writerow(row) # ๊ฐ ํ์ csv ํ์ผ์ ์ด๋ค
def simulate_shortcuts(): global listener, on_press_flag on_press_flag = True random_function() on_press_flag = False try: current_keys.clear() current_keys.add(keyboard.Key.ctrl_l) except KeyError: pass
def on_activate_simulate_shortcuts(): simulate_shortcuts()
def for_canonical(f): return lambda k: f(listener.canonical(k))
def start_keyboard_listener(): global listener listener = keyboard.Listener(on_press=on_press, on_release=on_release) listener.start()
def on_press(key): global on_press_flag
current_keys.add(key)
# Ctrl + ` ์กฐํฉ ๊ฐ์ง if keyboard.Key.ctrl_l in current_keys: if any(k.vk == 192 for k in current_keys if hasattr(k, 'vk')): on_press_flag = True simulate_shortcuts()
def on_release(key): try: current_keys.remove(key) except KeyError: pass
def v_automatic(save_position, prompt_position): # ํ๋กฌํํธ ์ฐฝ ํด๋ฆญ copy_to_clipboard() pyautogui.click(prompt_position) time.sleep(0.5) random_function() pyautogui.hotkey('ctrl', 'a', 'v','Right','Right','Enter') time.sleep(0.5) pyautogui.click(save_position)
def start_automation(save_position, prompt_position, label, window_to_close, automation_event): def automation_task(): while automation_event.is_set(): random_delay = random.uniform(17.5, 23.5) next_click_time = time.time() + random_delay while time.time() < next_click_time and automation_event.is_set(): time_remaining = max(next_click_time - time.time(), 0) label.config(text=f"๋ค์ ํด๋ฆญ๊น์ง: {time_remaining:.2f}์ด") time.sleep(0.1) if automation_event.is_set(): v_automatic(save_position, prompt_position)
automation_thread = threading.Thread(target=automation_task, daemon=True) automation_thread.start() random_function()
def stop_automation(): automation_event.clear() window_to_close.destroy()
window_to_close.protocol("WM_DELETE_WINDOW", stop_automation)
def stop_automation(window_to_close, automation_event, start_button, stop_button): automation_event.clear() # Stop the automation task start_button['state'] = 'normal' # Enable the start button stop_button['state'] = 'disabled' # Disable the stop button window_to_close.destroy() # Close the automation window window.deiconify()
# ๋ผ๋ฒจ์ ์
๋ฐ์ดํธํ๋ ํจ์def update_label(label, text): def task(): label.config(text=text) label.after(1000, task) # ๋ฉ์ธ ์ค๋ ๋์์ UI ์
๋ฐ์ดํธ
def open_automation_window(): window.iconify() automation_event = threading.Event() automation_event.set() # Enable the automation event auto_window = tk.Toplevel(window) auto_window.title("์๋ํ ์ค์ ") auto_window.geometry("300x200") # ์ฐฝ ํฌ๊ธฐ ์กฐ์ auto_window.attributes('-topmost', True) # ์ฐฝ์ ํญ์ ๋งจ ์์ ์์น auto_window.focus_force() # ์ฐฝ ์ด๋ฆด ๋ ํฌ์ปค์ค ๊ฐ์ ์ด๋
save_position = None prompt_position = None automation_running = threading.Event()
def get_mouse_position(event=None): nonlocal save_position, prompt_position x, y = pyautogui.position() if not save_position: save_position = (x, y) position_label.config(text=f"์ ์ฅ ๋ฒํผ์ ์ขํ: {x}, {y}\nํ๋กฌํํธ ์ฐฝ์ ์ขํ: ") elif not prompt_position: prompt_position = (x, y) position_label.config(text=f"์ ์ฅ ๋ฒํผ์ ์ขํ: {save_position[0]}, {save_position[1]}\nํ๋กฌํํธ ์ฐฝ์ ์ขํ: {x}, {y}") start_button.config(state="normal") if save_position and prompt_position: start_button.config(state="normal") stop_button.config(state="normal")
position_label = tk.Label(auto_window, text="์ํฐ๋ฅผ ๋๋ฌ ๋ง์ฐ์ค ์ขํ๋ฅผ ์ ์ฅํ์ธ์\n(ํด๋ฆญ X, 1.์ ์ฅ->2.ํ๋กฌํํธ์ฐฝ ์์)", justify=tk.LEFT) position_label.pack(pady=10)
start_button = tk.Button(auto_window, text="์์", state="disabled", command=lambda: start_automation(save_position, prompt_position, countdown_label, auto_window, automation_event)) start_button.pack(side=tk.LEFT, fill='x', expand=True)
stop_button = tk.Button(auto_window, text="์ค์ง", state="disabled", command=lambda: stop_automation(auto_window, automation_event, start_button, stop_button)) stop_button.pack(side=tk.RIGHT, fill='x', expand=True)
countdown_label = tk.Label(auto_window, text="") countdown_label.pack(pady=10)
auto_window.bind('<Return>', get_mouse_position)
def NAI_generation(width, height, button): global access_token_multi, NAI_width, NAI_height
pretest = text_output.get("1.0", tk.END).split(', ') if ('sex' not in pretest and '1girl' not in pretest and '1boy' not in pretest): tprint('ํ์ฌ ๋ถ์คํธ ๊ธฐ๋ฅ์ 1girl, 1boy, sex ์ธ๊ฐ์ง ํค์๋๊ฐ ์์ด์ผ ๋์ํฉ๋๋ค.') return
if(rand_resolution_var.get() == 1): resolutions = ["1024 x 1024", "960 x 1088", "896 x 1152", "832 x 1216", "1088 x 960", "1152 x 896", "1216 x 832"] random_resolution = random.choice(resolutions) selected_resolution.set(random_resolution) if(turbo_var.get() == 1 and access_token): NAI_generation_turbo(NAI_width, NAI_height, button) else: NAI_generation_normal(NAI_width, NAI_height, button)
def Auto_login_check(): global access_token, access_token_multi if os.path.exists('token.txt'): with open('token.txt', 'r', encoding='utf-8') as f: tokens = f.readlines() if(tokens[0]): access_token = tokens[0].strip() if(access_token): button_setting.config(state='disabled') if(access_token): button_generate.config(state='normal') def NAI_generation_normal(width, height, button): button.config(state=tk.DISABLED) positive = text_output.get("1.0", tk.END) negative = negative_text.get("1.0", "end-1c").strip() thread = threading.Thread(target=generate, args=(width, height, positive, negative, button)) thread.start()
def NAI_generation_turbo(width, height, button): global turbo_count, access_token, access_token_multi button.config(state=tk.DISABLED) positive = text_output.get("1.0", tk.END) negative = negative_text.get("1.0", "end-1c").strip()
def SELECT(positive): lines = positive[:25] result = { "boys": False, "girls": False, "1girl": False, "1boy": False, "1other": False, "others": False } state = { "nude,": False, "pov,": False, "cum,": False, "after ": False, "pussy juice": False, "barefoot": False, "breasts": False, "ejaculation": False, }
def insert_spaces(source_list, reference_list): modified_list = source_list.copy() for index, keyword in enumerate(reference_list): if keyword not in source_list: space_count = len(keyword) # ํค์๋ ๊ธธ์ด๋งํผ์ ๊ณต๋ฐฑ ๋ฌธ์ modified_list.insert(index, ' ' * space_count) return modified_list
keywords = positive.split(', ') filtered_keywords = [] removed_indices = [] positive0, positive1, positive2, positive3 = None, None, None, None
for word in result.keys(): if word in lines: result[word] = True for word in state.keys(): if word in positive: state[word] = True
if(result["boys"]): #group sex if(result["girls"]): pass #gangbang elif(result["1girl"]): pass
key_index = int((len(keywords)/2)-1)
global bag_of_tags eye_color = ['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'] hair_color = ['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'] if not wildcard_var2.get() or not rm_characteristic_var.get(): key_features = [] for tag in bag_of_tags: if tag in keywords: key_features.append(tag) keywords.remove(tag) if not any(color in key_features for color in eye_color): key_features.append(random.choice(eye_color)) if not any(color in key_features for color in hair_color): key_features.append(random.choice(hair_color)) key_feature = "{" +' ,'.join(key_features) + "}" keywords.insert(2, key_feature)
if(result["1boy"]): if(result["girls"]): pass elif(result["1girl"]): if('sex,' in positive): sex_pos_keywords = ['stomach bulge','insertion', 'fucked silly', 'x-ray', 'orgasm', 'cross-section', 'uterus', 'overflow', 'rape'] facial_keywords = ['tongue','ahegao'] temp_sex_pos = [] temp_facial = [] cum_events = [] explicit_check = [] if 'open mouth' in keywords: keywords.remove('open mouth') if 'closed mouth' in keywords: keywords.remove('closed mouth') if 'after rape' in keywords: keywords.remove('after rape') explicit_check.append('after rape') for keyword in keywords: if ('sex' not in keyword and 'cum' not in keyword and 'ejaculation' not in keyword and 'vaginal' not in keyword and 'penetration' not in keyword) and all(sex_pos not in keyword for sex_pos in sex_pos_keywords) and all(facial not in keyword for facial in facial_keywords): filtered_keywords.append(keyword) elif 'sex' in keyword: removed_indices.append(keyword) elif 'penetration' in keyword: removed_indices.append(keyword) elif 'cum' in keyword and keyword != 'cum': cum_events.append(keyword) elif any(sex_pos in keyword for sex_pos in sex_pos_keywords): for sex_pos in sex_pos_keywords: if sex_pos in keyword: temp_sex_pos.append(sex_pos) elif any(facial not in keyword for facial in facial_keywords): for facial in facial_keywords: if facial in keyword: temp_facial.append(facial) filtered_keywords.insert(int((len(filtered_keywords)/2)-1), ' no penetration, imminent penetration') filtered_keywords_positive0 = filtered_keywords.copy() filtered_keywords.remove(' no penetration, imminent penetration') #0 imminent penetration, imminent sex for i, keyword in enumerate(filtered_keywords): if 'pantyhose' in keyword: filtered_keywords[i] = 'torn ' + filtered_keywords[i] #1 default key_index = int((len(filtered_keywords)/2)-1) if 'pussy' in filtered_keywords: key_index = filtered_keywords.index('pussy') if 'penis' in filtered_keywords: key_index = filtered_keywords.index('penis') filtered_keywords[key_index:key_index] = ['motion lines', 'surprised'] for keyword in removed_indices: if 'cum' not in keyword and 'ejaculation' not in keyword: filtered_keywords.insert(key_index,keyword) if(temp_sex_pos): filtered_keywords[key_index:key_index] = temp_sex_pos if('clothed sex' in filtered_keywords and not 'bottomless' in filtered_keywords): filtered_keywords.insert(filtered_keywords.index('clothed sex')+1, 'bottomless') pos1_copied_keywords = filtered_keywords.copy() for i, keyword in enumerate(pos1_copied_keywords): if 'closed eyes' in keyword: rand_num = random.randint(0,2) if(rand_num == 0): pos1_copied_keywords[i] = 'half-' + pos1_copied_keywords[i] elif(rand_num == 1 and 'closed eyes' in pos1_copied_keywords): pos1_copied_keywords.remove('closed eyes') filtered_keywords[i] = 'half-closed eyes' filtered_keywords_positive1 = pos1_copied_keywords.copy() #2 ejaculation,cum in pussy key_index = filtered_keywords.index('surprised') filtered_keywords.remove('surprised') filtered_keywords[key_index:key_index] = ["ejaculation","cum"] for keyword in removed_indices: if 'cum' in keyword: filtered_keywords.insert(key_index,keyword) if(temp_facial): filtered_keywords[key_index:key_index] =temp_facial filtered_keywords_positive2 = filtered_keywords.copy() #3 after sex, after ejaculation for i, keyword in enumerate(filtered_keywords): if 'closed eyes' in keyword: rand_num = random.randint(0,2) if(rand_num == 0 and filtered_keywords[i] != 'half-closed eyes'): filtered_keywords[i] = 'half-' + filtered_keywords[i] elif(rand_num == 1): filtered_keywords[i] = 'empty eyes' else: filtered_keywords[i] = 'empty eyes, half-closed eyes' key_index = filtered_keywords.index('ejaculation') filtered_keywords.remove('ejaculation') filtered_keywords[key_index:key_index] = ['after ejaculation', 'after sex', 'cum drip', 'erection'] + cum_events if(explicit_check): filtered_keywords[key_index:key_index] = explicit_check if('pussy' in filtered_keywords and not 'anal' in filtered_keywords): filtered_keywords.insert(filtered_keywords.index('pussy')+1, 'spread pussy') elif('anal' in filtered_keywords): filtered_keywords.insert(filtered_keywords.index('anal')+1, 'cum in ass') positive0 = ', '.join(insert_spaces(filtered_keywords_positive0, filtered_keywords)).strip() print("round 1 : ",positive0) positive1 = ', '.join(insert_spaces(filtered_keywords_positive1, filtered_keywords)).strip() print("round 2 : ",positive1) positive2 = ', '.join(insert_spaces(filtered_keywords_positive2, filtered_keywords)).strip() print("round 3 : ",positive2) positive3 = ', '.join(filtered_keywords).strip() print("round 4 : ",positive3) elif(', penis' in positive): if(', oral' in positive): pass elif(', paizuri' in positive): pass elif('job,' in positive): if('handjob' in positive): pass elif('footjob' in positive): pass
return positive0, positive1, positive2, positive3
positive0, positive1, positive2, positive3 = SELECT(text_output.get("1.0", tk.END));
seed = random.randint(0,9999999999) sleep1 = random.uniform(13.5,19.5) sleep2 = sleep1 + random.uniform(13.5,19.5) sleep3 = sleep2 + random.uniform(13.5,19.5)
thread0 = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive0, negative, button, 1, 0)) thread0.start() thread1 = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive1, negative, button, 2, sleep1)) thread1.start() thread2 = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive2, negative, button, 3, sleep2)) thread2.start() thread3 = threading.Thread(target=generate_turbo, args=(seed,turbo_count, access_token, width, height, positive3, negative, button, 4, sleep3)) thread3.start()
turbo_count += 1
def generate_turbo(_seed, turbo_count, tb_access_token,width, height, positive, negative, button, pipe_number, sleeptime): global temp_clipboard_image global current_sampler global NAI_width, NAI_height global running_flag
try: scale = float(entry_CFG_value.get()) except: scale = 5.0 if scale > 7.0: scale = 7.0 elif scale < 4.0: scale = 4.0 else: scale = round(scale, 1)
try: scale2 = float(entry_rescale_value.get()) except: scale2 = 0 if scale2 > 1.00: scale = 1.00 elif scale2 < 0.0: scale = 0.00 else: scale2 = round(scale2, 2)
params = { "legacy": False, "quality_toggle": False, "width": width, "height": height, "n_samples": 1, "seed": _seed, "extra_noise_seed": random.randint(0,9999999999), "sampler": current_sampler, "steps": 28, "scale": scale, "uncond_scale": 1.0, "negative_prompt": negative, "sm" : sema_button_var.get(), "sm_dyn" : dyn_button_var.get(), "decrisper": False, "controlnet_strength": 1.0, "add_original_image": False, "cfg_rescale": scale2, "noise_schedule": "native", } def merge_images(image_queue): if len(image_queue) < 4: return None # ์ด๋ฏธ์ง๊ฐ 4๊ฐ ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ None์ ๋ฐํ
# ๋ชจ๋ ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๋์ผํ๊ฒ ์กฐ์ # ์์๋ฅผ ์ํด ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ์ฌ์ฉํฉ๋๋ค. ํ์์ ๋ฐ๋ผ ์์ ๊ฐ๋ฅ width, height = image_queue[0].size new_image = Image.new('RGB', (width * 2, height * 2))
# ์ด๋ฏธ์ง ์์น ๋งคํ positions = [(0, 0), (width, 0), (0, height), (width, height)]
# ์ด๋ฏธ์ง ๋ณํฉ for i, img in enumerate(image_queue): pos = positions[i] new_image.paste(img, pos)
return new_image def insert_queue(i, _number): global image_queue while len(image_queue) < 4: image_queue.append(None) if _number <= 4: image_queue[_number-1] = i.copy() i_resized = resize_and_fill(i) box_position = (i_resized.width - 25, 10) draw = ImageDraw.Draw(i_resized) draw.rectangle([box_position, (box_position[0] + 25, box_position[1] + 25)], fill="black") font = ImageFont.load_default() text_position = (box_position[0] + 12, box_position[1] + 12) # ํ
์คํธ ์์น ์กฐ์ draw.text(text_position, str(_number), fill="white", font=font) if 'tk_image' in globals(): globals()['tk_image'] = None tk_image = ImageTk.PhotoImage(i_resized) image_label.config(image=tk_image) image_label.image = tk_image # ์ฐธ์กฐ ์ ์ง if all(img is not None for img in image_queue): time.sleep(4) merged_image = merge_images(image_queue) if merged_image is not None: i_resized = resize_and_fill(merged_image) if 'tk_image' in globals(): globals()['tk_image'] = None tk_image = ImageTk.PhotoImage(i_resized) image_label.config(image=tk_image) image_label.image = tk_image # ์ฐธ์กฐ ์ ์ง output_file_path = "output_image.jpg" merged_image.save(output_file_path) image_queue = [] # ์ด๋ฏธ์ง ํ ์ด๊ธฐํ
def resize_and_fill(image, max_size=None): if max_size is None: max_size = get_max_size() original_width, original_height = image.size if original_width > max_size or original_height > max_size: # ๋น์จ์ ์ ์งํ๋ฉด์ ํฌ๊ธฐ ์กฐ์ image.thumbnail((max_size, max_size))
# ์ ์ด๋ฏธ์ง ํฌ๊ธฐ ๊ณ์ฐ width, height = image.size new_image = Image.new("RGB", (max_size, max_size), "black") new_image.paste(image, ((max_size - width) // 2, (max_size - height) // 2)) return new_image else: return image
def log_error(e, output_file_path="output_file_path"): # ํ์ฌ ์๊ฐ์ ์ป์ต๋๋ค current_time = datetime.now().strftime("%m/%d %H:%M:%S")
# ์๋ฌ ๋ก๊ทธ ๋ฉ์์ง error_message = f"#### Error occured at {current_time} ####\nError: {e}\n############################################\n"
# ์ง์ ๋ ์ถ๋ ฅ ํด๋์ error_log.txt ํ์ผ์ ์ฐ๊ธฐ with open(f"error_log.txt", "a") as file: file.write(error_message) if(pipe_number != 1): time.sleep(sleeptime) tprint("Running : request received, pipeline :",pipe_number) try: zipped_bytes = generate_image(tb_access_token, positive, "nai-diffusion-3", "generate", params) d = Path("output_NAI") d.mkdir(exist_ok=True) zipped = zipfile.ZipFile(io.BytesIO(zipped_bytes)) image_bytes = zipped.read(zipped.infolist()[0]) (d / f"{turbo_count:05}_{pipe_number}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png" ).write_bytes(image_bytes) i = Image.open(io.BytesIO(image_bytes)) i = ImageOps.exif_transpose(i).convert("RGB") if temp_clipboard_image is not None: temp_clipboard_image.close() if(pipe_number == 1 and len(image_queue) < 4): image_queue.clear() temp_clipboard_image = i insert_queue(i, pipe_number) tprint("image inserted, pipe number : ",pipe_number) except Exception as e: #text_output.insert(tk.END, f"Error: {e}", fg='red') log_error(e, "path_to_output_folder") time.sleep(random.uniform(3.0, 9.0)) insert_queue(temp_clipboard_image, pipe_number) if(pipe_number == 4): button.config(state=tk.NORMAL) if(mac_var.get()): window.event_generate(GENERATE_EVENT, when="tail")
time.sleep(random.uniform(3.0, 5.5)) if(pipe_number == 4): button.config(state=tk.NORMAL) running_flag = False
if pipe_number == 4 and mac_var.get() and not running_flag: random_function() time.sleep(random.uniform(2.1, 5.5)) button.config(state=tk.DISABLED) window.event_generate(GENERATE_EVENT, when="tail") else: if(pipe_number == 4): tprint('state : idle')
def NAI_setting(button, button_generate): global NAI_ID NAI_setting_window = tk.Toplevel(window) NAI_setting_window_title = "NAI ๋ก๊ทธ์ธ"
def NAI_close(): NAI_setting_window.destroy()
NAI_ID_label = tk.Label(NAI_setting_window, text="NAI ID: ") NAI_ID_label.grid(row=0, column=0, columnspan=2, sticky='w') entry_NAI_ID = tk.Entry(NAI_setting_window, width=50) entry_NAI_ID.grid(row=0, column=1, columnspan=2, padx=100, pady=5, sticky='e') if(NAI_ID): entry_NAI_ID.insert(tk.END,NAI_ID) NAI_PW_label = tk.Label(NAI_setting_window, text="NAI PW: ") NAI_PW_label.grid(row=1, column=0, columnspan=2, sticky='w') entry_NAI_PW = tk.Entry(NAI_setting_window, width=50, show="*") entry_NAI_PW.grid(row=1, column=1, columnspan=2, padx=100, pady=5, sticky='e')
def NAI_connect(button, connect_button): global access_token, NAI_ID username = entry_NAI_ID.get().strip() password = entry_NAI_PW.get().strip() access_key = get_access_key(username, password) try: access_token = login(access_key) access_result = requests.get("https://api.novelai.net/user/information", headers={ "Authorization": f"Bearer {access_token}" }) NAI_State_label.config(text="(๋ก๊ทธ์ธ ์ฑ๊ณต, ๋ซ๊ธฐ ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์.)", fg="blue") button.config(state=tk.DISABLED) button_generate.config(state="normal") connect_button.config(state=tk.DISABLED) NAI_ID = username except Exception as e: print(e) NAI_close()
connect_button = tk.Button(NAI_setting_window, text="์ฐ๊ฒฐ", command=lambda: NAI_connect(button, connect_button)) connect_button.grid(row=2, column=1, columnspan=2, padx=5, pady=5, sticky='w') close_button = tk.Button(NAI_setting_window, text="๋ซ๊ธฐ", command=NAI_close) close_button.grid(row=2, column=2, columnspan=2, padx=5, pady=5, sticky='w') NAI_State_label = tk.Label(NAI_setting_window, text="ํด๋น ์ ์๊ธฐ๋ฅ์ ์ ์์ ์ธ ์ ์ ํจํด์ด ์๋์ ์ฐธ๊ณ ๋ถํ๋๋ฆฝ๋๋ค.", fg="red") NAI_State_label.grid(row=3, column=1, sticky='ew')
def NAI_setting_multi(button): global NAI_ID_multi NAI_setting_window_multi = tk.Toplevel(window) NAI_setting_window_title = "NAI ๋ก๊ทธ์ธ"
def NAI_close(): NAI_setting_window_multi.destroy()
NAI_ID_label = tk.Label(NAI_setting_window_multi, text="NAI ID: ") NAI_ID_label.grid(row=0, column=0, columnspan=2, sticky='w') entry_NAI_ID = tk.Entry(NAI_setting_window_multi, width=50) entry_NAI_ID.grid(row=0, column=1, columnspan=2, padx=100, pady=5, sticky='e') if(NAI_ID_multi): entry_NAI_ID.insert(tk.END,NAI_ID_multi) NAI_PW_label = tk.Label(NAI_setting_window_multi, text="NAI PW: ") NAI_PW_label.grid(row=1, column=0, columnspan=2, sticky='w') entry_NAI_PW = tk.Entry(NAI_setting_window_multi, width=50, show="*") entry_NAI_PW.grid(row=1, column=1, columnspan=2, padx=100, pady=5, sticky='e')
def NAI_connect(button, connect_button): global access_token_multi, NAI_ID, NAI_ID_multi username = entry_NAI_ID.get().strip() password = entry_NAI_PW.get().strip() access_key = get_access_key(username, password) try: access_token_multi = login(access_key) access_result = requests.get("https://api.novelai.net/user/information", headers={ "Authorization": f"Bearer {access_token}" }) if NAI_ID == NAI_ID_multi: NAI_State_label.config(text="(๊ฐ์ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธ ํ์
จ์ต๋๋ค.)", fg="red") else: NAI_State_label.config(text="(๋ก๊ทธ์ธ ์ฑ๊ณต, ๋ซ๊ธฐ ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์.)", fg="blue") button.config(state=tk.DISABLED) connect_button.config(state=tk.DISABLED) NAI_ID_multi = username except Exception as e: print(e) NAI_close()
connect_button = tk.Button(NAI_setting_window_multi, text="์ฐ๊ฒฐ", command=lambda: NAI_connect(button, connect_button)) connect_button.grid(row=2, column=1, columnspan=2, padx=5, pady=5, sticky='w') close_button = tk.Button(NAI_setting_window_multi, text="๋ซ๊ธฐ", command=NAI_close) close_button.grid(row=2, column=2, columnspan=2, padx=5, pady=5, sticky='w') NAI_State_label = tk.Label(NAI_setting_window_multi, text="ํด๋น ๊ธฐ๋ฅ์ NAI Opus ๊ตฌ๋
๊ณ์ 2๊ฐ๊ฐ ์๊ตฌ๋ฉ๋๋ค..", fg="red") NAI_State_label.grid(row=3, column=1, sticky='ew')
def on_resolution_change(*args): global NAI_width, NAI_height resolution = selected_resolution.get() NAI_width, NAI_height = resolution.split(' x ')
def on_option_select(value): global current_sampler current_sampler = value
def open_file_explorer(): output_file_path = "output_NAI" if os.path.exists(output_file_path): os.startfile(output_file_path)
def on_generate_event(event): global running_flag if not (running_flag): NAI_generation(NAI_width, NAI_height, button_generate) running_flag = True
def random_artist_management(): global top_100_keywords, top_100_counts, cached_rows if not cached_rows: return if not (top_100_keywords): if not os.path.exists("counting_result.txt"): keyword_counts = analyze_cached_rows(cached_rows) excluded_keywords = set(whitelist[:2974]) with open("counting_result.txt", "w") as file: for keyword, count in sorted(keyword_counts.items(), key=lambda item: item[1], reverse=True): if keyword not in excluded_keywords and keyword in afilter_30000: file.write(f"{keyword}: {count}\n") with open("counting_result.txt", "r") as file: lines = file.readlines() top_100_data = [ (line.split(":")[0].strip(), int(line.split(":")[1].strip())) for line in lines[:3000] if line.split(":")[0].strip() in afilter_30000[:8528] ] top_100_keywords, top_100_counts = zip(*top_100_data) if top_100_data else ([], []) elif (not top_100_keywords): with open("counting_result.txt", "r") as file: lines = file.readlines() top_100_data = [ (line.split(":")[0].strip(), int(line.split(":")[1].strip())) for line in lines[:3000] if line.split(":")[0].strip() in afilter_30000[:8528] ] top_100_keywords, top_100_counts = zip(*top_100_data) if top_100_data else ([], []) # top_100_keywords ๋ด์ # ์ ์ฐฝ ์์ฑ random_artist_window = tk.Toplevel(window) # ์ฒซ ๋ฒ์งธ Text Output Box ์ค์ text_output1 = tk.Text(random_artist_window, height=40, width=50) text_output1.pack(padx=10, pady=10) for keyword, count in zip(top_100_keywords, top_100_counts): text_output1.insert(tk.END, f"{keyword}: {count}\n")
def update_lists(): # Text ์์ ฏ์์ ๋ด์ฉ์ ๊ฐ์ ธ์ต๋๋ค. content = text_output1.get("1.0", tk.END) lines = content.strip().split("\n") # ์ค๋ฐ๊ฟ์ผ๋ก ๊ตฌ๋ถํ์ฌ ๋ฆฌ์คํธ๋ฅผ ์์ฑํฉ๋๋ค.
# ๊ฐฑ์ ๋ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ๋ ๊ฐ์ ๋ฆฌ์คํธ๋ฅผ ์์ฑํฉ๋๋ค. updated_keywords = [] updated_counts = []
# ๊ฐ ์ค์ ์ฒ๋ฆฌํ์ฌ ๋ฆฌ์คํธ๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค. for line in lines: if line: # ๋น ์ค์ด ์๋ ๊ฒฝ์ฐ์๋ง ์ฒ๋ฆฌํฉ๋๋ค. parts = line.split(":") if len(parts) == 2: # "ํค์๋: ์นด์ดํธ" ํ์์ด ๋ง๋์ง ํ์ธํฉ๋๋ค. updated_keywords.append(parts[0].strip()) updated_counts.append(int(parts[1].strip())) # ์ ์ญ ๋ฆฌ์คํธ๋ฅผ ๊ฐฑ์ ํฉ๋๋ค. global top_100_keywords, top_100_counts top_100_keywords = updated_keywords top_100_counts = updated_counts with open("random_artist_keywords_"+str(len(top_100_keywords))+".txt", "w") as f: for keyword in updated_keywords: f.write('100: artist:'+keyword + "\n")
# ๋ฒํผ๋ค์ ๋ด์ ํ๋ ์ ์์ฑ buttons_frame = tk.Frame(random_artist_window) buttons_frame.pack(pady=10)
# '์ ์ฅ' ๋ฒํผ์ ํ๋ ์์ ์ผ์ชฝ์ ๋ฐฐ์น save_button = tk.Button(buttons_frame, text="์ ์ฅ", command=update_lists) save_button.pack(side=tk.LEFT, padx=5)
# '๋ซ๊ธฐ' ๋ฒํผ์ ํ๋ ์์ ์ค๋ฅธ์ชฝ์ ๋ฐฐ์น close_button = tk.Button(buttons_frame, text="๋ซ๊ธฐ", command=random_artist_window.destroy) close_button.pack(side=tk.RIGHT, padx=5)
random_artist_label = tk.Label(random_artist_window, text='์๊ฐ์ด๋ฆ ์ด '+str(len(top_100_keywords))+'๊ฐ, ์ ์ฅ์์น: exeํ์ผ ์์น') random_artist_label.pack()
def open_wildcard_setting(): global artist_wildcard_saved, character_wildcard_saved # ์ ์ฐฝ ์์ฑ wildcard_window = tk.Toplevel(window) wildcard_window.title("์์ผ๋ ์นด๋ ์ค์ ")
# ์๊ฐ๋ช
ํ์ผ ๋ถ๋ฌ์ค๊ธฐ artist_label = tk.Label(wildcard_window, text="์๊ฐ๋ช
ํ์ผ ๋ถ๋ฌ์ค๊ธฐ ->") artist_label.grid(row=0, column=0) artist_button = tk.Button(wildcard_window, text="์ด๊ธฐ", command=lambda: load_wildcard(artist_text, wildcard_window, 'artist')) artist_button.grid(row=0, column=1)
artist_text = tk.Text(wildcard_window, height=15, width=60) artist_text.grid(row=1, column=0, columnspan=2) if artist_wildcard_saved: artist_text_content = '\n'.join(artist_wildcard_saved) artist_text.insert('1.0', artist_text_content)
# ์บ๋ฆญํฐ ํ์ผ ๋ถ๋ฌ์ค๊ธฐ character_label = tk.Label(wildcard_window, text="์บ๋ฆญํฐ ํ์ผ ๋ถ๋ฌ์ค๊ธฐ ->") character_label.grid(row=2, column=0) character_button = tk.Button(wildcard_window, text="์ด๊ธฐ", command=lambda: load_wildcard(character_text, wildcard_window, 'character')) character_button.grid(row=2, column=1)
character_text = tk.Text(wildcard_window, height=15, width=60) character_text.grid(row=3, column=0, columnspan=2) if character_wildcard_saved: character_text_content = '\n'.join(character_wildcard_saved) character_text.insert('1.0', character_text_content)
# ๋ฒํผ๋ค buttons_frame = tk.Frame(wildcard_window) buttons_frame.grid(row=4, column=0, columnspan=2)
text_label = tk.Label(wildcard_window, text="wildcard ๋ฌธ๋ฒ(์๊ฐ):\noffset:wildcard1 150:null (helloworld)\noffset:wildcard2 100:none (goodbye)\n์์ผ๋ฉด 100: ์ผ๋ก ๊ฐ์ฃผ\noffset/offset ์ดํฉ: wildcard ํ๋ฅ ") text_label.grid(row=5, column=0,sticky='ew') 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...") text_label2.grid(row=6, column=0,sticky='ew')
load_button = tk.Button(buttons_frame, text="์์ผ๋์นด๋ ํ์ฌ", command=lambda: apply_wildcard(artist_text, character_text, wildcard_window)) load_button.pack(side=tk.LEFT, padx=10)
close_button = tk.Button(buttons_frame, text="๋ซ๊ธฐ", command=wildcard_window.destroy) close_button.pack(side=tk.RIGHT, padx=10)
def apply_wildcard(artist_text, character_text, window): global artist_wildcard_saved artist_wildcard_check = artist_text.get("1.0", tk.END) if len(artist_wildcard_check) > 5: lines = artist_wildcard_check.strip().split("\n") artist_wildcard_saved = lines.copy() akeywords = [] current_index = 0 for line in lines: parts = line.strip().split(':', 1) if len(parts) == 2 and parts[0].strip().isdigit(): weight = int(parts[0].strip()) else: weight = 100 parts = ['100', line.strip()] # '100:'์ ์์ ์ถ๊ฐํฉ๋๋ค. keyword = parts[1].strip() akeywords.append((current_index, current_index + weight - 1, keyword)) current_index += weight global artist_wildcard artist_wildcard = akeywords check_wildcard.config(state='normal')
character_wildcard_check = character_text.get("1.0", tk.END) global character_wildcard_saved if len(character_wildcard_check) > 5: lines = character_wildcard_check.strip().split("\n") character_wildcard_saved = lines.copy() ckeywords = [] current_index = 0 for line in lines: parts = line.strip().split(':', 1) if len(parts) == 2 and parts[0].strip().isdigit(): weight = int(parts[0].strip()) else: weight = 100 parts = ['100', line.strip()] # '100:'์ ์์ ์ถ๊ฐํฉ๋๋ค. keyword = parts[1].strip() ckeywords.append((current_index, current_index + weight - 1, keyword)) current_index += weight global character_wildcard character_wildcard = ckeywords check_wildcard2.config(state='normal')
window.destroy()
def load_wildcard(text_widget, window, _type): global artist_wildcard_saved, character_wildcard_saved window.iconify() filepath = filedialog.askopenfilename(filetypes=[("ํ
์คํธ ํ์ผ", "*.txt")]) if filepath: with open(filepath, 'r', encoding='utf-8') as file: lines = file.readlines() updated_lines = [] for line in lines: line = line.strip() if ':' in line: prefix, _ = line.split(':', 1) if not prefix.strip().isdigit(): line = f"100: {line}" else: line = f"100: {line}" updated_lines.append(line)
text_widget.delete('1.0', tk.END) text_widget.insert('1.0', '\n'.join(updated_lines))
if(_type == 'artist'): artist_wildcard_saved = updated_lines.copy() elif(_type == 'character'): character_wildcard_saved = updated_lines.copy()
window.deiconify()
def find_keyword(index, keywords): for start, end, keyword in keywords: if start <= index <= end: return keyword return None
def get_random_keyword(req_keyword): #called from artist_wildcard, character_wildcard global artist_wildcard, character_wildcard if(req_keyword == 'artist'): keywords = artist_wildcard elif(req_keyword == 'character'): keywords = character_wildcard print('lenghth = ',len(keywords)) max_index = keywords[-1][1] random_index = random.randint(0, max_index) return find_keyword(random_index, keywords)
def tprint(*args): ctext = "" for t in args: ctext += str(t) running_state.config(text=ctext)
thread_controller = Falseturbo_count = 0on_press_flag = Falsewindow = tk.Tk()window.title("Prompt Selector for Danbooru tags")last_deep_search_keywords = Nonecached_rows = []total_rows = 0last_selected_row_keywords = ['1girl','nahida (genshin impact)', 'looking at viewer', 'garden']top_100_keywords = []top_100_counts = []previous_artist = Nonelistener = Nonecurrent_keys = set()click_count = 0access_token = Nonetemp_clipboard_image = NoneNAI_width = 1024NAI_height = 1024current_sampler = "k_euler_ancestral"running_flag = FalseNAI_ID = Noneartist_wildcard = []character_wildcard_saved = []artist_wildcard_saved = []character_wildcard =[]access_token_multi = NoneNAI_ID_multi = Noneimage_queue = []
whitelist = wlist.whitelistbag_of_tags = tagbag.bag_of_tagsafilter_30000 = arti_list.afilter_30000
current_wildcard_artist = []current_wildcard_character = []
GENERATE_EVENT = "<<GenerateEvent>>"window.bind(GENERATE_EVENT, on_generate_event)
left_frame = tk.Frame(window)left_frame.grid(row=0, column=0, sticky="nsew")#left_frame.grid_columnconfigure(0, weight=1)right_frame = tk.Frame(window)right_frame.grid(row=0, column=1, sticky="nsew")window.grid_columnconfigure(0, weight=1)window.grid_columnconfigure(1, weight=1)
#ํ์ผ ๊ฒฝ๋ก ๋ฐ ํค์๋ ์
๋ ฅ์ฐฝ ๊ทธ๋ฆฌ๋ ๊ด๋ฆฌframe_row0 = tk.Frame(left_frame)frame_row0.grid(row=0, column=0, padx=5, pady=5, sticky='w')
# ํ์ผ ๊ฒฝ๋ก ์
๋ ฅ์ฐฝlabel_file_path = tk.Label(frame_row0, text="CSV ํ์ผ ๊ฒฝ๋ก:")label_file_path.grid(row=0, column=0, sticky='w')entry_file_path = tk.Entry(frame_row0, width=55)entry_file_path.grid(row=0, column=1, columnspan=4, padx=5, pady=5, sticky='ew')button_open_file = tk.Button(frame_row0, text="ํ์ผ ์ด๊ธฐ", command=open_file)button_open_file.grid(row=0, column=5, padx=5, pady=6, sticky='e')
# ํค์๋ ์
๋ ฅ์ฐฝkeyword_label = tk.Label(frame_row0, text="์ด๊ธฐํ ํค์๋: ")keyword_label.grid(row=1, column=0, sticky='w')entry_keyword = tk.Entry(frame_row0)entry_keyword.grid(row=1, column=1, columnspan=4, padx=5, pady=5, sticky='ew')button_export_csv = tk.Button(frame_row0, text=".csv ๋ด๋ณด๋ด๊ธฐ", command=export_csv)button_export_csv.grid(row=1, column=5, padx=5, pady=6, sticky='e')
# ๋ฒํผ ํ๋ ์frame_buttons = tk.Frame(left_frame)frame_buttons.grid(row=1, column=0, sticky='ew')frame_buttons.columnconfigure(0, weight=1) # ์ผ์ชฝ์ ๊ฐ์ค์น ๋ถ์ฌframe_buttons.columnconfigure(1, weight=0) # ๋ฒํผ ์ด์ ๊ฐ์ค์น ์์frame_buttons.columnconfigure(2, weight=0) # ๋ฒํผ ์ด์ ๊ฐ์ค์น ์์frame_buttons.columnconfigure(3, weight=1) # ์ค๋ฅธ์ชฝ์ ๊ฐ์ค์น ๋ถ์ฌ
# ๋ฒํผ๋คbutton_search = tk.Button(frame_buttons, text="ํด๋น ํค์๋ ๊ฒ์", command=search)button_search.grid(row=0, column=1, padx=5, sticky='ew') # ๋ณ๊ฒฝ: column=1button_exclude = tk.Button(frame_buttons, text="ํด๋น ํค์๋ ์ ์ธ", command=exclude)button_exclude.grid(row=0, column=2, padx=5, sticky='ew') # ๋ณ๊ฒฝ: column=2
total_rows_count_label = tk.Label(frame_buttons, text=".csv ๋ด ํ๋กฌํํธ ํ: 0")total_rows_count_label.grid(row=0, column=3, padx=5, sticky='ew')
# ์ฌ์ธต๊ฒ์ ํค์๋ ์
๋ ฅ์ฐฝdeep_search_frame = tk.Frame(left_frame)deep_search_frame.grid(row=2, column=0, pady=10, sticky='w')deep_search_frame.columnconfigure(0, weight=2)deep_search_frame.columnconfigure(1, weight=2)deep_search_frame.columnconfigure(2, weight=1)
label_deep_search = tk.Label(deep_search_frame, text="์ฌ์ธต๊ฒ์ ํค์๋ ์
๋ ฅ: key,*key,~key,{key1|key2} ")label_deep_search.grid(row=0, column=0, sticky='w')
# Tkinter UI ์ค์ ๋ถ๋ถ์ ๋ ์ด๋ธ ์ถ๊ฐcached_rows_count_label = tk.Label(deep_search_frame, text="์ฌ์ธต๊ฒ์ ํ๋กฌํํธ ํ: 0")cached_rows_count_label.grid(row=0, column=1, padx=5, sticky='w')
button_export_deep_csv = tk.Button(deep_search_frame, text=".csv ๋ด๋ณด๋ด๊ธฐ", command=export_csv_search)button_export_deep_csv.grid(row=0, column=2, padx=5, sticky='e')
entry_deep_search = tk.Entry(deep_search_frame, width=82)entry_deep_search.grid(row=1, column=0, columnspan=3,padx=5, pady=5, sticky='ew')
# ๋ฒํผ๋ค์ ํฌํจํ ํ๋ ์ ์์ฑbutton_frame = tk.Frame(left_frame)button_frame.grid(row=5, column=0, padx=5, sticky='w')
# ๋ฒํผ ํ๋ ์ ๋ด์ ์ด ์ค์ button_frame.columnconfigure(0, weight=1)button_frame.columnconfigure(1, weight=1)button_frame.columnconfigure(2, weight=1)button_frame.columnconfigure(3, weight=1)button_frame.columnconfigure(4, weight=1)button_frame.columnconfigure(5, weight=1)button_frame.columnconfigure(6, weight=1)
# "๋๋ค" ๋ฒํผbutton_random = tk.Button(button_frame, text="๋๋ค", command=random_function)button_random.grid(row=0, column=0, sticky='ew')
# "ํ๋กฌํํธ ๊ณ ์ " ํ ๊ธ ๋ฒํผtoggle_prompt_var = tk.IntVar()button_toggle_prompt = tk.Checkbutton(button_frame, text="ํ๋กฌํํธ ๊ณ ์ ", variable=toggle_prompt_var)button_toggle_prompt.grid(row=0, column=1, sticky='ew')
# "์๋ ๋ณต์ฌ" ์ฒดํฌ๋ฐ์คauto_copy_var = tk.IntVar()check_auto_copy = tk.Checkbutton(button_frame, text="์๋ ๋ณต์ฌ", variable=auto_copy_var)check_auto_copy.grid(row=0, column=2, sticky='ew')
# "๋ณต์ฌ" ๋ฒํผbutton_copy = tk.Button(button_frame, text="๋ณต์ฌ", command=copy_to_clipboard)button_copy.grid(row=0, column=3, sticky='ew')
# "์ข
๋ฃ" ๋ฒํผbutton_exit = tk.Button(button_frame, text="์ข
๋ฃ", command=exit_program)button_exit.grid(row=0, column=4, sticky='ew')
# "์์ฑ" ๋ฒํผbutton_generate = tk.Button(button_frame, text="NAI ์์ฒญ", command=lambda: NAI_generation(NAI_width, NAI_height, button_generate))button_generate.grid(row=0, column=5, sticky='ew')button_generate.config(state='disabled')
# "์ค์ " ๋ฒํผbutton_setting = tk.Button(button_frame, text="NAI ๋ก๊ทธ์ธ ์ค์ ", command=lambda: NAI_setting(button_setting, button_generate))button_setting.grid(row=0, column=6, sticky='ew')
# "ํฐ๋ณด" ๋ฒํผ#button_turbo = tk.Button(button_frame, text="ํฐ๋ณด", command=lambda: NAI_setting_multi(button_turbo))#button_turbo.grid(row=0, column=7, sticky='ew')
# '์๋ํ'์ 'ํฐ๋ณดon'์ ํฌํจํ ์๋ธ ํ๋ ์ ์์ฑsub_frame = tk.Frame(button_frame)sub_frame.grid(row=0, column=8, sticky='ns') # ์๋ธ ํ๋ ์์ ๏ฟฝ๏ฟฝ๏ฟฝ 8์ ๋ฐฐ์น
# '์๋ํ' ์ฒดํฌ๋ฐ์ค๋ฅผ ์๋ธ ํ๋ ์์ ๋ฐฐ์นmac_var = tk.IntVar() mac_button = tk.Checkbutton(sub_frame, text="์๋ํ", variable=mac_var)mac_button.grid(row=0, column=0, sticky='ew') # ์ฒซ ๋ฒ์งธ ํ์ ๋ฐฐ์น
# 'ํฐ๋ณดon' ์ฒดํฌ๋ฐ์ค๋ฅผ ์๋ธ ํ๋ ์์ ๋ฐฐ์นturbo_var = tk.IntVar()turbo_button = tk.Checkbutton(sub_frame, text="ํฐ๋ณดon", variable=turbo_var)turbo_button.grid(row=1, column=0, sticky='ew') # ๋ ๋ฒ์งธ ํ์ ๋ฐฐ์น
# ํ
์คํธ ๋ฐ ๊ณ ์ ํ๋กฌํํธ ๋ค๊ฑฐํฐ๋ธ ๋ฑ ํ๋กฌํํธ ์ฐฝtext_frame = tk.Frame(left_frame)text_frame.grid(row=6, column=0, padx=5, pady=5, sticky='w')text_frame.columnconfigure(0, weight=1)text_frame.columnconfigure(1, weight=7)
text_frame2 = tk.Frame(left_frame)text_frame2.grid(row=8, column=0, padx=5, pady=5, sticky='w')text_frame2.columnconfigure(0, weight=1)text_frame2.columnconfigure(1, weight=7)
_size = get_max_size()
# ์ถ๋ ฅ ํ
์คํธ ์ฐฝtext_output_label = tk.Label(text_frame, text="ํ๋กฌํํธ", borderwidth=1, relief="solid",height=6)text_output_label.grid(row=0, column=0, padx=5, pady=5, sticky='w')if _size<=768: text_output_width = 74 else: text_output_width = 65text_output = tk.Text(text_frame, width=text_output_width, height=7)text_output.grid(row=0, column=1, sticky='ew')
fixed_prompt_frame = tk.Frame(left_frame)fixed_prompt_frame.grid(row=7, column=0, padx=5, pady=5, sticky='w')fixed_prompt_frame.columnconfigure(0, weight=1)fixed_prompt_frame.columnconfigure(1, weight=1)
fixed_prompt_label_left = tk.Label(fixed_prompt_frame, text="์ ํ ๊ณ ์ ํ๋กฌํํธ (ํ๋กฌํํธ ์)")fixed_prompt_label_left.grid(row=0, column=0, sticky='ew')fixed_prompt_label_right = tk.Label(fixed_prompt_frame, text="ํํ ๊ณ ์ ํ๋กฌํํธ (ํ๋กฌํํธ ๋ค)")fixed_prompt_label_right.grid(row=0, column=1, sticky='ew')entry_fixed_prompt = tk.Entry(fixed_prompt_frame, width=40)entry_fixed_prompt.grid(row=1, column=0,padx=5, pady=5, sticky='ew')entry_fixed_prompt_after = tk.Entry(fixed_prompt_frame, width=40)entry_fixed_prompt_after.grid(row=1, column=1, padx=5, pady=5, sticky='ew')
# ๋ค๊ฑฐํฐ๋ธ ํ๋กฌํํธNP_label = tk.Label(text_frame2, text="๋ค๊ฑฐํฐ๋ธ\nํ๋กฌํํธ", borderwidth=1, relief="solid",height=2)NP_label.grid(row=0,column=0, padx=5, pady=5, sticky='ew')negative_text = tk.Text(text_frame2, width=65, height=3)negative_text.grid(row=0, column=1, padx=5, pady=5, sticky='w')
auto_hide_frame = tk.Frame(left_frame)auto_hide_frame.grid(row=9, column=0, padx=5, pady=5, sticky='w')auto_hide_frame.columnconfigure(0, weight=2)auto_hide_frame.columnconfigure(1, weight=2)auto_hide_frame.columnconfigure(2, weight=1)
# ์๋ ์จ๊น ํค์๋ ๋ผ๋ฒจ๊ณผ ์
๋ ฅ์ฐฝ ์ถ๊ฐauto_hide_label = tk.Label(auto_hide_frame, text="์๋ ์จ๊น ํค์๋: keyword1, keyword2, ...")auto_hide_label.grid(row=0, column=0, sticky='w')entry_auto_hide = tk.Entry(auto_hide_frame, width=82)entry_auto_hide.grid(row=1, column=0, columnspan=3, padx=5, pady=5, sticky='ew')# ์ถ์ฒ ํ๋กฌํํธ ์กฐํ ๋ฒํผ ์ค์ recommend_prompt_button = tk.Button(auto_hide_frame, text="์ถ์ฒ ํ๋กฌํํธ", command=open_prompt_window)recommend_prompt_button.grid(row=0, column=2, padx=2, pady=5, sticky='e') # sticky ์ต์
์ 'e'๋ก ๋ณ๊ฒฝํ์ฌ ์ค๋ฅธ์ชฝ ์ ๋ ฌ
# ์ฒดํฌ๋ฐ์ค๋ค์ ํฌํจํ ํ๋ ์ ์์ฑcheckbox_frame = tk.Frame(left_frame)checkbox_frame.grid(row=10, column=0, pady=15, sticky='ew')checkbox_frame2 = tk.Frame(left_frame)checkbox_frame2.grid(row=10, column=1, padx=5, pady=15, sticky='ew')
# ์ฒดํฌ๋ฐ์ค ํ๋ ์ ๋ด์ ์ด ์ค์ checkbox_frame.columnconfigure(0, weight=1) checkbox_frame.columnconfigure(1, weight=1) checkbox_frame.columnconfigure(2, weight=1) checkbox_frame.columnconfigure(3, weight=1) checkbox_frame.columnconfigure(4, weight=1) checkbox_frame.columnconfigure(5, weight=1)
# "์๊ฐ๋ช
์ ๊ฑฐ" ์ฒดํฌ๋ฐ์คremove_artist_var = tk.IntVar() # ์ฒดํฌ๋ฐ์ค ์ํ๋ฅผ ์ ์ฅํ ๋ณ์check_remove_artist = tk.Checkbutton(checkbox_frame, text="์๊ฐ๋ช
์ ๊ฑฐ", variable=remove_artist_var)check_remove_artist.grid(row=0, column=0, sticky='ew')
# "๋๋ค ์๊ฐ ์ถ๊ฐ" ์ฒดํฌ๋ฐ์คrandom_artist_var = tk.IntVar() check_random_artist = tk.Checkbutton(checkbox_frame, text="๋๋ค ์๊ฐ ์ถ๊ฐ", variable=random_artist_var)check_random_artist.grid(row=0, column=1, sticky='ew')
# ๋๋ค์๊ฐ ๊ด๋ฆฌrandom_artist_setting = tk.Button(checkbox_frame, text="๋๋ค ์๊ฐ ๊ด๋ฆฌ", command=random_artist_management) #output_file_pathrandom_artist_setting.grid(row=0, column=2, sticky='ew')
# "์บ๋ฆญํฐ ํน์ง ์ ๊ฑฐ" ์ฒดํฌ๋ฐ์คrm_characteristic_var = tk.IntVar()rm_characteristic_label = tk.Checkbutton(checkbox_frame, text="์บ๋ฆญํฐ ํน์ง ์ ๊ฑฐ", variable=rm_characteristic_var)rm_characteristic_label.grid(row=0, column=3, sticky='ew')
# ์์ผ๋ ์นด๋wildcard_var = tk.IntVar(value= 0)check_wildcard = tk.Checkbutton(checkbox_frame, text="์์ผ๋์นด๋(์๊ฐ)", variable=wildcard_var, state='disabled')check_wildcard.grid(row=1, column=0, sticky='ew')
# ์์ผ๋ ์นด๋2wildcard_var2 = tk.IntVar(value= 0)check_wildcard2 = tk.Checkbutton(checkbox_frame, text="์์ผ๋์นด๋(์บ๋ฆญํฐ)", variable=wildcard_var2, state='disabled')check_wildcard2.grid(row=1, column=1, sticky='ew')
# ์์ผ๋ ์นด๋ ์ค์ widldcard_button = tk.Button(checkbox_frame, text="์์ผ๋์นด๋ ์ค์ ", command=open_wildcard_setting) #output_file_pathwidldcard_button.grid(row=1, column=2, sticky='ew')
#ํด๋ ํธ์ถ ๋ฒํผfolder_button = tk.Button(checkbox_frame, text="์ ์ฅ ํด๋", command=open_file_explorer) #output_file_pathfolder_button.grid(row=1, column=3, padx=5, sticky='ew')
window.bind('<Control-Return>', on_ctrl_enter)window.bind('<Shift-Return>', on_shift_enter)
NAI_ID = load_settings()if not (entry_keyword.get()): entry_keyword.insert(0, "1girl")if not (entry_fixed_prompt.get()): entry_fixed_prompt.insert(0, '1girl,')if not (entry_fixed_prompt_after.get()): entry_fixed_prompt_after.insert(0, 'great quality, aesthetic, absurdres')if not (entry_auto_hide.get()): entry_auto_hide.insert(0, 'monochrome, doujin cover, bad source, censored, bar censor')
resolution1_frame = tk.Frame(left_frame)resolution1_frame.grid(row=15, column=0, padx=5, pady=5, sticky='ew')resolution2_frame = tk.Frame(left_frame)resolution2_frame.grid(row=16, column=0, padx=5, pady=5, sticky='ew')selected_resolution = tk.StringVar(value="1024 x 1024")
tk.Radiobutton(resolution1_frame, text="1024 x 1024", variable=selected_resolution, value="1024 x 1024").grid(row=0, column=0, sticky='w')tk.Radiobutton(resolution1_frame, text="960 x 1088", variable=selected_resolution, value="960 x 1088").grid(row=0, column=1, sticky='w')tk.Radiobutton(resolution1_frame, text="896 x 1152", variable=selected_resolution, value="896 x 1152").grid(row=0, column=2, sticky='w')tk.Radiobutton(resolution1_frame, text="832 x 1216", variable=selected_resolution, value="832 x 1216").grid(row=0, column=3, sticky='w')tk.Radiobutton(resolution2_frame, text="1088 x 960", variable=selected_resolution, value="1088 x 960").grid(row=0, column=0, sticky='w')tk.Radiobutton(resolution2_frame, text="1152 x 896", variable=selected_resolution, value="1152 x 896").grid(row=0, column=1, sticky='w')tk.Radiobutton(resolution2_frame, text="1216 x 832", variable=selected_resolution, value="1216 x 832").grid(row=0, column=2, sticky='w')selected_resolution.trace_add('write', on_resolution_change)
sema_button_var = tk.IntVar(value=1) sema_button = tk.Checkbutton(resolution1_frame, text="SEMA", variable=sema_button_var)sema_button.grid(row=0, column=5, sticky='w')
dyn_button_var = tk.IntVar() dyn_button = tk.Checkbutton(resolution1_frame, text="+DYN", variable=dyn_button_var)dyn_button.grid(row=0, column=6, sticky='w')
rand_resolution_var = tk.IntVar() rand_resolution_button = tk.Checkbutton(resolution1_frame, text="๋๋ค ํด์๋", variable=rand_resolution_var)rand_resolution_button.grid(row=0, column=7, sticky='w')
entry_CFG_value = tk.StringVar()entry_CFG_label = tk.Label(resolution2_frame, text=" CFG Scale : ", justify=tk.LEFT)entry_CFG_label.grid(row=0, column=4, sticky='w')entry_CFG_value.set("5.0")
entry_CFG = tk.Entry(resolution2_frame, width=5, textvariable=entry_CFG_value)entry_CFG.grid(row=0, column=5, sticky='w')
options = ["k_euler", "k_euler_ancestral", "k_dpmpp_2s_ancestral", "k_dpmpp_sde"]selected_option = tk.StringVar()selected_option.set(options[1])option_menu = tk.OptionMenu(resolution2_frame, selected_option, *options, command=on_option_select)option_menu.grid(row=0, column=6, padx=5, sticky='ew')
resolution3_frame = tk.Frame(left_frame)resolution3_frame.grid(row=17, column=0, padx=5, pady=5, sticky='ew')resolution3_frame.columnconfigure(0, weight=2) resolution3_frame.columnconfigure(1, weight=1) resolution3_frame.columnconfigure(2, weight=1)
running_state = tk.Label(resolution3_frame, text="state : idle")running_state.grid(row = 0, column= 0, sticky='w')entry_rescale_value = tk.StringVar()entry_rescale_label = tk.Label(resolution3_frame, text=" Prompt Guidance Rescale : ", justify=tk.LEFT)entry_rescale_label.grid(row=0, column=1, sticky='e')entry_rescale_value.set("0.0")entry_rescale = tk.Entry(resolution3_frame, width=5, textvariable=entry_rescale_value)entry_rescale.grid(row=0, column=2, sticky='w')
image_label = tk.Label(right_frame, relief='solid', borderwidth=1)image_label.grid(row=0, column=0, rowspan=15, padx=10, pady=10, sticky="n")
# ์ ๋น๋ ํค์๋ ์๋์ถ๊ฐ ๋ฒํผ ์ถ๊ฐbtn_add_low_freq = tk.Button(right_frame, text="์ด๋ฏธ์ง๋ฅผ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ", fg="blue", command=copy_image_to_clipboard)btn_add_low_freq.grid(row=16, column=0, padx=5, pady=5, sticky='ew')
# ํ์์ ์ด๋ฏธ์ง ์์ฑwhite_image = Image.new('RGB', (_size, _size), 'white')white_photo = ImageTk.PhotoImage(white_image)
# ๋ผ๋ฒจ์ ์ด๋ฏธ์ง ์ค์ image_label.config(image=white_photo)image_label.image = white_photo
# ๋ฆฌ์ค๋ ์์listener = keyboard.Listener(on_press=on_press, on_release=on_release)listener.start()
# ํค๋ณด๋ ๋ฆฌ์ค๋ ์ค๋ ๋ ์์listener_thread = threading.Thread(target=listener.join, daemon=True)listener_thread.start()
Auto_login_check()window.mainloop().gitattributes+1
Danbooru Prompt Selector/TEST/prompt_selector_auto_1204_test.exeAdded+3
Danbooru Prompt Selector/TEST/prompt_selector_auto_1204_test.pyAdded+1898