File size: 28,715 Bytes
908a50c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
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
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
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
import gradio as gr
from convert_url_to_diffusers_multi_gr import convert_url_to_diffusers_repo, get_dtypes, FLUX_BASE_REPOS, SD35_BASE_REPOS
from presets import (DEFAULT_DTYPE, schedulers, clips, t5s, sdxl_vaes, sdxl_loras, sdxl_preset_dict, sdxl_set_presets,
                     sd15_vaes, sd15_loras, sd15_preset_dict, sd15_set_presets, flux_vaes, flux_loras, flux_preset_dict, flux_set_presets,
                     sd35_vaes, sd35_loras, sd35_preset_dict, sd35_set_presets)
import os


HF_USER = os.getenv("HF_USER", "")
HF_REPO = os.getenv("HF_REPO", "")
HF_URL = os.getenv("HF_URL", "")
HF_OW = os.getenv("HF_OW", False)
HF_PR = os.getenv("HF_PR", False)

css = """
.title { font-size: 3em; align-items: center; text-align: center; }
.info { align-items: center; text-align: center; }
.block.result { margin: 1em 0; padding: 1em; box-shadow: 0 0 3px 3px #664422, 0 0 3px 2px #664422 inset; border-radius: 6px; background: #665544; }

.block.result p,
.block.result .prose,
.block-result * {
    color: aquamarine;
    font-family: "Atma", monospace !important;
    font-size: 1.06em;
    letter-spacing: 0.50px;
    word-spacing: 6px;
}
/* I know that I use a lot of !important instruction..
   Yeah, I know it's not really properly recommended to use !important instruction when writing CSS rules ..
   But it's because that Gradio interface use also a custom css-theme in gr.Blocks() from: "NoCrypt/miku@>=1.2.2"
   And all my !important instructions are for avoiding to get unexpected superceeded by that "NoCrypt/miku@>=1.2.2" css theme skin...
   No more, no less!
*/
.setting_tag::before {
    content: "::";
    font-family: system-ui, monospace !important;
    font-size: 1.2em !important;
    color: #736819 !important;
    font-weight: bold;
    display: block;
    text-align: center !important;
    margin: 0 auto !important;
}
.setting_tag {
    margin-top: 1em !important;
    font-size: 1.4em !important;
    color: darkgoldenrod !important;
    padding: 10px !important;
    font-weight: normal !important;
    border: 2px dotted gold !important;
    background: white !important;
    word-break: break-word !important;
    display: block;
    text-align: center !important;
    margin: 0 auto !important;
    text-shadow: 1px 1px 1px gold !important;
}
.setting_tag::after {
    content: "::";
    font-family: system-ui, monospace !important;
    font-size: 1.2em !important;
    color: #736819 !important;
    font-weight: bold !important;
    display: block !important;
    text-align: center !important;
    margin: 0 auto !important;
}
a.linkify_1,
a.linkify_1:focus,
a.linkify_1:visited {
    color: red !important;
    text-decoration: underline !important;
}
a.linkify_1:active,
a.linkify_1:hover {
    color: darkred !important;
    text-decoration: overline !important;
}
.details_info_block_expanded_override {
    font-size: 0.95em !important;
    color: grey !important;
    padding: 10px !important;
    font-weight: bold;
    border: none !important;
    box-shadow: 1px 1px 2px 3px whitesmoke, 3px 2px 1px 1px grey !important;
    background: whitesmoke !important;
    word-break: break-word !important;
}
.details_info_block {
    font-size: 0.95em !important;
    color: grey !important;
    padding: 10px !important;
    font-weight: bold;
    border: none !important;
    box-shadow: 1px 1px 2px 3px whitesmoke, 3px 2px 1px 1px grey !important;
    background: whitesmoke !important;
    word-break: break-word !important;
    height: initial !important;
    max-height: initial !important;
    overflow: auto !important;
}
.details_info_block[is-expanded="False"]::before {
    content: "(double-click to expand help...)";
    user-select: none;
    cursor: pointer;
    font-family: "Atma" !important;
    font-weight: 500 !important;
    letter-spacing: 2px !important;
    word-spacing: 5px !important;
    color: darkmagenta !important;
    display: inline-block !important;
    font-size: 0.99em !important;
    background: whitesmoke !important;
    padding: 10px !important;
    border: 2px solid black !important;
}
.details_info_block[is-expanded="False"] {
    transition: 1.2s all;
    height: 80px !important;
    max-height: 80px !important;
    overflow: hidden !important;
}
.details_info_block[is-expanded="True"]::before {
    content: "(double-click to reduce help...)";
    user-select: none;
    cursor: pointer;
    font-family: "Atma" !important;
    font-weight: 500 !important;
    letter-spacing: 2px !important;
    word-spacing: 5px !important;
    color: white !important;
    display: block !important;
    font-size: 0.99em !important;
    background: #1c9e5c !important;
    padding: 10px !important;
    border: 2px solid black !important;
    border-radius: 0px !important;
    margin-bottom: 1em !important;
}
.details_info_block[is-expanded="True"] {
    transition: 1.2s all;
    height: initial !important;
    max-height: initial !important;
    overflow: auto !important;
    margin-bottom: 1em !important;
}
.em_warning {
    font-family: "Atma", system-ui !important;
    font-weight: 400 !important;
    font-style: normal !important;
    font-size: 1.3em !important;
    word-spacing: 3.2px !important;
    color: orangered !important;
}
.spanify_safetensors_base_model {
    font-family: "Nunito", system-ui, monospace !important;
    font-weight: 600;
    color: green !important;
}
.spanify_safetensors_checkpoint_model {
    font-family: "Nunito", system-ui, monospace !important;
    font-weight: 600;
    color: orange !important;
}
.spanify_vae_model {
    font-family: "Nunito", system-ui, monospace !important;
    font-weight: 600;
    color: deeppink !important;
}
.spanify_lora_checkpoint_model {
    font-family: "Nunito", system-ui, monospace !important;
    font-weight: 600;
    color: #8c627b !important;
}
.spanify_other_model {
    font-family: "Nunito", system-ui, monospace !important;
    font-weight: 600;
    color: silver !important;
}
.setting_tag_as_mini {
    font-family: "Nunito", serif !important;
    font-optical-sizing: auto !important;
    font-weight: 600 !important;
    font-size: 1.2em !important;
    color: darkgoldenrod !important;
    padding: 4px !important;
    border: 2px dashed gold !important;
    background: white !important;
    word-break: break-word !important;
    display: inline-block !important;
    text-shadow: 1px 1px 1px gold !important;
}
li.has_divider_1 {
    list-style: none;
}
li.has_divider_1 > div.is_divider_1 {
    display: inline-block;
    width: 100%;
    height: 0.4em;
    background: burlywood;
}
.accordion-element,
.accordion-element button:not(.reset-button):not(.primary),
.accordion-element button:not(.reset-button):not(.primary) * {
    background: navy !important;
    color: white !important;
    font-family: "Nunito", serif !important;
    font-optical-sizing: auto !important;
    font-weight: 600 !important;
    font-size: 1.2em !important;
}
/* the issue with a Gradio gr.Tab() component,
is that if we specify a CSS class for it through
the declaration of the well-said component, then,
it would be useless as it don't permit to targetting
the TRUE button tab clickable DOMElement..
so this is a workaround which assume the TAB is at that XPath (at least for Gradio version 5) */
/* any NOT active Gradio tab : */
.tab-wrapper .tab-container[role="tablist"] button[role="tab"]:not(.selected) {
    background: red !important;
    color: white !important;
    font-family: "Nunito", serif !important;
    font-optical-sizing: auto !important;
    font-weight: 600 !important;
    font-size: 1.2em !important;
}
/* the CURRENT active Gradio tab : */
.tab-wrapper .tab-container[role="tablist"] button[role="tab"].selected {
    background: green !important;
    color: white !important;
    font-family: "Nunito", serif !important;
    font-optical-sizing: auto !important;
    font-weight: 600 !important;
    font-size: 1.6em !important;
}
/* here we only target Gradio button
that are reset-button
IN an accordion-element classe */
.accordion-element button.reset-button {
    background: #803e3e !important;
    color: white !important;
    font-family: "Atma", serif !important;
    font-weight: 700 !important;
    font-style: normal !important;
}
/* here we only target Gradio button
that are primary
IN an accordion-element classe */
.accordion-element button.primary {
    background: #5f925e !important;
    font-size: 1.6em !important;
    font-style: oblique !important;
    font-weight: normal !important;
    text-transform: uppercase !important;
    letter-spacing: 1px !important;
    border-bottom-right-radius: 100em !important;
    border-bottom-left-radius: 100em !important;
    font-family: "Atma", serif !important;
    font-weight: 700 !important;
    font-style: normal !important;
}
"""


help_dict = {
    "hf_username": """
        <article class="setting_tag" use-webfont="wf-nunito-regular">
            (hf_username)
        </article>
        <div class="details_info_block_expanded_override"
            use-webfont="wf-atma-light"
            >
            <em>Your HuggingFace username, no more, no less</em>
        </div>""",
    "hf_write_token_access": """
        <article class="setting_tag" use-webfont="wf-nunito-regular">
            (hf_write_token_access)
        </article>
        <div class="details_info_block"
            is-expanded="False"
            ondblclick="makeExpandable(this);"
            use-webfont="wf-atma-light"
            >
            <em>Your HuggingFace Token with WRITE access</em>
            <br>
            <br>
            - Your Token with WRITE access can be created for free at <a class="linkify_1" target="_blank" href="https://huggingface.co/settings/tokens">https://huggingface.co/settings/tokens</a>.
            <br>
            <br>
            <em class=\"em_warning\">
                please, note once created, note its value somewhere you can retrieve later,
                <br>
                because afterwards it would be no more possible to see its value from the
                <br>
                tokens HuggingFace account page!
            </em>
        </div>""",
}

def help(key):
    with gr.Accordion("Help", open=False) as help:
        gr.HTML(value=help_dict.get(key, ""))
    return help


with gr.Blocks(theme="theNeofr/Syne", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
    gr.Markdown("# Download SDXL / SD 1.5 / SD 3.5 / FLUX.1 safetensors and convert to HF🤗 Diffusers format and create your repo", elem_classes="title")
    gr.Markdown(f"""
### ⚠️IMPORTANT NOTICE⚠️<br>
It's dangerous to expose your access token or key to others.
If you do use it, I recommend that you duplicate this space on your own HF account in advance.
Keys and tokens could be set to **Secrets** (`HF_TOKEN`, `CIVITAI_API_KEY`) if it's placed in your own space.
It saves you the trouble of typing them in.<br>
It barely works in the CPU space, but larger files can be converted if duplicated on the more powerful **Zero GPU** space.
In particular, conversion of FLUX.1 or SD 3.5 is almost impossible in CPU space.
### The steps are the following:
1. Paste a write-access token from [hf.co/settings/tokens](https://huggingface.co/settings/tokens).
1. Input a model download url of the Hugging Face or Civitai or other sites.
1. If you want to download a model from Civitai, paste a Civitai API Key.
1. Input your HF user ID. e.g. 'yourid'.
1. Input your new repo name. If empty, auto-complete. e.g. 'newrepo'.
1. Set the parameters. If not sure, just use the defaults.
1. Click "Submit".
1. Patiently wait until the output changes. It takes approximately 2 to 3 minutes (on SDXL models downloading from HF).
            """)
    with gr.Column():
        dl_url = gr.Textbox(label="URL to download", placeholder="https://huggingface.co/bluepen5805/blue_pencil-XL/blob/main/blue_pencil-XL-v7.0.0.safetensors",
                            value=HF_URL, max_lines=1)
        with gr.Group():
            with gr.Row():
                with gr.Column():
                    hf_user = gr.Textbox(label="Your HF user ID", placeholder="username", value=HF_USER, max_lines=1)
                    help("hf_username")
                with gr.Column():
                    hf_repo = gr.Textbox(label="New repo name", placeholder="reponame", info="If empty, auto-complete", value=HF_REPO, max_lines=1)
            with gr.Row(equal_height=True):
                with gr.Column():
                    hf_token = gr.Textbox(label="Your HF write token", placeholder="hf_...", value="", max_lines=1)
                    gr.Markdown("Your token is available at [hf.co/settings/tokens](https://huggingface.co/settings/tokens).", elem_classes="info")
                    help("hf_write_token_access")
                with gr.Column():
                    civitai_key = gr.Textbox(label="Your Civitai API Key (Optional)", info="If you download model from Civitai...", placeholder="", value="", max_lines=1)
                    gr.Markdown("Your Civitai API key is available at [https://civitai.com/user/account](https://civitai.com/user/account).", elem_classes="info")
            with gr.Row():
                is_upload_sf = gr.Checkbox(label="Upload single safetensors file into new repo", value=False)
                is_private = gr.Checkbox(label="Create private repo", value=True)
                gated = gr.Radio(label="Create gated repo", info="Gated repo must be public", choices=["auto", "manual", "False"], value="False")
            with gr.Row():
                is_overwrite = gr.Checkbox(label="Overwrite repo", value=HF_OW)
                is_pr = gr.Checkbox(label="Create PR", value=HF_PR)
        with gr.Tab("SDXL"):
            with gr.Group():
                sdxl_presets = gr.Radio(label="Presets", choices=list(sdxl_preset_dict.keys()), value=list(sdxl_preset_dict.keys())[0])
                sdxl_mtype = gr.Textbox(value="SDXL", visible=False)
                sdxl_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value=DEFAULT_DTYPE)
                with gr.Accordion("Advanced settings", open=False):
                    with gr.Row():
                        sdxl_vae = gr.Dropdown(label="VAE", choices=sdxl_vaes, value="", allow_custom_value=True)
                        sdxl_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler a")
                        sdxl_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
                    with gr.Column():
                        with gr.Row():
                            sdxl_lora1 = gr.Dropdown(label="LoRA1", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sdxl_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
                        with gr.Row():
                            sdxl_lora2 = gr.Dropdown(label="LoRA2", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sdxl_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
                        with gr.Row():
                            sdxl_lora3 = gr.Dropdown(label="LoRA3", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sdxl_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
                        with gr.Row():
                            sdxl_lora4 = gr.Dropdown(label="LoRA4", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sdxl_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
                        with gr.Row():
                            sdxl_lora5 = gr.Dropdown(label="LoRA5", choices=sdxl_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sdxl_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
            sdxl_run_button = gr.Button(value="Submit", variant="primary")
        with gr.Tab("SD 1.5"):
            with gr.Group():
                sd15_presets = gr.Radio(label="Presets", choices=list(sd15_preset_dict.keys()), value=list(sd15_preset_dict.keys())[0])
                sd15_mtype = gr.Textbox(value="SD 1.5", visible=False)
                sd15_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value=DEFAULT_DTYPE)
                with gr.Row():
                    sd15_ema = gr.Checkbox(label="Extract EMA", value=True, visible=True)
                    sd15_isize = gr.Radio(label="Image size", choices=["768", "512"], value="768")
                    sd15_sc = gr.Checkbox(label="Safety checker", value=False)
                with gr.Accordion("Advanced settings", open=False):
                    with gr.Row():
                        sd15_vae = gr.Dropdown(label="VAE", choices=sd15_vaes, value="", allow_custom_value=True)
                        sd15_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=schedulers, value="Euler")
                        sd15_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
                    with gr.Column():
                        with gr.Row():
                            sd15_lora1 = gr.Dropdown(label="LoRA1", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd15_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
                        with gr.Row():
                            sd15_lora2 = gr.Dropdown(label="LoRA2", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd15_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
                        with gr.Row():
                            sd15_lora3 = gr.Dropdown(label="LoRA3", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd15_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
                        with gr.Row():
                            sd15_lora4 = gr.Dropdown(label="LoRA4", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd15_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
                        with gr.Row():
                            sd15_lora5 = gr.Dropdown(label="LoRA5", choices=sd15_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd15_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
            sd15_run_button = gr.Button(value="Submit", variant="primary")
        with gr.Tab("FLUX.1"):
            with gr.Group():
                flux_presets = gr.Radio(label="Presets", choices=list(flux_preset_dict.keys()), value=list(flux_preset_dict.keys())[0])
                flux_mtype = gr.Textbox(value="FLUX", visible=False)
                flux_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value="bf16")
                flux_base_repo = gr.Dropdown(label="Base repo ID", choices=FLUX_BASE_REPOS, value=FLUX_BASE_REPOS[0], allow_custom_value=True, visible=True)
                with gr.Accordion("Advanced settings", open=False):
                    with gr.Row():
                        flux_vae = gr.Dropdown(label="VAE", choices=flux_vaes, value="", allow_custom_value=True)
                        flux_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=[""], value="", visible=False)
                    with gr.Row():
                        flux_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
                        flux_t5 = gr.Dropdown(label="T5", choices=t5s, value="", allow_custom_value=True)
                    with gr.Column():
                        with gr.Row():
                            flux_lora1 = gr.Dropdown(label="LoRA1", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            flux_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
                        with gr.Row():
                            flux_lora2 = gr.Dropdown(label="LoRA2", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            flux_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
                        with gr.Row():
                            flux_lora3 = gr.Dropdown(label="LoRA3", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            flux_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
                        with gr.Row():
                            flux_lora4 = gr.Dropdown(label="LoRA4", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            flux_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
                        with gr.Row():
                            flux_lora5 = gr.Dropdown(label="LoRA5", choices=flux_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            flux_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
            flux_run_button = gr.Button(value="Submit", variant="primary")
        with gr.Tab("SD 3.5"):
            with gr.Group():
                sd35_presets = gr.Radio(label="Presets", choices=list(sd35_preset_dict.keys()), value=list(sd35_preset_dict.keys())[0])
                sd35_mtype = gr.Textbox(value="SD 3.5", visible=False)
                sd35_dtype = gr.Radio(label="Output data type", choices=get_dtypes(), value="bf16")
                sd35_base_repo = gr.Dropdown(label="Base repo ID", choices=SD35_BASE_REPOS, value=SD35_BASE_REPOS[0], allow_custom_value=True, visible=True)
                with gr.Accordion("Advanced settings", open=False):
                    with gr.Row():
                        sd35_vae = gr.Dropdown(label="VAE", choices=sd35_vaes, value="", allow_custom_value=True)
                        sd35_scheduler = gr.Dropdown(label="Scheduler (Sampler)", choices=[""], value="", visible=False)
                    with gr.Row():
                        sd35_clip = gr.Dropdown(label="CLIP", choices=clips, value="", allow_custom_value=True)
                        sd35_t5 = gr.Dropdown(label="T5", choices=t5s, value="", allow_custom_value=True)
                    with gr.Column():
                        with gr.Row():
                            sd35_lora1 = gr.Dropdown(label="LoRA1", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd35_lora1s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA1 weight scale")
                        with gr.Row():
                            sd35_lora2 = gr.Dropdown(label="LoRA2", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd35_lora2s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA2 weight scale")
                        with gr.Row():
                            sd35_lora3 = gr.Dropdown(label="LoRA3", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd35_lora3s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA3 weight scale")
                        with gr.Row():
                            sd35_lora4 = gr.Dropdown(label="LoRA4", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd35_lora4s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA4 weight scale")
                        with gr.Row():
                            sd35_lora5 = gr.Dropdown(label="LoRA5", choices=sd35_loras, value="", allow_custom_value=True, min_width=320, scale=2)
                            sd35_lora5s = gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label="LoRA5 weight scale")
            sd35_run_button = gr.Button(value="Submit", variant="primary")
        adv_args = gr.Textbox(label="Advanced arguments", value="", visible=False)
        with gr.Group():
            repo_urls = gr.CheckboxGroup(visible=False, choices=[], value=[])
            output_md = gr.Markdown(label="Output", value="<br><br>", elem_classes="result")
            clear_button = gr.Button(value="Clear Output", variant="secondary")
        gr.DuplicateButton(value="Duplicate Space")

    gr.Markdown("This webui was redesigned with ❤ by [theNeofr](https://huggingface.co/theNeofr)")
    gr.on(
        triggers=[sdxl_run_button.click],
        fn=convert_url_to_diffusers_repo,
        inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
                sdxl_dtype, sdxl_vae, sdxl_clip, flux_t5, sdxl_scheduler, sd15_ema, sd15_isize, sd15_sc, flux_base_repo, sdxl_mtype,
                sdxl_lora1, sdxl_lora1s, sdxl_lora2, sdxl_lora2s, sdxl_lora3, sdxl_lora3s, sdxl_lora4, sdxl_lora4s, sdxl_lora5, sdxl_lora5s, adv_args],
        outputs=[repo_urls, output_md],
    )
    sdxl_presets.change(
        fn=sdxl_set_presets,
        inputs=[sdxl_presets],
        outputs=[sdxl_dtype, sdxl_vae, sdxl_scheduler, sdxl_lora1, sdxl_lora1s, sdxl_lora2, sdxl_lora2s, sdxl_lora3, sdxl_lora3s,
                 sdxl_lora4, sdxl_lora4s, sdxl_lora5, sdxl_lora5s],
        queue=False,
    )
    gr.on(
        triggers=[sd15_run_button.click],
        fn=convert_url_to_diffusers_repo,
        inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
                sd15_dtype, sd15_vae, sd15_clip, flux_t5, sd15_scheduler, sd15_ema, sd15_isize, sd15_sc, flux_base_repo, sd15_mtype,
                sd15_lora1, sd15_lora1s, sd15_lora2, sd15_lora2s, sd15_lora3, sd15_lora3s, sd15_lora4, sd15_lora4s, sd15_lora5, sd15_lora5s, adv_args],
        outputs=[repo_urls, output_md],
    )
    sd15_presets.change(
        fn=sd15_set_presets,
        inputs=[sd15_presets],
        outputs=[sd15_dtype, sd15_vae, sd15_scheduler, sd15_lora1, sd15_lora1s, sd15_lora2, sd15_lora2s, sd15_lora3, sd15_lora3s,
                 sd15_lora4, sd15_lora4s, sd15_lora5, sd15_lora5s, sd15_ema],
        queue=False,
    )
    gr.on(
        triggers=[flux_run_button.click],
        fn=convert_url_to_diffusers_repo,
        inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
                flux_dtype, flux_vae, flux_clip, flux_t5, flux_scheduler, sd15_ema, sd15_isize, sd15_sc, flux_base_repo, flux_mtype,
                flux_lora1, flux_lora1s, flux_lora2, flux_lora2s, flux_lora3, flux_lora3s, flux_lora4, flux_lora4s, flux_lora5, flux_lora5s, adv_args],
        outputs=[repo_urls, output_md],
    )
    flux_presets.change(
        fn=flux_set_presets,
        inputs=[flux_presets],
        outputs=[flux_dtype, flux_vae, flux_scheduler, flux_lora1, flux_lora1s, flux_lora2, flux_lora2s, flux_lora3, flux_lora3s,
                 flux_lora4, flux_lora4s, flux_lora5, flux_lora5s, flux_base_repo],
        queue=False,
    )
    gr.on(
        triggers=[sd35_run_button.click],
        fn=convert_url_to_diffusers_repo,
        inputs=[dl_url, hf_user, hf_repo, hf_token, civitai_key, is_private, gated, is_overwrite, is_pr, is_upload_sf, repo_urls,
                sd35_dtype, sd35_vae, sd35_clip, sd35_t5, sd35_scheduler, sd15_ema, sd15_isize, sd15_sc, sd35_base_repo, sd35_mtype,
                sd35_lora1, sd35_lora1s, sd35_lora2, sd35_lora2s, sd35_lora3, sd35_lora3s, sd35_lora4, sd35_lora4s, sd35_lora5, sd35_lora5s, adv_args],
        outputs=[repo_urls, output_md],
    )
    sd35_presets.change(
        fn=sd35_set_presets,
        inputs=[sd35_presets],
        outputs=[sd35_dtype, sd35_vae, sd35_scheduler, sd35_lora1, sd35_lora1s, sd35_lora2, sd35_lora2s, sd35_lora3, sd35_lora3s,
                 sd35_lora4, sd35_lora4s, sd35_lora5, sd35_lora5s, sd35_base_repo],
        queue=False,
    )
    clear_button.click(lambda: ([], "<br><br>"), None, [repo_urls, output_md], queue=False, show_api=False)

demo.queue()
demo.launch(ssr_mode=False)