baqu2213 commited on
Commit
1abae11
โ€ข
1 Parent(s): 11935dc

Upload 5 files

Browse files
.gitattributes CHANGED
@@ -107,3 +107,4 @@ Danbooru[[:space:]]Prompt[[:space:]]Selector/csv2023_nsfw.csv filter=lfs diff=lf
107
  Danbooru[[:space:]]Prompt[[:space:]]Selector/csv2023_safeimage.csv filter=lfs diff=lfs merge=lfs -text
108
  Danbooru[[:space:]]Prompt[[:space:]]Selector/csv2023_sensitive.csv filter=lfs diff=lfs merge=lfs -text
109
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_1231_console_testv1.exe filter=lfs diff=lfs merge=lfs -text
 
 
107
  Danbooru[[:space:]]Prompt[[:space:]]Selector/csv2023_safeimage.csv filter=lfs diff=lfs merge=lfs -text
108
  Danbooru[[:space:]]Prompt[[:space:]]Selector/csv2023_sensitive.csv filter=lfs diff=lfs merge=lfs -text
109
  Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_1231_console_testv1.exe filter=lfs diff=lfs merge=lfs -text
110
+ Danbooru[[:space:]]Prompt[[:space:]]Selector/TEST2024/NAIA_0101_console_testv2.exe filter=lfs diff=lfs merge=lfs -text
Danbooru Prompt Selector/TEST2024/NAIA_0101_console_testv2.exe ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7e2af30547a1146aa983e950ca89d891f3ef108da60b6d2b5906cc802d9ab25
3
+ size 837862738
Danbooru Prompt Selector/TEST2024/NAIA_0101_testv2.py ADDED
The diff for this file is too large to render. See raw diff
 
Danbooru Prompt Selector/TEST2024/NAIA_generation.py CHANGED
@@ -186,7 +186,7 @@ def generate(gen_request):
186
  "seed": gen_request["seed"],
187
  "extra_noise_seed": random.randint(0,9999999999),
188
  "sampler": gen_request["sampler"],
189
- "steps": 28,
190
  "scale": gen_request["scale"],
191
  "uncond_scale": 1.0,
192
  "negative_prompt": gen_request["negative"],
 
186
  "seed": gen_request["seed"],
187
  "extra_noise_seed": random.randint(0,9999999999),
188
  "sampler": gen_request["sampler"],
189
+ "steps": 28 if gen_request["type"]!="upper" else gen_request["steps"],
190
  "scale": gen_request["scale"],
191
  "uncond_scale": 1.0,
192
  "negative_prompt": gen_request["negative"],
Danbooru Prompt Selector/TEST2024/NAIA_random_function_core.py CHANGED
@@ -42,7 +42,7 @@ def RFP(popped_row, fix_prompt, after_prompt, auto_hide_prompt, rm_a, rm_s, rm_c
42
  series = [item.strip() for item in popped_row['copyright'].split(',')]
43
  fix = fix + series
44
  after = [item.strip() for item in after_prompt[:-1].split(',')]
45
- auto_hide = [item.strip() for item in auto_hide_prompt[:-1].split(',')]
46
  fix_index = find_keyword_index(general)
47
  processed = general.copy()
48
  temp_hide_prompt = []
@@ -67,4 +67,21 @@ def RFP(popped_row, fix_prompt, after_prompt, auto_hide_prompt, rm_a, rm_s, rm_c
67
  if magic_word["random_artist"] == True:
68
  processed.insert(fix_index, magic_word["random_artist_name"])
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  return ', '.join(processed)
 
42
  series = [item.strip() for item in popped_row['copyright'].split(',')]
43
  fix = fix + series
44
  after = [item.strip() for item in after_prompt[:-1].split(',')]
45
+ auto_hide = [item.strip() for item in auto_hide_prompt[:-1].split(',')] + ["| |", ":|", "\||/", "<|> <|>", "|| ||", ";|"]
46
  fix_index = find_keyword_index(general)
47
  processed = general.copy()
48
  temp_hide_prompt = []
 
67
  if magic_word["random_artist"] == True:
68
  processed.insert(fix_index, magic_word["random_artist_name"])
69
 
70
+ boy_in_processed = girl_in_processed = None
71
+ for boy in boys:
72
+ if boy in processed:
73
+ boy_in_processed = boy
74
+ break
75
+
76
+ for girl in girls:
77
+ if girl in processed:
78
+ girl_in_processed = girl
79
+ break
80
+
81
+ if boy_in_processed and girl_in_processed:
82
+ boy_index = processed.index(boy_in_processed)
83
+ girl_index = processed.index(girl_in_processed)
84
+ if boy_index > girl_index:
85
+ processed.pop(boy_index)
86
+ processed.insert(girl_index, boy_in_processed)
87
  return ', '.join(processed)
Danbooru Prompt Selector/TEST2024/NAIA_search.py CHANGED
@@ -1,34 +1,45 @@
1
- import customtkinter
2
  import pandas as pd
 
3
 
4
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ํ–‰๋งŒ ํ•„ํ„ฐ๋งํ•˜๋Š” ํ•จ์ˆ˜
5
  def filter_rows_containing_all_keywords(df, keywords):
 
6
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•œ boolean mask ์ดˆ๊ธฐํ™”, df์˜ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉ
7
  final_mask = pd.Series([True] * len(df), index=df.index)
8
 
9
  # ๊ฐ ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•ด DataFrame์˜ ๋ชจ๋“  ์—ด์„ ๊ฒ€์‚ฌํ•˜๊ณ  boolean mask ์ƒ์„ฑ ๋ฐ ์ €์žฅ
10
  for keyword in keywords:
11
  keyword_mask = pd.Series([False] * len(df), index=df.index)
 
 
 
 
12
 
13
  for column in ['copyright', 'character', 'artist', 'meta', 'general']:
14
  if df[column].dtype == 'object':
15
- keyword_mask |= df[column].str.contains(keyword, na=False)
 
16
 
17
  final_mask &= keyword_mask
18
 
19
  return df[final_mask]
20
 
21
  def filter_rows_not_containing_all_keywords(df, keywords):
 
22
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋Š” ํ–‰์„ ํ•„ํ„ฐ๋งํ•˜๊ธฐ ์œ„ํ•œ boolean mask ์ดˆ๊ธฐํ™”, df์˜ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉ
23
  final_mask = pd.Series([True] * len(df), index=df.index)
24
 
25
  # ๊ฐ ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•ด DataFrame์˜ ๋ชจ๋“  ์—ด์„ ๊ฒ€์‚ฌํ•˜๊ณ  boolean mask ์ƒ์„ฑ ๋ฐ ์ €์žฅ
26
  for keyword in keywords:
27
  keyword_mask = pd.Series([False] * len(df), index=df.index)
28
-
 
 
 
29
  for column in ['copyright', 'character', 'artist', 'meta', 'general']:
30
  if df[column].dtype == 'object':
31
- keyword_mask |= df[column].str.contains(keyword, na=False)
 
32
 
33
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ํ–‰์— ๋Œ€ํ•œ mask๋ฅผ ๋ฐ˜์ „์‹œ์ผœ final_mask์— ์ €์žฅ
34
  final_mask &= ~keyword_mask
@@ -36,18 +47,25 @@ def filter_rows_not_containing_all_keywords(df, keywords):
36
  return df[final_mask]
37
 
38
  def process_asterisk_group(df, asterisk_group):
 
39
  # ๊ฐ ํ‚ค์›Œ๋“œ ์•ž์˜ '*'๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋งจ ๋’ค์— ',' ์ถ”๊ฐ€
40
  asterisk_keywords = [keyword.lstrip('*') + ',' for keyword in asterisk_group]
41
 
42
  # ๊ฐ ํ–‰์— ๋Œ€ํ•ด ์ž„์‹œ ๋ฌธ์ž์—ด search_string์„ ๋งŒ๋“ค๊ณ  ๊ฒ€์ƒ‰ ์ˆ˜ํ–‰
43
  df['search_string'] = df[['copyright', 'character', 'artist', 'meta', 'general']].apply(lambda x: ' ' + ', '.join(x.astype(str)) + ',', axis=1)
44
  for keyword in asterisk_keywords:
45
- df = df[df['search_string'].str.contains(keyword, na=False)]
 
 
 
 
 
46
  df.drop('search_string', axis=1, inplace=True)
47
 
48
  return df
49
 
50
  def process_perfect_negative_group(df, perfect_negative_group):
 
51
  # ๊ฐ ํ‚ค์›Œ๋“œ ์•ž์˜ '~'๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋งจ ๋’ค์— ',' ์ถ”๊ฐ€
52
  perfect_negative_keywords = [keyword.lstrip('~') + ',' for keyword in perfect_negative_group]
53
 
@@ -57,7 +75,12 @@ def process_perfect_negative_group(df, perfect_negative_group):
57
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ํ•˜๋‚˜์˜ boolean Series๋กœ ๊ฒฐํ•ฉ
58
  combined_mask = pd.Series([True] * len(df), index=df.index)
59
  for keyword in perfect_negative_keywords:
60
- keyword_mask = df['search_string'].str.contains(keyword, na=False)
 
 
 
 
 
61
  combined_mask &= ~keyword_mask
62
 
63
  # ์ตœ์ข…์ ์œผ๋กœ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ํ–‰๋งŒ ํ•„ํ„ฐ๋ง
@@ -80,6 +103,8 @@ def search(df, search_request, exclude_request, E, N, S, G):
80
  if(len(df) == 0):
81
  return None
82
 
 
 
83
  #search_request์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ
84
  #์ฒ˜๋ฆฌ์ˆœ์„œ normal -> curly -> asterisk
85
  split_requests = [item.strip() for item in search_request.split(',')]
@@ -87,10 +112,11 @@ def search(df, search_request, exclude_request, E, N, S, G):
87
  curly_brace_group = [item for item in split_requests if item.startswith('{') and item.endswith('}')]
88
  asterisk_group = [item for item in split_requests if item.startswith('*')]
89
  normal_group = [item for item in split_requests if item not in curly_brace_group + asterisk_group]
90
-
91
  negative_split_requests = [item.strip() for item in exclude_request.split(',')]
92
  perfect_negative_group = [item for item in negative_split_requests if item.startswith('~')]
93
  negative_group = [item for item in negative_split_requests if item not in perfect_negative_group]
 
94
 
95
  if '' in split_requests:
96
  split_requests.remove('')
@@ -113,8 +139,13 @@ def search(df, search_request, exclude_request, E, N, S, G):
113
  for keyword in or_search_keyword:
114
  if keyword.startswith('*'):
115
  keyword = keyword[1:]
 
 
 
 
116
  for column in ['copyright', 'character', 'artist', 'meta', 'general']:
117
- matched_rows = df[df[column].str.contains(keyword, na=False)]
 
118
  if not matched_rows.empty:
119
  results = pd.concat([results, matched_rows])
120
  break
 
 
1
  import pandas as pd
2
+ import re
3
 
4
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ํ–‰๋งŒ ํ•„ํ„ฐ๋งํ•˜๋Š” ํ•จ์ˆ˜
5
  def filter_rows_containing_all_keywords(df, keywords):
6
+ special_chars = r".^$*+?{}[]\|()"
7
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•œ boolean mask ์ดˆ๊ธฐํ™”, df์˜ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉ
8
  final_mask = pd.Series([True] * len(df), index=df.index)
9
 
10
  # ๊ฐ ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•ด DataFrame์˜ ๋ชจ๋“  ์—ด์„ ๊ฒ€์‚ฌํ•˜๊ณ  boolean mask ์ƒ์„ฑ ๋ฐ ์ €์žฅ
11
  for keyword in keywords:
12
  keyword_mask = pd.Series([False] * len(df), index=df.index)
13
+ request_regex = False
14
+ if any(char in keyword for char in special_chars):
15
+ keyword = re.escape(keyword)
16
+ request_regex = True
17
 
18
  for column in ['copyright', 'character', 'artist', 'meta', 'general']:
19
  if df[column].dtype == 'object':
20
+ if request_regex: keyword_mask |= df[column].str.contains(keyword, na=False, regex=True)
21
+ else: keyword_mask |= df[column].str.contains(keyword, na=False)
22
 
23
  final_mask &= keyword_mask
24
 
25
  return df[final_mask]
26
 
27
  def filter_rows_not_containing_all_keywords(df, keywords):
28
+ special_chars = r".^$*+?{}[]\|()"
29
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋Š” ํ–‰์„ ํ•„ํ„ฐ๋งํ•˜๊ธฐ ์œ„ํ•œ boolean mask ์ดˆ๊ธฐํ™”, df์˜ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉ
30
  final_mask = pd.Series([True] * len(df), index=df.index)
31
 
32
  # ๊ฐ ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•ด DataFrame์˜ ๋ชจ๋“  ์—ด์„ ๊ฒ€์‚ฌํ•˜๊ณ  boolean mask ์ƒ์„ฑ ๋ฐ ์ €์žฅ
33
  for keyword in keywords:
34
  keyword_mask = pd.Series([False] * len(df), index=df.index)
35
+ request_regex = False
36
+ if any(char in keyword for char in special_chars):
37
+ keyword = re.escape(keyword)
38
+ request_regex = True
39
  for column in ['copyright', 'character', 'artist', 'meta', 'general']:
40
  if df[column].dtype == 'object':
41
+ if request_regex: keyword_mask |= df[column].str.contains(keyword, na=False, regex=True)
42
+ else: keyword_mask |= df[column].str.contains(keyword, na=False)
43
 
44
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ํ–‰์— ๋Œ€ํ•œ mask๋ฅผ ๋ฐ˜์ „์‹œ์ผœ final_mask์— ์ €์žฅ
45
  final_mask &= ~keyword_mask
 
47
  return df[final_mask]
48
 
49
  def process_asterisk_group(df, asterisk_group):
50
+ special_chars = r".^$*+?{}[]\|()"
51
  # ๊ฐ ํ‚ค์›Œ๋“œ ์•ž์˜ '*'๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋งจ ๋’ค์— ',' ์ถ”๊ฐ€
52
  asterisk_keywords = [keyword.lstrip('*') + ',' for keyword in asterisk_group]
53
 
54
  # ๊ฐ ํ–‰์— ๋Œ€ํ•ด ์ž„์‹œ ๋ฌธ์ž์—ด search_string์„ ๋งŒ๋“ค๊ณ  ๊ฒ€์ƒ‰ ์ˆ˜ํ–‰
55
  df['search_string'] = df[['copyright', 'character', 'artist', 'meta', 'general']].apply(lambda x: ' ' + ', '.join(x.astype(str)) + ',', axis=1)
56
  for keyword in asterisk_keywords:
57
+ request_regex = False
58
+ if any(char in keyword for char in special_chars):
59
+ keyword = re.escape(keyword)
60
+ request_regex = True
61
+ if request_regex: df = df[df['search_string'].str.contains(keyword, na=False, regex=True)]
62
+ else: df = df[df['search_string'].str.contains(keyword, na=False)]
63
  df.drop('search_string', axis=1, inplace=True)
64
 
65
  return df
66
 
67
  def process_perfect_negative_group(df, perfect_negative_group):
68
+ special_chars = r".^$*+?{}[]\|()"
69
  # ๊ฐ ํ‚ค์›Œ๋“œ ์•ž์˜ '~'๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋งจ ๋’ค์— ',' ์ถ”๊ฐ€
70
  perfect_negative_keywords = [keyword.lstrip('~') + ',' for keyword in perfect_negative_group]
71
 
 
75
  # ๋ชจ๋“  ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ํ•˜๋‚˜์˜ boolean Series๋กœ ๊ฒฐํ•ฉ
76
  combined_mask = pd.Series([True] * len(df), index=df.index)
77
  for keyword in perfect_negative_keywords:
78
+ request_regex = False
79
+ if any(char in keyword for char in special_chars):
80
+ keyword = re.escape(keyword)
81
+ request_regex = True
82
+ if request_regex: keyword_mask = df['search_string'].str.contains(keyword, na=False, regex=True)
83
+ else: df['search_string'].str.contains(keyword, na=False)
84
  combined_mask &= ~keyword_mask
85
 
86
  # ์ตœ์ข…์ ์œผ๋กœ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ํ–‰๋งŒ ํ•„ํ„ฐ๋ง
 
103
  if(len(df) == 0):
104
  return None
105
 
106
+ special_chars = r".^$*+?{}[]\|()"
107
+
108
  #search_request์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ
109
  #์ฒ˜๋ฆฌ์ˆœ์„œ normal -> curly -> asterisk
110
  split_requests = [item.strip() for item in search_request.split(',')]
 
112
  curly_brace_group = [item for item in split_requests if item.startswith('{') and item.endswith('}')]
113
  asterisk_group = [item for item in split_requests if item.startswith('*')]
114
  normal_group = [item for item in split_requests if item not in curly_brace_group + asterisk_group]
115
+ #normal_group = [re.escape(item) if any(char in item for char in special_chars) else item for item in normal_group]
116
  negative_split_requests = [item.strip() for item in exclude_request.split(',')]
117
  perfect_negative_group = [item for item in negative_split_requests if item.startswith('~')]
118
  negative_group = [item for item in negative_split_requests if item not in perfect_negative_group]
119
+ #negative_group = [re.escape(item) if any(char in item for char in special_chars) else item for item in negative_group]
120
 
121
  if '' in split_requests:
122
  split_requests.remove('')
 
139
  for keyword in or_search_keyword:
140
  if keyword.startswith('*'):
141
  keyword = keyword[1:]
142
+ request_regex = False
143
+ if any(char in keyword for char in special_chars):
144
+ keyword = re.escape(keyword)
145
+ request_regex = True
146
  for column in ['copyright', 'character', 'artist', 'meta', 'general']:
147
+ if request_regex: matched_rows = df[df[column].str.contains(keyword, na=False, regex=True)]
148
+ else: matched_rows = df[df[column].str.contains(keyword, na=False)]
149
  if not matched_rows.empty:
150
  results = pd.concat([results, matched_rows])
151
  break