File size: 70,568 Bytes
f9de86b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## NovelAi sd-webui AI绘画项目 修复版(完全免费,无需任何配置!)\n",
    "**torch: 2.0.0+cu118  •  xformers: 0.0.19**\n",
    "​\n",
    "# <span style=\"color:red; font-weight:bold;\">有问题请加qq群632428790 (691/2000)</span>\n",
    "### 急需一名宣传人员,无偿,会做B站视频就行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用教程:https://www.kaggle.com/code/at2020dead/novelai-stable-diffusion/notebook \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana;\">\n",
    "    📌 2022年11月18日: Crtated By Yiyiooo & Loading\n",
    "</div>\n",
    "最近更新日志:\n",
    "<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana;\">\n",
    "     2023年3月5日更新:现在支持通过下载链接上传模型了,省去了下载模型后再上传后的麻烦.()\n",
    "</div>\n",
    "<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana;\">\n",
    "     2023年5月15日更新:现在可以双开webui了,可以双线程跑图(GPU请选择 T4 x2 , 将use2设置为True)\n",
    "</div>\n",
    "<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana;\">\n",
    "     2023年5月15日更新:更新了多线程启动,启动速度更快一些\n",
    "</div>\n",
    "<div class=\"alert alert-block alert-info\" style=\"font-size:14px; font-family:verdana;\">\n",
    "     2023年6月6日更新:更新了xformers版本,生成速度更快一些\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 注意事项/WARNING:\n",
    "- ### 1.将设置中的PERSISTENCE改为Files Only方便下次打开提高启动速度,第一次启动后下载Python环境包就不用下载第二次了\n",
    "- ### 2.检测到出现涩图会容易导致封号现象,建议到webui设置里把'始终保存所有生成的图像'和‘始终保存所有生成的宫格图’关了\n",
    "- ### 3.如果不能启动,请新建一个notebook并且重新导入\n",
    "- ### 4.若出现BUG,请跟我们反馈,我们是无偿组织,请不要催作者更新,谢谢配合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ai绘画模型下载站:\n",
    "#### [Civitai](http://civitai.com)\n",
    " \n",
    "#### [huggingface](http://huggingface.co)\n",
    "# 友情合作\n",
    "###   [pix.ink](http://pix.ink) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.526376Z",
     "iopub.status.busy": "2023-06-06T13:31:46.525502Z",
     "iopub.status.idle": "2023-06-06T13:31:46.542665Z",
     "shell.execute_reply": "2023-06-06T13:31:46.541657Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.526340Z"
    }
   },
   "outputs": [],
   "source": [
    "# 安装目录\n",
    "install_path=\"/kaggle/working\" #或者/kaggle\n",
    "updata_webui = False  #是否开机自动更新webui\n",
    "\n",
    "# 重置变量 会删掉sd_webui重新安装\n",
    "reLoad = False\n",
    "updata_webui = False\n",
    "\n",
    "#清理和打包生成的图片\n",
    "zip_output=True\n",
    "clear_output=True\n",
    "#打包环境减少下次启动时\n",
    "use_zip_venv = False\n",
    "\n",
    "# 使用huggingface保存和载入webui配置文件\n",
    "huggingface_use = True\n",
    "huggingface_token_file = '/kaggle/input/tenkens/hugfacetoken.txt'\n",
    "huggiingface_repo_id = 'ACCA225/sdconfig'\n",
    "# 将会同步的文件\n",
    "yun_files = [\n",
    "'ui-config.json',\n",
    "'config.json',\n",
    "'styles.csv'\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.547389Z",
     "iopub.status.busy": "2023-06-06T13:31:46.546557Z",
     "iopub.status.idle": "2023-06-06T13:31:46.562867Z",
     "shell.execute_reply": "2023-06-06T13:31:46.561790Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.547353Z"
    }
   },
   "outputs": [],
   "source": [
    "#模型和插件\n",
    "\n",
    "# 插件列表: git仓库地址\n",
    "# 不需要的插件在前面加 # ,插件地址之间需要用英语逗号隔开\n",
    "extensions = [\n",
    "    'https://github.com/Elldreth/loopback_scaler',\n",
    "    'https://github.com/jexom/sd-webui-depth-lib',\n",
    "    #'https://github.com/AlUlkesh/stable-diffusion-webui-images-browser',\n",
    "    'https://github.com/camenduru/sd-civitai-browser',\n",
    "    'https://github.com/Mikubill/sd-webui-controlnet',\n",
    "    'https://github.com/nonnonstop/sd-webui-3d-open-pose-editor',\n",
    "    'https://github.com/dtlnor/stable-diffusion-webui-localization-zh_CN',\n",
    "    'https://github.com/opparco/stable-diffusion-webui-two-shot',\n",
    "    #'https://github.com/minicacas/stable-diffusion-webui-composable-lora',\n",
    "    'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',\n",
    "    'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',\n",
    "    #'https://github.com/KohakuBlueleaf/a1111-sd-webui-locon',\n",
    "    'https://github.com/hnmr293/sd-webui-cutoff',\n",
    "    'https://github.com/hako-mikan/sd-webui-lora-block-weight',\n",
    "    'https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper',\n",
    "    'https://github.com/catppuccin/stable-diffusion-webui',\n",
    "    #'https://github.com/Nevysha/Cozy-Nest',\n",
    "    'https://github.com/Scholar01/sd-webui-mov2mov',\n",
    "    'https://github.com/toriato/stable-diffusion-webui-wd14-tagger',\n",
    "    'https://github.com/Physton/sd-webui-prompt-all-in-one',\n",
    "    'https://github.com/KohakuBlueleaf/a1111-sd-webui-lycoris',\n",
    "    #'https://github.com/deforum-art/sd-webui-deforum',\n",
    "    'https://github.com/Scholar01/sd-webui-mov2mov',\n",
    "    'https://github.com/zanllp/sd-webui-infinite-image-browsing',\n",
    "]\n",
    "\n",
    "# Stable Diffusion模型请放在这里(不用填模型的文件名,只填模型的目录即可)\n",
    "sd_model = [\n",
    "#'/kaggle/input/cetus-mix/',\n",
    "#'/kaggle/input/aom3ackpt',\n",
    "'/kaggle/input/9527-fp16',\n",
    "#'/kaggle/input/dalcefo-painting',\n",
    "            ]\n",
    "# Stable Diffusion模型下载链接放这里\n",
    "sd_model_urls=[\n",
    "#GhostMix_v1.2\n",
    "'https://civitai.com/api/download/models/59685',\n",
    "'https://huggingface.co/swl-models/9527/resolve/main/9527-non-ema-fp16.safetensors',\n",
    "#Counterfeit-V3.0\n",
    "'https://civitai.com/api/download/models/57618',\n",
    "#LibraMix\n",
    "'https://civitai.com/api/download/models/41391',\n",
    "'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/cetusMix_Coda2.safetensors',\n",
    "'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/cetusMix_Version35.safetensors',\n",
    "\n",
    "]\n",
    "\n",
    "# VAE模型请放在这里(不用填模型的文件名,只填模型的目录即可)\n",
    "vae_model = []\n",
    "#VAE模型下载链接放这里\n",
    "vae_model_urls=[\n",
    "'https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.safetensors',\n",
    "'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/clearvae.vae.pt',\n",
    "'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/klF8Anime2.vae.pt',\n",
    "'https://huggingface.co/dector/vae-840000/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt'\n",
    "]\n",
    "\n",
    "# Lora模型的数据集路径请写在这里:\n",
    "lora_model = [\n",
    "#'/kaggle/input/lora-1',\n",
    "] \n",
    "# Lora模型下载链接放这里\n",
    "lora_model_urls=[\n",
    "#墨心\n",
    "'https://civitai.com/api/download/models/14856',\n",
    "#山楂糕\n",
    "'https://civitai.com/api/download/models/41580',\n",
    "#细节调整\n",
    "'https://civitai.com/api/download/models/62833'\n",
    "]\n",
    "# Lycoris和loha模型的数据集路径请写在这里:\n",
    "lyco_model = [\n",
    "#'/kaggle/input/lora-1',\n",
    "] \n",
    "# Lycoris和loha模型下载链接放这里\n",
    "lyco_model_urls=[\n",
    "#FilmGirl 胶片风\n",
    "'https://civitai.com/api/download/models/75069',\n",
    "#Teacher clothes 教师衣服\n",
    "\"https://civitai.com/api/download/models/65426\",\n",
    "#伪日光\n",
    "'https://civitai.com/api/download/models/71235'\n",
    "]\n",
    "\n",
    "# ControlNet模型data请放在这里:\n",
    "cn_model = [\n",
    "]\n",
    "# controlnet模型下载链接放这里\n",
    "cn_model_urls = [\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors',\n",
    "'https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors',\n",
    "]\n",
    "\n",
    "# Hypernetworks超网络模型路径请放在这里:\n",
    "hypernetworks_model = []\n",
    "#Hypernetworks超网络模型下载链接请放在这里\n",
    "hypernetworks_model_urls = []\n",
    "\n",
    "#放大算法路径请放在这里\n",
    "ESRGAN = []\n",
    "#放大算法链接请放在这里\n",
    "ESRGAN_urls = [\n",
    "'https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth',\n",
    "'https://huggingface.co/konohashinobi4/4xAnimesharp/resolve/main/4x-AnimeSharp.pth',\n",
    "'https://huggingface.co/lokCX/4x-Ultrasharp/resolve/main/4x-UltraSharp.pth',\n",
    "]\n",
    "\n",
    "# embeddings(pt文件)请放在这里:\n",
    "embeddings_model = [\n",
    "'/kaggle/input/bad-embedding',\n",
    "] \n",
    "# embeddings(pt文件)下载链接请放在这里:\n",
    "embeddings_model_urls=[\n",
    "'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/EasyNegative.pt',\n",
    "'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad-artist-anime.pt',\n",
    "'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad-hands-5.pt',\n",
    "'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad_prompt_version2.pt',\n",
    "'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad-image-v2-39000.pt',\n",
    "]\n",
    "\n",
    "#script文件导入\n",
    "scripts = []\n",
    "#script文件下载链接导入\n",
    "scripts_urls = [\n",
    "'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/repositories/k-diffusion/k_diffusion/sampling.py'\n",
    "]\n",
    "\n",
    "#tag词库文件导入\n",
    "tags = []\n",
    "#tag词库文件下载链接导入\n",
    "tags_urls=[\n",
    "\"https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/danbooru.zh_CN.csv\",\n",
    "]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.566538Z",
     "iopub.status.busy": "2023-06-06T13:31:46.565625Z",
     "iopub.status.idle": "2023-06-06T13:31:46.577054Z",
     "shell.execute_reply": "2023-06-06T13:31:46.576054Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.566489Z"
    }
   },
   "outputs": [],
   "source": [
    "#ngrok穿透\n",
    "ngrok_use = True\n",
    "ngrokTokenFile='/kaggle/input/tenkens/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径\n",
    "#Frp 内网穿透\n",
    "use_frpc = False\n",
    "frpconfigfile = '/kaggle/input/tenkens/7860.ini'  # 非必填 frp 配置文件,本地端口 7860\n",
    "\n",
    "# 启动时默认加载的模型名称 填模型名称,名称建议带上文件名后缀\n",
    "usedCkpt = 'cetusMix_Coda2.safetensors'\n",
    "\n",
    "#启动参数\n",
    "args = [\n",
    "    '--share',\n",
    "    '--xformers',\n",
    "    '--lowram',\n",
    "    '--no-hashing',\n",
    "    '--disable-nan-check',\n",
    "    '--enable-insecure-extension-access',\n",
    "    '--disable-console-progressbars',\n",
    "    '--enable-console-prompts',\n",
    "    '--no-gradio-queue',\n",
    "    '--no-half-vae',\n",
    "    '--api',\n",
    "    f'--lyco-dir {install_path}/models/lyco',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.581718Z",
     "iopub.status.busy": "2023-06-06T13:31:46.580945Z",
     "iopub.status.idle": "2023-06-06T13:31:46.590885Z",
     "shell.execute_reply": "2023-06-06T13:31:46.589987Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.581685Z"
    }
   },
   "outputs": [],
   "source": [
    "use2 = False#是否开启两个webui\n",
    "#ngrok穿透\n",
    "ngrok_use1 = True\n",
    "ngrokTokenFile1='/kaggle/input/tenkens/Authtoken1.txt' # 非必填 存放ngrokToken的文件的路径\n",
    "#Frp 内网穿透\n",
    "use_frpc1 = False\n",
    "frpconfigfile1 = '/kaggle/input/tenkens/7861.ini'  # 非必填 frp 配置文件,本地端口 7860\n",
    "\n",
    "#第二个webui使用的模型\n",
    "usedCkpt1 = 'cetusMix_Coda2.safetensors'\n",
    "\n",
    "#启动参数\n",
    "args1 = [\n",
    "    '--share',\n",
    "    '--xformers',\n",
    "    '--lowram',\n",
    "    '--no-hashing',\n",
    "    '--disable-nan-check',\n",
    "    '--enable-insecure-extension-access',\n",
    "    '--disable-console-progressbars',\n",
    "    '--enable-console-prompts',\n",
    "    '--no-gradio-queue',\n",
    "    '--no-half-vae',\n",
    "    '--api',\n",
    "    f'--lyco-dir {install_path}/models/lyco',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.592964Z",
     "iopub.status.busy": "2023-06-06T13:31:46.592528Z",
     "iopub.status.idle": "2023-06-06T13:31:46.604934Z",
     "shell.execute_reply": "2023-06-06T13:31:46.603982Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.592932Z"
    }
   },
   "outputs": [],
   "source": [
    "#使用的库\n",
    "from pathlib import Path\n",
    "import subprocess\n",
    "import pandas as pd\n",
    "import shutil\n",
    "import os\n",
    "import time\n",
    "import re\n",
    "import gc\n",
    "import requests\n",
    "import zipfile\n",
    "from concurrent.futures import ProcessPoolExecutor\n",
    "os.environ['install_path'] = install_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.639329Z",
     "iopub.status.busy": "2023-06-06T13:31:46.638634Z",
     "iopub.status.idle": "2023-06-06T13:31:46.656693Z",
     "shell.execute_reply": "2023-06-06T13:31:46.655745Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.639297Z"
    }
   },
   "outputs": [],
   "source": [
    "#功能函数,内存优化\n",
    "def libtcmalloc():\n",
    "    if os.path.exists('/kaggle/temp'):\n",
    "        os.chdir('/kaggle')\n",
    "        os.chdir('temp')\n",
    "        os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n",
    "        print('内存优化已安装')\n",
    "    else:\n",
    "        \n",
    "        if use_frpc:\n",
    "            !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/datasets/ACCA225/Frp/resolve/main/frpc -d /kaggle/working/frpc -o frpc\n",
    "        os.system('pip install -q pyngrok ')\n",
    "        os.chdir('/kaggle')\n",
    "        os.makedirs('temp', exist_ok=True)\n",
    "        os.chdir('temp')\n",
    "        os.system('wget -qq  http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb')\n",
    "        os.system('wget -qq  https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb')\n",
    "        os.system('wget -qq  https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb')\n",
    "        os.system('wget -qq  https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb')\n",
    "        os.system('apt install -qq libunwind8-dev -y')\n",
    "        !dpkg -i *.deb\n",
    "        os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n",
    "        !rm *.deb\n",
    "        print('内存优化已安装')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.663280Z",
     "iopub.status.busy": "2023-06-06T13:31:46.662694Z",
     "iopub.status.idle": "2023-06-06T13:31:46.803906Z",
     "shell.execute_reply": "2023-06-06T13:31:46.802897Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.663234Z"
    }
   },
   "outputs": [],
   "source": [
    "#功能函数,环境和sd_webui安装\n",
    "def unzip_file(src: str, dest: str = '/kaggle/outputs'):\n",
    "    if os.path.exists(src):\n",
    "        with zipfile.ZipFile(src, 'r') as zip_ref:\n",
    "            for member in zip_ref.namelist():\n",
    "                filename = os.path.basename(member)\n",
    "                if not filename:\n",
    "                    continue\n",
    "                dest_file = os.path.join(dest, filename)\n",
    "                if os.path.exists(dest_file):\n",
    "                    os.remove(dest_file)\n",
    "                zip_ref.extract(member, dest)\n",
    "\n",
    "def webui_config_download(yun_files, huggiingface_repo_id):\n",
    "    %cd $install_path/stable-diffusion-webui/\n",
    "    for yun_file in yun_files:\n",
    "        url = f'https://huggingface.co/datasets/{huggiingface_repo_id}/resolve/main/{yun_file}'\n",
    "        response = requests.head(url)\n",
    "        if response.status_code == 200:\n",
    "            result = subprocess.run(['wget', '-O', yun_file, url, '-q'], capture_output=True)\n",
    "            if result.returncode != 0:\n",
    "                print(f'Error: Failed to download {yun_file} from {url}')\n",
    "        else:\n",
    "            print(f'Error: Invalid URL {url}')\n",
    "    \n",
    "def venv_install():\n",
    "    %cd /opt/conda/envs\n",
    "    if os.path.exists('venv'):\n",
    "        print('环境已安装')\n",
    "    else:\n",
    "        %cd /kaggle/working/\n",
    "        if not os.path.exists('venv.tar.gz'):\n",
    "            print('环境包下载中')\n",
    "            !wget https://huggingface.co/datasets/sukaka/venv_ai_drow/resolve/main/sd_webui/sd_webui_torch201_cu118_xf20.tar.gz -O venv.tar.gz\n",
    "        print('环境包已下载')\n",
    "        %cd /opt/conda/envs/\n",
    "        !mkdir venv\n",
    "        %cd venv\n",
    "        print('环境安装中')\n",
    "        os.system('apt -y install -qq pigz > /dev/null 2>&1')\n",
    "        !pigz -dc -p 5 /kaggle/working/venv.tar.gz | tar xf -\n",
    "        !source /opt/conda/bin/activate venv\n",
    "        print('环境安装完毕')\n",
    "\n",
    "#安装webui\n",
    "def install_webui():\n",
    "    %cd $install_path\n",
    "    if reLoad:\n",
    "        !rm -rf stable-diffusion-webui\n",
    "    if Path(\"stable-diffusion-webui\").exists():\n",
    "        if updata_webui:\n",
    "            %cd $install_path/stable-diffusion-webui/\n",
    "            !git pull\n",
    "        print('stable-diffusion-webui已安装')\n",
    "    else:\n",
    "        print('stable-diffusion-webui安装中')\n",
    "        #Download Automatic1111's Stable Diffusion Web UI\n",
    "        !git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
    "        %cd $install_path/stable-diffusion-webui/\n",
    "        #Use lastest version\n",
    "        !git checkout 20ae71faa8ef035c31aa3a410b707d792c8203a3\n",
    "        with open('launch.py', 'r') as f:\n",
    "            content = f.read()\n",
    "        with open('launch.py', 'w') as f:\n",
    "            f.write('import ssl\\n')\n",
    "            f.write('ssl._create_default_https_context = ssl._create_unverified_context\\n')\n",
    "            f.write(content)\n",
    "        print('stable-diffusion-webui已安装')\n",
    "    if huggingface_use:\n",
    "        webui_config_download(yun_files, huggiingface_repo_id)\n",
    "    \n",
    "    unzip_file('/kaggle/working/图片.zip')\n",
    "    install_extensions(install_path, extensions)\n",
    "    download_model()\n",
    "    link_models()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.807018Z",
     "iopub.status.busy": "2023-06-06T13:31:46.806411Z",
     "iopub.status.idle": "2023-06-06T13:31:46.833796Z",
     "shell.execute_reply": "2023-06-06T13:31:46.832760Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.806981Z"
    }
   },
   "outputs": [],
   "source": [
    "from concurrent.futures import ThreadPoolExecutor\n",
    "# 安装插件,下载和同步模型\n",
    "def install_extensions(install_path, extensions):\n",
    "    print('安装插件,此处出现红条是正常的')\n",
    "    os.chdir(os.path.join(install_path, 'stable-diffusion-webui'))\n",
    "    os.makedirs('extensions', exist_ok=True)\n",
    "    os.chdir('extensions')\n",
    "\n",
    "    def clone_repo(ex):\n",
    "        repo_name = ex.split('/')[-1]\n",
    "        if not os.path.exists(repo_name):\n",
    "            os.system('git clone ' + ex)\n",
    "\n",
    "    with ThreadPoolExecutor(max_workers=4) as executor:\n",
    "        executor.map(clone_repo, extensions)\n",
    "    \n",
    "def download_link(link, target_folder):\n",
    "    if link.startswith('https://huggingface.co/'):\n",
    "        filename = re.search(r'[^/]+$', link).group(0)\n",
    "        return f'aria2c --console-log-level=error -q -c -x 16 -s 16 -k 1M -d \"{target_folder}\" -o \"{filename}\" \"{link}\"'\n",
    "    else:\n",
    "        return f'aria2c --console-log-level=error -q -c -x 16 -s 16 -k 1M --remote-time -d \"{target_folder}\" \"{link}\"'\n",
    "\n",
    "def download_links(links, target_folder):\n",
    "    tasks = []\n",
    "    for link in links:\n",
    "        tasks.append(download_link(link, target_folder))\n",
    "    return tasks\n",
    "\n",
    "def download_links_all(tasks):\n",
    "    with ThreadPoolExecutor(max_workers=5) as executor:\n",
    "        for task in tasks:\n",
    "            executor.submit(os.system, task)\n",
    "        \n",
    "# 下载模型文件\n",
    "def download_model():\n",
    "    os.chdir('/kaggle')\n",
    "    os.makedirs('models', exist_ok=True)\n",
    "    os.chdir('models')\n",
    "    os.makedirs('VAE', exist_ok=True)\n",
    "    os.makedirs('Stable-diffusion', exist_ok=True)\n",
    "    os.makedirs('Lora', exist_ok=True)\n",
    "    os.makedirs('cn-model', exist_ok=True)\n",
    "    os.makedirs('hypernetworks', exist_ok=True)\n",
    "    os.makedirs('ESRGAN', exist_ok=True)\n",
    "    os.makedirs('lyco', exist_ok=True)\n",
    "    tasks = []\n",
    "    tasks.extend(download_links(vae_model_urls, 'VAE'))\n",
    "    tasks.extend(download_links(sd_model_urls, 'Stable-diffusion'))\n",
    "    tasks.extend(download_links(lora_model_urls, 'Lora'))\n",
    "    tasks.extend(download_links(cn_model_urls, 'cn-model'))\n",
    "    tasks.extend(download_links(hypernetworks_model_urls, 'hypernetworks'))\n",
    "    tasks.extend(download_links(ESRGAN_urls, 'ESRGAN'))\n",
    "    tasks.extend(download_links(lyco_model_urls, 'lyco'))\n",
    "    tasks.extend(download_links(embeddings_model_urls, f'{install_path}/stable-diffusion-webui/embeddings'))\n",
    "    tasks.extend(download_links(scripts_urls, f'{install_path}/stable-diffusion-webui/scripts'))\n",
    "    tasks.extend(download_links(tags_urls, f'{install_path}/stable-diffusion-webui/extensions/a1111-sd-webui-tagcomplete/tags'))\n",
    "    download_links_all(tasks)\n",
    "\n",
    "def create_symlinks(folder_paths, target_dir):\n",
    "    # Create target directory if it doesn't exist\n",
    "    if not os.path.exists(target_dir):\n",
    "        os.makedirs(target_dir)\n",
    "    # Remove broken symlinks in target directory\n",
    "    for filename in os.listdir(target_dir):\n",
    "        target_path = os.path.join(target_dir, filename)\n",
    "        if os.path.islink(target_path) and not os.path.exists(target_path):\n",
    "            os.unlink(target_path)\n",
    "    # Create new symlinks\n",
    "    for source_path in folder_paths:\n",
    "        if not os.path.exists(source_path):\n",
    "            continue\n",
    "        if os.path.isdir(source_path):\n",
    "            for filename in os.listdir(source_path):\n",
    "                source_file_path = os.path.join(source_path, filename)\n",
    "                target_file_path = os.path.join(target_dir, filename)\n",
    "                if not os.path.exists(target_file_path):\n",
    "                    os.symlink(source_file_path, target_file_path)\n",
    "                    print(f'Created symlink for {filename} in {target_dir}')\n",
    "        else:\n",
    "            filename = os.path.basename(source_path)\n",
    "            target_file_path = os.path.join(target_dir, filename)\n",
    "            if not os.path.exists(target_file_path):\n",
    "                os.symlink(source_path, target_file_path)\n",
    "                print(f'Created symlink for {filename} in {target_dir}')\n",
    "\n",
    "# 链接模型文件\n",
    "def link_models():\n",
    "    cn_model.append('/kaggle/models/cn-model')\n",
    "    vae_model.append('/kaggle/models/VAE')\n",
    "    sd_model.append('/kaggle/models/Stable-diffusion')\n",
    "    lora_model.append('/kaggle/models/Lora')\n",
    "    hypernetworks_model.append('/kaggle/models/hypernetworks')\n",
    "    ESRGAN.append('/kaggle/models/ESRGAN')\n",
    "    lyco_model.append('/kaggle/models/lyco')\n",
    "    \n",
    "    create_symlinks(vae_model,f'{install_path}/stable-diffusion-webui/models/VAE')\n",
    "    create_symlinks(sd_model,f'{install_path}/stable-diffusion-webui/models/Stable-diffusion')\n",
    "    create_symlinks(lora_model,f'{install_path}/stable-diffusion-webui/models/Lora')\n",
    "    create_symlinks(cn_model,f'{install_path}/stable-diffusion-webui/extensions/sd-webui-controlnet/models')\n",
    "    create_symlinks(embeddings_model,f'{install_path}/stable-diffusion-webui/embeddings')\n",
    "    create_symlinks(hypernetworks_model,f'{install_path}/stable-diffusion-webui/models/hypernetworks')\n",
    "    create_symlinks(ESRGAN,f'{install_path}/stable-diffusion-webui/models/ESRGAN')\n",
    "    create_symlinks(tags,f'{install_path}/stable-diffusion-webui/extensions/a1111-sd-webui-tagcomplete/tags')\n",
    "    create_symlinks(scripts,f'{install_path}/stable-diffusion-webui/scripts')\n",
    "    create_symlinks(lyco_model,f'{install_path}/stable-diffusion-webui/models/lyco')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.836148Z",
     "iopub.status.busy": "2023-06-06T13:31:46.835356Z",
     "iopub.status.idle": "2023-06-06T13:31:46.848925Z",
     "shell.execute_reply": "2023-06-06T13:31:46.847899Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.836114Z"
    }
   },
   "outputs": [],
   "source": [
    "# 功能函数:内网穿透\n",
    "#ngrok\n",
    "def ngrok_start(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):\n",
    "    if not should_run:\n",
    "        print('Skipping ngrok start')\n",
    "        return\n",
    "    if Path(ngrokTokenFile).exists():\n",
    "        with open(ngrokTokenFile, encoding=\"utf-8\") as nkfile:\n",
    "            ngrokToken = nkfile.readline()\n",
    "        print('use nrgok')\n",
    "        from pyngrok import conf, ngrok\n",
    "        conf.get_default().auth_token = ngrokToken\n",
    "        conf.get_default().monitor_thread = False\n",
    "        ssh_tunnels = ngrok.get_tunnels(conf.get_default())\n",
    "        if len(ssh_tunnels) == 0:\n",
    "            ssh_tunnel = ngrok.connect(port, bind_tls=True)\n",
    "            print(f'{address_name}:' + ssh_tunnel.public_url)\n",
    "        else:\n",
    "            print(f'{address_name}:' + ssh_tunnels[0].public_url)\n",
    "    else:\n",
    "        print('skip start ngrok')\n",
    "\n",
    "#Frp内网穿透 \n",
    "import subprocess\n",
    "\n",
    "def install_Frpc(port, frpconfigfile, use_frpc):\n",
    "    if use_frpc:\n",
    "        subprocess.run(['chmod', '+x', '/kaggle/working/frpc/frpc'], check=True)\n",
    "        print(f'正在启动frp ,端口{port}')\n",
    "        subprocess.Popen(['/kaggle/working/frpc/frpc', '-c', frpconfigfile])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.850990Z",
     "iopub.status.busy": "2023-06-06T13:31:46.850524Z",
     "iopub.status.idle": "2023-06-06T13:31:46.880599Z",
     "shell.execute_reply": "2023-06-06T13:31:46.879664Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.850959Z"
    }
   },
   "outputs": [],
   "source": [
    "#sd_webui启动\n",
    "def start_webui_1():\n",
    "    if use2:\n",
    "        install_Frpc('7861',frpconfigfile1,use_frpc1)\n",
    "        ngrok_start(ngrokTokenFile1,7861,'第二个webui',ngrok_use1)\n",
    "        !sleep 90\n",
    "        %cd $install_path/stable-diffusion-webui\n",
    "        args1.append(f'--ckpt=models/Stable-diffusion/{usedCkpt1}')\n",
    "        !/opt/conda/envs/venv/bin/python3 launch.py {' '.join(args1)} --port 7861 --device-id=1\n",
    "    pass\n",
    "\n",
    "def start_webui_0():\n",
    "    %cd $install_path\n",
    "    install_Frpc('7860',frpconfigfile,use_frpc)\n",
    "    ngrok_start(ngrokTokenFile,7860,'第一个webui',ngrok_use)\n",
    "    %cd $install_path/stable-diffusion-webui\n",
    "    !mkdir models/lyco\n",
    "    args.append(f'--ckpt=models/Stable-diffusion/{usedCkpt}')\n",
    "    !/opt/conda/envs/venv/bin/python3 launch.py {' '.join(args)}\n",
    "    \n",
    "def start_webui():\n",
    "    with ProcessPoolExecutor() as executor:\n",
    "        futures = []\n",
    "        for func in [start_webui_0, start_webui_1]:\n",
    "            futures.append(executor.submit(func))\n",
    "            time.sleep(1)\n",
    "        for future in futures:\n",
    "            future.result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecutionIndicator": {
     "show": false
    },
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.885282Z",
     "iopub.status.busy": "2023-06-06T13:31:46.884930Z",
     "iopub.status.idle": "2023-06-06T13:31:46.894440Z",
     "shell.execute_reply": "2023-06-06T13:31:46.893449Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.885258Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def main():\n",
    "    startTicks = time.time()\n",
    "    os.system('apt-get update')\n",
    "    os.system('apt -y install -qq aria2')\n",
    "    with ProcessPoolExecutor() as executor:\n",
    "        futures = []\n",
    "        for func in [install_webui, venv_install,libtcmalloc]:\n",
    "            futures.append(executor.submit(func))\n",
    "            time.sleep(0.5)\n",
    "        for future in futures:\n",
    "            future.result()\n",
    "    libtcmalloc()\n",
    "    ticks = time.time()\n",
    "    print(\"加载耗时:\",(ticks - startTicks),\"s\")\n",
    "    start_webui()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:46.897858Z",
     "iopub.status.busy": "2023-06-06T13:31:46.896912Z",
     "iopub.status.idle": "2023-06-06T13:31:47.215286Z",
     "shell.execute_reply": "2023-06-06T13:31:47.214328Z",
     "shell.execute_reply.started": "2023-06-06T13:31:46.897806Z"
    }
   },
   "outputs": [],
   "source": [
    "#功能函数,清理打包上传\n",
    "from pathlib import Path\n",
    "from huggingface_hub import HfApi, login\n",
    "\n",
    "def zip_venv():\n",
    "        !pip install conda-pack\n",
    "        !rm -rf /kaggle/working/venv.tar.gz\n",
    "        !conda pack -n venv -o /kaggle/working/venv.tar.gz --compress-level 0\n",
    "\n",
    "def hugface_upload(huggingface_token_file, yun_files, repo_id):\n",
    "    if Path(huggingface_token_file).exists():\n",
    "        with open(huggingface_token_file, encoding=\"utf-8\") as nkfile:\n",
    "            hugToken = nkfile.readline()\n",
    "        if hugToken != '':\n",
    "            # 使用您的 Hugging Face 访问令牌登录\n",
    "            login(token=hugToken)\n",
    "            # 实例化 HfApi 类\n",
    "            api = HfApi()\n",
    "            print(\"HfApi 类已实例化\")\n",
    "            %cd $install_path/stable-diffusion-webui\n",
    "            # 使用 upload_file() 函数上传文件\n",
    "            print(\"开始上传文件...\")\n",
    "            for yun_file in yun_files:\n",
    "                if Path(yun_file).exists():\n",
    "                    response = api.upload_file(\n",
    "                        path_or_fileobj=yun_file,\n",
    "                        path_in_repo=yun_file,\n",
    "                        repo_id=repo_id,\n",
    "                        repo_type=\"dataset\"\n",
    "                    )\n",
    "                    print(\"文件上传完成\")\n",
    "                    print(f\"响应: {response}\")\n",
    "                else:\n",
    "                    print(f'Error: File {yun_file} does not exist')\n",
    "    else:\n",
    "        print(f'Error: File {huggingface_token_file} does not exist')\n",
    "\n",
    "def clean_folder(folder_path):\n",
    "    if not os.path.exists(folder_path):\n",
    "        return\n",
    "    for filename in os.listdir(folder_path):\n",
    "        file_path = os.path.join(folder_path, filename)\n",
    "        if os.path.isfile(file_path):\n",
    "            os.remove(file_path)\n",
    "        elif os.path.isdir(file_path):\n",
    "            shutil.rmtree(file_path)\n",
    "\n",
    "def zip_clear_updata():\n",
    "    if zip_output:\n",
    "        output_folder = '/kaggle/outputs/'\n",
    "        if os.path.exists(output_folder):\n",
    "            shutil.make_archive('/kaggle/working/图片', 'zip', output_folder)\n",
    "            print('图片已压缩到output')\n",
    "        else:\n",
    "            print(f'文件夹 {output_folder} 不存在,跳过压缩操作')\n",
    "    if clear_output:\n",
    "        %cd /kaggle/outputs/\n",
    "        clean_folder('img2img-images')\n",
    "        clean_folder('txt2img-images')\n",
    "        clean_folder('img2img-grids')\n",
    "        clean_folder('txt2img-grids')\n",
    "        clean_folder('extras-images')\n",
    "        print('清理完毕')\n",
    "    if huggingface_use == True:\n",
    "        hugface_upload(huggingface_token_file,yun_files,huggiingface_repo_id)\n",
    "    if use_zip_venv == True:\n",
    "        zip_venv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "_kg_hide-input": true,
    "_kg_hide-output": false,
    "execution": {
     "iopub.execute_input": "2023-06-06T13:31:47.217158Z",
     "iopub.status.busy": "2023-06-06T13:31:47.216771Z",
     "iopub.status.idle": "2023-06-06T13:40:24.664600Z",
     "shell.execute_reply": "2023-06-06T13:40:24.661769Z",
     "shell.execute_reply.started": "2023-06-06T13:31:47.217124Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The following additional packages will be installed:\n",
      "  libaria2-0 libc-ares2 libssh2-1\n",
      "The following NEW packages will be installed:\n",
      "  aria2 libaria2-0 libc-ares2 libssh2-1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "dpkg-preconfigure: unable to re-open stdin: No such file or directory\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 upgraded, 4 newly installed, 0 to remove and 28 not upgraded.\n",
      "Need to get 1622 kB of archives.\n",
      "After this operation, 5817 kB of additional disk space will be used.\n",
      "Selecting previously unselected package libc-ares2:amd64.\n",
      "(Reading database ... 115376 files and directories currently installed.)\n",
      "Preparing to unpack .../libc-ares2_1.18.1-1ubuntu0.22.04.1_amd64.deb ...\n",
      "Unpacking libc-ares2:amd64 (1.18.1-1ubuntu0.22.04.1) ...\n",
      "Selecting previously unselected package libssh2-1:amd64.\n",
      "Preparing to unpack .../libssh2-1_1.10.0-3_amd64.deb ...\n",
      "Unpacking libssh2-1:amd64 (1.10.0-3) ...\n",
      "Selecting previously unselected package libaria2-0:amd64.\n",
      "Preparing to unpack .../libaria2-0_1.36.0-1_amd64.deb ...\n",
      "Unpacking libaria2-0:amd64 (1.36.0-1) ...\n",
      "Selecting previously unselected package aria2.\n",
      "Preparing to unpack .../aria2_1.36.0-1_amd64.deb ...\n",
      "Unpacking aria2 (1.36.0-1) ...\n",
      "Setting up libc-ares2:amd64 (1.18.1-1ubuntu0.22.04.1) ...\n",
      "Setting up libssh2-1:amd64 (1.10.0-3) ...\n",
      "Setting up libaria2-0:amd64 (1.36.0-1) ...\n",
      "Setting up aria2 (1.36.0-1) ...\n",
      "Processing triggers for man-db (2.10.2-1) ...\n",
      "Processing triggers for libc-bin (2.35-0ubuntu3.1) ...\n",
      "/kaggle/working\n",
      "stable-diffusion-webui安装中\n",
      "/opt/conda/envs\n",
      "/kaggle/working\n",
      "环境包下载中\n",
      "Cloning into 'stable-diffusion-webui'...\n",
      "--2023-06-06 13:31:56--  https://huggingface.co/datasets/sukaka/venv_ai_drow/resolve/main/sd_webui/sd_webui_torch201_cu118_xf20.tar.gz\n",
      "Resolving huggingface.co (huggingface.co)... 18.172.170.36, 18.172.170.44, 18.172.170.14, ...\n",
      "Connecting to huggingface.co (huggingface.co)|18.172.170.36|:443... connected.\n",
      "HTTP request sent, awaiting response... 302 Found\n",
      "Location: https://cdn-lfs.huggingface.co/repos/93/61/936160f9623602ad97a9fe4c639531b59f4fe39854fcc22d75692344fb5dfbe2/609336a63928c38f99b0f842dd5d08e1bf255a8add61cbe82301ca5611831b34?response-content-disposition=attachment%3B+filename*%3DUTF-8%27%27sd_webui_torch201_cu118_xf20.tar.gz%3B+filename%3D%22sd_webui_torch201_cu118_xf20.tar.gz%22%3B&response-content-type=application%2Fgzip&Expires=1686317516&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9jZG4tbGZzLmh1Z2dpbmdmYWNlLmNvL3JlcG9zLzkzLzYxLzkzNjE2MGY5NjIzNjAyYWQ5N2E5ZmU0YzYzOTUzMWI1OWY0ZmUzOTg1NGZjYzIyZDc1NjkyMzQ0ZmI1ZGZiZTIvNjA5MzM2YTYzOTI4YzM4Zjk5YjBmODQyZGQ1ZDA4ZTFiZjI1NWE4YWRkNjFjYmU4MjMwMWNhNTYxMTgzMWIzND9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSomcmVzcG9uc2UtY29udGVudC10eXBlPSoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2ODYzMTc1MTZ9fX1dfQ__&Signature=LwdrbEvX1FsAqiCMdTpr0MpZSEMQNNbdeFdUntUzSm0wgYI4id719q7A7SQsLFDp1Nxem0qv1SWZUOp56Rn4dDMLBompEERivj0WIDqUueRmZfBvVK6YevuBeACN4Vc8XGtepe0XDJdfRf3fbeAmOwzAClyVbwAvrbXm6vCREihObTNQ4-SOTR2Lps6vWXn1K-z%7EhbUVAINqrFC1mNsRLcUYGx8ZHCiQA%7Ez35UiOURAONM-0myvcZlM0wZQRy819DJsD5q1SSfe27yyO262PkWt4dv0ra%7EmqLcP1msDNmyB2%7E%7EgRCKPTFX-r4SO0Il7WvtoupBEuqjou7LLyWzh2UA__&Key-Pair-Id=KVTP0A1DKRTAX [following]\n",
      "--2023-06-06 13:31:56--  https://cdn-lfs.huggingface.co/repos/93/61/936160f9623602ad97a9fe4c639531b59f4fe39854fcc22d75692344fb5dfbe2/609336a63928c38f99b0f842dd5d08e1bf255a8add61cbe82301ca5611831b34?response-content-disposition=attachment%3B+filename*%3DUTF-8%27%27sd_webui_torch201_cu118_xf20.tar.gz%3B+filename%3D%22sd_webui_torch201_cu118_xf20.tar.gz%22%3B&response-content-type=application%2Fgzip&Expires=1686317516&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9jZG4tbGZzLmh1Z2dpbmdmYWNlLmNvL3JlcG9zLzkzLzYxLzkzNjE2MGY5NjIzNjAyYWQ5N2E5ZmU0YzYzOTUzMWI1OWY0ZmUzOTg1NGZjYzIyZDc1NjkyMzQ0ZmI1ZGZiZTIvNjA5MzM2YTYzOTI4YzM4Zjk5YjBmODQyZGQ1ZDA4ZTFiZjI1NWE4YWRkNjFjYmU4MjMwMWNhNTYxMTgzMWIzND9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSomcmVzcG9uc2UtY29udGVudC10eXBlPSoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE2ODYzMTc1MTZ9fX1dfQ__&Signature=LwdrbEvX1FsAqiCMdTpr0MpZSEMQNNbdeFdUntUzSm0wgYI4id719q7A7SQsLFDp1Nxem0qv1SWZUOp56Rn4dDMLBompEERivj0WIDqUueRmZfBvVK6YevuBeACN4Vc8XGtepe0XDJdfRf3fbeAmOwzAClyVbwAvrbXm6vCREihObTNQ4-SOTR2Lps6vWXn1K-z%7EhbUVAINqrFC1mNsRLcUYGx8ZHCiQA%7Ez35UiOURAONM-0myvcZlM0wZQRy819DJsD5q1SSfe27yyO262PkWt4dv0ra%7EmqLcP1msDNmyB2%7E%7EgRCKPTFX-r4SO0Il7WvtoupBEuqjou7LLyWzh2UA__&Key-Pair-Id=KVTP0A1DKRTAX\n",
      "Resolving cdn-lfs.huggingface.co (cdn-lfs.huggingface.co)... 18.65.229.16, 18.65.229.73, 18.65.229.83, ...\n",
      "Connecting to cdn-lfs.huggingface.co (cdn-lfs.huggingface.co)|18.65.229.16|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 2912904935 (2.7G) [application/gzip]\n",
      "Saving to: ‘venv.tar.gz’\n",
      "\n",
      "venv.tar.gz           0%[                    ]       0  --.-KB/s               remote: Enumerating objects: 22280, done.\u001b[K\n",
      "remote: Counting objects: 100% (426/426), done.\u001b[K\n",
      "remote: Compressing objects: 100% (250/250), done.\u001b[K\n",
      "remote: Total 22280 (delta 235), reused 291 (delta 156), pack-reused 21854\u001b[K  Receiving objects:   2% (446/22280)Receiving objects:  23% (5125/22280)Receiving objects:  30% (6684/22280), 5.04 MiB | 10.07 MiB/sReceiving objects:  36% (8021/22280), 5.04 MiB | 10.07 MiB/sReceiving objects:  46% (10249/22280), 5.04 MiB | 10.07 MiB/sReceiving objects:  54% (12032/22280), 16.66 MiB | 11.08 MiB/sReceiving objects:  70% (15596/22280), 16.66 MiB | 11.08 MiB/sReceiving objects:  70% (15600/22280), 24.78 MiB | 12.37 MiB/sReceiving objects:  71% (15819/22280), 24.78 MiB | 12.37 MiB/sReceiving objects:  98% (21835/22280), 24.78 MiB | 12.37 MiB/s\n",
      "Receiving objects: 100% (22280/22280), 30.32 MiB | 12.89 MiB/s, done.\n",
      "Resolving deltas: 100% (15566/15566), done.  ] 557.84M   138MB/s    eta 17s    Resolving deltas:   6% (934/15566)Resolving deltas:  14% (2180/15566)Resolving deltas:  16% (2491/15566)Resolving deltas:  25% (3892/15566)Resolving deltas:  32% (4982/15566)Resolving deltas:  56% (8717/15566)Resolving deltas:  95% (14788/15566)\n",
      "venv.tar.gz          23%[===>                ] 649.56M   146MB/s    eta 15s    /kaggle/working/stable-diffusion-webui\n",
      "venv.tar.gz          33%[=====>              ] 933.63M   168MB/s    eta 12s    Note: switching to '20ae71faa8ef035c31aa3a410b707d792c8203a3'.\n",
      "\n",
      "You are in 'detached HEAD' state. You can look around, make experimental\n",
      "changes and commit them, and you can discard any commits you make in this\n",
      "state without impacting any branches by switching back to a branch.\n",
      "\n",
      "If you want to create a new branch to retain commits you create, you may\n",
      "do so (now or later) by using -c with the switch command. Example:\n",
      "\n",
      "  git switch -c <new-branch-name>\n",
      "\n",
      "Or undo this operation with:\n",
      "\n",
      "  git switch -\n",
      "\n",
      "Turn off this advice by setting config variable advice.detachedHead to false\n",
      "\n",
      "HEAD is now at 20ae71fa fix linter issue for 1.3.0\n",
      "venv.tar.gz          34%[=====>              ] 966.61M   167MB/s    eta 12s    stable-diffusion-webui已安装\n",
      "/kaggle/working/stable-diffusion-webui\n",
      "venv.tar.gz          43%[=======>            ]   1.19G   179MB/s    eta 11s    安装插件,此处出现红条是正常的\n",
      "venv.tar.gz          45%[========>           ]   1.25G   186MB/s    eta 11s    "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Cloning into 'loopback_scaler'...\n",
      "Cloning into 'sd-webui-depth-lib'...\n",
      "Cloning into 'sd-civitai-browser'...\n",
      "Cloning into 'sd-webui-controlnet'...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "venv.tar.gz          96%[==================> ]   2.63G   218MB/s    eta 1s     "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Cloning into 'sd-webui-3d-open-pose-editor'...\n",
      "Cloning into 'stable-diffusion-webui-localization-zh_CN'...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "venv.tar.gz          97%[==================> ]   2.64G   203MB/s    eta 1s     "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Cloning into 'stable-diffusion-webui-two-shot'...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "venv.tar.gz          98%[==================> ]   2.67G   145MB/s    eta 0s     "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Updating files:  95% (876/922)\r"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "venv.tar.gz          98%[==================> ]   2.67G   133MB/s    eta 0s     "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Updating files: 100% (922/922), done.\n",
      "Cloning into 'a1111-sd-webui-tagcomplete'...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "venv.tar.gz         100%[===================>]   2.71G   107MB/s    in 16s     \n",
      "\n",
      "2023-06-06 13:32:12 (173 MB/s) - ‘venv.tar.gz’ saved [2912904935/2912904935]\n",
      "\n",
      "环境包已下载\n",
      "/opt/conda/envs\n",
      "/opt/conda/envs/venv\n",
      "环境安装中\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Cloning into 'multidiffusion-upscaler-for-automatic1111'...\n",
      "Cloning into 'sd-webui-cutoff'...\n",
      "Cloning into 'sd-webui-lora-block-weight'...\n",
      "Cloning into 'Stable-Diffusion-Webui-Civitai-Helper'...\n",
      "Cloning into 'stable-diffusion-webui'...\n",
      "Cloning into 'sd-webui-mov2mov'...\n",
      "Cloning into 'stable-diffusion-webui-wd14-tagger'...\n",
      "Cloning into 'sd-webui-prompt-all-in-one'...\n",
      "Cloning into 'a1111-sd-webui-lycoris'...\n",
      "Cloning into 'sd-webui-infinite-image-browsing'...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created symlink for clearvae.vae.pt in /kaggle/working/stable-diffusion-webui/models/VAE\n",
      "Created symlink for vae-ft-mse-840000-ema-pruned.ckpt in /kaggle/working/stable-diffusion-webui/models/VAE\n",
      "Created symlink for vae-ft-ema-560000-ema-pruned.safetensors in /kaggle/working/stable-diffusion-webui/models/VAE\n",
      "Created symlink for klF8Anime2.vae.pt in /kaggle/working/stable-diffusion-webui/models/VAE\n",
      "Created symlink for libramix_v10.safetensors in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\n",
      "Created symlink for cetusMix_Coda2.safetensors in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\n",
      "Created symlink for 9527-non-ema-fp16.safetensors in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\n",
      "Created symlink for CounterfeitV30_v30.safetensors in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\n",
      "Created symlink for cetusMix_Version35.safetensors in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\n",
      "Created symlink for shanzhagao128dim-epoch-000010.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\n",
      "Created symlink for add_detail.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\n",
      "Created symlink for MoXinV1.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\n",
      "Created symlink for control_v11p_sd15_mlsd_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15s2_lineart_anime_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_openpose_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_normalbae_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_canny_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_lineart_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11e_sd15_ip2p_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_inpaint_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_scribble_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11u_sd15_tile_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11f1p_sd15_depth_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11e_sd15_shuffle_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for control_v11p_sd15_softedge_fp16.safetensors in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n",
      "Created symlink for 4x-AnimeSharp.pth in /kaggle/working/stable-diffusion-webui/models/ESRGAN\n",
      "Created symlink for 4x_foolhardy_Remacri.pth in /kaggle/working/stable-diffusion-webui/models/ESRGAN\n",
      "Created symlink for 4x-UltraSharp.pth in /kaggle/working/stable-diffusion-webui/models/ESRGAN\n",
      "Created symlink for FilmProvia2.safetensors in /kaggle/working/stable-diffusion-webui/models/lyco\n",
      "环境安装完毕\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\n",
      "\n",
      "WARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The following additional packages will be installed:\n",
      "  liblzma-dev\n",
      "Suggested packages:\n",
      "  liblzma-doc\n",
      "The following NEW packages will be installed:\n",
      "  liblzma-dev libunwind-dev\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "dpkg-preconfigure: unable to re-open stdin: No such file or directory\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 upgraded, 2 newly installed, 0 to remove and 28 not upgraded.\n",
      "Need to get 2040 kB of archives.\n",
      "After this operation, 6754 kB of additional disk space will be used.\n",
      "Selecting previously unselected package liblzma-dev:amd64.\n",
      "(Reading database ... 115466 files and directories currently installed.)\n",
      "Preparing to unpack .../liblzma-dev_5.2.5-2ubuntu1_amd64.deb ...\n",
      "Unpacking liblzma-dev:amd64 (5.2.5-2ubuntu1) ...\n",
      "Selecting previously unselected package libunwind-dev:amd64.\n",
      "Preparing to unpack .../libunwind-dev_1.3.2-2build2_amd64.deb ...\n",
      "Unpacking libunwind-dev:amd64 (1.3.2-2build2) ...\n",
      "Setting up liblzma-dev:amd64 (5.2.5-2ubuntu1) ...\n",
      "Setting up libunwind-dev:amd64 (1.3.2-2build2) ...\n",
      "Processing triggers for man-db (2.10.2-1) ...\n",
      "Selecting previously unselected package google-perftools.\n",
      "(Reading database ... 115559 files and directories currently installed.)\n",
      "Preparing to unpack google-perftools_2.5-2.2ubuntu3_all.deb ...\n",
      "Unpacking google-perftools (2.5-2.2ubuntu3) ...\n",
      "Selecting previously unselected package libgoogle-perftools-dev.\n",
      "Preparing to unpack libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb ...\n",
      "Unpacking libgoogle-perftools-dev (2.5-2.2ubuntu3) ...\n",
      "Selecting previously unselected package libgoogle-perftools4.\n",
      "Preparing to unpack libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb ...\n",
      "Unpacking libgoogle-perftools4 (2.5-2.2ubuntu3) ...\n",
      "Selecting previously unselected package libtcmalloc-minimal4.\n",
      "Preparing to unpack libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb ...\n",
      "Unpacking libtcmalloc-minimal4 (2.5-2.2ubuntu3) ...\n",
      "Setting up libtcmalloc-minimal4 (2.5-2.2ubuntu3) ...\n",
      "Setting up libgoogle-perftools4 (2.5-2.2ubuntu3) ...\n",
      "Setting up google-perftools (2.5-2.2ubuntu3) ...\n",
      "Setting up libgoogle-perftools-dev (2.5-2.2ubuntu3) ...\n",
      "Processing triggers for man-db (2.10.2-1) ...\n",
      "Processing triggers for libc-bin (2.35-0ubuntu3.1) ...\n",
      "内存优化已安装\n",
      "内存优化已安装\n",
      "加载耗时: 249.6120264530182 s\n",
      "/kaggle/working\n",
      "skip start ngrok\n",
      "/kaggle/working/stable-diffusion-webui\n",
      "mkdir: cannot create directory ‘models/lyco’: File exists\n",
      "Python 3.10.11 | packaged by conda-forge | (main, May 10 2023, 18:58:44) [GCC 11.3.0]\n",
      "Version: v1.3.0\n",
      "Commit hash: 20ae71faa8ef035c31aa3a410b707d792c8203a3\n",
      "Installing clip\n",
      "Installing open_clip\n",
      "Cloning Stable Diffusion into /kaggle/working/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...\n",
      "Cloning Taming Transformers into /kaggle/working/stable-diffusion-webui/repositories/taming-transformers...\n",
      "Cloning K-diffusion into /kaggle/working/stable-diffusion-webui/repositories/k-diffusion...\n",
      "Cloning CodeFormer into /kaggle/working/stable-diffusion-webui/repositories/CodeFormer...\n",
      "Cloning BLIP into /kaggle/working/stable-diffusion-webui/repositories/BLIP...\n",
      "Installing requirements for CodeFormer\n",
      "Installing requirements\n",
      "Installing sd-webui-infinite-image-browsing requirement: python-dotenv\n",
      "Installing sd-webui-infinite-image-browsing requirement: Pillow\n",
      "\n",
      "Installing sd-webui-controlnet requirement: mediapipe\n",
      "Installing sd-webui-controlnet requirement: svglib\n",
      "Installing sd-webui-controlnet requirement: fvcore\n",
      "\n",
      "Installing requirements for CivitAI Browser\n",
      "\n",
      "Installing sd-webui-prompt-all-in-one: translators\n",
      "Installing sd-webui-prompt-all-in-one: openai\n",
      "Installing sd-webui-prompt-all-in-one: boto3\n",
      "Installing sd-webui-prompt-all-in-one: aliyunsdkcore\n",
      "Installing sd-webui-prompt-all-in-one: aliyunsdkalimt\n",
      "\n",
      "Installing requirements for Mov2mov\n",
      "Installing requirements for ffmpeg\n",
      "\n",
      "Downloading pose_landmark_full.tflite...\n",
      "Downloading pose_web.binarypb...\n",
      "Downloading pose_solution_packed_assets.data...\n",
      "Downloading pose_solution_simd_wasm_bin.wasm...\n",
      "Downloading pose_solution_packed_assets_loader.js...\n",
      "Downloading pose_solution_simd_wasm_bin.js...\n",
      "\n",
      "Launching Web UI with arguments: --share --xformers --lowram --no-hashing --disable-nan-check --enable-insecure-extension-access --disable-console-progressbars --enable-console-prompts --no-gradio-queue --no-half-vae --api --lyco-dir /kaggle/working/models/lyco --ckpt=models/Stable-diffusion/cetusMix_Coda2.safetensors\n",
      "Error loading script: sampling.py\n",
      "Traceback (most recent call last):\n",
      "  File \"/kaggle/working/stable-diffusion-webui/modules/scripts.py\", line 263, in load_scripts\n",
      "    script_module = script_loading.load_module(scriptfile.path)\n",
      "  File \"/kaggle/working/stable-diffusion-webui/modules/script_loading.py\", line 10, in load_module\n",
      "    module_spec.loader.exec_module(module)\n",
      "  File \"<frozen importlib._bootstrap_external>\", line 883, in exec_module\n",
      "  File \"<frozen importlib._bootstrap>\", line 241, in _call_with_frames_removed\n",
      "  File \"/kaggle/working/stable-diffusion-webui/scripts/sampling.py\", line 10, in <module>\n",
      "    from . import utils\n",
      "ModuleNotFoundError: No module named 'sampling'\n",
      "\n",
      "Civitai Helper: Get Custom Model Folder\n",
      "Civitai Helper: Load setting from: /kaggle/working/stable-diffusion-webui/extensions/Stable-Diffusion-Webui-Civitai-Helper/setting.json\n",
      "Civitai Helper: No setting file, use default\n",
      "2023-06-06 13:38:28,215 - ControlNet - \u001b[0;32mINFO\u001b[0m - ControlNet v1.1.218\n",
      "ControlNet preprocessor location: /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads\n",
      "2023-06-06 13:38:28,433 - ControlNet - \u001b[0;32mINFO\u001b[0m - ControlNet v1.1.218\n",
      "sd-webui-prompt-all-in-one background API service started successfully.\n",
      "Loading weights [None] from /kaggle/working/stable-diffusion-webui/models/Stable-diffusion/cetusMix_Coda2.safetensors\n",
      "Creating model from config: /kaggle/working/stable-diffusion-webui/configs/v1-inference.yaml\n",
      "LatentDiffusion: Running in eps-prediction mode\n",
      "DiffusionWrapper has 859.52 M params.\n",
      "Downloading (…)olve/main/vocab.json: 100%|███| 961k/961k [00:00<00:00, 5.12MB/s]\n",
      "Downloading (…)olve/main/merges.txt: 100%|███| 525k/525k [00:00<00:00, 2.66MB/s]\n",
      "Downloading (…)cial_tokens_map.json: 100%|█████| 389/389 [00:00<00:00, 2.00MB/s]\n",
      "Downloading (…)okenizer_config.json: 100%|█████| 905/905 [00:00<00:00, 5.70MB/s]\n",
      "Downloading (…)lve/main/config.json: 100%|█| 4.52k/4.52k [00:00<00:00, 17.6MB/s]\n",
      "Loading VAE weights specified in settings: /kaggle/working/stable-diffusion-webui/models/VAE/clearvae.vae.pt\n",
      "Applying optimization: xformers... done.\n",
      "Textual inversion embeddings loaded(5): bad-artist-anime, bad-hands-5, bad-image-v2-39000, bad_prompt_version2, EasyNegative\n",
      "Model loaded in 32.4s (load weights from disk: 21.1s, create model: 2.8s, apply weights to model: 4.7s, apply half(): 1.2s, load VAE: 1.7s, move model to device: 0.7s).\n",
      "Running on local URL:  http://127.0.0.1:7860\n",
      "Running on public URL: https://e881356cce029f957d.gradio.live\n",
      "\n",
      "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n",
      "Startup time: 52.3s (import torch: 2.8s, import gradio: 2.4s, import ldm: 2.4s, other imports: 2.1s, setup codeformer: 0.2s, load scripts: 2.7s, create ui: 32.9s, gradio launch: 6.5s, scripts app_started_callback: 0.2s).\n",
      "\n",
      "txt2img: masterpiece, best quality,\n",
      "\n",
      ",delicate, beautiful,colorful, vividcolor, lighting,\n",
      "\n",
      "100%|███████████████████████████████████████████| 24/24 [00:12<00:00,  1.93it/s]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Process ForkProcess-4:\n",
      "Traceback (most recent call last):\n",
      "  File \"/opt/conda/lib/python3.10/multiprocessing/process.py\", line 314, in _bootstrap\n",
      "    self.run()\n",
      "  File \"/opt/conda/lib/python3.10/multiprocessing/process.py\", line 108, in run\n",
      "    self._target(*self._args, **self._kwargs)\n",
      "  File \"/opt/conda/lib/python3.10/concurrent/futures/process.py\", line 240, in _process_worker\n",
      "    call_item = call_queue.get(block=True)\n",
      "  File \"/opt/conda/lib/python3.10/multiprocessing/queues.py\", line 103, in get\n",
      "    res = self._recv_bytes()\n",
      "  File \"/opt/conda/lib/python3.10/multiprocessing/connection.py\", line 216, in recv_bytes\n",
      "    buf = self._recv_bytes(maxlength)\n",
      "  File \"/opt/conda/lib/python3.10/multiprocessing/connection.py\", line 414, in _recv_bytes\n",
      "    buf = self._recv(4)\n",
      "  File \"/opt/conda/lib/python3.10/multiprocessing/connection.py\", line 379, in _recv\n",
      "    chunk = read(handle, remaining)\n",
      "KeyboardInterrupt\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[13], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# start\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mmain\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "Cell \u001b[0;32mIn[11], line 14\u001b[0m, in \u001b[0;36mmain\u001b[0;34m()\u001b[0m\n\u001b[1;32m     12\u001b[0m ticks \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[1;32m     13\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m加载耗时:\u001b[39m\u001b[38;5;124m\"\u001b[39m,(ticks \u001b[38;5;241m-\u001b[39m startTicks),\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ms\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 14\u001b[0m \u001b[43mstart_webui\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "Cell \u001b[0;32mIn[10], line 27\u001b[0m, in \u001b[0;36mstart_webui\u001b[0;34m()\u001b[0m\n\u001b[1;32m     25\u001b[0m     time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m     26\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m future \u001b[38;5;129;01min\u001b[39;00m futures:\n\u001b[0;32m---> 27\u001b[0m     \u001b[43mfuture\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mresult\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/concurrent/futures/_base.py:453\u001b[0m, in \u001b[0;36mFuture.result\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m    450\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;241m==\u001b[39m FINISHED:\n\u001b[1;32m    451\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__get_result()\n\u001b[0;32m--> 453\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_condition\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwait\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    455\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;129;01min\u001b[39;00m [CANCELLED, CANCELLED_AND_NOTIFIED]:\n\u001b[1;32m    456\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m CancelledError()\n",
      "File \u001b[0;32m/opt/conda/lib/python3.10/threading.py:320\u001b[0m, in \u001b[0;36mCondition.wait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m    318\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:    \u001b[38;5;66;03m# restore state no matter what (e.g., KeyboardInterrupt)\u001b[39;00m\n\u001b[1;32m    319\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m timeout \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 320\u001b[0m         \u001b[43mwaiter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43macquire\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    321\u001b[0m         gotit \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m    322\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "# start\n",
    "main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "execution": {
     "iopub.status.busy": "2023-06-06T13:40:24.667167Z",
     "iopub.status.idle": "2023-06-06T13:40:24.667871Z",
     "shell.execute_reply": "2023-06-06T13:40:24.667621Z",
     "shell.execute_reply.started": "2023-06-06T13:40:24.667592Z"
    }
   },
   "outputs": [],
   "source": [
    "#跑图结束,手动执行,清理图片并打包到output方便下载,同时同步配置文件\n",
    "zip_clear_updata()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-06-16T04:55:41.756128Z",
     "iopub.status.busy": "2023-06-16T04:55:41.755667Z",
     "iopub.status.idle": "2023-06-16T04:55:46.996151Z",
     "shell.execute_reply": "2023-06-16T04:55:46.994580Z",
     "shell.execute_reply.started": "2023-06-16T04:55:41.756066Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Get:1 http://packages.cloud.google.com/apt gcsfuse-focal InRelease [5002 B]\n",
      "Get:2 https://packages.cloud.google.com/apt cloud-sdk InRelease [6361 B]       \n",
      "Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease                         \n",
      "Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]        \n",
      "Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]\n",
      "Get:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]      \n",
      "Get:7 https://packages.cloud.google.com/apt cloud-sdk/main amd64 Packages [464 kB]\n",
      "Get:8 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1359 kB]\n",
      "Get:9 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [2539 kB]\n",
      "Get:10 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [2352 kB]\n",
      "Get:11 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3282 kB]\n",
      "Get:12 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [1060 kB]\n",
      "Get:13 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2781 kB]\n",
      "Fetched 14.2 MB in 2s (5993 kB/s)                           \n",
      "Reading package lists... Done\n"
     ]
    }
   ],
   "source": [
    "# Traceback (most recent call la\n",
    "#!apt-get update"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}