baqu2213 commited on
Commit
2da904c
โ€ข
1 Parent(s): 7557ddd

Upload 4 files

Browse files
.gitattributes CHANGED
@@ -116,3 +116,4 @@ Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0108_testv3.exe filte
116
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0110_testv3.exe filter=lfs diff=lfs merge=lfs -text
117
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/WEBUIA_0119.exe filter=lfs diff=lfs merge=lfs -text
118
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/WEBUIA_0124.exe filter=lfs diff=lfs merge=lfs -text
 
 
116
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0110_testv3.exe filter=lfs diff=lfs merge=lfs -text
117
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/WEBUIA_0119.exe filter=lfs diff=lfs merge=lfs -text
118
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/WEBUIA_0124.exe filter=lfs diff=lfs merge=lfs -text
119
+ Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0201_testv1.exe filter=lfs diff=lfs merge=lfs -text
Danbooru Prompt Selector/TEST2024/NAIA_0201_testv1.exe ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eadf0db1dcefdd362dea653cb4c23bc8e4ababdcab8ba5eddba726518d0d6064
3
+ size 838001698
Danbooru Prompt Selector/TEST2024/NAIA_0201_testv1.py ADDED
The diff for this file is too large to render. See raw diff
 
Danbooru Prompt Selector/TEST2024/NAIA_generation.py CHANGED
@@ -4,7 +4,7 @@ from PIL import Image, ImageOps, ImageTk
4
  from datetime import datetime
5
  import time
6
  from pathlib import Path
7
- import io
8
  import zipfile
9
 
10
  BASE_URL="https://api.novelai.net"
@@ -176,6 +176,90 @@ def generate_image(access_token, prompt, model, action, parameters):
176
  return response.content
177
 
178
  def generate(gen_request):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  params = {
181
  "legacy": False,
@@ -199,15 +283,29 @@ def generate(gen_request):
199
  "noise_schedule": "native"
200
  }
201
 
202
- # ์™€์ผ๋“œ์นด๋“œ ๊ธฐ๋Šฅ ๋งŒ๋“ค์–ด์•ผํ•จ
203
  positive = gen_request["prompt"]
204
 
 
 
 
 
 
205
  filename_rule = gen_request["png_rule"]
206
  save_folder = gen_request["save_folder"]
207
 
208
  access_token = gen_request["access_token"]
209
  additional_folder = ""
210
 
 
 
 
 
 
 
 
 
 
211
  def resize_and_fill(image, max_size=None):
212
  if max_size is None:
213
  max_size = gen_request["user_screen_size"]
@@ -236,7 +334,7 @@ def generate(gen_request):
236
  file.write(error_message)
237
 
238
  try:
239
- zipped_bytes = generate_image(access_token, positive, "nai-diffusion-3", "generate", params)
240
  if gen_request["png_rule"] == "count":
241
  additional_folder = "/" + gen_request["start_time"]
242
  if gen_request["type"] == "turbo":
 
4
  from datetime import datetime
5
  import time
6
  from pathlib import Path
7
+ import io, re
8
  import zipfile
9
 
10
  BASE_URL="https://api.novelai.net"
 
176
  return response.content
177
 
178
  def generate(gen_request):
179
+ def parse_and_execute_commands(_prompt, negative, user_input, rating):
180
+ negative = negative.split(',')
181
+ negative = [neg.strip() for neg in negative]
182
+ prompt = _prompt.split(',')
183
+ prompt = [key.strip() for key in prompt]
184
+ commands = [cmd.strip() for cmd in user_input.split(',')]
185
+ for command in commands:
186
+ condition, cmd = parse_conditional_command(command)
187
+ if check_condition(prompt, condition, rating):
188
+ negative = execute_command(negative, cmd)
189
+ return ', '.join(negative)
190
+
191
+ def parse_conditional_command(command):
192
+ match = re.match(r"\((.*?)\)\:(.*)", command)
193
+ if match:
194
+ return match.groups()
195
+ return '', command
196
+
197
+ def check_condition(prompt, condition, rating):
198
+ if not condition:
199
+ return True
200
+ sub_conditions = re.split(r'\)\s*&\s*\(', condition)
201
+ sub_conditions = [re.sub(r'^\(|\)$', '', cond) for cond in sub_conditions]
202
+
203
+ results = []
204
+ for sub_cond in sub_conditions:
205
+ if '&' in sub_cond:
206
+ results.append(all(check_condition(prompt, cond, rating) for cond in sub_cond.split('&')))
207
+ elif '|' in sub_cond:
208
+ results.append(any(check_condition(prompt, cond, rating) for cond in sub_cond.split('|')))
209
+ else:
210
+ if sub_cond in ['e', 'q', 's', 'g']:
211
+ results.append(sub_cond == rating)
212
+ elif sub_cond in ['~e', '~q', '~s', '~g']:
213
+ results.append(sub_cond != rating)
214
+ # PM
215
+ elif sub_cond.startswith('*'):
216
+ results.append(sub_cond[1:] in prompt)
217
+ # NOT IN
218
+ elif sub_cond.startswith('~!'):
219
+ results.append(sub_cond[2:] not in prompt)
220
+ elif sub_cond.startswith('~'):
221
+ results.append(any(sub_cond[1:] not in element for element in prompt))
222
+ # CONTAIN
223
+ else:
224
+ results.append(any(sub_cond in element for element in prompt))
225
+ return all(results)
226
+
227
+ def execute_command(negative, command):
228
+ if '+=' in command:
229
+ keyword, addition = command.split('+=', 1)
230
+ addition = addition.replace('^', ', ')
231
+ return insert_text_after_keyword(negative, keyword, addition)
232
+ elif command.startswith('add '):
233
+ keyword = command[4:]
234
+ keyword = keyword.replace('^', ', ')
235
+ keys = keyword.split(',')
236
+ keys = [key.strip() for key in keys]
237
+ for key in keys:
238
+ if key not in negative:
239
+ negative.append(key)
240
+ return negative
241
+ elif command.startswith('rem '):
242
+ keyword = command[4:]
243
+ keyword = keyword.replace('^', ', ')
244
+ keys = keyword.split(',')
245
+ keys = [key.strip() for key in keys]
246
+ for key in keys:
247
+ if key in negative:
248
+ negative.remove(key)
249
+ return negative
250
+ elif '=' in command:
251
+ keyword, replacement = command.split('=', 1)
252
+ if keyword in negative:
253
+ replacement = replacement.replace('^', ', ')
254
+ index = negative.index(keyword)
255
+ negative[index] = replacement
256
+ return negative
257
+
258
+ def insert_text_after_keyword(negative, user_keyword, user_additional_keyword):
259
+ if user_keyword in negative:
260
+ index = negative.index(user_keyword) + 1
261
+ negative.insert(index, user_additional_keyword)
262
+ return negative
263
 
264
  params = {
265
  "legacy": False,
 
283
  "noise_schedule": "native"
284
  }
285
 
286
+
287
  positive = gen_request["prompt"]
288
 
289
+ if "cond_negative" in gen_request and gen_request["cond_negative"]:
290
+ user_input = gen_request["cond_negative"]
291
+ rating = gen_request["rating"]
292
+ params["negative_prompt"] = parse_and_execute_commands(positive, params["negative_prompt"], user_input, rating)
293
+
294
  filename_rule = gen_request["png_rule"]
295
  save_folder = gen_request["save_folder"]
296
 
297
  access_token = gen_request["access_token"]
298
  additional_folder = ""
299
 
300
+ request_type = "generate"
301
+ if "image" in gen_request:
302
+ params["image"] = gen_request["image"]
303
+ params["strength"] = gen_request["strength"]
304
+ params["noise"] = gen_request["noise"]
305
+ params["sm"] = False
306
+ params["sm_dyn"] = False
307
+ request_type = "img2img"
308
+
309
  def resize_and_fill(image, max_size=None):
310
  if max_size is None:
311
  max_size = gen_request["user_screen_size"]
 
334
  file.write(error_message)
335
 
336
  try:
337
+ zipped_bytes = generate_image(access_token, positive, "nai-diffusion-3", request_type, params)
338
  if gen_request["png_rule"] == "count":
339
  additional_folder = "/" + gen_request["start_time"]
340
  if gen_request["type"] == "turbo":
Danbooru Prompt Selector/TEST2024/NAIA_random_function_core.py CHANGED
@@ -1,5 +1,77 @@
1
  import pandas
2
  import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def find_keyword_index(general):
5
  # boys์™€ girls ๋ฆฌ์ŠคํŠธ์˜ ์›์†Œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ ๋ฐ ์ธ๋ฑ์Šค ์ €์žฅ
@@ -54,13 +126,18 @@ def RFP(popped_row, fix_prompt, after_prompt, auto_hide_prompt, rm_a, rm_s, rm_c
54
  fix_index = find_keyword_index(general)
55
  processed = general.copy()
56
  temp_hide_prompt = []
57
- processed[fix_index:fix_index] = fix
58
- processed += after
59
  for keyword in processed:
60
  if keyword in auto_hide:
61
  temp_hide_prompt.append(keyword)
62
  for keyword in temp_hide_prompt:
63
  processed.remove(keyword)
 
 
 
 
 
 
 
64
 
65
  if rm_c == 0:
66
  if popped_row['character']:
@@ -87,4 +164,4 @@ def RFP(popped_row, fix_prompt, after_prompt, auto_hide_prompt, rm_a, rm_s, rm_c
87
  if boy_index > girl_index:
88
  processed.pop(boy_index)
89
  processed.insert(girl_index, boy_in_processed)
90
- return ', '.join(processed)
 
1
  import pandas
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 ๋ฆฌ์ŠคํŠธ์˜ ์›์†Œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ ๋ฐ ์ธ๋ฑ์Šค ์ €์žฅ
 
126
  fix_index = find_keyword_index(general)
127
  processed = general.copy()
128
  temp_hide_prompt = []
 
 
129
  for keyword in processed:
130
  if keyword in auto_hide:
131
  temp_hide_prompt.append(keyword)
132
  for keyword in temp_hide_prompt:
133
  processed.remove(keyword)
134
+ #์—ฌ๊ธฐ์—์„œ ๋ฌธ์ œ์˜ magic word ์ฒ˜๋ฆฌ
135
+ if "cond" in magic_word and magic_word["cond"]:
136
+ user_input = magic_word["cond"]
137
+ processed = parse_and_execute_commands(processed, user_input, fix, after, popped_row)
138
+
139
+ processed[fix_index:fix_index] = fix
140
+ processed += after
141
 
142
  if rm_c == 0:
143
  if popped_row['character']:
 
164
  if boy_index > girl_index:
165
  processed.pop(boy_index)
166
  processed.insert(girl_index, boy_in_processed)
167
+ return ', '.join(processed), popped_row['rating']