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