File size: 81,715 Bytes
0a05936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/0ktoo/Linaqruf-Difusion/blob/main/Linaqru_Diffusion_.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "<center>\n",
        "\n",
        "#<font color=\"#FFD700\">***LINAQRUF DIFFUSION***</font>\n",
        "\n",
        "*Hak cipta © 2023 oleh saya. Notebook ini adalah hasil modifikasi dari notebook milik linaqurf. Saya telah mendapatkan izin untuk melakukan modifikasi ini untuk keperluan pribadi(bukan komersil).\n",
        "kalian wajib mengikuti akun media sosial linaqruf untuk melihat karya-karya hebat lainnya.*\n"
      ],
      "metadata": {
        "id": "rA4rv1H4uMTP"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "##<font color=\"#7FFF00\">***1. MEMPERSIAPKAN DATA***</font>\n"
      ],
      "metadata": {
        "id": "fof1qg-QUyFv"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title ### <font color=\"#FFD700\">***Mempersiapkan Data Stable Diffusion***</font>\n",
        "import os\n",
        "import time\n",
        "import json\n",
        "import base64\n",
        "import shutil\n",
        "import subprocess\n",
        "import threading\n",
        "import sys\n",
        "from IPython.display import display, HTML\n",
        "from google.colab.output import eval_js\n",
        "from IPython.utils import capture\n",
        "from tqdm import tqdm\n",
        "\n",
        "python_version      = \".\".join(sys.version.split(\".\")[:2])\n",
        "colablib_path       = f\"/usr/local/lib/python{python_version}/dist-packages/colablib\"\n",
        "if not os.path.exists(colablib_path):\n",
        "    subprocess.run(['pip', 'install', 'git+https://github.com/Linaqruf/colablib'])\n",
        "\n",
        "from colablib.colored_print import cprint, print_line\n",
        "from colablib.utils import py_utils, config_utils, package_utils\n",
        "from colablib.utils.config_utils import pastebin_reader as read\n",
        "from colablib.utils.ubuntu_utils import ubuntu_deps\n",
        "from colablib.sd_models.downloader import aria2_download\n",
        "from colablib.utils.git_utils import update_repo, batch_update, validate_repo, reset_repo, patch_repo\n",
        "\n",
        "%store -r\n",
        "\n",
        "\n",
        "################################\n",
        "# COLAB ARGUMENTS GOES HERE\n",
        "################################\n",
        "\n",
        "#@markdown ### <font color=\"#00CED\">***Sambungkan ke Google Drive***</font>\n",
        "mount_drive         = False  # @param {type:'boolean'}\n",
        "output_drive_folder = \"cagliostro-colab-ui/outputs\" #@param {type:'string'}\n",
        "#@markdown ### <font color=\"#00CED\">***Repo Config/Pilih Jenis UI***</font>\n",
        "repo_type           = \"AUTOMATIC1111\" #@param [\"AUTOMATIC1111\", \"AUTOMATIC1111-Dev\", \"Anapnoe\"]\n",
        "update_webui        = False  # @param {type:'boolean'}\n",
        "update_extensions   = False  # @param {type:'boolean'}\n",
        "commit_hash         = \"\"  # @param {type:'string'}\n",
        "dpmpp_2m_v2_patch   = True  # @param {type:'boolean'}\n",
        "#@markdown ### <font color=\"#00CED\">***Optimization Config***</font>\n",
        "# @markdown > Tidak disarankan untuk `Mencentang` di bawah ini jika Anda memiliki langganan Colab Pro.\n",
        "ram_alloc_patch     = True  # @param {type:'boolean'}\n",
        "colab_optimizations = True  # @param {type:'boolean'}\n",
        "#@markdown > Centang `mobile_optimizations` Jika Kalian Pengguna Handphone/Mobile\n",
        "mobile_optimizations = True  # @param {type:'boolean'}\n",
        "\n",
        "################################\n",
        "# DIRECTORY CONFIG\n",
        "################################\n",
        "\n",
        "# VAR\n",
        "voldemort, voldy = read(\"kq6ZmHFU\")[:2]\n",
        "\n",
        "# ROOT DIR\n",
        "root_dir            = \"/content\"\n",
        "drive_dir           = os.path.join(root_dir, \"drive\", \"MyDrive\")\n",
        "repo_dir            = os.path.join(root_dir, \"cagliostro-colab-ui\")\n",
        "tmp_dir             = os.path.join(root_dir, \"tmp\")\n",
        "patches_dir         = os.path.join(root_dir, \"patches\")\n",
        "deps_dir            = os.path.join(root_dir, \"deps\")\n",
        "fused_dir           = os.path.join(root_dir, \"fused\")\n",
        "\n",
        "# REPO DIR\n",
        "models_dir          = os.path.join(repo_dir, \"models\", \"Stable-diffusion\")\n",
        "vaes_dir            = os.path.join(repo_dir, \"models\", \"VAE\")\n",
        "hypernetworks_dir   = os.path.join(repo_dir, \"models\", \"hypernetworks\")\n",
        "lora_dir            = os.path.join(repo_dir, \"models\", \"Lora\")\n",
        "control_dir         = os.path.join(repo_dir, \"models\", \"ControlNet\")\n",
        "esrgan_dir          = os.path.join(repo_dir, \"models\", \"ESRGAN\")\n",
        "embeddings_dir      = os.path.join(repo_dir, \"embeddings\")\n",
        "extensions_dir      = os.path.join(repo_dir, \"extensions\")\n",
        "annotator_dir       = os.path.join(extensions_dir, f\"{voldy}-controlnet\", \"annotator\")\n",
        "output_subdir       = [\"txt2img-images\", \"img2img-images\", \"extras-images\", \"txt2img-grids\", \"img2img-grids\"]\n",
        "\n",
        "# CONFIG\n",
        "config_file         = os.path.join(repo_dir, \"config.json\")\n",
        "ui_config_file      = os.path.join(repo_dir, \"ui-config.json\")\n",
        "style_path          = os.path.join(repo_dir, \"style.css\")\n",
        "download_list       = os.path.join(root_dir, \"download_list.txt\")\n",
        "\n",
        "\n",
        "################################\n",
        "# REPO TYPE CONFIG\n",
        "################################\n",
        "\n",
        "repo_type_lower = repo_type.lower()\n",
        "\n",
        "package_url = [\n",
        "    f\"https://huggingface.co/Linaqruf/fast-repo/resolve/main/{repo_type_lower}-webui.tar.lz4\",\n",
        "    f\"https://huggingface.co/Linaqruf/fast-repo/resolve/main/{repo_type_lower}-webui-deps.tar.lz4\",\n",
        "    f\"https://huggingface.co/Linaqruf/fast-repo/resolve/main/{repo_type_lower}-webui-cache.tar.lz4\",\n",
        "]\n",
        "\n",
        "repo_type_to_repo_name = {\n",
        "    \"anapnoe\"           : f\"anapnoe/{voldemort}-ux\",\n",
        "    \"automatic1111\"     : f\"AUTOMATIC1111/{voldemort}\",\n",
        "    \"automatic1111-dev\" : f\"AUTOMATIC1111/{voldemort}\",\n",
        "}\n",
        "\n",
        "branch_type_to_branch = {\n",
        "    \"automatic1111\"     : \"master\",\n",
        "    \"automatic1111-dev\" : \"dev\"\n",
        "}\n",
        "\n",
        "with capture.capture_output() as cap:\n",
        "    for dir in  [\"root_dir\", \"fused_dir\", \"repo_dir\", \"tmp_dir\", \"models_dir\", \"vaes_dir\", \"hypernetworks_dir\", \"embeddings_dir\", \"extensions_dir\", \"lora_dir\", \"control_dir\", \"esrgan_dir\"]:\n",
        "        %store {dir}\n",
        "    for file in [\"config_file\", \"ui_config_file\", \"style_path\", \"download_list\"]:\n",
        "        %store {file}\n",
        "    for var in  [\"voldemort\", \"voldy\"]:\n",
        "        %store {var}\n",
        "    del cap\n",
        "\n",
        "def mount_func(directory):\n",
        "    output_dir = os.path.join(repo_dir, \"outputs\")\n",
        "\n",
        "    if mount_drive:\n",
        "        print_line(80, color=\"green\")\n",
        "        if not os.path.exists(directory):\n",
        "            from google.colab import drive\n",
        "            cprint(\"Mounting google drive...\", color=\"green\", reset=False)\n",
        "            drive.mount(os.path.dirname(directory))\n",
        "        output_dir  = os.path.join(directory, output_drive_folder)\n",
        "        cprint(\"Set default output path to:\", output_dir, color=\"green\")\n",
        "\n",
        "    return output_dir\n",
        "\n",
        "def setup_directories():\n",
        "    for dir in [fused_dir, models_dir, vaes_dir,\n",
        "                hypernetworks_dir, embeddings_dir, extensions_dir,\n",
        "                lora_dir, control_dir, esrgan_dir]:\n",
        "        os.makedirs(dir, exist_ok=True)\n",
        "\n",
        "def pre_download(dir, urls, desc, overwrite=False):\n",
        "    gpu_info              = py_utils.get_gpu_info()\n",
        "    version               = py_utils.get_python_version().split()[0]\n",
        "    major_minor           = \".\".join(version.split(\".\")[:2])\n",
        "    xformers_version      = \"0.0.20\"\n",
        "    insightface_version   = \"0.7.3\"\n",
        "    python_path           = f\"/usr/local/lib/python{major_minor}/dist-packages/\"\n",
        "    ffmpy_path            = os.path.join(python_path, \"ffmpy-0.3.0.dist-info\")\n",
        "\n",
        "    for url in tqdm(urls, desc=desc):\n",
        "        filename  = py_utils.get_filename(url)\n",
        "        aria2_download(dir, filename, url, quiet=True)\n",
        "        if filename == f\"{repo_type.lower()}-webui-deps.tar.lz4\":\n",
        "            package_utils.extract_package(filename, python_path, overwrite=True)\n",
        "        else:\n",
        "            package_utils.extract_package(filename, \"/\", overwrite=overwrite)\n",
        "        os.remove(filename)\n",
        "\n",
        "    if os.path.exists(ffmpy_path):\n",
        "        shutil.rmtree(ffmpy_path)\n",
        "\n",
        "    if not 'T4' in gpu_info:\n",
        "        subprocess.run(['pip', 'uninstall', '-y', 'xformers'], check=True)\n",
        "        subprocess.run(['pip', 'install', '-q', f'xformers=={xformers_version}'], check=True)\n",
        "        subprocess.run(['pip', 'install', '-q', f'insightface=={insightface_version}'], check=True)\n",
        "\n",
        "def install_dependencies():\n",
        "    ubuntu_deps_url = \"https://huggingface.co/Linaqruf/fast-repo/resolve/main/ubuntu-deps.zip\"\n",
        "    ram_patch_url   = \"https://huggingface.co/Linaqruf/fast-repo/resolve/main/ram_patch.zip\"\n",
        "\n",
        "    ubuntu_deps(ubuntu_deps_url, deps_dir, cprint(\"Installing ubuntu dependencies\", color=\"green\", tqdm_desc=True))\n",
        "\n",
        "    if ram_alloc_patch:\n",
        "        subprocess.run([\"apt\", \"install\",  'libunwind8-dev', \"-y\"], check=True)\n",
        "        ubuntu_deps(ram_patch_url, deps_dir, cprint(\"Installing RAM allocation patch\", color=\"green\", tqdm_desc=True))\n",
        "\n",
        "def install_webui(repo_dir, desc):\n",
        "    try:\n",
        "        if not os.path.exists(repo_dir):\n",
        "            pre_download(root_dir, package_url, desc, overwrite=False)\n",
        "            return\n",
        "\n",
        "        repo_name, _, current_branch = validate_repo(repo_dir)\n",
        "        repo_type_lower = repo_type.lower()\n",
        "        expected_repo_name = repo_type_to_repo_name.get(repo_type_lower)\n",
        "\n",
        "        if expected_repo_name == repo_name:\n",
        "            expected_branch = branch_type_to_branch.get(repo_type_lower)\n",
        "            if expected_branch is None or expected_branch == current_branch:\n",
        "                cprint(f\"'{repo_name}' {current_branch if expected_branch else ''} already installed, skipping...\", color=\"green\")\n",
        "                return\n",
        "\n",
        "        cprint(f\"Another repository exist. Uninstall '{repo_name}'...\", color=\"green\")\n",
        "        shutil.rmtree(repo_dir)\n",
        "        pre_download(root_dir, package_url, desc)\n",
        "    except Exception as e:\n",
        "        cprint(f\"An error occurred: {e}\", color=\"green\")\n",
        "\n",
        "def configure_output_path(config_path, output_dir, output_subdir):\n",
        "    config = config_utils.read_config(config_path)\n",
        "    config_updates = {\n",
        "        \"outdir_txt2img_samples\"  : os.path.join(output_dir, output_subdir[0]),\n",
        "        \"outdir_img2img_samples\"  : os.path.join(output_dir, output_subdir[1]),\n",
        "        \"outdir_extras_samples\"   : os.path.join(output_dir, output_subdir[2]),\n",
        "        \"outdir_txt2img_grids\"    : os.path.join(output_dir, output_subdir[3]),\n",
        "        \"outdir_img2img_grids\"    : os.path.join(output_dir, output_subdir[4])\n",
        "    }\n",
        "\n",
        "    config.update(config_updates)\n",
        "    config_utils.write_config(config_path, config)\n",
        "\n",
        "    for dir in output_subdir:\n",
        "        os.makedirs(os.path.join(output_dir, dir), exist_ok=True)\n",
        "\n",
        "def prepare_environment():\n",
        "    cprint(f\"Preparing environment...\", color=\"green\")\n",
        "\n",
        "    os.environ[\"colab_url\"]               = eval_js(\"google.colab.kernel.proxyPort(7860, {'cache': false})\")\n",
        "    os.environ[\"TF_CPP_MIN_LOG_LEVEL\"]    = \"3\"\n",
        "    os.environ[\"SAFETENSORS_FAST_GPU\"]    = \"1\"\n",
        "    os.environ['PYTORCH_CUDA_ALLOC_CONF'] = \"garbage_collection_threshold:0.9,max_split_size_mb:512\"\n",
        "    os.environ[\"PYTHONWARNINGS\"]          = \"ignore\"\n",
        "\n",
        "def play_audio(url):\n",
        "    display(HTML(f''))\n",
        "\n",
        "def main():\n",
        "    global output_dir\n",
        "\n",
        "    os.chdir(root_dir)\n",
        "    start_time = time.time()\n",
        "\n",
        "    output_dir = mount_func(drive_dir)\n",
        "\n",
        "    gpu_info    = py_utils.get_gpu_info(get_gpu_name=True)\n",
        "    python_info = py_utils.get_python_version()\n",
        "    torch_info  = py_utils.get_torch_version()\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "    cprint(f\" [-] Current GPU:\", gpu_info, color=\"flat_yellow\")\n",
        "    cprint(f\" [-] Python\", python_info, color=\"flat_yellow\")\n",
        "    cprint(f\" [-] Torch\", torch_info, color=\"flat_yellow\")\n",
        "    print_line(80, color=\"green\")\n",
        "\n",
        "    install_dependencies()\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "    install_webui(repo_dir, cprint(f\"Unpacking {repo_type} Webui\", color=\"green\", tqdm_desc=True))\n",
        "    prepare_environment()\n",
        "\n",
        "    configure_output_path(config_file, output_dir, output_subdir)\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "    if update_webui and not commit_hash:\n",
        "        update_repo(cwd=repo_dir, args=\"-X theirs --rebase --autostash\")\n",
        "\n",
        "    setup_directories ()\n",
        "\n",
        "    if commit_hash:\n",
        "        reset_repo(repo_dir, commit_hash)\n",
        "\n",
        "    repo_name, current_commit_hash, current_branch = validate_repo(repo_dir)\n",
        "    cprint(f\"Using '{repo_name}' repository...\", color=\"green\")\n",
        "    cprint(f\"Branch: {current_branch}, Commit hash: {current_commit_hash}\", color=\"green\")\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "    cprint(\"Hotfixes and Optimization:\", color=\"green\")\n",
        "\n",
        "    if dpmpp_2m_v2_patch:\n",
        "        dpmpp_2m_v2_url  = \"https://gist.githubusercontent.com/Linaqruf/514d40676e97a70ffc3a2451bbf51555/raw/3fa447ebfac6b98a25485374b70447f848267589/01-add-DPMPP-2M-V2.patch\"\n",
        "        patch_repo(url=dpmpp_2m_v2_url, dir=patches_dir, cwd=repo_dir, whitespace_fix=True, quiet=True)\n",
        "        shutil.rmtree(patches_dir)\n",
        "        cprint(\" [-] DPM++ 2m V2 and DPM++ 2m Karras V2 patch done!\", color=\"green\")\n",
        "\n",
        "    if ram_alloc_patch:\n",
        "        os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n",
        "        cprint(\" [-] Camenduru's ram allocation patch done!\", color=\"green\")\n",
        "\n",
        "    if colab_optimizations:\n",
        "        lowram_patch_url = \"https://raw.githubusercontent.com/ddPn08/automatic1111-colab/main/patches/stablediffusion-lowram.patch\"\n",
        "        stable_diffusion_repo_dir = os.path.join(repo_dir, \"repositories/stable-diffusion-stability-ai\")\n",
        "        patch_repo(url=lowram_patch_url, dir=patches_dir, cwd=stable_diffusion_repo_dir, quiet=True)\n",
        "        shutil.rmtree(patches_dir)\n",
        "        cprint(\" [-] Stable Diffusion V2.x lowram patch done!\", color=\"green\")\n",
        "\n",
        "        subprocess.run([\"sed\", \"-i\", f\"s@os.path.splitext(checkpoint_file)@os.path.splitext(checkpoint_file); map_location='cuda'@\", os.path.join(repo_dir, \"modules\", \"sd_models.py\")])\n",
        "        subprocess.run([\"sed\", \"-i\", f\"s@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@\", os.path.join(repo_dir, \"webui.py\")])\n",
        "        subprocess.run([\"sed\", \"-i\", f\"s@map_location='cpu'@map_location='cuda'@\", os.path.join(repo_dir, \"modules\", \"extras.py\")])\n",
        "        cprint(\" [-] TheLastben's colab optimization done!\", color=\"green\")\n",
        "\n",
        "    if mobile_optimizations:\n",
        "        audio_url    = \"https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a\"\n",
        "        audio_thread = threading.Thread(target=play_audio, args=(audio_url,))\n",
        "        audio_thread.start()\n",
        "        cprint(\" [-] Mobile Optimization done!\", color=\"green\")\n",
        "\n",
        "    if \"anapnoe\" in repo_name and \"9931e861dfb128735c4a928a7beb5b5c0af30593\" in current_commit_hash:\n",
        "        hires_prompt_fix = \"https://gist.githubusercontent.com/Linaqruf/8fef456d53604f8c3bcd16722ea7d2f6/raw/a3382087c6e32f9a171f4b5e8aeb572a61682801/0001-Add-New-Label-for-Hires-Prompt.patch\"\n",
        "        patch_repo(url=hires_prompt_fix, dir=patches_dir, cwd=repo_dir, whitespace_fix=True, quiet=True)\n",
        "        shutil.rmtree(patches_dir)\n",
        "        cprint(\" [-] Hires Prompt patch done!\", color=\"green\")\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "\n",
        "    if update_extensions:\n",
        "        batch_update(fetch=True, directory=extensions_dir, desc=cprint(f\"Updating extensions\", color=\"green\", tqdm_desc=True))\n",
        "\n",
        "    if not os.path.exists(download_list):\n",
        "        download_list_url = \"https://raw.githubusercontent.com/Linaqruf/sd-notebook-collection/main/config/download_list.txt\"\n",
        "        aria2_download(os.path.dirname(download_list), os.path.basename(download_list), download_list_url, quiet=True)\n",
        "\n",
        "    elapsed_time = py_utils.calculate_elapsed_time(start_time)\n",
        "    print_line(80, color=\"green\")\n",
        "    cprint(f\"Finished installation. Took {elapsed_time}.\", color=\"flat_yellow\")\n",
        "    cprint(\"All is done! Go to the next step.\", color=\"flat_yellow\")\n",
        "    print_line(80, color=\"green\")\n",
        "\n",
        "main()"
      ],
      "metadata": {
        "id": "dMeAsZmWUyFx"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "##<font color=\"#7FFF00\">***2. MEMPERSIAPKAN BAHAN***</font>\n"
      ],
      "metadata": {
        "id": "v9md6r0tG0jQ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "import time\n",
        "import base64\n",
        "from datetime import timedelta\n",
        "from IPython.utils import capture\n",
        "from tqdm import tqdm\n",
        "\n",
        "os.chdir(root_dir)\n",
        "\n",
        "\n",
        "#@title ### <font color=\"#FFD700\">**_PILIH MODEL DAN VAE_**</font>\n",
        "\n",
        "#@markdown <font color=\"#00CED1\">**Pilih Model yang akan di gunakan di stable diffusion**:</font>\n",
        "\n",
        "#@markdown <font color=\"#CC3E3E\">**JANGAN CENTANG SEMUA!!!**</font>\n",
        "\n",
        "#@markdown (hapus centang model yang tidak dipakai)\n",
        "anylora = False  # @param {type: 'boolean'}\n",
        "Majic_Mix_V5          = True  # @param {type: 'boolean'}\n",
        "Chilloutmix = False  # @param {type: 'boolean'}\n",
        "PerfectWorld = False #@param {type:\"boolean\"}\n",
        "Figure = False #@param {type:\"boolean\"}\n",
        "RevAnimated = False #@param {type:\"boolean\"}\n",
        "CyberReal = False #@param {type:\"boolean\"}\n",
        "MarvelWhatIf = False #@param {type:\"boolean\"}\n",
        "\n",
        "\n",
        "downloadModels = []\n",
        "\n",
        "\n",
        "models = [\n",
        "    (\"anylora\", \"https://huggingface.co/Lykon/AnyLoRA/resolve/main/AnyLoRA_noVae_fp16.safetensors\"),\n",
        "    (\"Majic_Mix_V5\", \"https://huggingface.co/Linaqruf/stolen/resolve/main/fp16/majicmixRealistic_v5.safetensors\"),\n",
        "    (\"Chilloutmix\", \"https://huggingface.co/AnonPerson/ChilloutMix/resolve/main/ChilloutMix-ni-fp16.safetensors\"),\n",
        "    (\"PerfectWorld\", \"https://huggingface.co/ckpt/perfect_world/resolve/main/perfectWorld_v2Baked.safetensors\"),\n",
        "    (\"Figure\", \"https://huggingface.co/vorstcavry/figurestyle/resolve/main/figure.safetensors\"),\n",
        "    (\"RevAnimated\", \"https://huggingface.co/ckpt/rev-animated/resolve/main/revAnimated_v11.safetensors\"),\n",
        "    (\"CyberReal\", \"https://huggingface.co/ckpt/CyberRealistic/resolve/main/cyberrealistic_v13.safetensors\"),\n",
        "    (\"MarvelWhatIf\", \"https://huggingface.co/ItsJayQz/Marvel_WhatIf_Diffusion/resolve/main/Marvel_WhatIf_DiffusionV2_whatif_style.safetensors\"),\n",
        "]\n",
        "\n",
        "\n",
        "\n",
        "for model, url in models:\n",
        "    if locals()[model]:  # if checkbox is checked\n",
        "        downloadModels.append((model, url))\n",
        "\n",
        "def download(checkpoint_name, url, is_vae=None, is_control=None):\n",
        "    basename = os.path.basename(url)\n",
        "    hf_token = \"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\"\n",
        "    user_header = f'\"Authorization: Bearer {hf_token}\"'\n",
        "    if is_vae:\n",
        "        !aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {vaes_dir} -o {checkpoint_name}.vae.pt {url}\n",
        "    else:\n",
        "        if url.startswith(\"https://huggingface.co/\"):\n",
        "            ext = \"ckpt\" if url.endswith(\".ckpt\") else \"safetensors\"\n",
        "            !aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {models_dir} -o {checkpoint_name}.{ext} {url}\n",
        "        else:\n",
        "            !aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {models_dir} {url}\n",
        "\n",
        "def main():\n",
        "    downloaded_model = []\n",
        "\n",
        "    for model in tqdm(downloadModels, desc=\"\u001b[1;32mDownloading Models\"):\n",
        "        with capture.capture_output() as cap:\n",
        "            download(model[0], model[1], is_vae=False)\n",
        "            downloaded_model.append(model[0])\n",
        "            del cap\n",
        "\n",
        "print(f\"\u001b[1;32mDownloading...\")\n",
        "start_time = time.time()\n",
        "\n",
        "main()\n",
        "\n",
        "end_time = time.time()\n",
        "elapsed_time = int(end_time - start_time)\n",
        "\n",
        "if elapsed_time < 60:\n",
        "    print(f\"\\n\u001b[1;32mDownload completed. Took {elapsed_time} sec\")\n",
        "else:\n",
        "    mins, secs = divmod(elapsed_time, 60)\n",
        "    print(f\"\\n\u001b[1;32mDownload completed. Took {mins} mins {secs} sec\")\n",
        "\n",
        "#install-vae-untuk-model-checkpoint-yang-akan-dipakai\n",
        "#@markdown <font color=\"#00CED1\">**Pilih VAE**:</font> `Rekomendasi VAE : VaeftMse`\n",
        "Pilih_VAE = \"VaeftMse\" #@param [\"VaeftMse\", \"WDv2\", \"ClearVae\", \"Klf8Anime\", \"Klf8Anime2\", \"Nai\", \"OrangeVae\", \"PastelWaifu\"]\n",
        "\n",
        "with open(\"vae.txt\", \"w\") as f:\n",
        "     if Pilih_VAE == \"VaeftMse\":\n",
        "        f.write(\"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\\n\"\n",
        "                \" out=vae-ft-mse-840000-ema-pruned.ckpt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"WDv2\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/WD-v2.vae.pt\\n\"\n",
        "                \" out=WD-v2.vae.pt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"ClearVae\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/clearvae_main.safetensors\\n\"\n",
        "                \" out=clearvae_main.safetensors\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"Klf8Anime\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/kl-f8-anime.ckpt\\n\"\n",
        "                \" out=kl-f8-anime.ckpt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"Klf8Anime2\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/kl-f8-anime2.ckpt\\n\"\n",
        "                \" out=kl-f8-anime2.ckpt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"Nai\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/nai.vae.pt\\n\"\n",
        "                \" out=nai.vae.pt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"OrangeVae\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/orangemix.vae.pt\\n\"\n",
        "                \" out=orangemix.vae.pt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "     if Pilih_VAE == \"PastelWaifu\":\n",
        "        f.write(\"https://huggingface.co/vorstcavry/vaecollection/resolve/main/pastel-waifu-diffusion.vae.pt\\n\"\n",
        "                \" out=pastel-waifu-diffusion.vae.pt\\n\")\n",
        "     else:\n",
        "          pass\n",
        "\n",
        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --input-file vae.txt -d /content/cagliostro-colab-ui/models/VAE\n",
        "!rm -rf /content/vae.txt\n",
        "\n",
        "print(\"\u001b[1;32mAll is done! Go to the next step\")"
      ],
      "metadata": {
        "id": "15oA4o1eqtbt",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "import time\n",
        "from pydantic import BaseModel\n",
        "from colablib.utils.py_utils import get_filename\n",
        "from colablib.sd_models.downloader import aria2_download, download\n",
        "from colablib.utils.ubuntu_utils import unionfuse\n",
        "from colablib.utils.git_utils import clone_repo\n",
        "from colablib.colored_print import cprint, print_line\n",
        "from colablib.utils.config_utils import read_config\n",
        "\n",
        "%store -r\n",
        "\n",
        "#@title ## <font color=\"#FFD700\">***Custom Download Model,Vae, Embedding, LoRA, Hypernetwork, Ekstension, dan Upscaler***</font>\n",
        "\n",
        "# @markdown\n",
        "# @markdown ### <font color=\"#00CED1\">***Download Bahan tambahan yang kalian inginkan :***</font>\n",
        "# @markdown\n",
        "# @markdown - Jika kalian ingin mendownload lebih dari satu, kalian bisa memsiakannya dengan koma. <font color=\"#00CED1\">**CONTOH**:</font> `url1, url2, url3`.\n",
        "# @markdown - Download dari file Google Drive, gunakan `fuse:` lalu dilanjutkan tata letak foldernya. <font color=\"#00CED1\">**CONTOH**:</font> `fuse:/content/drive/MyDrive/LoRA`.\n",
        "# @markdown - Letakan Salinan jalur model dari Google Drive ke kolom URL untuk menyalin model ke direktori model UI web.\n",
        "custom_model_url        = \"\"  # @param {'type': 'string'}\n",
        "custom_vae_url          = \"\"  # @param {'type': 'string'}\n",
        "custom_embedding_url    = \"\"  # @param {'type': 'string'}\n",
        "custom_LoRA_url         = \"\"  # @param {'type': 'string'}\n",
        "custom_hypernetwork_url = \"\"  # @param {'type': 'string'}\n",
        "custom_extensions_url   = \"\"  # @param {'type': 'string'}\n",
        "custom_upscaler_url     = \"\"  # @param {'type': 'string'}\n",
        "# @markdown ### <br>`NEW` <font color=\"#00CED1\">***Download Bahan tambahan yang kalian inginkan dengan list file.txt***\n",
        "# @markdown - Berikan URL unduhan khusus untuk file `.txt` alih-alih menggunakan bidang URL. Mengedit file tersebut: `/content/download_list.txt`.\n",
        "# @markdown - Hastag yang dipakai: `#model`, `#vae`, `#embedding`, `#lora`, `#hypernetwork`, `#extensions`, `#upscaler`.\n",
        "# @markdown - Atau Kalian dapat memasukkan Link file `.txt` di `custom_download_list_url` Untuk Mendownload bahan tambahan secara instan.\n",
        "custom_download_list_url = \"https://huggingface.co/vorstcavry/test/resolve/main/download_list.txt\"  # @param {'type': 'string'}\n",
        "\n",
        "\n",
        "class CustomDirs(BaseModel):\n",
        "    url: str\n",
        "    dst: str\n",
        "\n",
        "custom_dirs = {\n",
        "    \"model\"       : CustomDirs(url=custom_model_url, dst=models_dir),\n",
        "    \"vae\"         : CustomDirs(url=custom_vae_url, dst=vaes_dir),\n",
        "    \"embedding\"   : CustomDirs(url=custom_embedding_url, dst=embeddings_dir),\n",
        "    \"lora\"        : CustomDirs(url=custom_LoRA_url, dst=lora_dir),\n",
        "    \"hypernetwork\": CustomDirs(url=custom_hypernetwork_url, dst=hypernetworks_dir),\n",
        "    \"extensions\"  : CustomDirs(url=custom_extensions_url, dst=extensions_dir),\n",
        "    \"upscaler\"    : CustomDirs(url=custom_upscaler_url, dst=esrgan_dir)\n",
        "}\n",
        "\n",
        "def fuse(url, key, dst):\n",
        "    if \"extensions\" in key:\n",
        "        cprint(f\"Folder can't be fused, skipping...\")\n",
        "        return\n",
        "\n",
        "    path = url.split(\"fuse:\")[1].strip()\n",
        "    category_dir = os.path.join(fused_dir, key)\n",
        "    if os.path.exists(category_dir):\n",
        "        cprint(f\"Folder '{category_dir}' is already fused, skipping...\", color=\"yellow\")\n",
        "        return\n",
        "\n",
        "    cprint(f\"Fusing process started for PATH: '{path}'\", color=\"green\")\n",
        "    unionfuse(category_dir, path, dst)\n",
        "    cprint(f\"Fusing process completed. Valid '{key}' folder located at: '{category_dir}' \", color=\"green\")\n",
        "\n",
        "def parse_urls(filename):\n",
        "    content = read_config(filename)\n",
        "    lines   = content.strip().split('\\n')\n",
        "    result  = {}\n",
        "    key     = ''\n",
        "    for line in lines:\n",
        "        if not line.strip():\n",
        "            continue\n",
        "        if line.startswith('//'):\n",
        "            continue\n",
        "        if line.startswith('#'):\n",
        "            key = line[1:].lower()\n",
        "            result[key] = []\n",
        "        else:\n",
        "            urls = [url.strip() for url in line.split(',') if url.strip() != '']\n",
        "            result[key].extend(urls)\n",
        "    return result\n",
        "\n",
        "def custom_download(custom_dirs):\n",
        "    for key, value in custom_dirs.items():\n",
        "        urls     = value.url.split(\",\")  # Split the comma-separated URLs\n",
        "        dst      = value.dst\n",
        "\n",
        "        if value.url:\n",
        "            print_line(80, color=\"green\")\n",
        "            cprint(f\" [-] Downloading Custom {key}...\", color=\"flat_yellow\")\n",
        "\n",
        "        for url in urls:\n",
        "            url = url.strip()  # Remove leading/trailing whitespaces from each URL\n",
        "            if url != \"\":\n",
        "                print_line(80, color=\"green\")\n",
        "                if \"|\" in url:\n",
        "                    url, filename = map(str.strip, url.split(\"|\"))\n",
        "                    if not filename.endswith((\".safetensors\", \".ckpt\", \".pt\", \"pth\", \".png\", \".jpeg\", \".jpg\")):\n",
        "                        filename = filename + os.path.splitext(get_filename(url))[1]\n",
        "                else:\n",
        "                    if not url.startswith(\"fuse:\"):\n",
        "                        filename = get_filename(url)\n",
        "\n",
        "                if url.startswith(\"fuse:\"):\n",
        "                    fuse(url, key, dst)\n",
        "                elif key == \"extensions\":\n",
        "                    clone_repo(url, cwd=dst)\n",
        "                else:\n",
        "                    download(url=url, filename=filename, dst=dst, quiet=False)\n",
        "\n",
        "def download_from_textfile(filename):\n",
        "    for key, urls in parse_urls(filename).items():\n",
        "        key_lower = key.lower()\n",
        "        if key_lower in custom_dirs:\n",
        "            if custom_dirs[key_lower].url:\n",
        "                custom_dirs[key_lower].url += ',' + ','.join(urls)\n",
        "            else:\n",
        "                custom_dirs[key_lower].url = ','.join(urls)\n",
        "        else:\n",
        "            cprint(f\"Warning: Category '{key}' from the file is not found in custom_dirs.\", color=\"yellow\")\n",
        "\n",
        "def custom_download_list(url):\n",
        "    filename = \"custom_download_list.txt\"\n",
        "    filepath = os.path.join(root_dir, filename)\n",
        "    if os.path.exists(filepath):\n",
        "        os.remove(filepath)\n",
        "    if 'pastebin.com' in url:\n",
        "        if 'raw' not in url:\n",
        "            url = url.replace('pastebin.com', 'pastebin.com/raw')\n",
        "    download(url=url, filename=filename, dst=root_dir, quiet=True)\n",
        "    return filepath\n",
        "\n",
        "def main():\n",
        "    start_time    = time.time()\n",
        "    textfile_path = download_list\n",
        "    if custom_download_list_url:\n",
        "        textfile_path = custom_download_list(custom_download_list_url)\n",
        "    download_from_textfile(textfile_path)\n",
        "    custom_download(custom_dirs)\n",
        "\n",
        "    elapsed_time  = py_utils.calculate_elapsed_time(start_time)\n",
        "    print_line(80, color=\"green\")\n",
        "    cprint(f\"Download finished. Took {elapsed_time}.\", color=\"flat_yellow\")\n",
        "    cprint(\"All is done! Go to the next step.\", color=\"flat_yellow\")\n",
        "    print_line(80, color=\"green\")\n",
        "\n",
        "main()"
      ],
      "metadata": {
        "cellView": "form",
        "id": "v-CXDLscV5HM"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "##<font color=\"#7FFF00\">***3. INSTALL CONTROLNET DAN EKSTENSION SPESIAL LAINNYA***</font>\n",
        "\n",
        "<small><font color=\"#00CED1\">**bisa di lewati jika tidak diperlukan**:</font> </small></small>\n"
      ],
      "metadata": {
        "id": "6TtktCcHHBmo"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title ## <font color=\"#FFD700\">***Install Controlnet***</font>\n",
        "# @markdown **1.ControlNet Annotator**\n",
        "pre_download_annotator = True  # @param {type: 'boolean'}\n",
        "# @markdown **2.Stable Diffusion v1.x ControlNet Model**\n",
        "control_v11_sd15_model = True  # @param {type: 'boolean'}\n",
        "# @markdown **3.Stable Diffusion v2.x ControlNet Model**\n",
        "control_v11_sd21_model = True  # @param {type: 'boolean'}\n",
        "# @markdown **4.Stable Diffusion text2img ControlNet Model**\n",
        "t2i_adapter_model = True  # @param {type: 'boolean'}\n",
        "# @markdown **ControlNet Config** <small><font color=\"#00CED1\">*Bagian Bawah ini Tidak perlu diubah jika belum paham*</font> </small></small>\n",
        "control_net_max_models_num = 2 #@param {type:\"slider\", min:1, max:10, step:1}\n",
        "config_file = os.path.join(repo_dir, \"config.json\")\n",
        "\n",
        "annotator_dict = {\n",
        "    \"oneformer\"     : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/150_16_swin_l_oneformer_coco_100ep.pth\",\n",
        "    \"oneformer\"     : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/250_16_swin_l_oneformer_ade20k_160k.pth\",\n",
        "    \"zoedepth\"      : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/ZoeD_M12_N.pt\",\n",
        "    \"midas\"         : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/dpt_beit_large_512.pt\",\n",
        "    \"midas\"         : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/dpt_hybrid-midas-501f0c75.pt\",\n",
        "    \"midas\"         : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/dpt_large-midas-2f21e586.pt\",\n",
        "    \"openpose\"      : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/facenet.pth\",\n",
        "    \"openpose\"      : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/hand_pose_model.pth\",\n",
        "    \"openpose\"      : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/body_pose_model.pth\",\n",
        "    \"keypose\"       : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth\",\n",
        "    \"keypose\"       : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/hrnet_w48_coco_256x192-b9e0b3ab_20200708.pth\",\n",
        "    \"leres\"         : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/latest_net_G.pth\",\n",
        "    \"leres\"         : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/res101.pth\",\n",
        "    \"mlsd\"          : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/mlsd_large_512_fp32.pth\",\n",
        "    \"lineart_anime\" : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/netG.pth\",\n",
        "    \"hed\"           : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/network-bsds500.pth\",\n",
        "    \"normal_bae\"    : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/scannet.pt\",\n",
        "    \"lineart\"       : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/sk_model.pth\",\n",
        "    \"lineart\"       : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/sk_model2.pth\",\n",
        "    \"pidinet\"       : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/table5_pidinet.pth\",\n",
        "    \"uniformer\"     : \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/upernet_global_small.pth\",\n",
        "}\n",
        "\n",
        "control_v11_sd15_url = [\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors\",\n",
        "    \"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\",\n",
        "]\n",
        "\n",
        "control_v11_sd21_url = [\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_ade20k.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_color.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_lineart.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_normalbae.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openpose.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors\",\n",
        "    \"https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_zoedepth.safetensors\"\n",
        "]\n",
        "\n",
        "t2i_adapter_url = [\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_canny_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_canny_sd15v2.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_color_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_depth_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_depth_sd15v2.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_keypose_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_openpose_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_seg_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_sketch_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_sketch_sd15v2.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_style_sd14v1.pth\",\n",
        "    \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_zoedepth_sd15v1.pth\"\n",
        "]\n",
        "\n",
        "def read_config(filename):\n",
        "    with open(filename, \"r\") as f:\n",
        "        config = json.load(f)\n",
        "    return config\n",
        "\n",
        "def write_config(filename, config):\n",
        "    with open(filename, \"w\") as f:\n",
        "        json.dump(config, f, indent=4)\n",
        "\n",
        "def cldm_config_path(destination_path):\n",
        "    if \"control\" in destination_path and \"sd15\" in destination_path:\n",
        "        if \"_shuffle_\" in destination_path:\n",
        "            return \"control_v11e_sd15_shuffle.yaml\"\n",
        "        else:\n",
        "            return \"cldm_v15.yaml\"\n",
        "    elif \"control\" in destination_path and \"sd21\"in destination_path:\n",
        "        return \"cldm_v21.yaml\"\n",
        "    elif \"t2i\" in destination_path:\n",
        "        adapter_name = os.path.splitext(os.path.basename(destination_path))[0]\n",
        "        return adapter_name + \".yaml\"\n",
        "    else:\n",
        "        return None\n",
        "\n",
        "def cldm_config(destination_path):\n",
        "    control_net_model_config = cldm_config_path(destination_path)\n",
        "    if control_net_model_config is not None:\n",
        "        cldm_config_src = os.path.join(extensions_dir, os.path.join(\"sd-webui-controlnet/models\", control_net_model_config))\n",
        "        cldm_config_dst = os.path.splitext(destination_path)[0] + \".yaml\"\n",
        "        if not os.path.exists(cldm_config_dst):\n",
        "            shutil.copy(cldm_config_src, cldm_config_dst)\n",
        "\n",
        "def download(url, destination_path, is_annotator=None):\n",
        "    hf_token = \"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\"\n",
        "    user_header = f'\"Authorization: Bearer {hf_token}\"'\n",
        "    basename = os.path.basename(url)\n",
        "    dst_dir = os.path.join(os.path.dirname(control_dir), destination_path) if is_annotator else destination_path\n",
        "    os.makedirs(dst_dir, exist_ok=True)\n",
        "    !aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {dst_dir} -o {basename} {url}\n",
        "    cldm_config(os.path.join(dst_dir, basename))\n",
        "\n",
        "def batch(url, download_description, is_annotator=None):\n",
        "    if is_annotator:\n",
        "        for dest_path, url in tqdm(annotator_dict.items(), desc=f\"\u001b[1;32mDownloading {download_description}\"):\n",
        "            with capture.capture_output() as cap:\n",
        "                download(url, dest_path, is_annotator=True)\n",
        "                del cap\n",
        "    else:\n",
        "        for control in tqdm(url, desc=f\"\u001b[1;32mDownloading {download_description}\"):\n",
        "            with capture.capture_output() as cap:\n",
        "                download(control, control_dir, is_annotator=False)\n",
        "                del cap\n",
        "\n",
        "def main():\n",
        "    config = read_config(config_file)\n",
        "    config[\"control_net_max_models_num\"] = control_net_max_models_num\n",
        "    config[\"control_net_models_path\"] = control_dir\n",
        "    config[\"control_net_allow_script_control\"] = True\n",
        "    write_config(config_file, config)\n",
        "\n",
        "    if pre_download_annotator:\n",
        "        batch(annotator_dict, \"ControlNet Annotator/Preprocessor\", is_annotator=True)\n",
        "    if control_v11_sd15_model:\n",
        "        batch(control_v11_sd15_url, \"SDv1.x ControlNet Model\", is_annotator=False)\n",
        "    if t2i_adapter_model:\n",
        "        batch(t2i_adapter_url, \"SDv1.x Text2Image Adapter Model\", is_annotator=False)\n",
        "    if control_v11_sd21_model:\n",
        "        batch(control_v11_sd21_url, \"SDv2.x ControlNet Model\", is_annotator=False)\n",
        "\n",
        "print(f\"\u001b[1;32mDownloading...\")\n",
        "start_time = time.time()\n",
        "\n",
        "main()\n",
        "\n",
        "end_time = time.time()\n",
        "elapsed_time = int(end_time - start_time)\n",
        "\n",
        "if elapsed_time < 60:\n",
        "    print(f\"\\n\u001b[1;32mDownload completed. Took {elapsed_time} sec\")\n",
        "else:\n",
        "    mins, secs = divmod(elapsed_time, 60)\n",
        "    print(f\"\\n\u001b[1;32mDownload completed. Took {mins} mins {secs} sec\")\n",
        "\n",
        "print(\"\u001b[1;32mAll is done! Go to the next step\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "LKKtxDoIIg1T"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download Deforum**\n",
        "# @markdown ###**Deforum**\n",
        "\n",
        "#@markdown ###Deforum adalah fitur ekstension spesial di stable diffusion yang dapat membuat video pendek yang menakjubkan dari hasil generate gambar dari sebuah cuplikan video pendek, ataupun dari text untuk membuat karya AI.\n",
        "!git clone https://github.com/deforum-art/deforum-for-automatic1111-$masbro /content/cagliostro-colab-ui/extensions/deforum-for-automatic1111-$masbro\n",
        "!mkdir /content/cagliostro-colab-ui/extensions/deforum-for-automatic1111-$masbro/models\n",
        "!sed -i -e 's/\\\"sd_model_checkpoint\\\"\\,/\\\"sd_model_checkpoint\\,sd_vae\\,CLIP_stop_at_last_layers\\\"\\,/g' /content/cagliostro-colab-ui/modules/shared.py"
      ],
      "metadata": {
        "id": "URRJW7Gm6gCf",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download SD Animation**\n",
        "# @markdown ###**SD Animation**\n",
        "\n",
        "#@markdown ###SD Animation adalah fitur ekstension spesial di stable diffusion yang dapat membuat video animasi AI, untuk pembuatan animasi ai memiliki dua tipe pembuatan(video menjadi animasi AI, dan Text Menjadi Animasi AI)\n",
        "!git clone https://github.com/volotat/SD-CN-Animation /content/cagliostro-colab-ui/extensions/SD-CN-Animation"
      ],
      "metadata": {
        "cellView": "form",
        "id": "mTG_NHlGGn8E"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download TemporalKit**\n",
        "# @markdown ###**TemporalKit**\n",
        "\n",
        "#@markdown ###TemporalKit adalah fitur ekstension spesial di stable diffusion yang dapat membuat video pendek yang menakjubkan dari hasil generate gambar dari sebuah cuplikan video pendek, fitur ini mirip seperti deforum\n",
        "!git clone https://github.com/vorstcavry/TemporalKit /content/cagliostro-colab-ui/extensions/TemporalKit"
      ],
      "metadata": {
        "cellView": "form",
        "id": "kybH-cavkMLN"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download Photopea** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
        "# @markdown ###**Photopea**\n",
        "\n",
        "#@markdown ###Photopea adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi seperti Photoshop yang dapat digunakan untuk mengedit gambar secara langsung di stable diffusion.\n",
        "!git clone https://github.com/vorstcavry/photopea-embed /content/cagliostro-colab-ui/extensions/photopea"
      ],
      "metadata": {
        "cellView": "form",
        "id": "QrVUPNNJ9_zj"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download Open Pose 2D Editor** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
        "# @markdown ###**Open Pose 2D Editor**\n",
        "\n",
        "#@markdown ###Open Pose 2D Editor adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi untuk membuat pose dengan model 2D untuk membuat gambar sesuai dengan pose yang di inginkan\n",
        "!git clone https://github.com/vorstcavry/openpose-editor /content/cagliostro-colab-ui/extensions/openpose-editor\n",
        "!git clone https://github.com/hnmr293/posex /content/cagliostro-colab-ui/extensions/posex"
      ],
      "metadata": {
        "id": "AjrbWxNvltmK",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download Open Pose 3D Editor** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
        "# @markdown ###**Open Pose 3D Editor**\n",
        "\n",
        "#@markdown ###Open Pose 3D Editor adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi untuk membuat pose dengan model 3D untuk membuat gambar sesuai dengan pose yang di inginkan\n",
        "!git clone https://github.com/vorstcavry/3d-open-pose-editor /content/cagliostro-colab-ui/extensions/3d-open-pose-editor"
      ],
      "metadata": {
        "cellView": "form",
        "id": "CezKb0BHjlWO"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download Manekin Model Loader** <small><small><small><font color=\"#00CED1\">**Tidak Direkomendasikan untuk Pengguna HandPhone**:</font> </small></small>\n",
        "# @markdown ###**Manekin Model Loader**\n",
        "\n",
        "#@markdown ###Manekin Model Loader adalah fitur ekstension spesial di stable diffusion yang memiliki fungsi untuk membuat pose dengan model Manekin untuk membuat gambar sesuai dengan pose yang di inginkan\n",
        "!git clone https://github.com/vorstcavry/sd-manekin-model-loader /content/cagliostro-colab-ui/extensions/sd-manekin-model-loader"
      ],
      "metadata": {
        "id": "un6YnwGKOvs-",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ## **Download SD MOV2MOV**\n",
        "# @markdown ###**SD MOV2MOV**\n",
        "\n",
        "#@markdown ###SD MOV2MOV adalah fitur ekstension spesial di stable diffusion yang dapat membuat Animasi AI dengan prompt dan video\n",
        "!git clone https://github.com/vorstcavry/mov2mov /content/cagliostro-colab-ui/extensions/sd-$masbro-mov2mov"
      ],
      "metadata": {
        "id": "ZWhRKcEomuYB",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "##<font color=\"#7FFF00\">***4. MULAI MENJALANKAN WEB UI***</font>\n"
      ],
      "metadata": {
        "id": "Nyv6g0sNHJaO"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title ## <font color=\"#FFD700\">**_Menjalankan Alternative UI_**</font>\n",
        "!git clone https://github.com/Iyashinouta/sd-model-downloader /content/cagliostro-colab-ui/extensions/sd-model-downloader\n",
        "!git clone https://github.com/vorstcavry/images-browser /content/cagliostro-colab-ui/extensions/images-browser\n",
        "\n",
        "import random\n",
        "import string\n",
        "from pydantic import BaseModel\n",
        "from typing import List, Optional\n",
        "from colablib.utils import config_utils\n",
        "from colablib.colored_print import cprint, print_line\n",
        "from colablib.utils.git_utils import validate_repo\n",
        "\n",
        "%store -r\n",
        "\n",
        "################################\n",
        "# ARGUMEN COLAB ADA DI SINI\n",
        "################################\n",
        "\n",
        "\n",
        "#@markdown ### <font color=\"#00CED1\">**Alternative Tunnel**:</font>\n",
        "# @markdown > Recommended Tunnels: `ngrok` > `gradio` > `cloudflared` > `remotemoe` > `localhostrun` > `googleusercontent`\n",
        "select_tunnel         = \"multiple\" # @param ['gradio', 'multiple','cloudflared', 'localhostrun', 'remotemoe', \"googleusercontent\"]\n",
        "# @markdown > dapatkan `ngrok_token` [disini](https://dashboard.ngrok.com/get-started/your-authtoken)\n",
        "ngrok_token           = \"\" # @param {type: 'string'}\n",
        "ngrok_region          = \"in\" # @param [\"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n",
        "#@markdown ### <font color=\"#00CED1\">**UI/UX Config**:</font>\n",
        "select_theme          = \"minimal_orange\" # @param ['moonlight', 'ogxRed', 'fun', 'ogxCyan', 'ogxCyanInvert', 'ogxBGreen', 'default_orange', 'tron2', 'd-230-52-94', 'minimal', 'ogxRedYellow', 'retrog', 'ogxRedPurple', 'ogxGreen', 'tron', 'default_cyan', 'default', 'backup', 'minimal_orange', 'Golde']\n",
        "# @markdown > Centang `use_preset` Untuk Menggunakan default prompt, resolusi, sampler, dan pengaturan lainnya\n",
        "use_presets           = True # @param {type: 'boolean'}\n",
        "#@markdown ### <font color=\"#00CED1\">**Arguments**:</font>\n",
        "use_gradio_auth       = False # @param {type: 'boolean'}\n",
        "accelerator           = \"xformers\" # @param ['xformers', 'opt-sdp-attention', 'opt-sdp-no-mem-attention', 'opt-split-attention']\n",
        "auto_select_model     = True # @param {type: 'boolean'}\n",
        "auto_select_vae       = True # @param {type: 'boolean'}\n",
        "additional_arguments  = \"--lowram --theme dark\" #@param {type: 'string'}\n",
        "\n",
        "# GRADIO AUTH\n",
        "user                  = \"cagliostro\"\n",
        "password              = \"\".join(random.choices(string.ascii_letters + string.digits, k=6))\n",
        "\n",
        "def change_theme(filename):\n",
        "    themes_folder   = os.path.join(repo_dir, \"extensions-builtin\", \"sd_theme_editor\", \"themes\")\n",
        "    themes_file     = os.path.join(themes_folder, f\"{filename}.css\")\n",
        "\n",
        "    style_config    = config_utils.read_config(style_path)\n",
        "    style_contents  = style_config.split(\"/*BREAKPOINT_CSS_CONTENT*/\")[1]\n",
        "\n",
        "    theme_config    = config_utils.read_config(themes_file)\n",
        "    style_data      = \":host{\" + theme_config + \"}\" + \"/*BREAKPOINT_CSS_CONTENT*/\" + style_contents\n",
        "    config_utils.write_config(style_path, style_data)\n",
        "\n",
        "def is_valid(valid_dir, file_types):\n",
        "    return [f for f in os.listdir(valid_dir) if f.endswith(file_types)]\n",
        "\n",
        "def auto_select_file(valid_dir, config_key, file_types):\n",
        "    valid_files = is_valid(valid_dir, file_types)\n",
        "    if valid_files:\n",
        "        file_path = random.choice(valid_files)\n",
        "        if os.path.exists(os.path.join(valid_dir, file_path)):\n",
        "            config = config_utils.read_config(config_file)\n",
        "            config[config_key] = file_path\n",
        "            config_utils.write_config(config_file, config)\n",
        "        return file_path\n",
        "    else:\n",
        "        return None\n",
        "\n",
        "def ui_preset_config():\n",
        "    global default_upscaler, default_sampler_v2\n",
        "\n",
        "    default_prompt        = \"masterpiece, best quality,\"\n",
        "    default_neg_prompt    = \"(worst quality, low quality:1.4)\"\n",
        "    default_sampler       = \"DPM++ 2M Karras\"\n",
        "    default_steps         = 20\n",
        "    default_width         = 512\n",
        "    default_height        = 768\n",
        "    default_strength      = 0.55\n",
        "    default_cfg_scale     = 7\n",
        "    default_upscaler       = \"Latent (nearest-exact)\"\n",
        "\n",
        "    config = {\n",
        "        \"Prompt/value\"              : default_prompt,\n",
        "        \"Negative prompt/value\"     : default_neg_prompt,\n",
        "        \"Sampling method/value\"     : default_sampler,\n",
        "        \"Sampling steps/value\"      : default_steps,\n",
        "        \"Width/value\"               : default_width,\n",
        "        \"Height/value\"              : default_height,\n",
        "        \"Denoising strength/value\"  : default_strength,\n",
        "        \"CFG Scale/value\"           : default_cfg_scale\n",
        "    }\n",
        "\n",
        "    return config\n",
        "\n",
        "def configure_main_settings(config_file: str, lora_dir: str, use_presets: bool, ui_config_file: str):\n",
        "    config = config_utils.read_config(config_file)\n",
        "\n",
        "    config[\"additional_networks_extra_lora_path\"] = lora_dir\n",
        "    config[\"CLIP_stop_at_last_layers\"] = 2\n",
        "    config[\"eta_noise_seed_delta\"] = 0\n",
        "    config[\"show_progress_every_n_steps\"] = 10\n",
        "    config[\"show_progressbar\"] = True\n",
        "    config[\"samples_filename_pattern\"] = \"[model_name]_[seed]\"\n",
        "    config[\"show_progress_type\"] = \"Approx NN\" # Full, Approx NN, TAESD, Approx cheap\n",
        "    config[\"live_preview_content\"] = \"Prompt\" # Combined, Prompt, Negative Prompt\n",
        "    config[\"hires_fix_show_sampler\"] = True\n",
        "    config[\"hires_fix_show_prompts\"] = True\n",
        "    config[\"state\"] = [\"tabs\"]\n",
        "    config[\"state_txt2img\"] = [\"prompt\", \"negative_prompt\", \"styles\", \"sampling\", \"sampling_steps\", \"width\", \"height\", \"batch_count\", \"batch_size\", \"hires_resize_y\", \"hires_resize_x\", \"hires_scale\", \"hires_steps\", \"hires_upscaler\", \"hires_fix\", \"tiling\", \"restore_faces\", \"cfg_scale\", \"hires_denoising_strength\"]\n",
        "    config[\"state_img2img\"] = [\"prompt\", \"negative_prompt\", \"styles\", \"sampling\", \"resize_mode\", \"sampling_steps\", \"tiling\", \"restore_faces\", \"width\", \"height\", \"batch_count\", \"batch_size\", \"cfg_scale\", \"denoising_strength\"]\n",
        "    config[\"state_extensions\"] = [\"control-net\"]\n",
        "\n",
        "    quicksettings_values = [\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\",\n",
        "                            \"use_old_karras_scheduler_sigmas\", \"always_discard_next_to_last_sigma\",\n",
        "                            \"token_merging_ratio\", \"s_min_uncond\"]\n",
        "\n",
        "    if \"quicksettings\" in config:\n",
        "        config[\"quicksettings\"] = \", \".join(quicksettings_values)\n",
        "    elif \"quicksettings_list\" in config:\n",
        "        config[\"quicksettings_list\"] = quicksettings_values\n",
        "\n",
        "    config_utils.write_config(config_file, config)\n",
        "\n",
        "    if use_presets:\n",
        "        configure_ui_settings(ui_config_file)\n",
        "\n",
        "def configure_ui_settings(ui_config_file: str):\n",
        "    config = config_utils.read_config(ui_config_file)\n",
        "    preset_config = ui_preset_config()\n",
        "    for key in [\"txt2img\", \"img2img\"]:\n",
        "        for subkey, value in preset_config.items():\n",
        "            config[f\"{key}/{subkey}\"] = value\n",
        "\n",
        "    config[\"txt2img/Upscaler/value\"] = default_upscaler\n",
        "    config_utils.write_config(ui_config_file, config)\n",
        "\n",
        "def is_dir_exist(cloned_dir, original_dir):\n",
        "    if os.path.exists(cloned_dir):\n",
        "        return cloned_dir\n",
        "    else:\n",
        "        return original_dir\n",
        "\n",
        "def parse_args(config):\n",
        "    args = \"\"\n",
        "    for k, v in config.items():\n",
        "        if k.startswith(\"_\"):\n",
        "            args += f'\"{v}\" '\n",
        "        elif isinstance(v, str):\n",
        "            args += f'--{k}=\"{v}\" '\n",
        "        elif isinstance(v, bool) and v:\n",
        "            args += f\"--{k} \"\n",
        "        elif isinstance(v, float) and not isinstance(v, bool):\n",
        "            args += f\"--{k}={v} \"\n",
        "        elif isinstance(v, int) and not isinstance(v, bool):\n",
        "            args += f\"--{k}={v} \"\n",
        "\n",
        "    return args\n",
        "\n",
        "def main():\n",
        "    global auto_select_model, auto_select_vae\n",
        "\n",
        "    repo_name, _, _ = validate_repo(repo_dir)\n",
        "    if \"anapnoe\" in repo_name:\n",
        "        change_theme(select_theme)\n",
        "\n",
        "    valid_ckpt_dir          = is_dir_exist(os.path.join(fused_dir, \"model\"), models_dir)\n",
        "    valid_vae_dir           = is_dir_exist(os.path.join(fused_dir, \"vae\"), vaes_dir)\n",
        "    valid_embedding_dir     = is_dir_exist(os.path.join(fused_dir, \"embedding\"), embeddings_dir)\n",
        "    valid_lora_dir          = is_dir_exist(os.path.join(fused_dir, \"lora\"), lora_dir)\n",
        "    valid_hypernetwork_dir  = is_dir_exist(os.path.join(fused_dir, \"hypernetwork\"), hypernetworks_dir)\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "    cprint(f\"Launching '{repo_name}'\", color=\"flat_yellow\")\n",
        "    print_line(80, color=\"green\")\n",
        "\n",
        "    if not is_valid(valid_ckpt_dir, ('.ckpt', '.safetensors')):\n",
        "        cprint(f\"No checkpoints were found in the directory '{valid_ckpt_dir}'.\", color=\"yellow\")\n",
        "        url = \"https://huggingface.co/vorstcavry/mymodel/resolve/main/Cavry_V2.safetensors\"\n",
        "        filename = \"Cavry_V2.safetensors\"\n",
        "        aria2_download(url=url, download_dir=valid_ckpt_dir, filename=filename)\n",
        "        print_line(80, color=\"green\")\n",
        "        auto_select_model = True\n",
        "\n",
        "    if not is_valid(valid_vae_dir, ('.vae.pt', '.vae.safetensors', '.pt', '.ckpt')):\n",
        "        cprint(f\"No VAEs were found in the directory '{valid_vae_dir}'.\", color=\"yellow\")\n",
        "        url = \"https://huggingface.co/vorstcavry/vaecollection/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\"\n",
        "        filename = \"vae-ft-mse-840000-ema-pruned.ckpt\"\n",
        "        aria2_download(url=url, download_dir=valid_vae_dir, filename=filename)\n",
        "        print_line(80, color=\"green\")\n",
        "        auto_select_vae = True\n",
        "\n",
        "    if auto_select_model:\n",
        "        selected_model  = auto_select_file(valid_ckpt_dir, \"sd_model_checkpoint\", ('.ckpt', '.safetensors'))\n",
        "        cprint(f\"Selected Model: {selected_model}\", color=\"green\")\n",
        "\n",
        "    if auto_select_vae:\n",
        "        selected_vae    = auto_select_file(valid_vae_dir, \"sd_vae\", ('.vae.pt', '.vae.safetensors', '.pt', '.ckpt'))\n",
        "        cprint(f\"Selected VAE: {selected_vae}\", color=\"green\")\n",
        "\n",
        "    print_line(80, color=\"green\")\n",
        "\n",
        "    configure_main_settings(config_file, valid_lora_dir, use_presets, ui_config_file)\n",
        "\n",
        "    if use_gradio_auth:\n",
        "      cprint(\"Gradio Auth (use this account to login):\", color=\"green\")\n",
        "      cprint(\"[-] Username: cagliostro\", color=\"green\")\n",
        "      cprint(\"[-] Password:\", password, color=\"green\")\n",
        "      print_line(80, color=\"green\")\n",
        "\n",
        "    config = {\n",
        "        \"enable-insecure-extension-access\": True,\n",
        "        \"disable-safe-unpickle\"           : True,\n",
        "        f\"{accelerator}\"                  : True,\n",
        "        f\"{select_tunnel}\"                : True if not select_tunnel == \"gradio\" and not ngrok_token else False,\n",
        "        \"share\"                           : True if not ngrok_token else False,\n",
        "        \"gradio-auth\"                     : f\"{user}:{password}\" if use_gradio_auth else None,\n",
        "        \"no-hashing\"                      : True,\n",
        "        \"disable-console-progressbars\"    : True,\n",
        "        \"ngrok\"                           : ngrok_token if ngrok_token else None,\n",
        "        \"ngrok-region\"                    : ngrok_region if ngrok_token else None,\n",
        "        \"opt-sub-quad-attention\"          : True,\n",
        "        \"opt-channelslast\"                : True,\n",
        "        \"no-download-sd-model\"            : True,\n",
        "        \"gradio-queue\"                    : True,\n",
        "        \"listen\"                          : True,\n",
        "        \"ckpt-dir\"                        : valid_ckpt_dir,\n",
        "        \"vae-dir\"                         : valid_vae_dir,\n",
        "        \"hypernetwork-dir\"                : valid_hypernetwork_dir,\n",
        "        \"embeddings-dir\"                  : valid_embedding_dir,\n",
        "        \"lora-dir\"                        : valid_lora_dir,\n",
        "        \"lyco-dir\"                        : valid_lora_dir,\n",
        "    }\n",
        "\n",
        "    args = parse_args(config)\n",
        "    final_args = f\"python launch.py {args} {additional_arguments}\"\n",
        "\n",
        "    cprint()\n",
        "    os.chdir(repo_dir)\n",
        "    !{final_args}\n",
        "\n",
        "main()"
      ],
      "metadata": {
        "id": "Gh3uUu-RT6fV",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "##<font color=\"#7FFF00\">***Fitur Download dan Upload***</font>\n"
      ],
      "metadata": {
        "id": "frYxBNQhVHSK"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@title ## <font color=\"#FFD700\">**_Download Hasil Stable Diffusion_**</font>\n",
        "\n",
        "# @markdown Centang di bawah ini jika ingin menyimpannya di Google Drive\n",
        "\n",
        "import os\n",
        "\n",
        "from pydrive.auth import GoogleAuth\n",
        "from pydrive.drive import GoogleDrive\n",
        "from google.colab import auth, drive\n",
        "from oauth2client.client import GoogleCredentials\n",
        "from colablib.colored_print import cprint, print_line\n",
        "\n",
        "%store -r\n",
        "\n",
        "os.chdir(output_dir)\n",
        "\n",
        "use_drive = False  # @param {type:\"boolean\"}\n",
        "folder_name = \"cagliostro-colab-ui\"  # @param {type: \"string\"}\n",
        "filename = \"output.zip\"  # @param {type: \"string\"}\n",
        "save_as = filename\n",
        "\n",
        "if os.path.exists(filename):\n",
        "    i = 1\n",
        "    while os.path.exists(f\"waifu({i}).zip\"):\n",
        "        i += 1\n",
        "    filename = f\"waifu({i}).zip\"\n",
        "\n",
        "os.system('zip -r /content/outputs.zip .')\n",
        "\n",
        "if use_drive:\n",
        "    auth.authenticate_user()\n",
        "    gauth = GoogleAuth()\n",
        "    gauth.credentials = GoogleCredentials.get_application_default()\n",
        "    drive = GoogleDrive(gauth)\n",
        "\n",
        "    def create_folder(folder_name):\n",
        "        file_list = drive.ListFile({\n",
        "            \"q\": f\"title='{folder_name}' and mimeType='application/vnd.google-apps.folder' and trashed=false\"\n",
        "        }).GetList()\n",
        "        if file_list:\n",
        "            cprint(\"Debug: Folder exists\", color=\"green\")\n",
        "            folder_id = file_list[0][\"id\"]\n",
        "        else:\n",
        "            cprint(\"Debug: Creating folder\", color=\"green\")\n",
        "            file = drive.CreateFile({\n",
        "                \"title\": folder_name,\n",
        "                \"mimeType\": \"application/vnd.google-apps.folder\"\n",
        "            })\n",
        "            file.Upload()\n",
        "            folder_id = file.attr[\"metadata\"][\"id\"]\n",
        "        return folder_id\n",
        "\n",
        "    def upload_file(file_name, folder_id, save_as):\n",
        "        file_list = drive.ListFile({\"q\": f\"title='{save_as}' and trashed=false\"}).GetList()\n",
        "        if file_list:\n",
        "            cprint(\"Debug: File already exists\", color=\"green\")\n",
        "            i = 1\n",
        "            while True:\n",
        "                new_name = f\"{os.path.splitext(save_as)[0]}({i}){os.path.splitext(save_as)[1]}\"\n",
        "                file_list = drive.ListFile({\"q\": f\"title='{new_name}' and trashed=false\"}).GetList()\n",
        "                if not file_list:\n",
        "                    save_as = new_name\n",
        "                    break\n",
        "                i += 1\n",
        "        file = drive.CreateFile({\"title\": save_as, \"parents\": [{\"id\": folder_id}]})\n",
        "        file.SetContentFile(file_name)\n",
        "        file.Upload()\n",
        "        file.InsertPermission({\"type\": \"anyone\", \"value\": \"anyone\", \"role\": \"reader\"})\n",
        "        return file.attr[\"metadata\"][\"id\"]\n",
        "\n",
        "    file_id = upload_file(\"/content/outputs.zip\", create_folder(folder_name), save_as)\n",
        "    cprint(f\"Your sharing link: https://drive.google.com/file/d/{file_id}/view?usp=sharing\", color=\"green\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "LphRDI1JVHS8"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "DscmcGPtVHTd"
      },
      "outputs": [],
      "source": [
        "#@title ## <font color=\"#FFD700\">**_Login Akun dan Konfirmasi Letak Penyimpan Huggingface_**</font>\n",
        "from huggingface_hub import login\n",
        "from huggingface_hub import HfApi\n",
        "from huggingface_hub.utils import validate_repo_id, HfHubHTTPError\n",
        "\n",
        "# @markdown Login akun Huggingface Hub (Jika belum punya akun, bisa daftar dulu [**Join di sini**](https://huggingface.co/join))\n",
        "# @markdown > Dapatkan huggingface [disini](https://huggingface.co/settings/tokens)\n",
        "write_token = \"\"  # @param {type:\"string\"}\n",
        "# @markdown Masukan Nama organisasi, Jika tidak ada bisa di kosongkan.\n",
        "# @markdown >tekan [Masuk](https://huggingface.co/organizations/INDONESIA-AI/share/rcGdQObpefOQvqndOutQcfYFZfRYVGitTy) untuk bergabung ke Komunitas Huggingface saya\n",
        "orgs_name = \"\"  # @param{type:\"string\"}\n",
        "# @markdown Masukan repositori model dan dataset huggingface, kosongkan jika ingin terbuat secara otomatis.\n",
        "model_name = \"\"  # @param{type:\"string\"}\n",
        "dataset_name = \"\"  # @param{type:\"string\"}\n",
        "# @markdown Simpan sebagi menjadi Privat\n",
        "make_private = False  # @param{type:\"boolean\"}\n",
        "\n",
        "def authenticate(write_token):\n",
        "    login(write_token, add_to_git_credential=True)\n",
        "    api = HfApi()\n",
        "    return api.whoami(write_token), api\n",
        "\n",
        "\n",
        "def create_repo(api, user, orgs_name, repo_name, repo_type, make_private=False):\n",
        "    global model_repo\n",
        "    global datasets_repo\n",
        "\n",
        "    if orgs_name == \"\":\n",
        "        repo_id = user[\"name\"] + \"/\" + repo_name.strip()\n",
        "    else:\n",
        "        repo_id = orgs_name + \"/\" + repo_name.strip()\n",
        "\n",
        "    try:\n",
        "        validate_repo_id(repo_id)\n",
        "        api.create_repo(repo_id=repo_id, repo_type=repo_type, private=make_private)\n",
        "        print(f\"{repo_type.capitalize()} repo '{repo_id}' didn't exist, creating repo\")\n",
        "    except HfHubHTTPError as e:\n",
        "        print(f\"{repo_type.capitalize()} repo '{repo_id}' exists, skipping create repo\")\n",
        "\n",
        "    if repo_type == \"model\":\n",
        "        model_repo = repo_id\n",
        "        print(f\"{repo_type.capitalize()} repo '{repo_id}' link: https://huggingface.co/{repo_id}\\n\")\n",
        "    else:\n",
        "        datasets_repo = repo_id\n",
        "        print(f\"{repo_type.capitalize()} repo '{repo_id}' link: https://huggingface.co/datasets/{repo_id}\\n\")\n",
        "\n",
        "user, api = authenticate(write_token)\n",
        "\n",
        "if model_name:\n",
        "    create_repo(api, user, orgs_name, model_name, \"model\", make_private)\n",
        "if dataset_name:\n",
        "    create_repo(api, user, orgs_name, dataset_name, \"dataset\", make_private)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "vb6LoMwPVHTh"
      },
      "outputs": [],
      "source": [
        "#@title ## <font color=\"#FFD700\">**_Proses Upload ke Huggingface_**</font>\n",
        "\n",
        "from huggingface_hub import HfApi\n",
        "from pathlib import Path\n",
        "\n",
        "%store -r\n",
        "\n",
        "api = HfApi()\n",
        "\n",
        "# @markdown Masukkan tata letak file yang ingin di Upload\n",
        "model_path = \"/content/\"  # @param {type :\"string\"}\n",
        "#@markdown Masukkan tata letak file path dan config (jika ada)\n",
        "path_in_repo = \"\"  # @param {type :\"string\"}\n",
        "config_path = \"\"  # @param {type :\"string\"}\n",
        "\n",
        "# @markdown Masukan informasi untuk Upload\n",
        "commit_message = \"upload\"  # @param {type :\"string\"}\n",
        "\n",
        "if not commit_message:\n",
        "    commit_message = f\"feat: upload {project_name} lora model\"\n",
        "\n",
        "def upload_to_hf(model_path, is_folder, is_config):\n",
        "    path_obj = Path(model_path)\n",
        "    trained_model = path_obj.parts[-1]\n",
        "\n",
        "    if path_in_repo:\n",
        "        trained_model = path_in_repo\n",
        "\n",
        "    if is_config:\n",
        "        trained_model = f\"{project_name}_config\"\n",
        "\n",
        "    print(f\"Uploading {trained_model} to https://huggingface.co/{model_repo}\")\n",
        "    print(\"Please wait...\")\n",
        "\n",
        "    if is_folder:\n",
        "        api.upload_folder(\n",
        "            folder_path=model_path,\n",
        "            path_in_repo=trained_model,\n",
        "            repo_id=model_repo,\n",
        "            commit_message=commit_message,\n",
        "            ignore_patterns=\".ipynb_checkpoints\",\n",
        "        )\n",
        "        print(f\"Upload success, located at https://huggingface.co/{model_repo}/tree/main\\n\")\n",
        "    else:\n",
        "        api.upload_file(\n",
        "            path_or_fileobj=model_path,\n",
        "            path_in_repo=trained_model,\n",
        "            repo_id=model_repo,\n",
        "            commit_message=commit_message,\n",
        "        )\n",
        "        print(f\"Upload success, located at https://huggingface.co/{model_repo}/blob/main/{trained_model}\\n\")\n",
        "\n",
        "def upload():\n",
        "    is_model_file = model_path.endswith((\".ckpt\", \".safetensors\", \".pt\", \".png\", \".zip\"))\n",
        "    upload_to_hf(model_path, not is_model_file, False)\n",
        "\n",
        "    if config_path:\n",
        "        upload_to_hf(config_path, True, True)\n",
        "\n",
        "upload()"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "private_outputs": true,
      "provenance": [],
      "collapsed_sections": [
        "upiFioaJfziP",
        "fof1qg-QUyFv",
        "v9md6r0tG0jQ",
        "6TtktCcHHBmo",
        "Nyv6g0sNHJaO",
        "frYxBNQhVHSK",
        "oEk611XKY623",
        "kfdbFRjs1Q-T"
      ],
      "include_colab_link": true
    },
    "gpuClass": "standard",
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}