Upload 3 files
Browse files- .gitattributes +1 -0
- NAIA_0217_testv1.exe +3 -0
- NAIA_0217_testv1.py +0 -0
- NAIA_random_function_core.py +206 -0
.gitattributes
CHANGED
@@ -126,3 +126,4 @@ Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0214_testv1.exe filte
|
|
126 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/NAIA_0214_testv2.exe filter=lfs diff=lfs merge=lfs -text
|
127 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0216_testv1.exe filter=lfs diff=lfs merge=lfs -text
|
128 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0217_testv1.exe filter=lfs diff=lfs merge=lfs -text
|
|
|
|
126 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/NAIA_0214_testv2.exe filter=lfs diff=lfs merge=lfs -text
|
127 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0216_testv1.exe filter=lfs diff=lfs merge=lfs -text
|
128 |
Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0217_testv1.exe filter=lfs diff=lfs merge=lfs -text
|
129 |
+
NAIA_0217_testv1.exe filter=lfs diff=lfs merge=lfs -text
|
NAIA_0217_testv1.exe
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8803a6e4f5776eff4333f0733ca9ac2c27befa04f810906d52da3cf6ed4095bc
|
3 |
+
size 888962570
|
NAIA_0217_testv1.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
NAIA_random_function_core.py
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import re
|
4 |
+
|
5 |
+
def parse_and_execute_commands(processed, user_input, fix, after, popped_row):
|
6 |
+
commands = [cmd.strip() for cmd in user_input.split(',')]
|
7 |
+
for command in commands:
|
8 |
+
condition, cmd = parse_conditional_command(command)
|
9 |
+
if check_condition(processed, condition, popped_row):
|
10 |
+
processed = execute_command(processed, cmd, fix, after)
|
11 |
+
return processed
|
12 |
+
|
13 |
+
def parse_conditional_command(command):
|
14 |
+
match = re.match(r"\((.*?)\)\:(.*)", command)
|
15 |
+
if match:
|
16 |
+
return match.groups()
|
17 |
+
return '', command
|
18 |
+
|
19 |
+
def check_condition(processed, condition, popped_row):
|
20 |
+
if not condition:
|
21 |
+
return True
|
22 |
+
sub_conditions = re.split(r'\)\s*&\s*\(', condition)
|
23 |
+
sub_conditions = [re.sub(r'^\(|\)$', '', cond) for cond in sub_conditions]
|
24 |
+
|
25 |
+
results = []
|
26 |
+
for sub_cond in sub_conditions:
|
27 |
+
if '&' in sub_cond:
|
28 |
+
results.append(all(check_condition(processed, cond, popped_row) for cond in sub_cond.split('&')))
|
29 |
+
elif '|' in sub_cond:
|
30 |
+
results.append(any(check_condition(processed, cond, popped_row) for cond in sub_cond.split('|')))
|
31 |
+
else:
|
32 |
+
if sub_cond in ['e', 'q', 's', 'g']:
|
33 |
+
results.append(sub_cond == popped_row['rating'])
|
34 |
+
elif sub_cond in ['~e', '~q', '~s', '~g']:
|
35 |
+
results.append(sub_cond != popped_row['rating'])
|
36 |
+
# PM
|
37 |
+
elif sub_cond.startswith('*'):
|
38 |
+
results.append(sub_cond[1:] in processed)
|
39 |
+
# NOT IN
|
40 |
+
elif sub_cond.startswith('~!'):
|
41 |
+
results.append(sub_cond[2:] not in processed)
|
42 |
+
elif sub_cond.startswith('~'):
|
43 |
+
results.append(any(sub_cond[1:] not in element for element in processed))
|
44 |
+
# CONTAIN
|
45 |
+
else:
|
46 |
+
results.append(any(sub_cond in element for element in processed))
|
47 |
+
return all(results)
|
48 |
+
|
49 |
+
def execute_command(processed, command, fix, after):
|
50 |
+
if '+=' in command:
|
51 |
+
keyword, addition = command.split('+=', 1)
|
52 |
+
addition = addition.replace('^', ', ')
|
53 |
+
#addiction split ํด์ ํ๋กฌํํธ ์กด์ฌํ๋์ง ์ฒดํฌ ํ์
|
54 |
+
return insert_text_after_keyword(processed, keyword, addition, fix, after)
|
55 |
+
elif '=' in command:
|
56 |
+
keyword, replacement = command.split('=', 1)
|
57 |
+
if keyword in processed:
|
58 |
+
replacement = replacement.replace('^', ', ')
|
59 |
+
#replacement split ํด์ ํ๋กฌํํธ ์กด์ฌํ๋์ง ์ฒดํฌ ํ์
|
60 |
+
index = processed.index(keyword)
|
61 |
+
processed[index] = replacement
|
62 |
+
return processed
|
63 |
+
|
64 |
+
def insert_text_after_keyword(processed, user_keyword, user_additional_keyword, fix, after):
|
65 |
+
if user_keyword == "prompt":
|
66 |
+
processed.append(user_additional_keyword)
|
67 |
+
elif user_keyword == "prefix":
|
68 |
+
fix.append(user_additional_keyword)
|
69 |
+
elif user_keyword == "postfix":
|
70 |
+
after.append(user_additional_keyword)
|
71 |
+
elif user_keyword in processed:
|
72 |
+
index = processed.index(user_keyword) + 1
|
73 |
+
processed.insert(index, user_additional_keyword)
|
74 |
+
return processed
|
75 |
+
|
76 |
+
def find_keyword_index(general):
|
77 |
+
# boys์ girls ๋ฆฌ์คํธ์ ์์๊ฐ ์๋์ง ํ์ธ ๋ฐ ์ธ๋ฑ์ค ์ ์ฅ
|
78 |
+
boys = ["1boy", "2boys", "3boys", "4boys", "5boys", "6+boys"]
|
79 |
+
girls = ["1girl", "2girls", "3girls", "4girls", "5girls", "6+girls"]
|
80 |
+
#others = ["1other", "2others", "3others", "4others", "5others", "6+others"]
|
81 |
+
boys_indices = [i for i, item in enumerate(general[:6]) if item in boys]
|
82 |
+
girls_indices = [i for i, item in enumerate(general[:6]) if item in girls]
|
83 |
+
|
84 |
+
# case 1๊ณผ case 2: girls ๋ฆฌ์คํธ์ ์์ ์ฐพ๊ธฐ
|
85 |
+
if girls_indices:
|
86 |
+
return girls_indices[0]+1
|
87 |
+
|
88 |
+
# case 3: boys ๋ฆฌ์คํธ์ ์์ ์ฐพ๊ธฐ
|
89 |
+
if boys_indices:
|
90 |
+
return boys_indices[0]+1
|
91 |
+
|
92 |
+
# case 4: ํด๋น ์ฌํญ ์์
|
93 |
+
# 2์ 12์ผ์ ํด๋น ๋ถ๋ถ return 2 -> return 0 ์ผ๋ก ์์ ํ์์ผ๋ฉฐ ์ด ๋ถ๋ถ ํธ๋ํน ํ์
|
94 |
+
return 0
|
95 |
+
|
96 |
+
def RFP(popped_row, fix_prompt, after_prompt, auto_hide_prompt, rm_a, rm_s, rm_c, nsfw, data, magic_word):
|
97 |
+
boys = ["1boy", "2boys", "3boys", "4boys", "5boys", "6+boys"]
|
98 |
+
girls = ["1girl", "2girls", "3girls", "4girls", "5girls", "6+girls"]
|
99 |
+
general = [item.strip() for item in popped_row['general'].split(',')]
|
100 |
+
special_word_check = fix_prompt+', '+after_prompt
|
101 |
+
special_word_check = [item.strip() for item in special_word_check.split(',')]
|
102 |
+
special_word_check = [item for item in special_word_check if item.startswith('*')]
|
103 |
+
exc = []
|
104 |
+
for keyword in general:
|
105 |
+
if keyword == '!' or keyword == '!?' or keyword == '!!':
|
106 |
+
exc.append(keyword)
|
107 |
+
if exc:
|
108 |
+
for keyword in exc:
|
109 |
+
general.remove(keyword)
|
110 |
+
general[3:3] = exc
|
111 |
+
|
112 |
+
if nsfw == 1:
|
113 |
+
nsfw_word = []
|
114 |
+
for keyword in general:
|
115 |
+
if keyword in data.qe_word or keyword in data.bag_of_tags or "horns" in keyword or "(" in keyword or keyword in boys or keyword in girls:
|
116 |
+
nsfw_word.append(keyword)
|
117 |
+
general = nsfw_word
|
118 |
+
if rm_c == 1:
|
119 |
+
temp_general = []
|
120 |
+
for keyword in general:
|
121 |
+
if keyword in data.bag_of_tags:
|
122 |
+
temp_general.append(keyword)
|
123 |
+
for keyword in temp_general:
|
124 |
+
general.remove(keyword)
|
125 |
+
fix = [item.strip() for item in fix_prompt.split(',')]
|
126 |
+
at_first = []
|
127 |
+
for fp in fix:
|
128 |
+
if fp.startswith('*'):
|
129 |
+
at_first.append(fp[1:])
|
130 |
+
if at_first:
|
131 |
+
for af in at_first:
|
132 |
+
if '*'+af in fix:
|
133 |
+
fix.remove('*'+af)
|
134 |
+
if rm_a == 0:
|
135 |
+
if popped_row['artist']:
|
136 |
+
artists = [item.strip() for item in popped_row['artist'].split(',')]
|
137 |
+
artist = ["artist:" + _artist for _artist in artists]
|
138 |
+
fix = fix + artist
|
139 |
+
if rm_s == 0:
|
140 |
+
if popped_row['copyright']:
|
141 |
+
series = [item.strip() for item in popped_row['copyright'].split(',')]
|
142 |
+
else:
|
143 |
+
series = []
|
144 |
+
fix = fix + series
|
145 |
+
after = [item.strip() for item in after_prompt[:-1].split(',')]
|
146 |
+
auto_hide = [item.strip() for item in auto_hide_prompt[:-1].split(',')] + ["| |", ":|", "\||/", "<|> <|>", "|| ||", ";|"]
|
147 |
+
fix_index = find_keyword_index(general)
|
148 |
+
processed = general.copy()
|
149 |
+
temp_hide_prompt = []
|
150 |
+
for keyword in processed:
|
151 |
+
if keyword in auto_hide:
|
152 |
+
temp_hide_prompt.append(keyword)
|
153 |
+
for keyword in temp_hide_prompt:
|
154 |
+
processed.remove(keyword)
|
155 |
+
#์ฌ๊ธฐ์์ ๋ฌธ์ ์ magic word ์ฒ๋ฆฌ
|
156 |
+
if "cond" in magic_word and magic_word["cond"]:
|
157 |
+
user_input = magic_word["cond"]
|
158 |
+
processed = parse_and_execute_commands(processed, user_input, fix, after, popped_row)
|
159 |
+
|
160 |
+
processed[fix_index:fix_index] = fix
|
161 |
+
processed += after
|
162 |
+
|
163 |
+
if rm_c == 0 and '*(remove character name)' not in special_word_check and '*(set character name after prefix)' not in special_word_check and '*(set character name before prefix)' not in special_word_check:
|
164 |
+
if popped_row['character']:
|
165 |
+
character = [item.strip() for item in popped_row['character'].split(',')]
|
166 |
+
processed[fix_index:fix_index] = character
|
167 |
+
fix_index+=len(character)
|
168 |
+
elif rm_c == 0 and '*(set character name after prefix)' in special_word_check:
|
169 |
+
if popped_row['character']:
|
170 |
+
character = [item.strip() for item in popped_row['character'].split(',')]
|
171 |
+
processed[fix_index+len(fix):fix_index+len(fix)] = character
|
172 |
+
#fix_index+=len(character)
|
173 |
+
elif rm_c == 0 and '*(set character name before prefix)' in special_word_check:
|
174 |
+
if popped_row['character']:
|
175 |
+
character = [item.strip() for item in popped_row['character'].split(',')]
|
176 |
+
processed[fix_index+1:fix_index+1] = character
|
177 |
+
fix_index+=len(character)
|
178 |
+
if magic_word["random_artist"] == True:
|
179 |
+
processed.insert(fix_index, magic_word["random_artist_name"])
|
180 |
+
|
181 |
+
boy_in_processed = girl_in_processed = None
|
182 |
+
for boy in boys:
|
183 |
+
if boy in processed:
|
184 |
+
boy_in_processed = boy
|
185 |
+
break
|
186 |
+
|
187 |
+
for girl in girls:
|
188 |
+
if girl in processed:
|
189 |
+
girl_in_processed = girl
|
190 |
+
break
|
191 |
+
|
192 |
+
if boy_in_processed and girl_in_processed:
|
193 |
+
boy_index = processed.index(boy_in_processed)
|
194 |
+
girl_index = processed.index(girl_in_processed)
|
195 |
+
if boy_index > girl_index:
|
196 |
+
processed.pop(boy_index)
|
197 |
+
processed.insert(girl_index, boy_in_processed)
|
198 |
+
|
199 |
+
s_word = ['*(remove character name)', '*(set character name after prefix)', '*(set character name before prefix)']
|
200 |
+
for keyword in s_word:
|
201 |
+
if keyword in processed:
|
202 |
+
processed.remove(keyword)
|
203 |
+
|
204 |
+
if at_first:
|
205 |
+
processed = at_first + processed
|
206 |
+
return ', '.join(processed), popped_row['rating']
|