fix: underscores_replace did not alter character tags

#3
by dwgrth - opened
Files changed (1) hide show
  1. scripts/prompts.py +219 -219
scripts/prompts.py CHANGED
@@ -1,220 +1,220 @@
1
- import random
2
-
3
- prompts_b = {
4
- "long_thoughts_v2": """Your answer must contain 6 parts:
5
- <format>
6
- # 1. Thoughts about characters
7
- You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
8
- # 2. Key details
9
- Here you need to determine key details on comic and list them.
10
- # 3. Long description
11
- Here come up with a long and detailed description of image content. Be creative, mention all detailes you listed above and other important things.
12
- # 4. Detailed description for each character
13
- ## Name 1
14
- Detailed and long description for the first character
15
- ## Name 2
16
- Same for each one (if present)
17
- </format>
18
- """,
19
- "long_thoughts": """Your answer must contain 6 parts:
20
- <format>
21
- # 1. Thoughts about characters
22
- You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
23
- If no characters are listed in input - just write here "No named characters"
24
- # 2. General description
25
- A one-two paragraph summary of the image. Mention all individual parts/objects/characters/positions/interactions/etc.
26
- # 3. Detailed description for each character
27
- ## Character name 1 (put here the name if any)
28
- In very detail write about features, poses, look, used objects, interactions, and other things for character on the picture.
29
- ## Character name 2 (put here the name if any)
30
- Same for each character.
31
- ...
32
- # 4. Individual Parts
33
- List the individual things you see in the image and their relative positions to other parts. Use a numbered list of between 5 and 20 items depending on image complexity.
34
- # 5. Texts on image
35
- Mention every texts that you notice on image, including types (a speech bubble, watermark, banner, etc.) and content.
36
- # 6. Background and effects
37
- Give some info about objects on background, describe the location (if seen). Then mention effects (style, camera angle, clarity/blurrines, effects like depth of field, strange angle/forshortening, etc.)
38
- </format>
39
- """,
40
- "json": """Use json-style caption for given image with following structure:
41
- {"character" : "Description for character or object. Name (if defined), main details, features, position, pose, etc.",
42
- /or in case of multiple
43
- "character_1" : "Description for first"
44
- "character_2" : "Description for second ",
45
- "character_N"...
46
- /or if there are no characters
47
- "main content" : "long and detailed description of main content of image that might be the main focus if characters are missing",
48
- /
49
- "background" : "Detailed descritpion of background and it's content",
50
- "image_effects" : "If there are some visual effects like fisheye distortion, chromatic aberration, glitches, messy drawing or anything else - write about it. If it's just a general anime art - omit this field."
51
- "texts" : "Speech bubbles, bars, marks, signs etc. with texts if present, else None",
52
- "atmosphere" : "...",
53
- }
54
- In special cases you can add extra keys.
55
- """,
56
- "long": """Make a caption for given image with natural text. Use 2 to 5 paragraphs. Make your description long and vivid, mentioning all the details.
57
- """,
58
- "min_structured_md": """Your answer must contain 3 parts:
59
- <format>
60
- # 1. Thoughts about characters
61
- You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
62
- If no characters are listed in input - just write here "No named characters"
63
- # 2. Key details
64
- Here you need to write about the key details on image, prefere using regular text.
65
- # 3. Structured description
66
- ## General
67
- Write about general composition, content of image, background and all things that are not related to characters directly.
68
- ## Character name 1 (put here the name if any)
69
- Write about datails and content related to specific character, including features, poses, look, used objects, interactions, and other things.
70
- ## Character name 2 (put here the name if any)
71
- Same for each character.
72
- ## Image effects
73
- Mention image effect, style, camera angle
74
- </format>
75
- In general stick to shorter descriptions.
76
- """,
77
- "json_comic": """Use json-style caption to describe to comin, stick to following structure:
78
- {
79
- "comic_format": "menation the format, for example Comic of N frames",
80
- "1st_frame": "Main description of the content for fist frame",
81
- "2nd_frame": "Same for the second",
82
- ...
83
- "Nth_ftame": "...",
84
- "character_1": "Describe the characters in comic",
85
- ...
86
- "character_N": "Separate description for each",
87
- "meaning": "Try to guess general mood, vibe and meaning of the comic"
88
- }
89
- """,
90
- "md_comic": """Use markdown format to describe to comic, 5 parts are recommended:
91
- <format>
92
- # 1. Thoughts about characters
93
- You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
94
- # 2. Key details
95
- Here you need to determine key details on comic and list them.
96
- # 3. Comic format
97
- In this section come up with the description of comic format, how many pages there are, horisontal/vertical orientation and other things. Optionally you can list main characters here.
98
- # 4. Details for each frame
99
- ## 4.1 Frame 1 (position)
100
- Description for each frame, includding characters, objects, interactions, texts/speech bubbles and other things. Be detailed but not overdoo.
101
- ## 4.2 Frame 2 (position)
102
- Same for each frame.
103
- ...
104
- # 5. Extra comment
105
- Here you should write general desciption and some other info about the image.
106
- </format>
107
- """,
108
- "min_structured_json": """
109
- Use json-style caption for given image with following structure:
110
- {"General" : "Here you need to come up with general/common information about picture, overall composition. Stick to shorter phrases and tags instead of long purple prose. Avoid bullets and markdown, write in plain text.",
111
- "character_1 (put here the name if any)" : "Description of first character."
112
- "character_2 (if present" : "Description for second ",
113
- "character_N"
114
- ...
115
- "image_effects" : "Mention here effects on image if there are any distinct."
116
- "texts" : "Speech bubbles, bars, marks, signs etc. with texts if present, else None",
117
- "watermarks" : "If present",
118
- }
119
- Prefere shorter description and tags.
120
- """,
121
- "chroma-style": """Your task is to describe the picture in very detail using a structure of 4 parts.
122
- ### 1. Regular Summary:
123
- [A one-paragraph summary of the image. The paragraph should mention all individual parts/things/characters/etc.]
124
- ### 2. Individual Parts:
125
- [List the individual things you see in the image and their relative positions to other parts. Use a numbered list of between 5 and 30 items depending on image complexity.]
126
- ### 3. Midjourney-Style Summary:
127
- [A summary that has higher concept density by using comma-separated partial sentences instead of proper sentence structure.]
128
- ### 4. DeviantArt Commission Request
129
- [Write a description as if you're commissioning this *exact* image via someone who is currently taking requests.]
130
- """,
131
- "short":"""The caption for image should be quite short without long purple prose and slop. Cover main objects and details.
132
- """,
133
- }
134
-
135
- prompts_names_only = {
136
- "long_thoughts_v2":True,
137
- "long_thoughts": True,
138
- "json": False,
139
- "long": False,
140
- "json_comic": False,
141
- "md_comic": True,
142
- "min_structured_md": True,
143
- "min_structured_json": False,
144
- "chroma-style": False,
145
- "short":False,
146
- }
147
-
148
-
149
- def make_user_query(item, c_type, use_names, add_tags, add_characters, add_char_tags, add_description, underscores_replace = False):
150
- tags = item.get('tags', [])
151
- random.shuffle(tags)
152
- if underscores_replace:
153
- tags = [a.replace('_', ' ') if len(a)>3 else a for a in tags]
154
- tags_string = ', '.join(tags)
155
- else:
156
- tags_string = ' '.join(tags)
157
-
158
- user_request = '# Captioning format:\n'
159
- user_request += prompts_b[c_type]
160
- user_request += '\n'
161
-
162
- if add_tags:
163
- user_request += f"# Booru tags for the image\n[{tags_string}]\n\n"
164
-
165
- if use_names: #Имена персонажей
166
- if add_characters:
167
- chars_tags = item.get('characters',[])
168
- if underscores_replace:
169
- tags = [a.replace('_', ' ') for a in chars_tags]
170
- chars_string = ', '.join(chars_tags)
171
- else:
172
- chars_string = ' '.join(chars_tags)
173
-
174
- user_request += f"# Characters on picture:\nHere are names/tags for characters from the picture, make sure to use them: [{chars_string}].\n\n"
175
-
176
- chars_popular_tags = (item.get('char_p_tags',"{'chars':{},'skins':{}}"))
177
- chars_description = (item.get('char_descr',"{'chars':{},'skins':{}}"))
178
-
179
- if len(chars_popular_tags['chars']) > 0 and (add_char_tags or add_description):
180
-
181
- user_request += "# Known traits for characters\n"
182
- char_underscores = underscores_replace
183
-
184
- if add_char_tags:
185
- user_request += "Here are popular tags for each characters on picture:\n"
186
-
187
- for c_name, c_tags in chars_popular_tags['chars'].items():
188
- name = c_name.replace('_',' ') if char_underscores else c_name
189
- tags_s = (', '.join([a.replace('_', ' ') if len(a)>3 else a for a in c_tags]) if char_underscores else
190
- ' '.join(c_tags))
191
- user_request += f"{name}: [{tags_s}]\n"
192
- if len(chars_popular_tags['skins']) > 0:
193
- user_request += "Extra tags for characters skins:\n"
194
- for c_name, c_tags in chars_popular_tags['skins'].items():
195
- name = c_name.replace('_',' ') if char_underscores else c_name
196
- tags_s = (', '.join([a.replace('_', ' ') if len(a)>3 else a for a in c_tags]) if char_underscores else
197
- ' '.join(c_tags))
198
- user_request += f"{name}: [{tags_s}]\n"
199
-
200
- elif add_description:
201
-
202
- user_request += "Here are general descriptions for each characters on the picture:\n"
203
- for c_name, c_descr in chars_description['chars'].items():
204
- name = c_name.replace('_',' ') if char_underscores else c_name
205
- user_request += f"## {name}\n{c_descr}\n\n"
206
- if len(chars_description['skins']) > 0:
207
- user_request += "Here are also descriptions for specific skin of characters:\n"
208
- for c_name, c_descr in chars_description['skins'].items():
209
- name = c_name.replace('_',' ') if char_underscores else c_name
210
- user_request += f"## {name}\n{c_descr}\n\n"
211
- else:
212
- user_request += "# Characters on picture:\nTry to recognize the characters in the picture and use their names.\n"
213
-
214
- user_request += '\n'
215
- else:
216
- user_request += "# Characters on picture:\nAvoid to guess names for characters.\n"
217
-
218
- return user_request
219
-
220
  system_prompt = "You are image captioning expert. Describe user's picture according to requested format and instructions."
 
1
+ import random
2
+
3
+ prompts_b = {
4
+ "long_thoughts_v2": """Your answer must contain 6 parts:
5
+ <format>
6
+ # 1. Thoughts about characters
7
+ You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
8
+ # 2. Key details
9
+ Here you need to determine key details on comic and list them.
10
+ # 3. Long description
11
+ Here come up with a long and detailed description of image content. Be creative, mention all detailes you listed above and other important things.
12
+ # 4. Detailed description for each character
13
+ ## Name 1
14
+ Detailed and long description for the first character
15
+ ## Name 2
16
+ Same for each one (if present)
17
+ </format>
18
+ """,
19
+ "long_thoughts": """Your answer must contain 6 parts:
20
+ <format>
21
+ # 1. Thoughts about characters
22
+ You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
23
+ If no characters are listed in input - just write here "No named characters"
24
+ # 2. General description
25
+ A one-two paragraph summary of the image. Mention all individual parts/objects/characters/positions/interactions/etc.
26
+ # 3. Detailed description for each character
27
+ ## Character name 1 (put here the name if any)
28
+ In very detail write about features, poses, look, used objects, interactions, and other things for character on the picture.
29
+ ## Character name 2 (put here the name if any)
30
+ Same for each character.
31
+ ...
32
+ # 4. Individual Parts
33
+ List the individual things you see in the image and their relative positions to other parts. Use a numbered list of between 5 and 20 items depending on image complexity.
34
+ # 5. Texts on image
35
+ Mention every texts that you notice on image, including types (a speech bubble, watermark, banner, etc.) and content.
36
+ # 6. Background and effects
37
+ Give some info about objects on background, describe the location (if seen). Then mention effects (style, camera angle, clarity/blurrines, effects like depth of field, strange angle/forshortening, etc.)
38
+ </format>
39
+ """,
40
+ "json": """Use json-style caption for given image with following structure:
41
+ {"character" : "Description for character or object. Name (if defined), main details, features, position, pose, etc.",
42
+ /or in case of multiple
43
+ "character_1" : "Description for first"
44
+ "character_2" : "Description for second ",
45
+ "character_N"...
46
+ /or if there are no characters
47
+ "main content" : "long and detailed description of main content of image that might be the main focus if characters are missing",
48
+ /
49
+ "background" : "Detailed descritpion of background and it's content",
50
+ "image_effects" : "If there are some visual effects like fisheye distortion, chromatic aberration, glitches, messy drawing or anything else - write about it. If it's just a general anime art - omit this field."
51
+ "texts" : "Speech bubbles, bars, marks, signs etc. with texts if present, else None",
52
+ "atmosphere" : "...",
53
+ }
54
+ In special cases you can add extra keys.
55
+ """,
56
+ "long": """Make a caption for given image with natural text. Use 2 to 5 paragraphs. Make your description long and vivid, mentioning all the details.
57
+ """,
58
+ "min_structured_md": """Your answer must contain 3 parts:
59
+ <format>
60
+ # 1. Thoughts about characters
61
+ You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
62
+ If no characters are listed in input - just write here "No named characters"
63
+ # 2. Key details
64
+ Here you need to write about the key details on image, prefere using regular text.
65
+ # 3. Structured description
66
+ ## General
67
+ Write about general composition, content of image, background and all things that are not related to characters directly.
68
+ ## Character name 1 (put here the name if any)
69
+ Write about datails and content related to specific character, including features, poses, look, used objects, interactions, and other things.
70
+ ## Character name 2 (put here the name if any)
71
+ Same for each character.
72
+ ## Image effects
73
+ Mention image effect, style, camera angle
74
+ </format>
75
+ In general stick to shorter descriptions.
76
+ """,
77
+ "json_comic": """Use json-style caption to describe to comin, stick to following structure:
78
+ {
79
+ "comic_format": "menation the format, for example Comic of N frames",
80
+ "1st_frame": "Main description of the content for fist frame",
81
+ "2nd_frame": "Same for the second",
82
+ ...
83
+ "Nth_ftame": "...",
84
+ "character_1": "Describe the characters in comic",
85
+ ...
86
+ "character_N": "Separate description for each",
87
+ "meaning": "Try to guess general mood, vibe and meaning of the comic"
88
+ }
89
+ """,
90
+ "md_comic": """Use markdown format to describe to comic, 5 parts are recommended:
91
+ <format>
92
+ # 1. Thoughts about characters
93
+ You need to think here and compare peoples/creatures that you see on the picture with given popular tags, or descriptions, or your memories for each characters to determine who is who.
94
+ # 2. Key details
95
+ Here you need to determine key details on comic and list them.
96
+ # 3. Comic format
97
+ In this section come up with the description of comic format, how many pages there are, horisontal/vertical orientation and other things. Optionally you can list main characters here.
98
+ # 4. Details for each frame
99
+ ## 4.1 Frame 1 (position)
100
+ Description for each frame, includding characters, objects, interactions, texts/speech bubbles and other things. Be detailed but not overdoo.
101
+ ## 4.2 Frame 2 (position)
102
+ Same for each frame.
103
+ ...
104
+ # 5. Extra comment
105
+ Here you should write general desciption and some other info about the image.
106
+ </format>
107
+ """,
108
+ "min_structured_json": """
109
+ Use json-style caption for given image with following structure:
110
+ {"General" : "Here you need to come up with general/common information about picture, overall composition. Stick to shorter phrases and tags instead of long purple prose. Avoid bullets and markdown, write in plain text.",
111
+ "character_1 (put here the name if any)" : "Description of first character."
112
+ "character_2 (if present" : "Description for second ",
113
+ "character_N"
114
+ ...
115
+ "image_effects" : "Mention here effects on image if there are any distinct."
116
+ "texts" : "Speech bubbles, bars, marks, signs etc. with texts if present, else None",
117
+ "watermarks" : "If present",
118
+ }
119
+ Prefere shorter description and tags.
120
+ """,
121
+ "chroma-style": """Your task is to describe the picture in very detail using a structure of 4 parts.
122
+ ### 1. Regular Summary:
123
+ [A one-paragraph summary of the image. The paragraph should mention all individual parts/things/characters/etc.]
124
+ ### 2. Individual Parts:
125
+ [List the individual things you see in the image and their relative positions to other parts. Use a numbered list of between 5 and 30 items depending on image complexity.]
126
+ ### 3. Midjourney-Style Summary:
127
+ [A summary that has higher concept density by using comma-separated partial sentences instead of proper sentence structure.]
128
+ ### 4. DeviantArt Commission Request
129
+ [Write a description as if you're commissioning this *exact* image via someone who is currently taking requests.]
130
+ """,
131
+ "short":"""The caption for image should be quite short without long purple prose and slop. Cover main objects and details.
132
+ """,
133
+ }
134
+
135
+ prompts_names_only = {
136
+ "long_thoughts_v2":True,
137
+ "long_thoughts": True,
138
+ "json": False,
139
+ "long": False,
140
+ "json_comic": False,
141
+ "md_comic": True,
142
+ "min_structured_md": True,
143
+ "min_structured_json": False,
144
+ "chroma-style": False,
145
+ "short":False,
146
+ }
147
+
148
+
149
+ def make_user_query(item, c_type, use_names, add_tags, add_characters, add_char_tags, add_description, underscores_replace = False):
150
+ tags = item.get('tags', [])
151
+ random.shuffle(tags)
152
+ if underscores_replace:
153
+ tags = [a.replace('_', ' ') if len(a)>3 else a for a in tags]
154
+ tags_string = ', '.join(tags)
155
+ else:
156
+ tags_string = ' '.join(tags)
157
+
158
+ user_request = '# Captioning format:\n'
159
+ user_request += prompts_b[c_type]
160
+ user_request += '\n'
161
+
162
+ if add_tags:
163
+ user_request += f"# Booru tags for the image\n[{tags_string}]\n\n"
164
+
165
+ if use_names: #Имена персонажей
166
+ if add_characters:
167
+ chars_tags = item.get('characters',[])
168
+ if underscores_replace:
169
+ chars_tags = [a.replace('_', ' ') for a in chars_tags]
170
+ chars_string = ', '.join(chars_tags)
171
+ else:
172
+ chars_string = ' '.join(chars_tags)
173
+
174
+ user_request += f"# Characters on picture:\nHere are names/tags for characters from the picture, make sure to use them: [{chars_string}].\n\n"
175
+
176
+ chars_popular_tags = (item.get('char_p_tags',"{'chars':{},'skins':{}}"))
177
+ chars_description = (item.get('char_descr',"{'chars':{},'skins':{}}"))
178
+
179
+ if len(chars_popular_tags['chars']) > 0 and (add_char_tags or add_description):
180
+
181
+ user_request += "# Known traits for characters\n"
182
+ char_underscores = underscores_replace
183
+
184
+ if add_char_tags:
185
+ user_request += "Here are popular tags for each characters on picture:\n"
186
+
187
+ for c_name, c_tags in chars_popular_tags['chars'].items():
188
+ name = c_name.replace('_',' ') if char_underscores else c_name
189
+ tags_s = (', '.join([a.replace('_', ' ') if len(a)>3 else a for a in c_tags]) if char_underscores else
190
+ ' '.join(c_tags))
191
+ user_request += f"{name}: [{tags_s}]\n"
192
+ if len(chars_popular_tags['skins']) > 0:
193
+ user_request += "Extra tags for characters skins:\n"
194
+ for c_name, c_tags in chars_popular_tags['skins'].items():
195
+ name = c_name.replace('_',' ') if char_underscores else c_name
196
+ tags_s = (', '.join([a.replace('_', ' ') if len(a)>3 else a for a in c_tags]) if char_underscores else
197
+ ' '.join(c_tags))
198
+ user_request += f"{name}: [{tags_s}]\n"
199
+
200
+ elif add_description:
201
+
202
+ user_request += "Here are general descriptions for each characters on the picture:\n"
203
+ for c_name, c_descr in chars_description['chars'].items():
204
+ name = c_name.replace('_',' ') if char_underscores else c_name
205
+ user_request += f"## {name}\n{c_descr}\n\n"
206
+ if len(chars_description['skins']) > 0:
207
+ user_request += "Here are also descriptions for specific skin of characters:\n"
208
+ for c_name, c_descr in chars_description['skins'].items():
209
+ name = c_name.replace('_',' ') if char_underscores else c_name
210
+ user_request += f"## {name}\n{c_descr}\n\n"
211
+ else:
212
+ user_request += "# Characters on picture:\nTry to recognize the characters in the picture and use their names.\n"
213
+
214
+ user_request += '\n'
215
+ else:
216
+ user_request += "# Characters on picture:\nAvoid to guess names for characters.\n"
217
+
218
+ return user_request
219
+
220
  system_prompt = "You are image captioning expert. Describe user's picture according to requested format and instructions."