Spaces:
Running
Running
mirabarukaso
commited on
Commit
·
b0fc198
1
Parent(s):
901270b
add character info
Browse files- app.py +7 -6
- scripts/lib.py +36 -22
app.py
CHANGED
@@ -28,15 +28,16 @@ if __name__ == '__main__':
|
|
28 |
label=LANG["character3"],
|
29 |
value='none',
|
30 |
allow_custom_value=False,
|
31 |
-
)
|
32 |
|
33 |
dummy_dropdown = gr.Dropdown(visible=False, allow_custom_value=True)
|
34 |
dummy_textbox = gr.Textbox(visible=False)
|
35 |
|
36 |
with gr.Row(elem_classes='main_row'):
|
37 |
with gr.Column(elem_classes='column_prompts'):
|
38 |
-
|
39 |
-
|
|
|
40 |
with gr.Column():
|
41 |
custom_prompt = gr.Textbox(value='', label='Semi-auto tag complete test. Try tag* *tag *tag* (e621_sfw.csv@DominikDoom)', elem_id="custom_prompt_text")
|
42 |
with gr.Column():
|
@@ -45,13 +46,13 @@ if __name__ == '__main__':
|
|
45 |
|
46 |
character1.change(fn=refresh_character_thumb_image,
|
47 |
inputs=[character1,character2,character3],
|
48 |
-
outputs=[thumb_image])
|
49 |
character2.change(fn=refresh_character_thumb_image,
|
50 |
inputs=[character1,character2,character3],
|
51 |
-
outputs=[thumb_image])
|
52 |
character3.change(fn=refresh_character_thumb_image,
|
53 |
inputs=[character1,character2,character3],
|
54 |
-
outputs=[thumb_image])
|
55 |
|
56 |
# Prompt Auto Complete JS
|
57 |
# Have to use dummy components
|
|
|
28 |
label=LANG["character3"],
|
29 |
value='none',
|
30 |
allow_custom_value=False,
|
31 |
+
)
|
32 |
|
33 |
dummy_dropdown = gr.Dropdown(visible=False, allow_custom_value=True)
|
34 |
dummy_textbox = gr.Textbox(visible=False)
|
35 |
|
36 |
with gr.Row(elem_classes='main_row'):
|
37 |
with gr.Column(elem_classes='column_prompts'):
|
38 |
+
thumb_image = gr.Gallery(type="pil", columns=3, show_download_button=False, object_fit='contain', label="Thumb")
|
39 |
+
output_info = gr.Textbox(label="Characters' Info")
|
40 |
+
with gr.Row():
|
41 |
with gr.Column():
|
42 |
custom_prompt = gr.Textbox(value='', label='Semi-auto tag complete test. Try tag* *tag *tag* (e621_sfw.csv@DominikDoom)', elem_id="custom_prompt_text")
|
43 |
with gr.Column():
|
|
|
46 |
|
47 |
character1.change(fn=refresh_character_thumb_image,
|
48 |
inputs=[character1,character2,character3],
|
49 |
+
outputs=[thumb_image, output_info])
|
50 |
character2.change(fn=refresh_character_thumb_image,
|
51 |
inputs=[character1,character2,character3],
|
52 |
+
outputs=[thumb_image, output_info])
|
53 |
character3.change(fn=refresh_character_thumb_image,
|
54 |
inputs=[character1,character2,character3],
|
55 |
+
outputs=[thumb_image, output_info])
|
56 |
|
57 |
# Prompt Auto Complete JS
|
58 |
# Have to use dummy components
|
scripts/lib.py
CHANGED
@@ -102,26 +102,16 @@ def load_jsons():
|
|
102 |
character_list_cn = list(character_dict.keys())
|
103 |
character_list_cn.insert(0, "none")
|
104 |
|
105 |
-
def illustrious_character_select_ex(character = 'random', optimise_tags = True,
|
106 |
chara = ''
|
107 |
-
rnd_character = ''
|
108 |
|
109 |
if 'none' == character:
|
110 |
return '', '', None
|
111 |
-
|
112 |
-
if 'random' == character:
|
113 |
-
index = random_action_seed % len(character_list)
|
114 |
-
rnd_character = character_list[index]
|
115 |
-
if 'random' == rnd_character:
|
116 |
-
rnd_character = character_list[index+2]
|
117 |
-
elif 'none' == rnd_character:
|
118 |
-
rnd_character = character_list[index+1]
|
119 |
-
else:
|
120 |
-
rnd_character = character
|
121 |
if not use_cn:
|
122 |
-
chara =
|
123 |
else:
|
124 |
-
chara = character_dict[
|
125 |
|
126 |
md5_chara = get_md5_hash(chara.replace('(','\\(').replace(')','\\)'))
|
127 |
thumb_image = Image.new('RGB', (128, 128), (128, 128, 128))
|
@@ -131,26 +121,50 @@ def illustrious_character_select_ex(character = 'random', optimise_tags = True,
|
|
131 |
opt_chara = chara
|
132 |
if optimise_tags:
|
133 |
opt_chara = opt_chara.replace('(', '\\(').replace(')', '\\)')
|
134 |
-
|
135 |
|
136 |
if not opt_chara.endswith(','):
|
137 |
opt_chara = f'{opt_chara},'
|
138 |
|
139 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
def refresh_character_thumb_image(character1, character2, character3):
|
142 |
thumb_image = []
|
143 |
-
|
144 |
-
|
145 |
-
thumb_image.append(thumb_image1)
|
146 |
|
|
|
|
|
|
|
147 |
if 'none' != character2 and 'random' != character2:
|
148 |
-
|
149 |
thumb_image.append(thumb_image2)
|
150 |
if 'none' != character3 and 'random' != character3:
|
151 |
-
|
152 |
thumb_image.append(thumb_image3)
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
def get_prompt_manager():
|
156 |
return PROMPT_MANAGER
|
|
|
102 |
character_list_cn = list(character_dict.keys())
|
103 |
character_list_cn.insert(0, "none")
|
104 |
|
105 |
+
def illustrious_character_select_ex(character = 'random', optimise_tags = True, use_cn=False):
|
106 |
chara = ''
|
|
|
107 |
|
108 |
if 'none' == character:
|
109 |
return '', '', None
|
110 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
if not use_cn:
|
112 |
+
chara = character
|
113 |
else:
|
114 |
+
chara = character_dict[character]
|
115 |
|
116 |
md5_chara = get_md5_hash(chara.replace('(','\\(').replace(')','\\)'))
|
117 |
thumb_image = Image.new('RGB', (128, 128), (128, 128, 128))
|
|
|
121 |
opt_chara = chara
|
122 |
if optimise_tags:
|
123 |
opt_chara = opt_chara.replace('(', '\\(').replace(')', '\\)')
|
124 |
+
print(f'{CAT}:Optimise Tags:[{chara}]->[{opt_chara}]')
|
125 |
|
126 |
if not opt_chara.endswith(','):
|
127 |
opt_chara = f'{opt_chara},'
|
128 |
|
129 |
+
return character, opt_chara, thumb_image
|
130 |
+
|
131 |
+
def create_prompt_info(rnd_character1, opt_chara1,
|
132 |
+
rnd_character2, opt_chara2,
|
133 |
+
rnd_character3, opt_chara3):
|
134 |
+
info = ''
|
135 |
+
if '' != opt_chara1:
|
136 |
+
info += f'Character 1:{rnd_character1}\nPrompt: {opt_chara1}\n\n'
|
137 |
+
|
138 |
+
if '' != opt_chara2:
|
139 |
+
info += f'Character 2:{rnd_character2}\nPrompt: {opt_chara2}\n\n'
|
140 |
+
|
141 |
+
if '' != opt_chara3:
|
142 |
+
info += f'Character 3:{rnd_character3}\nPrompt: {opt_chara3}'
|
143 |
+
|
144 |
+
prompt = f'{opt_chara1}{opt_chara2}{opt_chara3}'
|
145 |
+
|
146 |
+
return prompt, info
|
147 |
|
148 |
def refresh_character_thumb_image(character1, character2, character3):
|
149 |
thumb_image = []
|
150 |
+
rnd_character = [''] *3
|
151 |
+
opt_chara = [''] *3
|
|
|
152 |
|
153 |
+
if 'none' != character1 and 'random' != character1:
|
154 |
+
rnd_character[0], opt_chara[0], thumb_image1 = illustrious_character_select_ex(character = character1)
|
155 |
+
thumb_image.append(thumb_image1)
|
156 |
if 'none' != character2 and 'random' != character2:
|
157 |
+
rnd_character[1], opt_chara[1], thumb_image2 = illustrious_character_select_ex(character = character2)
|
158 |
thumb_image.append(thumb_image2)
|
159 |
if 'none' != character3 and 'random' != character3:
|
160 |
+
rnd_character[2], opt_chara[2], thumb_image3 = illustrious_character_select_ex(character = character3, use_cn=True)
|
161 |
thumb_image.append(thumb_image3)
|
162 |
+
|
163 |
+
_, character_info = create_prompt_info(rnd_character[0], opt_chara[0],
|
164 |
+
rnd_character[1], opt_chara[1],
|
165 |
+
rnd_character[2], opt_chara[2])
|
166 |
+
|
167 |
+
return thumb_image, character_info
|
168 |
|
169 |
def get_prompt_manager():
|
170 |
return PROMPT_MANAGER
|