Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -1,423 +1,424 @@
|
|
1 |
-
import spaces
|
2 |
-
import gradio as gr
|
3 |
-
import numpy as np
|
4 |
-
|
5 |
-
# DiffuseCraft
|
6 |
-
from dc import (infer, _infer, pass_result, get_diffusers_model_list, get_samplers,
|
7 |
-
get_vaes, enable_model_recom_prompt, enable_diffusers_model_detail,
|
8 |
-
get_t2i_model_info, get_all_lora_tupled_list, update_loras,
|
9 |
-
apply_lora_prompt, download_my_lora, search_civitai_lora,
|
10 |
-
select_civitai_lora, search_civitai_lora_json, extract_exif_data, esrgan_upscale, UPSCALER_KEYS,
|
11 |
-
preset_quality, preset_styles, process_style_prompt)
|
12 |
-
# Translator
|
13 |
-
from llmdolphin import (dolphin_respond_auto, dolphin_parse_simple,
|
14 |
-
get_llm_formats, get_dolphin_model_format, get_dolphin_models,
|
15 |
-
get_dolphin_model_info, select_dolphin_model, select_dolphin_format, get_dolphin_sysprompt)
|
16 |
-
# Tagger
|
17 |
-
from tagger.v2 import v2_upsampling_prompt, V2_ALL_MODELS
|
18 |
-
from tagger.utils import (gradio_copy_text, gradio_copy_prompt, COPY_ACTION_JS,
|
19 |
-
V2_ASPECT_RATIO_OPTIONS, V2_RATING_OPTIONS, V2_LENGTH_OPTIONS, V2_IDENTITY_OPTIONS)
|
20 |
-
from tagger.tagger import (predict_tags_wd, convert_danbooru_to_e621_prompt,
|
21 |
-
remove_specific_prompt, insert_recom_prompt, compose_prompt_to_copy,
|
22 |
-
translate_prompt, select_random_character)
|
23 |
-
from tagger.fl2sd3longcap import predict_tags_fl2_sd3
|
24 |
-
def description_ui():
|
25 |
-
gr.Markdown(
|
26 |
-
"""
|
27 |
-
## Danbooru Tags Transformer V2 Demo with WD Tagger & SD3 Long Captioner
|
28 |
-
(Image =>) Prompt => Upsampled longer prompt
|
29 |
-
- Mod of p1atdev's [Danbooru Tags Transformer V2 Demo](https://huggingface.co/spaces/p1atdev/danbooru-tags-transformer-v2) and [WD Tagger with 🤗 transformers](https://huggingface.co/spaces/p1atdev/wd-tagger-transformers).
|
30 |
-
- Models: p1atdev's [wd-swinv2-tagger-v3-hf](https://huggingface.co/p1atdev/wd-swinv2-tagger-v3-hf), [dart-v2-moe-sft](https://huggingface.co/p1atdev/dart-v2-moe-sft), [dart-v2-sft](https://huggingface.co/p1atdev/dart-v2-sft)\
|
31 |
-
, gokaygokay's [Florence-2-SD3-Captioner](https://huggingface.co/gokaygokay/Florence-2-SD3-Captioner)
|
32 |
-
"""
|
33 |
-
)
|
34 |
-
|
35 |
-
|
36 |
-
MAX_SEED = np.iinfo(np.int32).max
|
37 |
-
MAX_IMAGE_SIZE = 1216
|
38 |
-
|
39 |
-
css = """
|
40 |
-
#container { margin: 0 auto; !important; }
|
41 |
-
#col-container { margin: 0 auto; !important; }
|
42 |
-
#result { max-width: 520px; max-height: 520px; margin: 0px auto; !important; }
|
43 |
-
.lora { min-width: 480px; !important; }
|
44 |
-
#model-info { text-align: center; !important; }
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
["
|
179 |
-
["
|
180 |
-
["1girl"],
|
181 |
-
["
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
.success(
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
.
|
291 |
-
|
292 |
-
.
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
translate_input_prompt_button.click(translate_prompt, [
|
346 |
-
translate_input_prompt_button.click(translate_prompt, [
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
[
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
gr.
|
421 |
-
|
422 |
-
|
423 |
-
demo.
|
|
|
|
1 |
+
import spaces
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# DiffuseCraft
|
6 |
+
from dc import (infer, _infer, pass_result, get_diffusers_model_list, get_samplers,
|
7 |
+
get_vaes, enable_model_recom_prompt, enable_diffusers_model_detail,
|
8 |
+
get_t2i_model_info, get_all_lora_tupled_list, update_loras,
|
9 |
+
apply_lora_prompt, download_my_lora, search_civitai_lora,
|
10 |
+
select_civitai_lora, search_civitai_lora_json, extract_exif_data, esrgan_upscale, UPSCALER_KEYS,
|
11 |
+
preset_quality, preset_styles, process_style_prompt)
|
12 |
+
# Translator
|
13 |
+
from llmdolphin import (dolphin_respond_auto, dolphin_parse_simple,
|
14 |
+
get_llm_formats, get_dolphin_model_format, get_dolphin_models,
|
15 |
+
get_dolphin_model_info, select_dolphin_model, select_dolphin_format, get_dolphin_sysprompt)
|
16 |
+
# Tagger
|
17 |
+
from tagger.v2 import v2_upsampling_prompt, V2_ALL_MODELS
|
18 |
+
from tagger.utils import (gradio_copy_text, gradio_copy_prompt, COPY_ACTION_JS,
|
19 |
+
V2_ASPECT_RATIO_OPTIONS, V2_RATING_OPTIONS, V2_LENGTH_OPTIONS, V2_IDENTITY_OPTIONS)
|
20 |
+
from tagger.tagger import (predict_tags_wd, convert_danbooru_to_e621_prompt,
|
21 |
+
remove_specific_prompt, insert_recom_prompt, compose_prompt_to_copy,
|
22 |
+
translate_prompt, select_random_character)
|
23 |
+
from tagger.fl2sd3longcap import predict_tags_fl2_sd3
|
24 |
+
def description_ui():
|
25 |
+
gr.Markdown(
|
26 |
+
"""
|
27 |
+
## Danbooru Tags Transformer V2 Demo with WD Tagger & SD3 Long Captioner
|
28 |
+
(Image =>) Prompt => Upsampled longer prompt
|
29 |
+
- Mod of p1atdev's [Danbooru Tags Transformer V2 Demo](https://huggingface.co/spaces/p1atdev/danbooru-tags-transformer-v2) and [WD Tagger with 🤗 transformers](https://huggingface.co/spaces/p1atdev/wd-tagger-transformers).
|
30 |
+
- Models: p1atdev's [wd-swinv2-tagger-v3-hf](https://huggingface.co/p1atdev/wd-swinv2-tagger-v3-hf), [dart-v2-moe-sft](https://huggingface.co/p1atdev/dart-v2-moe-sft), [dart-v2-sft](https://huggingface.co/p1atdev/dart-v2-sft)\
|
31 |
+
, gokaygokay's [Florence-2-SD3-Captioner](https://huggingface.co/gokaygokay/Florence-2-SD3-Captioner)
|
32 |
+
"""
|
33 |
+
)
|
34 |
+
|
35 |
+
|
36 |
+
MAX_SEED = np.iinfo(np.int32).max
|
37 |
+
MAX_IMAGE_SIZE = 1216
|
38 |
+
|
39 |
+
css = """
|
40 |
+
#container { margin: 0 auto; !important; }
|
41 |
+
#col-container { margin: 0 auto; !important; }
|
42 |
+
#result { max-width: 520px; max-height: 520px; margin: 0px auto; !important; }
|
43 |
+
.lora { min-width: 480px; !important; }
|
44 |
+
#model-info { text-align: center; !important; }
|
45 |
+
.title{ text-align: center; !important; }
|
46 |
+
"""
|
47 |
+
|
48 |
+
with gr.Blocks(fill_width=True, elem_id="container", css=css, delete_cache=(60, 3600)) as demo:
|
49 |
+
gr.Markdown("# Votepurchase Multiple Model", elem_classes="title")
|
50 |
+
with gr.Tab("Image Generator"):
|
51 |
+
with gr.Column(elem_id="col-container"):
|
52 |
+
with gr.Row():
|
53 |
+
prompt = gr.Text(label="Prompt", show_label=False, lines=1, max_lines=8, placeholder="Enter your prompt", container=False)
|
54 |
+
|
55 |
+
with gr.Row():
|
56 |
+
run_button = gr.Button("Run", variant="primary", scale=5)
|
57 |
+
run_translate_button = gr.Button("Run with LLM Enhance", variant="secondary", scale=3)
|
58 |
+
auto_trans = gr.Checkbox(label="Auto translate to English", value=False, scale=2)
|
59 |
+
|
60 |
+
result = gr.Image(label="Result", elem_id="result", format="png", show_label=False, interactive=False,
|
61 |
+
show_download_button=True, show_share_button=False, container=True)
|
62 |
+
|
63 |
+
with gr.Accordion("Advanced Settings", open=False):
|
64 |
+
with gr.Row():
|
65 |
+
negative_prompt = gr.Text(label="Negative prompt", lines=1, max_lines=6, placeholder="Enter a negative prompt",
|
66 |
+
value="(low quality, worst quality:1.2), very displeasing, watermark, signature, ugly")
|
67 |
+
|
68 |
+
with gr.Row():
|
69 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
70 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
71 |
+
|
72 |
+
with gr.Row():
|
73 |
+
width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024) # 832
|
74 |
+
height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024) # 1216
|
75 |
+
guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=30.0, step=0.1, value=7)
|
76 |
+
num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=100, step=1, value=28)
|
77 |
+
|
78 |
+
with gr.Row():
|
79 |
+
with gr.Column(scale=4):
|
80 |
+
model_name = gr.Dropdown(label="Model", info="You can enter a huggingface model repo_id to want to use.",
|
81 |
+
choices=get_diffusers_model_list(), value=get_diffusers_model_list()[0],
|
82 |
+
allow_custom_value=True, interactive=True, min_width=320)
|
83 |
+
model_info = gr.Markdown(elem_id="model-info")
|
84 |
+
with gr.Column(scale=1):
|
85 |
+
model_detail = gr.Checkbox(label="Show detail of model in list", value=False)
|
86 |
+
|
87 |
+
with gr.Row():
|
88 |
+
sampler = gr.Dropdown(label="Sampler", choices=get_samplers(), value="Euler a")
|
89 |
+
vae_model = gr.Dropdown(label="VAE Model", choices=get_vaes(), value=get_vaes()[0])
|
90 |
+
|
91 |
+
with gr.Accordion("LoRA", open=True, visible=True):
|
92 |
+
def lora_dropdown(label):
|
93 |
+
return gr.Dropdown(label=label, choices=get_all_lora_tupled_list(), value="", allow_custom_value=True, elem_classes="lora", min_width=320)
|
94 |
+
|
95 |
+
def lora_scale_slider(label):
|
96 |
+
return gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label=label)
|
97 |
+
|
98 |
+
def lora_textbox():
|
99 |
+
return gr.Textbox(label="", info="Example of prompt:", value="", show_copy_button=True, interactive=False, visible=False)
|
100 |
+
|
101 |
+
with gr.Row():
|
102 |
+
with gr.Column():
|
103 |
+
with gr.Row():
|
104 |
+
lora1 = lora_dropdown("LoRA 1")
|
105 |
+
lora1_wt = lora_scale_slider("LoRA 1: weight")
|
106 |
+
with gr.Row():
|
107 |
+
lora1_info = lora_textbox()
|
108 |
+
lora1_copy = gr.Button(value="Copy example to prompt", visible=False)
|
109 |
+
lora1_md = gr.Markdown(value="", visible=False)
|
110 |
+
with gr.Column():
|
111 |
+
with gr.Row():
|
112 |
+
lora2 = lora_dropdown("LoRA 2")
|
113 |
+
lora2_wt = lora_scale_slider("LoRA 2: weight")
|
114 |
+
with gr.Row():
|
115 |
+
lora2_info = lora_textbox()
|
116 |
+
lora2_copy = gr.Button(value="Copy example to prompt", visible=False)
|
117 |
+
lora2_md = gr.Markdown(value="", visible=False)
|
118 |
+
with gr.Column():
|
119 |
+
with gr.Row():
|
120 |
+
lora3 = lora_dropdown("LoRA 3")
|
121 |
+
lora3_wt = lora_scale_slider("LoRA 3: weight")
|
122 |
+
with gr.Row():
|
123 |
+
lora3_info = lora_textbox()
|
124 |
+
lora3_copy = gr.Button(value="Copy example to prompt", visible=False)
|
125 |
+
lora3_md = gr.Markdown(value="", visible=False)
|
126 |
+
with gr.Column():
|
127 |
+
with gr.Row():
|
128 |
+
lora4 = lora_dropdown("LoRA 4")
|
129 |
+
lora4_wt = lora_scale_slider("LoRA 4: weight")
|
130 |
+
with gr.Row():
|
131 |
+
lora4_info = lora_textbox()
|
132 |
+
lora4_copy = gr.Button(value="Copy example to prompt", visible=False)
|
133 |
+
lora4_md = gr.Markdown(value="", visible=False)
|
134 |
+
with gr.Column():
|
135 |
+
with gr.Row():
|
136 |
+
lora5 = lora_dropdown("LoRA 5")
|
137 |
+
lora5_wt = lora_scale_slider("LoRA 5: weight")
|
138 |
+
with gr.Row():
|
139 |
+
lora5_info = lora_textbox()
|
140 |
+
lora5_copy = gr.Button(value="Copy example to prompt", visible=False)
|
141 |
+
lora5_md = gr.Markdown(value="", visible=False)
|
142 |
+
with gr.Accordion("From URL", open=True, visible=True):
|
143 |
+
with gr.Row():
|
144 |
+
lora_search_civitai_basemodel = gr.CheckboxGroup(label="Search LoRA for", choices=["Pony", "SD 1.5", "SDXL 1.0", "Flux.1 D", "Flux.1 S"], value=["Pony", "SDXL 1.0"])
|
145 |
+
lora_search_civitai_sort = gr.Radio(label="Sort", choices=["Highest Rated", "Most Downloaded", "Newest"], value="Highest Rated")
|
146 |
+
lora_search_civitai_period = gr.Radio(label="Period", choices=["AllTime", "Year", "Month", "Week", "Day"], value="AllTime")
|
147 |
+
with gr.Row():
|
148 |
+
lora_search_civitai_query = gr.Textbox(label="Query", placeholder="oomuro sakurako...", lines=1)
|
149 |
+
lora_search_civitai_tag = gr.Textbox(label="Tag", lines=1)
|
150 |
+
lora_search_civitai_submit = gr.Button("Search on Civitai")
|
151 |
+
with gr.Row():
|
152 |
+
lora_search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False)
|
153 |
+
lora_search_civitai_json = gr.JSON(value={}, visible=False)
|
154 |
+
lora_search_civitai_desc = gr.Markdown(value="", visible=False)
|
155 |
+
lora_download_url = gr.Textbox(label="LoRA URL", placeholder="https://civitai.com/api/download/models/28907", lines=1)
|
156 |
+
lora_download = gr.Button("Get and set LoRA and apply to prompt")
|
157 |
+
|
158 |
+
with gr.Row():
|
159 |
+
quality_selector = gr.Radio(label="Quality Tag Presets", interactive=True, choices=list(preset_quality.keys()), value="None", scale=3)
|
160 |
+
style_selector = gr.Radio(label="Style Presets", interactive=True, choices=list(preset_styles.keys()), value="None", scale=3)
|
161 |
+
recom_prompt = gr.Checkbox(label="Recommended prompt", value=True, scale=1)
|
162 |
+
|
163 |
+
with gr.Accordion("Translation Settings", open=False):
|
164 |
+
chatbot = gr.Chatbot(render_markdown=False, visible=False) # component for auto-translation
|
165 |
+
chat_model = gr.Dropdown(choices=get_dolphin_models(), value=get_dolphin_models()[0][1], allow_custom_value=True, label="Model")
|
166 |
+
chat_model_info = gr.Markdown(value=get_dolphin_model_info(get_dolphin_models()[0][1]), label="Model info")
|
167 |
+
chat_format = gr.Dropdown(choices=get_llm_formats(), value=get_dolphin_model_format(get_dolphin_models()[0][1]), label="Message format")
|
168 |
+
with gr.Row():
|
169 |
+
chat_tokens = gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max tokens")
|
170 |
+
chat_temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
171 |
+
chat_topp = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
|
172 |
+
chat_topk = gr.Slider(minimum=0, maximum=100, value=40, step=1, label="Top-k")
|
173 |
+
chat_rp = gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label="Repetition penalty")
|
174 |
+
chat_sysmsg = gr.Textbox(value=get_dolphin_sysprompt(), label="System message")
|
175 |
+
|
176 |
+
examples = gr.Examples(
|
177 |
+
examples = [
|
178 |
+
["souryuu asuka langley, 1girl, neon genesis evangelion, plugsuit, pilot suit, red bodysuit, sitting, crossing legs, black eye patch, cat hat, throne, symmetrical, looking down, from bottom, looking at viewer, outdoors"],
|
179 |
+
["sailor moon, magical girl transformation, sparkles and ribbons, soft pastel colors, crescent moon motif, starry night sky background, shoujo manga style"],
|
180 |
+
["kafuu chino, 1girl, solo"],
|
181 |
+
["1girl"],
|
182 |
+
["beautiful sunset"],
|
183 |
+
],
|
184 |
+
inputs=[prompt],
|
185 |
+
cache_examples=False,
|
186 |
+
)
|
187 |
+
|
188 |
+
gr.on( #lambda x: None, inputs=None, outputs=result).then(
|
189 |
+
triggers=[run_button.click, prompt.submit],
|
190 |
+
fn=infer,
|
191 |
+
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height,
|
192 |
+
guidance_scale, num_inference_steps, model_name,
|
193 |
+
lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt, lora5, lora5_wt,
|
194 |
+
sampler, vae_model, auto_trans],
|
195 |
+
outputs=[result],
|
196 |
+
queue=True,
|
197 |
+
show_progress="full",
|
198 |
+
show_api=True,
|
199 |
+
)
|
200 |
+
|
201 |
+
gr.on( #lambda x: None, inputs=None, outputs=result).then(
|
202 |
+
triggers=[run_translate_button.click],
|
203 |
+
fn=_infer, # dummy fn for api
|
204 |
+
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height,
|
205 |
+
guidance_scale, num_inference_steps, model_name,
|
206 |
+
lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt, lora5, lora5_wt,
|
207 |
+
sampler, vae_model, auto_trans],
|
208 |
+
outputs=[result],
|
209 |
+
queue=False,
|
210 |
+
show_api=True,
|
211 |
+
api_name="infer_translate",
|
212 |
+
).success(
|
213 |
+
fn=dolphin_respond_auto,
|
214 |
+
inputs=[prompt, chatbot],
|
215 |
+
outputs=[chatbot],
|
216 |
+
queue=True,
|
217 |
+
show_progress="full",
|
218 |
+
show_api=False,
|
219 |
+
).success(
|
220 |
+
fn=dolphin_parse_simple,
|
221 |
+
inputs=[prompt, chatbot],
|
222 |
+
outputs=[prompt],
|
223 |
+
queue=False,
|
224 |
+
show_api=False,
|
225 |
+
).success(
|
226 |
+
fn=infer,
|
227 |
+
inputs=[prompt, negative_prompt, seed, randomize_seed, width, height,
|
228 |
+
guidance_scale, num_inference_steps, model_name,
|
229 |
+
lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt, lora5, lora5_wt,
|
230 |
+
sampler, vae_model],
|
231 |
+
outputs=[result],
|
232 |
+
queue=True,
|
233 |
+
show_progress="full",
|
234 |
+
show_api=False,
|
235 |
+
).success(lambda: None, None, chatbot, queue=False, show_api=False)\
|
236 |
+
.success(pass_result, [result], [result], queue=False, show_api=False) # dummy fn for api
|
237 |
+
|
238 |
+
gr.on(
|
239 |
+
triggers=[lora1.change, lora1_wt.change, lora2.change, lora2_wt.change, lora3.change, lora3_wt.change,
|
240 |
+
lora4.change, lora4_wt.change, lora5.change, lora5_wt.change],
|
241 |
+
fn=update_loras,
|
242 |
+
inputs=[prompt, lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt, lora5, lora5_wt],
|
243 |
+
outputs=[prompt, lora1, lora1_wt, lora1_info, lora1_copy, lora1_md,
|
244 |
+
lora2, lora2_wt, lora2_info, lora2_copy, lora2_md, lora3, lora3_wt, lora3_info, lora3_copy, lora3_md,
|
245 |
+
lora4, lora4_wt, lora4_info, lora4_copy, lora4_md, lora5, lora5_wt, lora5_info, lora5_copy, lora5_md],
|
246 |
+
queue=False,
|
247 |
+
trigger_mode="once",
|
248 |
+
show_api=False,
|
249 |
+
)
|
250 |
+
lora1_copy.click(apply_lora_prompt, [prompt, lora1_info], [prompt], queue=False, show_api=False)
|
251 |
+
lora2_copy.click(apply_lora_prompt, [prompt, lora2_info], [prompt], queue=False, show_api=False)
|
252 |
+
lora3_copy.click(apply_lora_prompt, [prompt, lora3_info], [prompt], queue=False, show_api=False)
|
253 |
+
lora4_copy.click(apply_lora_prompt, [prompt, lora4_info], [prompt], queue=False, show_api=False)
|
254 |
+
lora5_copy.click(apply_lora_prompt, [prompt, lora5_info], [prompt], queue=False, show_api=False)
|
255 |
+
|
256 |
+
gr.on(
|
257 |
+
triggers=[lora_search_civitai_submit.click, lora_search_civitai_query.submit, lora_search_civitai_tag.submit],
|
258 |
+
fn=search_civitai_lora,
|
259 |
+
inputs=[lora_search_civitai_query, lora_search_civitai_basemodel, lora_search_civitai_sort, lora_search_civitai_period, lora_search_civitai_tag],
|
260 |
+
outputs=[lora_search_civitai_result, lora_search_civitai_desc, lora_search_civitai_submit, lora_search_civitai_query],
|
261 |
+
scroll_to_output=True,
|
262 |
+
queue=True,
|
263 |
+
show_api=False,
|
264 |
+
)
|
265 |
+
lora_search_civitai_json.change(search_civitai_lora_json, [lora_search_civitai_query, lora_search_civitai_basemodel], [lora_search_civitai_json], queue=True, show_api=True) # fn for api
|
266 |
+
lora_search_civitai_result.change(select_civitai_lora, [lora_search_civitai_result], [lora_download_url, lora_search_civitai_desc], scroll_to_output=True, queue=False, show_api=False)
|
267 |
+
gr.on(
|
268 |
+
triggers=[lora_download.click, lora_download_url.submit],
|
269 |
+
fn=download_my_lora,
|
270 |
+
inputs=[lora_download_url,lora1, lora2, lora3, lora4, lora5],
|
271 |
+
outputs=[lora1, lora2, lora3, lora4, lora5],
|
272 |
+
scroll_to_output=True,
|
273 |
+
queue=True,
|
274 |
+
show_api=False,
|
275 |
+
)
|
276 |
+
|
277 |
+
recom_prompt.change(enable_model_recom_prompt, [recom_prompt], [recom_prompt], queue=False, show_api=False)
|
278 |
+
gr.on(
|
279 |
+
triggers=[quality_selector.change, style_selector.change],
|
280 |
+
fn=process_style_prompt,
|
281 |
+
inputs=[prompt, negative_prompt, style_selector, quality_selector],
|
282 |
+
outputs=[prompt, negative_prompt],
|
283 |
+
queue=False,
|
284 |
+
trigger_mode="once",
|
285 |
+
)
|
286 |
+
|
287 |
+
model_detail.change(enable_diffusers_model_detail, [model_detail, model_name], [model_detail, model_name], queue=False, show_api=False)
|
288 |
+
model_name.change(get_t2i_model_info, [model_name], [model_info], queue=False, show_api=False)
|
289 |
+
|
290 |
+
chat_model.change(select_dolphin_model, [chat_model], [chat_model, chat_format, chat_model_info], queue=True, show_progress="full", show_api=False)\
|
291 |
+
.success(lambda: None, None, chatbot, queue=False, show_api=False)
|
292 |
+
chat_format.change(select_dolphin_format, [chat_format], [chat_format], queue=False, show_api=False)\
|
293 |
+
.success(lambda: None, None, chatbot, queue=False, show_api=False)
|
294 |
+
|
295 |
+
# Tagger
|
296 |
+
with gr.Tab("Tags Transformer with Tagger"):
|
297 |
+
with gr.Column():
|
298 |
+
with gr.Group():
|
299 |
+
input_image = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
|
300 |
+
with gr.Accordion(label="Advanced options", open=False):
|
301 |
+
general_threshold = gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.01, interactive=True)
|
302 |
+
character_threshold = gr.Slider(label="Character threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
303 |
+
input_tag_type = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
304 |
+
recom_prompt = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
305 |
+
image_algorithms = gr.CheckboxGroup(["Use WD Tagger", "Use Florence-2-SD3-Long-Captioner"], label="Algorithms", value=["Use WD Tagger"])
|
306 |
+
keep_tags = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
307 |
+
generate_from_image_btn = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
|
308 |
+
with gr.Group():
|
309 |
+
with gr.Row():
|
310 |
+
input_character = gr.Textbox(label="Character tags", placeholder="hatsune miku")
|
311 |
+
input_copyright = gr.Textbox(label="Copyright tags", placeholder="vocaloid")
|
312 |
+
random_character = gr.Button(value="Random character 🎲", size="sm")
|
313 |
+
input_general = gr.TextArea(label="General tags", lines=4, placeholder="1girl, ...", value="")
|
314 |
+
input_tags_to_copy = gr.Textbox(value="", visible=False)
|
315 |
+
with gr.Row():
|
316 |
+
copy_input_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
|
317 |
+
copy_prompt_btn_input = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
|
318 |
+
translate_input_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
|
319 |
+
tag_type = gr.Radio(label="Output tag conversion", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="e621", visible=False)
|
320 |
+
input_rating = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="explicit")
|
321 |
+
with gr.Accordion(label="Advanced options", open=False):
|
322 |
+
input_aspect_ratio = gr.Radio(label="Aspect ratio", info="The aspect ratio of the image.", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square")
|
323 |
+
input_length = gr.Radio(label="Length", info="The total length of the tags.", choices=list(V2_LENGTH_OPTIONS), value="very_long")
|
324 |
+
input_identity = gr.Radio(label="Keep identity", info="How strictly to keep the identity of the character or subject. If you specify the detail of subject in the prompt, you should choose `strict`. Otherwise, choose `none` or `lax`. `none` is very creative but sometimes ignores the input prompt.", choices=list(V2_IDENTITY_OPTIONS), value="lax")
|
325 |
+
input_ban_tags = gr.Textbox(label="Ban tags", info="Tags to ban from the output.", placeholder="alternate costumen, ...", value="censored")
|
326 |
+
model_name = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0])
|
327 |
+
dummy_np = gr.Textbox(label="Negative prompt", value="", visible=False)
|
328 |
+
recom_animagine = gr.Textbox(label="Animagine reccomended prompt", value="Animagine", visible=False)
|
329 |
+
recom_pony = gr.Textbox(label="Pony reccomended prompt", value="Pony", visible=False)
|
330 |
+
generate_btn = gr.Button(value="GENERATE TAGS", size="lg", variant="primary")
|
331 |
+
with gr.Row():
|
332 |
+
with gr.Group():
|
333 |
+
output_text = gr.TextArea(label="Output tags", interactive=False, show_copy_button=True)
|
334 |
+
with gr.Row():
|
335 |
+
copy_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
|
336 |
+
copy_prompt_btn = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
|
337 |
+
with gr.Group():
|
338 |
+
output_text_pony = gr.TextArea(label="Output tags (Pony e621 style)", interactive=False, show_copy_button=True)
|
339 |
+
with gr.Row():
|
340 |
+
copy_btn_pony = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
|
341 |
+
copy_prompt_btn_pony = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
|
342 |
+
|
343 |
+
random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character], queue=False, show_api=False)
|
344 |
+
|
345 |
+
translate_input_prompt_button.click(translate_prompt, [input_general], [input_general], queue=False, show_api=False)
|
346 |
+
translate_input_prompt_button.click(translate_prompt, [input_character], [input_character], queue=False, show_api=False)
|
347 |
+
translate_input_prompt_button.click(translate_prompt, [input_copyright], [input_copyright], queue=False, show_api=False)
|
348 |
+
|
349 |
+
generate_from_image_btn.click(
|
350 |
+
lambda: ("", "", ""), None, [input_copyright, input_character, input_general], queue=False, show_api=False,
|
351 |
+
).success(
|
352 |
+
predict_tags_wd,
|
353 |
+
[input_image, input_general, image_algorithms, general_threshold, character_threshold],
|
354 |
+
[input_copyright, input_character, input_general, copy_input_btn],
|
355 |
+
show_api=False,
|
356 |
+
).success(
|
357 |
+
predict_tags_fl2_sd3, [input_image, input_general, image_algorithms], [input_general], show_api=False,
|
358 |
+
).success(
|
359 |
+
remove_specific_prompt, [input_general, keep_tags], [input_general], queue=False, show_api=False,
|
360 |
+
).success(
|
361 |
+
convert_danbooru_to_e621_prompt, [input_general, input_tag_type], [input_general], queue=False, show_api=False,
|
362 |
+
).success(
|
363 |
+
insert_recom_prompt, [input_general, dummy_np, recom_prompt], [input_general, dummy_np], queue=False, show_api=False,
|
364 |
+
).success(lambda: gr.update(interactive=True), None, [copy_prompt_btn_input], queue=False, show_api=False)
|
365 |
+
copy_input_btn.click(compose_prompt_to_copy, [input_character, input_copyright, input_general], [input_tags_to_copy], show_api=False)\
|
366 |
+
.success(gradio_copy_text, [input_tags_to_copy], js=COPY_ACTION_JS, show_api=False)
|
367 |
+
copy_prompt_btn_input.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy], show_api=False)\
|
368 |
+
.success(gradio_copy_prompt, inputs=[input_tags_to_copy], outputs=[prompt], show_api=False)
|
369 |
+
|
370 |
+
generate_btn.click(
|
371 |
+
v2_upsampling_prompt,
|
372 |
+
[model_name, input_copyright, input_character, input_general,
|
373 |
+
input_rating, input_aspect_ratio, input_length, input_identity, input_ban_tags],
|
374 |
+
[output_text],
|
375 |
+
show_api=False,
|
376 |
+
).success(
|
377 |
+
convert_danbooru_to_e621_prompt, [output_text, tag_type], [output_text_pony], queue=False, show_api=False,
|
378 |
+
).success(
|
379 |
+
insert_recom_prompt, [output_text, dummy_np, recom_animagine], [output_text, dummy_np], queue=False, show_api=False,
|
380 |
+
).success(
|
381 |
+
insert_recom_prompt, [output_text_pony, dummy_np, recom_pony], [output_text_pony, dummy_np], queue=False, show_api=False,
|
382 |
+
).success(lambda: (gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)),
|
383 |
+
None, [copy_btn, copy_btn_pony, copy_prompt_btn, copy_prompt_btn_pony], queue=False, show_api=False)
|
384 |
+
copy_btn.click(gradio_copy_text, [output_text], js=COPY_ACTION_JS, show_api=False)
|
385 |
+
copy_btn_pony.click(gradio_copy_text, [output_text_pony], js=COPY_ACTION_JS, show_api=False)
|
386 |
+
copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt], show_api=False)
|
387 |
+
copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt], show_api=False)
|
388 |
+
|
389 |
+
with gr.Tab("PNG Info"):
|
390 |
+
with gr.Row():
|
391 |
+
with gr.Column():
|
392 |
+
image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
|
393 |
+
|
394 |
+
with gr.Column():
|
395 |
+
result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
|
396 |
+
|
397 |
+
image_metadata.change(
|
398 |
+
fn=extract_exif_data,
|
399 |
+
inputs=[image_metadata],
|
400 |
+
outputs=[result_metadata],
|
401 |
+
)
|
402 |
+
|
403 |
+
with gr.Tab("Upscaler"):
|
404 |
+
with gr.Row():
|
405 |
+
with gr.Column():
|
406 |
+
image_up_tab = gr.Image(label="Image", type="pil", sources=["upload"])
|
407 |
+
upscaler_tab = gr.Dropdown(label="Upscaler", choices=UPSCALER_KEYS[9:], value=UPSCALER_KEYS[11])
|
408 |
+
upscaler_size_tab = gr.Slider(minimum=1., maximum=4., step=0.1, value=1.1, label="Upscale by")
|
409 |
+
generate_button_up_tab = gr.Button(value="START UPSCALE", variant="primary")
|
410 |
+
|
411 |
+
with gr.Column():
|
412 |
+
result_up_tab = gr.Image(label="Result", type="pil", interactive=False, format="png")
|
413 |
+
|
414 |
+
generate_button_up_tab.click(
|
415 |
+
fn=esrgan_upscale,
|
416 |
+
inputs=[image_up_tab, upscaler_tab, upscaler_size_tab],
|
417 |
+
outputs=[result_up_tab],
|
418 |
+
)
|
419 |
+
|
420 |
+
gr.LoginButton()
|
421 |
+
gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
|
422 |
+
|
423 |
+
demo.queue()
|
424 |
+
demo.launch()
|