Transformers
Inference Endpoints
File size: 28,388 Bytes
2d1ecea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "##~   WIDGET CODE | BY: ANXETY   ~##\n",
        "\n",
        "import os\n",
        "import json\n",
        "import time\n",
        "import ipywidgets as widgets\n",
        "from ipywidgets import widgets, Layout, Label, Button, VBox, HBox\n",
        "from IPython.display import display, HTML, Javascript, clear_output\n",
        "\n",
        "\n",
        "#  ================= DETECT ENV =================\n",
        "def detect_environment():\n",
        "    free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
        "    environments = {\n",
        "        'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
        "        'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
        "    }\n",
        "\n",
        "    for env_var, (environment, path) in environments.items():\n",
        "        if env_var in os.environ:\n",
        "            return environment, path, free_plan\n",
        "\n",
        "env, root_path, free_plan = detect_environment()\n",
        "webui_path = f\"{root_path}/sdw\"\n",
        "\n",
        "!mkdir -p {root_path}\n",
        "#  ----------------------------------------------\n",
        "\n",
        "\n",
        "# ==================== CSS JS ====================\n",
        "# custom background images V1.5\n",
        "import argparse\n",
        "parser = argparse.ArgumentParser(description='This script processes an background image.')\n",
        "parser.add_argument('-i', '--image', type=str, help='URL of the image to process', metavar='')\n",
        "parser.add_argument('-o', '--opacity', type=float, help='Opacity level for the image, between 0 and 1', metavar='', default=0.3)\n",
        "parser.add_argument('-b', '--blur', type=str, help='Blur level for the image', metavar='', default=0)\n",
        "parser.add_argument('-y', type=int, help='Y coordinate for the image in px', metavar='', default=0)\n",
        "parser.add_argument('-x', type=int, help='X coordinate for the image in px', metavar='', default=0)\n",
        "parser.add_argument('-s', '--scale', type=int, help='Scale image in %%', metavar='', default=100)\n",
        "parser.add_argument('-m', '--mode',action='store_true', help='Removes repetitive image tiles')\n",
        "parser.add_argument('-t', '--transparent', action='store_true', help='Makes input/selection fields 35%% more transparent')\n",
        "parser.add_argument('-bf', '--blur-fields', type=str, help='Background blur level for input/selection fields', metavar='', default=2)\n",
        "args = parser.parse_args()\n",
        "\"\"\"---\"\"\"\n",
        "url_img = args.image\n",
        "opacity_img = args.opacity\n",
        "blur_img = args.blur\n",
        "y_img = args.y\n",
        "x_img = args.x\n",
        "scale_img = args.scale\n",
        "blur_fields = args.blur_fields\n",
        "\n",
        "## ---\n",
        "\"\"\" WTF KAGGLE - WHAT THE FUCK IS THE DIFFERENCE OF 35 PIXELS!?!?!? \"\"\"\n",
        "fix_heigh_img = \"-810px\" if env == \"Kaggle\" else \"-775px\"\n",
        "\n",
        "\"\"\" transperent fields \"\"\"\n",
        "t_bg_alpha = \"1\" if not args.transparent else \"0.65\"\n",
        "\n",
        "\"\"\" mode img - repeats \"\"\"\n",
        "mode_img = \"repeat\" if not args.mode else \"no-repeat\"\n",
        "## ---\n",
        "\n",
        "container_background = f'''\n",
        "<style>\n",
        ":root {{\n",
        "  /* for background container*/\n",
        "  --img_background: url({url_img});\n",
        "  --img_opacity: {opacity_img};\n",
        "  --img_blur: {blur_img}px;\n",
        "  --image_y: {y_img}px;\n",
        "  --image_x: {x_img}px;\n",
        "  --img_scale: {scale_img}%;\n",
        "  --img_mode: {mode_img};\n",
        "  --img_height_dif: {fix_heigh_img};\n",
        "\n",
        "  /* for fields */\n",
        "  --bg-field-color: rgba(28, 28, 28, {t_bg_alpha}); /* -> #1c1c1c */\n",
        "  --bg-field-color-hover: rgba(38, 38, 38, {t_bg_alpha}); /* -> #262626; */\n",
        "  --bg-field-blur-level: {blur_fields}px;\n",
        "}}\n",
        "'''\n",
        "\n",
        "display(HTML(container_background))\n",
        "# ---\n",
        "\n",
        "CSS = '''\n",
        "<style>\n",
        "/* General Styles */\n",
        ".header {\n",
        "    font-family: cursive;\n",
        "    font-size: 20px;\n",
        "    font-weight: bold;\n",
        "    color: #ff8cee;\n",
        "    margin-bottom: 15px;\n",
        "    user-select: none;\n",
        "    cursor: default;\n",
        "    display: inline-block;\n",
        "}\n",
        "\n",
        "hr {\n",
        "    border-color: grey;\n",
        "    background-color: grey;\n",
        "    opacity: 0.25;\n",
        "}\n",
        "\n",
        "a {\n",
        "  text-decoration: none;\n",
        "  color: inherit;\n",
        "}\n",
        "\n",
        "\n",
        "/* Container style */\n",
        "\n",
        ".container {\n",
        "    position: relative;\n",
        "    background-color: #232323;\n",
        "    width: 1080px;\n",
        "    padding: 10px 15px;\n",
        "    border-radius: 15px;\n",
        "    box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
        "    margin-bottom: 5px;\n",
        "    overflow: hidden;\n",
        "}\n",
        "\n",
        ".container::after {\n",
        "    position: absolute;\n",
        "    top: 5px;\n",
        "    right: 10px;\n",
        "    content: \"ANXETY\";\n",
        "    font-weight: bold;\n",
        "    font-size: 24px;\n",
        "    color: rgba(0, 0, 0, 0.2);\n",
        "}\n",
        "\n",
        "/* background img */\n",
        ".container::before {\n",
        "  content: \"\";\n",
        "  position: absolute;\n",
        "  top: 0;\n",
        "  left: 0;\n",
        "  right: 0;\n",
        "  bottom: 0;\n",
        "  background-image: var(--img_background);\n",
        "  background-size: var(--img_scale);\n",
        "  background-repeat: var(--img_mode);\n",
        "  opacity: var(--img_opacity);\n",
        "  mix-blend-mode: screen;\n",
        "  pointer-events: none;\n",
        "  filter: blur(var(--img_blur));\n",
        "  z-index: -1;\n",
        "}\n",
        "\n",
        ".image_1::before {\n",
        "  background-position: var(--image_x) calc(-120px - var(--image_y));\n",
        "}\n",
        ".image_2::before {\n",
        "  background-position: var(--image_x) calc(-290px - var(--image_y));\n",
        "}\n",
        ".image_3::before {\n",
        "  background-position: var(--image_x) calc(-430px - var(--image_y));\n",
        "}\n",
        ".image_4::before {\n",
        "  background-position: var(--image_x) calc(var(--img_height_dif) - var(--image_y));\n",
        "}\n",
        "\n",
        ".container_custom_downlad {\n",
        "    height: 55px;\n",
        "    transition: all 0.5s;\n",
        "}\n",
        "\n",
        ".container_custom_downlad.expanded {\n",
        "    height: 270px;\n",
        "}\n",
        "\n",
        "\n",
        "/* Element text style */\n",
        "\n",
        ".widget-html,\n",
        ".widget-button,\n",
        ".widget-text label,\n",
        ".widget-checkbox label,\n",
        ".widget-dropdown label,\n",
        ".widget-dropdown select,\n",
        ".widget-text input[type=\"text\"] {\n",
        "    font-family: cursive;\n",
        "    font-size: 14px;\n",
        "    color: white !important;\n",
        "    user-select: none;\n",
        "}\n",
        "\n",
        ".widget-text input[type=\"text\"]::placeholder {\n",
        "    color: grey;\n",
        "}\n",
        "\n",
        "\n",
        "/* Input field styles */\n",
        "\n",
        ".widget-dropdown select,\n",
        ".widget-text input[type=\"text\"] {\n",
        "    height: 30px;\n",
        "    background-color: var(--bg-field-color);\n",
        "    border: 1px solid #262626;\n",
        "    border-radius: 10px;\n",
        "    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
        "    transition: all 0.3s ease-in-out;\n",
        "    backdrop-filter: blur(var(--bg-field-blur-level));\n",
        "}\n",
        "\n",
        ".widget-dropdown select:focus,\n",
        ".widget-text input[type=\"text\"]:focus {\n",
        "    border-color: #006ee5;\n",
        "}\n",
        "\n",
        ".widget-dropdown select:hover,\n",
        ".widget-text input[type=\"text\"]:hover {\n",
        "    transform: scale(1.003);\n",
        "    background-color: var(--bg-field-color-hover);\n",
        "    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);\n",
        "}\n",
        "\n",
        ".widget-dropdown option {\n",
        "    background-color: #1c1c1c;\n",
        "}\n",
        "\n",
        "\n",
        "/* Slider Checkbox style */\n",
        "\n",
        ".widget-checkbox input[type=\"checkbox\"] {\n",
        "    appearance: none;\n",
        "    position: relative;\n",
        "    top: 4px; /* Why is he taller?! */\n",
        "    width: 40px;\n",
        "    height: 20px;\n",
        "    border: none;\n",
        "    border-radius: 10px;\n",
        "    background-color: #20b2aa;\n",
        "    cursor: pointer;\n",
        "    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);\n",
        "    transition: background-color 0.3s ease;\n",
        "}\n",
        ".widget-checkbox input[type=\"checkbox\"]:checked {\n",
        "    background-color: #2196F3;\n",
        "}\n",
        "\n",
        ".widget-checkbox input[type=\"checkbox\"]:before {\n",
        "    content: '';\n",
        "    position: absolute;\n",
        "    top: 50%;\n",
        "    left: 3px;\n",
        "    width: 16px;\n",
        "    height: 16px;\n",
        "    border-radius: inherit;\n",
        "    background-color: white;\n",
        "    box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);\n",
        "    transform: translateY(-50%);\n",
        "    transition: left 0.3s ease;\n",
        "}\n",
        ".widget-checkbox input[type=\"checkbox\"]:checked:before {\n",
        "    left: 21px;\n",
        "}\n",
        "\n",
        "\n",
        "/* Button styles */\n",
        "\n",
        ".button_save {\n",
        "    font-size: 15px;\n",
        "    font-weight: bold;\n",
        "    width: 120px;\n",
        "    height: 35px;\n",
        "    border-radius: 15px;\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
        "    background-size: 200% 200%;\n",
        "    background-position: left bottom;\n",
        "    transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
        "}\n",
        "\n",
        ".button_save:hover {\n",
        "    cursor: pointer;\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
        "    background-size: 200% 200%;\n",
        "    background-position: right bottom;\n",
        "    transform: translateY(1px);\n",
        "}\n",
        "\n",
        ".button_ngrok {\n",
        "    font-size: 12px;\n",
        "    height: 30px;\n",
        "    border-radius: 10px;\n",
        "    padding: 1px 12px;\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
        "    background-size: 200% 200%;\n",
        "    background-position: left bottom;\n",
        "    transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
        "    white-space: nowrap;\n",
        "}\n",
        "\n",
        ".button_ngrok:hover  {\n",
        "    cursor: pointer;\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, #1D94BB 90%);\n",
        "    background-size: 200% 200%;\n",
        "    background-position: right bottom;\n",
        "    transform: translateY(1px);\n",
        "}\n",
        "\n",
        ".button_save:active,\n",
        ".button_ngrok:active {\n",
        "    filter: brightness(0.75) !important;\n",
        "}\n",
        "\n",
        "/* Removes ugly stroke from widget buttons. */\n",
        ".jupyter-widgets.lm-Widget:focus {\n",
        "    outline: none;\n",
        "}\n",
        "\n",
        "\n",
        "/* Popup style of `INFO` window */\n",
        "\n",
        ".info {\n",
        "    position: absolute;\n",
        "    top: -5px;\n",
        "    right: 95px;\n",
        "    color: grey;\n",
        "    font-family: cursive;\n",
        "    font-size: 14px;\n",
        "    font-weight: normal;\n",
        "    user-select: none;\n",
        "    pointer-events: none;\n",
        "    opacity: 0;\n",
        "    transition: opacity 0.3s ease-in-out;\n",
        "    display: inline-block;\n",
        "}\n",
        "\n",
        ".popup {\n",
        "    position: absolute;\n",
        "    top: 120px;\n",
        "    z-index: 999;\n",
        "    width: auto;\n",
        "    padding: 10px;\n",
        "    text-align: center;\n",
        "    background-color: rgba(255, 255, 255, 0.05);\n",
        "    backdrop-filter: blur(20px);\n",
        "    border: 1px solid rgba(255, 255, 255, 0.45);\n",
        "    border-radius: 8px;\n",
        "    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);\n",
        "    opacity: 0;\n",
        "    color: #fff;\n",
        "    font-size: 16px;\n",
        "    font-family: cursive;\n",
        "    user-select: none;\n",
        "    cursor: default;\n",
        "    pointer-events: none;\n",
        "    transform: rotate(-5deg);\n",
        "    transition: top 0.3s ease-in-out, opacity 0.3s ease-in-out, transform 0.3s ease-in-out;\n",
        "}\n",
        "\n",
        ".sample {\n",
        "    display: inline-block;\n",
        "    margin-top: 25px;\n",
        "    padding: 10px 100px;\n",
        "    background-color: rgba(255, 255, 255, 0.2);\n",
        "    color: #c6e2ff;\n",
        "    border: 2px solid rgba(255, 255, 255, 0.2);\n",
        "    border-radius: 8px;\n",
        "    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2), inset 0 0 25px rgba(255, 255, 255, 0.2);\n",
        "}\n",
        "\n",
        ".info.showed {\n",
        "    opacity: 1;\n",
        "    pointer-events: auto;\n",
        "}\n",
        "\n",
        ".info:hover + .popup {\n",
        "    top: 35px;\n",
        "    opacity: 1;\n",
        "    pointer-events: initial;\n",
        "    transform: rotate(0deg);\n",
        "}\n",
        "\n",
        "\n",
        "/* Animation of elements */\n",
        "\n",
        ".container,\n",
        ".button_save {\n",
        "    animation-name: showedWidgets;\n",
        "    animation-duration: 1s;\n",
        "    animation-fill-mode: forwards;\n",
        "}\n",
        "\n",
        ".container.hide,\n",
        ".button_save.hide {\n",
        "    animation-name: hideWidgets;\n",
        "    animation-duration: 0.5s;\n",
        "    animation-fill-mode: forwards;\n",
        "}\n",
        "\n",
        "@keyframes showedWidgets {\n",
        "    0% {\n",
        "        transform: translate3d(-65%, 15%, 0) scale(0) rotate(15deg);\n",
        "        filter: blur(25px) grayscale(1) brightness(0.3);\n",
        "        opacity: 0;\n",
        "    }\n",
        "    100% {\n",
        "        transform: translate3d(0, 0, 0) scale(1) rotate(0deg);\n",
        "        filter: blur(0) grayscale(0) brightness(1);\n",
        "        opacity: 1;\n",
        "    }\n",
        "}\n",
        "\n",
        "@keyframes hideWidgets {\n",
        "    0% {\n",
        "        transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
        "        filter: blur(0) grayscale(0) brightness(1);\n",
        "        opacity: 1;\n",
        "    }\n",
        "    100% {\n",
        "        transform: translate3d(0, 5%, 0) scale(0.9) rotate3d(1, 0, 0, 90deg);\n",
        "        filter: blur(15px) grayscale(1) brightness(0.5);\n",
        "        opacity: 0;\n",
        "    }\n",
        "}\n",
        "</style>\n",
        "\n",
        "<!-- TOGGLE 'CustomDL' SCRIPT -->\n",
        "<script>\n",
        "function toggleContainer() {\n",
        "    let downloadContainer = document.querySelector('.container_custom_downlad');\n",
        "    let info = document.querySelector('.info');\n",
        "\n",
        "    downloadContainer.classList.toggle('expanded');\n",
        "    info.classList.toggle('showed');\n",
        "}\n",
        "</script>\n",
        "'''\n",
        "\n",
        "display(HTML(CSS))\n",
        "# ==================== CSS JS ====================\n",
        "\n",
        "\n",
        "# ==================== WIDGETS ====================\n",
        "# --- global widgets ---\n",
        "style = {'description_width': 'initial'}\n",
        "layout = widgets.Layout(min_width='1047px')\n",
        "\n",
        "HR = widgets.HTML('<hr>')\n",
        "\n",
        "# --- MODEL ---\n",
        "model_header = widgets.HTML('<div class=\"header\">Выбор Модели<div>')\n",
        "model_options = ['none',\n",
        "                 '1.Anime (by XpucT) + INP',\n",
        "                 '2.BluMix [Anime] [V7] + INP',\n",
        "                 '3.Cetus-Mix [Anime] [V4] + INP',\n",
        "                 '4.Counterfeit [Anime] [V3] + INP',\n",
        "                 '5.CuteColor [Anime] [V3]',\n",
        "                 '6.Dark-Sushi-Mix [Anime]',\n",
        "                 '7.Deliberate [Realism] [V6] + INP',\n",
        "                 '8.Meina-Mix [Anime] [V11] + INP',\n",
        "                 '9.Mix-Pro [Anime] [V4] + INP']\n",
        "# ---\n",
        "Model_widget = widgets.Dropdown(options=model_options, value='4.Counterfeit [Anime] [V3] + INP', description='Модель:', style=style, layout=layout)\n",
        "Model_Num_widget = widgets.Text(description='Номер Модели:', placeholder='Введите номера моделей для скачивания через запятую/пробел.', style=style, layout=layout)\n",
        "Inpainting_Model_widget = widgets.Checkbox(value=False, description='Inpainting Модели', style=style)\n",
        "\n",
        "''' Display Model'''\n",
        "all_model_box = widgets.VBox([model_header, Model_widget, Model_Num_widget, Inpainting_Model_widget]).add_class(\"container\").add_class(\"image_1\")\n",
        "display(all_model_box)\n",
        "\n",
        "# --- VAE ---\n",
        "vae_header = widgets.HTML('<div class=\"header\" >Выбор VAE</div>')\n",
        "vae_options = ['none',\n",
        "               '1.Anime.vae',\n",
        "               '2.Anything.vae',\n",
        "               '3.Blessed2.vae',\n",
        "               '4.ClearVae.vae',\n",
        "               '5.WD.vae']\n",
        "Vae_widget = widgets.Dropdown(options=vae_options, value='3.Blessed2.vae', description='Vae:', style=style, layout=layout)\n",
        "Vae_Num_widget = widgets.Text(description='Номер Vae:', placeholder='Введите номера vae для скачивания через запятую/пробел.', style=style, layout=layout)\n",
        "\n",
        "''' Display Vae'''\n",
        "all_vae_box= widgets.VBox([vae_header, Vae_widget, Vae_Num_widget]).add_class(\"container\").add_class(\"image_2\")\n",
        "display(all_vae_box)\n",
        "\n",
        "# --- ADDITIONAL ---\n",
        "additional_header = widgets.HTML('<div class=\"header\">Дополнительно</div>')\n",
        "latest_webui_widget = widgets.Checkbox(value=True, description='Обновить WebUI', style=style)\n",
        "latest_exstensions_widget = widgets.Checkbox(value=True, description='Обновить Расширения', style=style)\n",
        "detailed_download_widget = widgets.Dropdown(options=['off', 'on'], value='off', description='Подробная Загрузка:', style=style)\n",
        "latest_changes_widget = HBox([latest_webui_widget, latest_exstensions_widget, detailed_download_widget], layout=widgets.Layout(justify_content='space-between'))\n",
        "controlnet_options = ['none', 'ALL', '1.canny',\n",
        "                      '2.openpose', '3.depth',\n",
        "                      '4.normal_map', '5.mlsd',\n",
        "                      '6.lineart', '7.soft_edge',\n",
        "                      '8.scribble', '9.segmentation',\n",
        "                      '10.shuffle', '11.tile',\n",
        "                      '12.inpaint', '13.instruct_p2p']\n",
        "# ---\n",
        "controlnet_widget = widgets.Dropdown(options=controlnet_options, value='none', description='ControlNet:', style=style, layout=layout)\n",
        "controlnet_Num_widget = widgets.Text(description='Номер ControlNet:', placeholder='Введите номера моделей ControlNet для скачивания через запятую/пробел.', style=style, layout=layout)\n",
        "commit_hash_widget = widgets.Text(description='Commit Hash:', style=style, layout=layout)\n",
        "optional_huggingface_token_widget = widgets.Text(description='Токен HuggingFace:', style=style, layout=layout)\n",
        "ngrok_token_widget = widgets.Text(description='Токен Ngrok:', style=style, layout=widgets.Layout(width='1047px'))\n",
        "ngrock_button = widgets.HTML('<a href=\"https://dashboard.ngrok.com/get-started/your-authtoken\" target=\"_blank\">Получить Ngrok Токен</a>').add_class(\"button_ngrok\")\n",
        "ngrok_widget = widgets.HBox([ngrok_token_widget, ngrock_button], style=style, layout=layout)\n",
        "zrok_token_widget = widgets.Text(description='Zrok Token:', style=style, layout=widgets.Layout(width='1047px'))\n",
        "zrok_button = widgets.HTML('<a href=\"https://colab.research.google.com/drive/1d2sjWDJi_GYBUavrHSuQyHTDuLy36WpU\" target=\"_blank\">Зарегать Zrok Токен</a>').add_class(\"button_ngrok\")\n",
        "zrok_widget = widgets.HBox([zrok_token_widget, zrok_button], style=style, layout=layout)\n",
        "# ---\n",
        "commandline_arguments_options = \"--listen --enable-insecure-extension-access --theme dark --no-half-vae --disable-console-progressbars --xformers\"\n",
        "commandline_arguments_widget = widgets.Text(description='Аргументы:', value=commandline_arguments_options, style=style, layout=layout)\n",
        "\n",
        "''' Display Additional'''\n",
        "additional_widget_list = [additional_header, latest_changes_widget, HR, controlnet_widget, controlnet_Num_widget, commit_hash_widget, optional_huggingface_token_widget, ngrok_widget, zrok_widget, HR, commandline_arguments_widget]\n",
        "if free_plan and env == \"Google Colab\": # remove ngrok from colab\n",
        "    additional_widget_list.remove(ngrok_widget)\n",
        "# ```\n",
        "all_additional_box = widgets.VBox(additional_widget_list).add_class(\"container\").add_class(\"image_3\")\n",
        "display(all_additional_box)\n",
        "\n",
        "# --- CUSTOM DOWNLOAD ---\n",
        "custom_download_header_popup = widgets.HTML('''\n",
        "<style>\n",
        "/* Color */\n",
        ".sample_label {color: #dbafff;}\n",
        ".braces {color: #ffff00;}\n",
        ".extension {color: #eb934b;}\n",
        ".file_name {color: #ffffd8;}\n",
        "</style>\n",
        "\n",
        "<div class=\"header\" style=\"cursor: pointer;\" onclick=\"toggleContainer()\">Кастомная Загрузка</div>\n",
        "<!-- PopUp window -->\n",
        "<div class=\"info\" id=\"info_dl\">INFO</div>\n",
        "<div class=\"popup\">\n",
        "    Разделите несколько URL-адресов запятой/пробелом. Для <span class=\"file_name\">пользовательского имени</span> файла/расширения укажите его через <span class=\"braces\">[]</span>\n",
        "    после URL без пробелов.\n",
        "    <span style=\"color: #ff9999\">Для файлов обязательно укажите</span> - <span class=\"extension\">Расширение Файла.</span>\n",
        "    <div class=\"sample\">\n",
        "        <span class=\"sample_label\">Пример для Файла:</span>\n",
        "        https://civitai.com/api/download/models/229782<span class=\"braces\">[</span><span class=\"file_name\">Detailer</span><span class=\"extension\">.safetensors</span><span class=\"braces\">]</span>\n",
        "        <br>\n",
        "        <span class=\"sample_label\">Пример для Расширения:</span>\n",
        "        https://github.com/hako-mikan/sd-webui-regional-prompter<span class=\"braces\">[</span><span class=\"file_name\">Regional-Prompter</span><span class=\"braces\">]</span>\n",
        "    </div>\n",
        "</div>\n",
        "''')\n",
        "# ---\n",
        "Model_url_widget = widgets.Text(description='Model:', style=style, layout=layout)\n",
        "Vae_url_widget = widgets.Text(description='Vae:', style=style, layout=layout)\n",
        "LoRA_url_widget = widgets.Text(description='LoRa:', style=style, layout=layout)\n",
        "Embedding_url_widget = widgets.Text(description='Embedding:', style=style, layout=layout)\n",
        "Extensions_url_widget = widgets.Text(description='Extensions:', style=style, layout=layout)\n",
        "custom_file_urls_widget = widgets.Text(description='Файл (txt):', style=style, layout=layout)\n",
        "\n",
        "''' Display CustomDl'''\n",
        "all_custom_box = widgets.VBox([\n",
        "    custom_download_header_popup, Model_url_widget, Vae_url_widget, LoRA_url_widget, Embedding_url_widget, Extensions_url_widget, custom_file_urls_widget\n",
        "    ]).add_class(\"container\").add_class(\"image_4\").add_class(\"container_custom_downlad\")\n",
        "display(all_custom_box)\n",
        "\n",
        "# --- Save Button ---\n",
        "save_button = widgets.Button(description='Сохранить').add_class(\"button_save\")\n",
        "display(save_button)\n",
        "\n",
        "\n",
        "# ============ Load / Save - Settings V2 ============\n",
        "SETTINGS_FILE = f'{root_path}/settings.json'\n",
        "\n",
        "settings_keys = [\n",
        "    'Model', 'Model_Num', 'Inpainting_Model',\n",
        "    'Vae', 'Vae_Num',\n",
        "    'latest_webui', 'latest_exstensions', 'detailed_download',\n",
        "    'controlnet', 'controlnet_Num', 'commit_hash', 'optional_huggingface_token',\n",
        "    'ngrok_token', 'zrok_token', 'commandline_arguments',\n",
        "    'Model_url', 'Vae_url', 'LoRA_url', 'Embedding_url', 'Extensions_url', 'custom_file_urls'\n",
        "]\n",
        "\n",
        "def save_settings():\n",
        "    settings = {key: globals()[f\"{key}_widget\"].value for key in settings_keys}\n",
        "    with open(SETTINGS_FILE, 'w') as f:\n",
        "        json.dump(settings, f, indent=2)\n",
        "\n",
        "def load_settings():\n",
        "    if os.path.exists(SETTINGS_FILE):\n",
        "        with open(SETTINGS_FILE, 'r') as f:\n",
        "            settings = json.load(f)\n",
        "            for key in settings_keys:\n",
        "                globals()[f\"{key}_widget\"].value = settings.get(key)\n",
        "\n",
        "def save_data(button):\n",
        "    save_settings()\n",
        "\n",
        "    # --- uhh - hide... ---\n",
        "    widgets_list = [all_model_box, all_vae_box, all_additional_box, all_custom_box, save_button]\n",
        "    for widget in widgets_list:\n",
        "        widget.add_class(\"hide\")\n",
        "    time.sleep(0.5)\n",
        "\n",
        "    widgets.Widget.close_all()\n",
        "\n",
        "settings = load_settings()\n",
        "save_button.on_click(save_data)"
      ],
      "metadata": {
        "id": "2lJmbqrs3Mu8"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}