File size: 76,382 Bytes
45fe93c |
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 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"collapsed_sections": [
"iLsO_riJrAEl",
"QAvV1XNM3TxR"
]
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "markdown",
"source": [
"\n",
"# **NoCrypt's Colab Remastered 🔮**\n",
"\n",
"[](https://lookup.guru/442099748669751297) [](https://ko-fi.com/nocrypt) [](https://patreon.com/nocrypt)\n",
"\n",
"\n",
"y'all know what this is. check out my [QoL userscript](https://greasyfork.org/en/scripts/463547-nocrypt-colab-qol) for better experience\n",
"\n",
"<!-- [Guide for using krita with this colab](https://rentry.org/krita-ext-colab) -->\n",
"\n",
"<!-- [Hey you, thanks for looking into my colab, please ignore messages below, I just added it to announce stuff faster] -->\n",
"<!-- # <font color=red>BROKEN FOR NOW, WILL FIX ASAP ⚠️ -->\n",
"\n",
"<!-- # <font color=red>Under construction ⚠️ -->\n",
"\n",
"<small><font color=gray> V23-09-09B | [latest](https://colab.research.google.com/drive/1wEa-tS10h4LlDykd87TF5zzpXIIQoCmq) | [faq](https://rentry.org/ncpt_faq).</font></small>\n",
"\n",
"\n",
"note: google hates us\n",
"<!-- <font color=yellow><big>Use stable build for now. Do not check latest_webui unless you know what you're doing.</big></font> -->\n",
"\n",
"<!-- <font color=yellow><big>If the image output is not what you want. Read the terminal</big></font> -->\n",
"\n",
"<details>\n",
" <summary><font color=gray>Latest Changes</summary>\n",
" \n",
"**Update V23-09-09B**\n",
"\n",
"```diff\n",
"+ cirno will stay, to remember a time when colab wasnt evil\n",
"```\n",
"</details>\n",
"\n",
"\n",
"<details>\n",
" <summary><font color=gray>Old Changes</summary>\n",
"\n",
" + the funky cirno!\n",
" + removed some more slanderous things \n",
" + Added HF OUT extension (use optional hf token to start)\n",
" + Fix for clipskip and other options not showing\n",
" + UmiAI is now in an accordion (thanks ao)\n",
" + Fix the order of parameters (hires fix no longer being on top)\n",
" + Improved interuption speed\n",
" + Readjusted XYZ bg colors\n",
" + Readjusted image gallery height\n",
" + Readjusted UmiAI to be auto enabled (for ur own good, wildcards etc.)\n",
" + Readjusted pooling speed so it didn't goes to fast (potential fix for generate button stuck)\n",
" + Potential fix for some tunnels having the exact same url for everyone\n",
" + Disabled deprication warnings!\n",
" + Updated custom theme (NoCrypt/miku)\n",
" + Added Privacy Mode Toggle in webui\n",
" + Added Dark/Light mode Toggle in webui\n",
" + Fixed \"no custom theme\" option\n",
" + Added disable-inpainting-overlay extension (for better inpainting)\n",
" + Added pixelization extension (with models, check extras tab)\n",
" + Adjusted defaults for Tiled Diffusion and Tilled Vae in IMG2IMG (for better experience)\n",
" + Attempt to reduce memory usage (especially while upscaling, thx camenduru!)\n",
" + Updated to webui 1.5\n",
" + Changes to controlnet model path (again, sorry config_to_drive users)\n",
" + Fixed DPMPP 2M v2 (for now)\n",
" + Fixed ram sd2 patch (for now)\n",
" + Fixed some bugs introduced on latest 1.5 using patch (extensions git failure, for now)\n",
" + Fix very high memory usage while idle (thanks neggles! 😭)\n",
" + Fix ubuntu deps broken\n",
" + Changed Branch back to master\n",
" + Keep using gradio 3.33.1 (battle-tested)\n",
" + Fix unable to start colab in general... (sorry for late fix, I was taking break for 7 days 🙏)\n",
" + Fixed ubuntu deps failing to install\n",
" + Updated pip deps\n",
" + Updated all extensions\n",
" + Cleaning up quicksettings area (mostly moved to Options panel under hiresfix)\n",
" + Some fixes and improvement with git (no more merge conflict while changing branch or latest webui hopefully)\n",
" + Renamed controlnet back to default (fixed deforum)\n",
" + Disabled Access Control mode in IIB\n",
" + Removed taming transformers\n",
" + Changed composable lora to an updated fork by a2569875\n",
" + Added neutral prompt extension (AND_PREP etc)\n",
" + Removed some files to make the size smaller\n",
" + Added surprise for ppl who copied this colab :p\n",
" + Added Amedira model\n",
" + Update all extensions\n",
" + Update all deps\n",
" + Added krita-ext fork by ashen\n",
" + Fixed anything 4.5 link\n",
" + Replace Holokuki2 -> Gishiki\n",
" + Fixed image preview looks fried\n",
" + Add more negative embeddings by Lykon and Luna\n",
" + Changed extensions paths\n",
" + Decrease live_preview_refresh_period\n",
" + Less warcrimes\n",
" + Switched to release_candidate branch as default\n",
" + Fixed \"visualize\" in two-shot\n",
" + Added openpose-editor\n",
" + Removed Posex\n",
" + Minor fix for gdown\n",
" + Using gradio 3.33.1 to fix tmp file name bug\n",
" + Updated to latest webui\n",
" + Updated extensions\n",
" + Fixed Controlnet v1.1 for good now (yes, including tile stuff)\n",
" + Removed canvas-zoom as it's unstable for mobile usage for now (can still be manually installed)\n",
" + [QoL Userscript] Fixed ngrok token autosave (pls update manually via ur userscript manager)\n",
" + Added sam models support with `sam:` prefix (thanks ZeroDuri#7380)\n",
" + Removed notification sound from colab since it's buggy and sometimes rang for no reason XD\n",
" + added more negative TIs (EN2, negative_hand, simple5.5, simple5.6)\n",
" + updated all extensions\n",
" + using different gradio for now to fix gen button stuck\n",
" + attempts to fix vae first load issue\n",
" - removed locon extension (replaced by lycoris ext fully)\n",
" + added waifu diffusion 1.5 b3 all aesthetic variants\n",
" + attempts to make colab start faster\n",
" + added lycoris support with lycoris prefix like this `lycoris:https://link.com`\n",
" + added notification sounds after download complete (in colab itself, not webui)\n",
" - disabled stealth pnginfo for now due to some bug\n",
" + change image browser to infinite img browser\n",
" + add adetailer\n",
" + add canvas-zoom\n",
" + update webui to the latest commit\n",
" + update all extensions\n",
" - removed custom theme as of now (y-yes im lazy)\n",
" + adapted to py 3.10.11\n",
" + updated all extension\n",
" + revised blapshemy\n",
" + updated configs to match blapshemy dir\n",
" + Blapshemy!\n",
" + Controlnet 1.1\n",
" + Google updated torch to 2.0.0+cu118\n",
" + Updated all deps to adapt the google's new update\n",
" + Updated xformers to 0.0.18\n",
" + Added 2 NMKD Upscaler (YandereNeo and Superscale)\n",
" + Added DEPD Upscaler\n",
" + Added `[REDACTED]-state` and `sd_webui_stealth_pnginfo` extension\n",
" + New quicksettings item: stealth_pnginfo checkbox\n",
" + Disabled april fools troll\n",
" - Revert back to STABLE COMMIT (Stable by default)\n",
" - Disabled pulling latest webui checkbox\n",
" + Added [mofu]-3d-open-pose-editor\n",
" + Changed image browser to AlUlkesh's fork\n",
" + Updated necessary deps\n",
" + Updated extensions\n",
" + Added more tunnels to \"Alternative Tunnels\"\n",
" + Added more ram optimization (camenduru's ram patch)\n",
" + Added fun stuff :>\n",
" + Changes to output name to be more meaningful\n",
" + Attempt to fix broken start link\n",
" - Disabled openpose-editor\n",
" - Disabled [mofu]-depth-lib\n",
" - Deleted Easter Egg (will add more in future without noticing)\n",
" + Change defaults: negative prompts, max res, max batch size\n",
" + Added [mofu]-runtime-block-merge\n",
" + Added multidiffusion-upscaler-for-automatic1111\n",
" + Added [REDACTED]-image-filters\n",
" + Added sd-dynamic-prompts + wildcards (credit: CtD)\n",
" + Fixed configs_in_drive and output_to_drive can't work together\n",
" + Fixed merge conflict issue that preventing webui from starting\n",
" + Updated xformers\n",
" + Added [mofu]-tunnels (fork by camenduru)\n",
" + Changed `[REDACTED]-images-browser` extension to `sd_images_browser` (fork by aka7774)\n",
" + Added sd-fast-pnginfo extension\n",
" + Replaced blessed_vae -> blessed2_vae\n",
" + Adapted to python 3.9 update\n",
" + Added t2iadapter models (including style)\n",
" + Increase ControlNet Max Models to 4\n",
" + New Default Extension: [[mofu]-llul] gh: hnmr293 sd + webui-llul\n",
" + Fixed broken img2img\n",
"\n",
" + Added Composable Lora extension\n",
" + Added Custom tags + easter eggs :>\n",
" + Added poseX and [REDACTED]-fix-image-paste extensions\n",
" + Added Colab Mobile Keep Alive cell (in useful utils, run it before start cell)\n",
" + Fixed extra networks tab after re-ordering tool buttons\n",
" + Added an option to disable notification sound in webui\n",
" + Lowered the notification sound by 40%. (thanks RileyX for the suggestion)\n",
" + Replaced two_shot_ext options (already built in)\n",
" + All_ControlNet is now enabled by default\n",
" + Notification sounds when finished generating, forked from https://github.com/etherealxx/batchlinks-webui\n",
" + New default extensions:\n",
" + [REDACTED]-two-shot\n",
" + [mofu]-supermerger\n",
" + batchlinks-webui\n",
" + a1111-[mofu]-locon\n",
" + [mofu]-depth-lib\n",
" + openpose-editor\n",
"\n",
" + Manual Downloads is now supported. Guide soon!\n",
" + Added Waifu Diffusion Beta2 Aesthetic\n",
" + Replaced WD 1.5 Beta -> Waifu Diffusion Beta2\n",
" + Fixed SD vae\n",
" + New option: fast_start. This will make the startup speed faster by bypassing dependency installations (will break extensions, use with caution)\n",
" + New option: configs_in_drive. This will use configs (config, uiconfig, styles) in your drive\n",
" + Changed git pull logic to first install only for saving time (will add old option soon)\n",
" + Updated xformers, deps, and some UI settings\n",
" + New model: All DIFF control models (see the differences [here](https://huggingface.co/kohya-ss/ControlNet-diff-modules/discussions/1))\n",
" + Fixed umiAI and two shot can't be installed together (Thanks Aojiru)\n",
" + Fixed control models hardlink (Thanks Aojiru)\n",
" + New model: All Control Models (fp16)\n",
" + New option: Two_shot Extension\n",
" + Support for control models in `custom_urls`\n",
" + Added controlnet extension by default\n",
" + Preload with self-trimmed and self-converted safetensors openpose model (+openpose hands and body pth models)\n",
" - Installation speed slowed by few seconds due to models addition (1.7gb -> 3gb)\n",
" - Changed console text to cyan\n",
" - Model replaced: WD 1.4 e1 -> WD 1.5 Beta\n",
" - New option: UmiAI. Now it's a separate option, no more bloated embeddings :D\n",
" - New option: Update extensions. Basically updating all the extension the latest version (Might be slow)\n",
" - New option: Colab Optimization. (basically Load in vram + aggressive gradio queue)\n",
" - Added support for old commits by removing inbuilt negative embeddings. (if you use commit_hash that is)\n",
" - Gradio server is turned off when `alternative tunnel` or `ngrok` is active.\n",
"\n",
"\n",
"</details>\n",
"\n",
"<img src=\"https://count.getloli.com/get/@:ncpt-colab?theme=rule34\" height=\"90px\" alt=\"counted since: May 14\"/>\n",
"<br>\n",
"<img src=\"https://media.tenor.com/6lm-svEn7dEAAAAC/cirno-fumo.gif\" height=\"90px\" alt=\"cirno day exclusive\"/>\n"
],
"metadata": {
"id": "mgKX41doZJ3u"
}
},
{
"cell_type": "markdown",
"source": [
"# Seems like this is the end...\n",
"Sadly colab decided not to support any A1111 notebooks anymore... so you might starting to get disconnected for no reason at all. Thank you for everything."
],
"metadata": {
"id": "QJodVVDuufSW"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8Uvqba0yKW7U",
"cellView": "form"
},
"outputs": [],
"source": [
"# Dear Google, I love you! Please don't ban me from colab T_T\n",
"#added yoinked\n",
"#@title # **Start** 🚀\n",
"# All necessary imports goes here\n",
"from IPython.display import clear_output, display, HTML\n",
"import os\n",
"import time\n",
"from datetime import timedelta\n",
"from google.colab import drive\n",
"from IPython.utils import capture\n",
"from subprocess import getoutput\n",
"from urllib.parse import unquote\n",
"from google.colab.output import eval_js\n",
"%cd /content\n",
"\n",
"try:\n",
" start_colab\n",
"except:\n",
" start_colab = int(time.time())-5\n",
"\n",
"print(\"\\033[96m\") #Cyan text\n",
"# Check if gpu exist, stop if don't.\n",
"try:\n",
" output\n",
"except:\n",
" print('⌚ Checking GPU...', end='')\n",
" output = getoutput('nvidia-smi --query-gpu=gpu_name --format=csv')\n",
" if \"name\" in output:\n",
" gpu_name = output[5:]\n",
" print('\\r✅ Current GPU:', gpu_name, flush=True)\n",
" else:\n",
" print('\\r\\033[91m❎ ERROR: No GPU detected. Please do step below to enable.\\n', flush=True)\n",
" display(HTML(\"<img src='https://i.ibb.co/HC9KH17/NVIDIA-Share-23-01-02-173037.png' width='800px'/>\"))\n",
" print('\\033[91m\\nIf it says \"Cannot connect to GPU backend\", meaning you\\'ve either reached free usage limit. OR there\\'s no gpu available.\\n\\nDon\\'t mind me... I\\'m destroying your current session for your own good...')\n",
" display(HTML(\"<img src='https://media.tenor.com/E9omRGF7x0AAAAAC/hitori-gotou-bocchi-rock.gif' width='500px'/>\"))\n",
" time.sleep(5)\n",
" from google.colab import runtime\n",
" runtime.unassign()\n",
"\n",
"# [ALL PARAMS]-----------------------------------------------\n",
"#@markdown ### **Install Configurations [?](https://rentry.org/ncpt_what)**\n",
"#@markdown These options only runs on First Install\n",
"latest_webui = False #@param{type:\"boolean\"}\n",
"latest_extensions = True #@param{type:\"boolean\"}\n",
"branch = \"master\" #@param [\"master\",\"release_candidate\",\"dev\"]\n",
"sdxl_patch = False\n",
"\n",
"#@markdown ### <br> **Configurations**\n",
"output_to_drive = False #@param{type:\"boolean\"}\n",
"configs_in_drive = False #@param{type:\"boolean\"}\n",
"fast_start = False #@param{type:\"boolean\"}\n",
"auto_vae = False #@param{type:\"boolean\"}\n",
"no_custom_theme = False #@param {type:\"boolean\"}\n",
"merge_in_vram = False #@param {type:\"boolean\"}\n",
"load_in_vram = False #@param {type:\"boolean\"}\n",
"ram_patch_for_sd2 = False #@param{type:\"boolean\"}\n",
"dpmpp_v2 = False #@param{type:\"boolean\"}\n",
"krita_paint_ext = False #@param {type:\"boolean\"}\n",
"verbose_download = False #@param {type:\"boolean\"}\n",
"commandline_arguments = \"--listen --xformers --enable-insecure-extension-access --theme dark --gradio-queue --multiple\" #@param{type:\"string\"}\n",
"commit_hash = \"\" #@param{type:\"string\"}\n",
"ngrok_token = \"\" #@param{type:\"string\"}\n",
"ngrok_region = \"jp\" #@param [\"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n",
"ngrok_auto_save_load = False #@param{type:\"boolean\"}\n",
"alternative_tunnels = False #@param{type:\"boolean\"}\n",
"with_bore = False #@param{type:\"boolean\"}\n",
"\n",
"#@markdown ### <br> **Models, VAEs, Embeddings, Hypernetworks, Yaml, LoRA**\n",
"#@markdown *Check only what you need, colab storage is not unlimited.*\n",
"optional_huggingface_token=\"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\" #@param{type:\"string\"}\n",
"model_url = \"\" # waifu_diffusion_beta2\n",
"# waifu_diffusion_AES = False #@param{type:\"boolean\"}\n",
"# waifu_diffusion = False #@param{type:\"boolean\"}\n",
"waifu_diffusion = \"none\" #@param [\"radiance\", \"ink\", \"mofu\", \"illusion\", \"none\"]\n",
"# anything_v3 = False #@param{type:\"boolean\"}\n",
"anything_v4_5 = False #@param{type:\"boolean\"}\n",
"anylora = True #@param{type:\"boolean\"}\n",
"amedira = False #@param{type:\"boolean\"}\n",
"awooooooo = False #@param{type:\"boolean\"}\n",
"gishiki_v1_1 = False #@param{type:\"boolean\"}\n",
"something_v2_2 = True #@param{type:\"boolean\"}\n",
"anything_vae = False #@param{type:\"boolean\"}\n",
"blessed2_vae = True #@param{type:\"boolean\"}\n",
"wd_vae = False #@param{type:\"boolean\"}\n",
"sd_vae = True #@param{type:\"boolean\"}\n",
"controlnet = \"v1.1\" #@param [\"v1.1\", \"v1.0\", \"v1.0-diff\", \"t2i\", \"none\"]\n",
"null_model = False #@param{type:\"boolean\"}\n",
"custom_urls = \"\" #@param {type:\"string\"}\n",
"#@markdown <font color=gray><i> Put any models, embeddings, configs, hypernetworks, loras links and separate it with comma.<br>\n",
"#@markdown <img src=\"https://cdn.discordapp.com/emojis/930580027135901777.webp?size=56\" width=\"18\"/> [How to use this custom url box?](https://rentry.org/custom_url_nocrypt) - [**Awesome Models List**](https://rentry.org/ncpt_fav_models) ✨\n",
"\n",
"# CONFIG DIR (not recommended to change unless you know what you're doing) modules/sd_models.py\n",
"destination_dir = \"/content/.downloaded/\"\n",
"config_dir=\"/content/sdw/config.json\"\n",
"models_dir = \"/content/sdw/models/Stable-diffusion/\"\n",
"vaes_dir = \"/content/sdw/models/VAE/\"\n",
"hypernetworks_dir = \"/content/sdw/models/hypernetworks/\"\n",
"embeddings_dir = \"/content/sdw/embeddings/\"\n",
"loras_dir = \"/content/sdw/models/Lora/\"\n",
"# lycoris_dir = \"/content/sdw/models/LyCORIS/\"\n",
"patches_dir = \"/content/patches/\"\n",
"extensions_dir = \"/content/sdw/extensions/\"\n",
"control_dir = \"/content/sdw/models/ControlNet/\"\n",
"drive_config_dir = \"/content/gdrive/MyDrive/WebUI/configs/\"\n",
"sam_dir = \"/content/sdw/models/sam/\"\n",
"\n",
"# -----------------------------------------------\n",
"\n",
"# Append models to model_url\n",
"model_url+=custom_urls+\", \" if custom_urls else \"\"\n",
"# if anything_v3:\n",
"# model_url+=\"https://huggingface.co/NoCrypt/safetensor_models/resolve/main/Anything-V3.0-pruned-fp32.safetensors, \"\n",
"\n",
"if anylora:\n",
" model_url+=\"https://huggingface.co/Lykon/AnyLoRA/resolve/main/AnyLoRA_noVae_fp16-pruned.safetensors, \"\n",
"if amedira:\n",
" model_url+=\"https://huggingface.co/AshtakaOOf/Amedira/resolve/main/Amedira-bV.safetensors, \"\n",
"if anything_v4_5:\n",
" model_url+=\"https://huggingface.co/ckpt/anything-v4.0/resolve/main/anything-v4.5-pruned.safetensors, \"\n",
"if gishiki_v1_1:\n",
" model_url+=\"https://huggingface.co/Aotsuyu/Gishiki/resolve/main/Gishikiv1.1.safetensors, \"\n",
"if something_v2_2:\n",
" model_url+=\"https://huggingface.co/NoCrypt/SomethingV2_2/resolve/main/SomethingV2_2.safetensors, \"\n",
"if waifu_diffusion == \"radiance\":\n",
" model_url+=\"https://huggingface.co/waifu-diffusion/wd-1-5-beta3/resolve/main/wd-radiance-fp16.safetensors, \"\n",
"if waifu_diffusion == \"ink\":\n",
" model_url+=\"https://huggingface.co/waifu-diffusion/wd-1-5-beta3/resolve/main/wd-ink-fp16.safetensors, \"\n",
"if waifu_diffusion == \"mofu\": #mofu!\n",
" model_url+=\"https://huggingface.co/waifu-diffusion/wd-1-5-beta3/resolve/main/wd-mofu-fp16.safetensors, \"\n",
"if waifu_diffusion == \"illusion\":\n",
" model_url+=\"https://huggingface.co/waifu-diffusion/wd-1-5-beta3/resolve/main/wd-illusion-fp16.safetensors, \"\n",
"if awooooooo:\n",
" model_url+=\"https://huggingface.co/yoinked/merges/resolve/main/awoo/awooooooo.safetensors, \"\n",
"\n",
"if anything_vae or anything_v4_5 or anylora:\n",
" model_url+=\" https://huggingface.co/NoCrypt/resources/resolve/main/VAE/any.vae.safetensors, \"\n",
"if blessed2_vae:\n",
" model_url+=\"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/blessed2.vae.safetensors, \"\n",
"if wd_vae or waifu_diffusion!=\"none\":\n",
" model_url+=\"https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors, \"\n",
"if sd_vae:\n",
" model_url+=\"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors, \"\n",
"if controlnet == \"v1.0\":\n",
" model_url+=\"https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_canny-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_depth-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_hed-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_mlsd-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_normal-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_openpose-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_scribble-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_seg-fp16.safetensors, \"\n",
"if controlnet == \"v1.0-diff\":\n",
" model_url+=\"https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_canny_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_depth_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_hed_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_mlsd_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_normal_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_openpose_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_scribble_fp16.safetensors, https://huggingface.co/kohya-ss/ControlNet-diff-modules/resolve/main/diff_control_sd15_seg_fp16.safetensors, \"\n",
"if controlnet == \"t2i\":\n",
" model_url+=\"https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_canny-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_color-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_depth-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_keypose-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_openpose-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_seg-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_sketch-fp16.safetensors, https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/t2iadapter_style-fp16.safetensors,\"\n",
"if controlnet == \"v1.1\":\n",
" model_url+=\"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_depth_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_depth_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.yaml, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11u_sd15_tile_fp16.safetensors, control:https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11u_sd15_tile_fp16.yaml, \"\n",
"\n",
"# Image outputs to drive (part 1)\n",
"if output_to_drive or configs_in_drive:\n",
" if not os.path.exists('/content/gdrive'):\n",
" drive.mount('/content/gdrive')\n",
"\n",
"# Unpack Repo, Dependencies, Caches\n",
"if not os.path.exists(\"/content/sdw\"):\n",
" start_install = int(time.time())\n",
"\n",
" # [!] Copy Warning ⚠️ --------------------------------------\n",
" # By removing these, you understand that updates will most likely breaks some stuff.\n",
" # I suggest you to use \"permanent\" link for repo, deps, and cache. This will prevent this colab from breaking when I update it.\n",
" # How to get permanent link? Go to a commit in my repo (https://huggingface.co/NoCrypt/fast-repo/commits/main) then click browse file.\n",
" # Then copy repo file link from that commit, it should be something like this: https://huggingface.co/NoCrypt/fast-repo/resolve/faa7a6c0a7d4d456415326285446225d12d0d426/repo.tar.lz4\n",
" # Replace the repo link below (in aria2c) to permanent link\n",
" # -----------------------------------------------------------\n",
" with capture.capture_output() as cap:\n",
" !pip install -q ipynbname\n",
" from ipynbname import name as nnb\n",
" if not nnb().split('=')[1].startswith(\"1dio8NjvFrM3yHeNI7TrPVu2CNQxBpXQf\"):\n",
" display(HTML(\"\"\"\n",
" <p style=\"color:red;font-size:25px\"><u> 💀 Colab copy detected 💀</u></p>\n",
" <p style=\"font-size:20px\">Please keep your copy up-to-date, do not report any bugs to NoCrypt<br/><br/></p>\n",
" <img src=\"https://i.ibb.co/2kV0btp/download-74.png\"/><br/><br/>\n",
" <p style=\"font-size:20px\">Please keep your copy up-to-date, do not report any bugs to NoCrypt</p>\n",
" <p style=\"font-size:20px\">P.s. Feel free to remove this warning! I've included a note on how to prevent colab from breaking in the code </p>\n",
" \"\"\"))\n",
" time.sleep(10)\n",
" # ------------------------------------ Feel free to remove! Don't forget to read notes above ✌️\n",
"\n",
"\n",
" print(\"🚀 Unpacking... Please do not stop this process at all cost...\", end='')\n",
" with capture.capture_output() as cap:\n",
" # !rm -rf /usr/local/lib/python3.10/dist-packages/scipy /usr/local/lib/python3.10/dist-packages/scipy-*.dist-info/ /usr/local/lib/python3.10/dist-packages/scipy.libs\n",
" # !apt install -qq libunwind8-dev\n",
" !wget https://huggingface.co/NoCrypt/fast-repo/resolve/main/ubuntu_deps.zip ; unzip ubuntu_deps.zip -d ./deps ; dpkg -i ./deps/* ; rm -rf ubuntu_deps.zip /content/deps/\n",
" # !apt install liblz4-tool aria2\n",
" # !pip uninstall -q -y huggingface_hub\n",
" # !{'curl -LO https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb && dpkg -i ripgrep_13.0.0_amd64.deb && rm -rf ripgrep_13.0.0_amd64.deb'}\n",
"\n",
" # !aria2c --summary-interval=10 -c -x 16 -k 1M -s 16 -d /content -Z \\\n",
" # https://huggingface.co/NoCrypt/fast-repo/resolve/main/dep.tar.lz4 \\\n",
" # https://huggingface.co/NoCrypt/fast-repo/resolve/main/repo.tar.lz4 \\\n",
" # https://huggingface.co/NoCrypt/fast-repo/resolve/main/cache.tar.lz4\n",
"\n",
" # !aria2c -d /content -o dep.tar.lz4 --summary-interval=10 -c -x 16 -k 1M -s 16 https://huggingface.co/NoCrypt/fast-repo/resolve/main/dep.tar.lz4\n",
" # !aria2c -d /content -o repo.tar.lz4 --summary-interval=10 -c -x 16 -k 1M -s 16 https://huggingface.co/NoCrypt/fast-repo/resolve/main/repo.tar.lz4\n",
" # !aria2c -d /content -o cache.tar.lz4 --summary-interval=10 -c -x 16 -k 1M -s 16 https://huggingface.co/NoCrypt/fast-repo/resolve/main/cache.tar.lz4\n",
"\n",
" !echo -e \"https://huggingface.co/NoCrypt/fast-repo/resolve/main/dep.tar.lz4\\n\\tout=dep.tar.lz4\\nhttps://huggingface.co/NoCrypt/fast-repo/resolve/main/repo.tar.lz4\\n\\tout=repo.tar.lz4\\nhttps://huggingface.co/NoCrypt/fast-repo/resolve/main/cache.tar.lz4\\n\\tout=cache.tar.lz4\\n\" \\\n",
" | aria2c -i- -j5 -x16 -s16 -k1M -c\n",
"\n",
" !tar -xI lz4 -f dep.tar.lz4 --overwrite-dir --directory=/usr/local/lib/python3.10/dist-packages/ #(manual dir)\n",
" !tar -xI lz4 -f repo.tar.lz4 --directory=/ #/content/sdw/ (auto dir)\n",
" !tar -xI lz4 -f cache.tar.lz4 --directory=/ #/root/.cache/huggingface (auto dir)\n",
"\n",
" !rm -rf /content/dep.tar.lz4 /content/repo.tar.lz4 /content/cache.tar.lz4\n",
" os.environ[\"SAFETENSORS_FAST_GPU\"]='1'\n",
" os.environ[\"CUDA_MODULE_LOADING\"]=\"LAZY\"\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[\"PYTHONWARNINGS\"] = \"ignore\"\n",
" # %env PYTHONDONTWRITEBYTECODE=1\n",
" os.environ[\"TCMALLOC_AGGRESSIVE_DECOMMIT\"] = \"t\"\n",
"\n",
" !rm /content/sdw/extensions/tunnels/id_rsa.pub\n",
" !rm /content/sdw/extensions/tunnels/id_rsa\n",
"\n",
" # os.environ['PYTORCH_CUDA_ALLOC_CONF'] = \"garbage_collection_threshold:0.9,max_split_size_mb:512\"\n",
" # !apt -y update -qq\n",
"\n",
" !wget https://github.com/camenduru/gperftools/releases/download/v1.0/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4 -c\n",
" %env LD_PRELOAD=/content/libtcmalloc_minimal.so.4\n",
" del cap\n",
" if not os.path.exists(hypernetworks_dir):\n",
" os.makedirs(hypernetworks_dir)\n",
" # if not 'T4' in gpu_name: # [For colab makers out there, facebook's xformers pypi already support almost all gpu now]\n",
" # !pip uninstall -y xformers\n",
" install_time = timedelta(seconds=time.time()-start_install)\n",
" print(\"\\r🚀 Finished unpacking. Took\",\"%02d:%02d:%02d ⚡\\n\" % (install_time.seconds / 3600, (install_time.seconds / 60) % 60, install_time.seconds % 60), end='', flush=True)\n",
" # Colab 🤝 Gradio (Colab timer integration for gradio)\n",
" !echo -n {start_colab} > /content/sdw/static/colabTimer.txt\n",
" print(\"🤝 Colab timer integration complete! You can see your colab time inside webui.\")\n",
"\n",
" # Update using git pull\n",
" if latest_webui:\n",
" !git config --global user.email \"you@example.com\"\n",
" !git config --global user.name \"Your Name\"\n",
" print('⌚ Pulling latest changes...', end=\"\")\n",
" with capture.capture_output() as cap:\n",
" %cd /content/sdw\n",
" !git restore .\n",
" !git pull -X theirs --rebase --autostash\n",
" del cap\n",
" print('\\r🪄 \\033[96mYou are currently using latest version of webui. Please use commit_hash if there is error', flush=True)\n",
"\n",
" if branch != \"master\":\n",
" print(f'⌚ Changing branch to {branch}', end=\"\")\n",
" with capture.capture_output() as cap:\n",
" !git restore .\n",
" !git checkout {branch}\n",
" !git pull\n",
" print(f'\\r🪄 \\033[96mYou are currently using {branch} branch of webui', flush=True)\n",
"\n",
" # 3.32.xx sucks! Pngwn made some changes on 3.33.1 and it's 300% better\n",
" !sed -i 's@gradio==3.32.*@gradio==3.33.1@' /content/sdw/requirements_versions.txt\n",
"\n",
" # Update extensions\n",
" if latest_extensions:\n",
" print('⌚ Updating extensions (might take a while)...', end=\"\")\n",
" with capture.capture_output() as cap:\n",
" !{'for dir in /content/sdw/extensions/*/; do cd \"$dir\" && git fetch origin && git pull; done'}\n",
" del cap\n",
" print('\\r🪄 \\033[96mInbuilt extensions are updated to its latest versions', flush=True)\n",
"\n",
" !cd /content/sdw/repositories/stable-diffusion-stability-ai && git restore .\n",
" if sdxl_patch:\n",
" !sed -i -e '''/from modules import launch_utils/a\\import os''' /content/sdw/launch.py\n",
" !sed -i -e '''/ prepare_environment()/a\\ os.system\\(f\\\"\"\"sed -i -e ''\\\"s/dict()))/dict())).cuda()/g\\\"'' /content/sdw/repositories/stable-diffusion-stability-ai/ldm/util.py\"\"\")''' /content/sdw/launch.py\n",
"\n",
"else:\n",
" print(\"🚀 Already unpacked... Skipping.\")\n",
" time_since_start = timedelta(seconds=time.time()-start_colab)\n",
" print(\"⌚ You've been running this colab for\",\"%02d:%02d:%02d\" % (time_since_start.seconds / 3600, (time_since_start.seconds / 60) % 60, time_since_start.seconds % 60))\n",
"\n",
"os.makedirs(patches_dir, exist_ok=True)\n",
"# Revert changes using time-machine (git reset)\n",
"if commit_hash:\n",
" print('⌚ Activating time machine...', end=\"\")\n",
" with capture.capture_output() as cap:\n",
" %cd /content/sdw\n",
" !git config --global user.email \"you@example.com\"\n",
" !git config --global user.name \"Your Name\"\n",
" # !git stash\n",
" !git reset --hard {commit_hash}\n",
" # !git stash apply\n",
" # !rm -rf /content/sdw/embeddings/*\n",
" del cap\n",
" print('\\r⌚ Time machine activated, you\\'re on commit', commit_hash, flush=True)\n",
" # print('✌️ Embeddings have been deleted for time machine support')\n",
"\n",
"# Colab patches for quality of life improvements\n",
"with capture.capture_output() as cap:\n",
" !wget https://gist.github.com/NoCrypt/6e7331eda3d670c2156852ae5e300a42/raw/e52dac97fcabcb054b5737e0c5188cbc600c6582/DPMPP_2M_V2.patch -P {patches_dir} -c\n",
" !wget https://gist.github.com/NoCrypt/6e7331eda3d670c2156852ae5e300a42/raw/e52dac97fcabcb054b5737e0c5188cbc600c6582/idgaf_about_git_ext.patch -P {patches_dir} -c\n",
" !wget https://gist.github.com/NoCrypt/6e7331eda3d670c2156852ae5e300a42/raw/e52dac97fcabcb054b5737e0c5188cbc600c6582/sd-lowram.patch -P {patches_dir} -c\n",
" if ram_patch_for_sd2:\n",
" pass # no needed\n",
" # !cd /content/sdw/ && git apply --ignore-whitespace {patches_dir}/sd-lowram.patch\n",
" # else:\n",
" # !cd /content/sdw/ && git apply --ignore-whitespace -R {patches_dir}/sd-lowram.patch\n",
"\n",
"\n",
" if dpmpp_v2:\n",
" !cd /content/sdw/ && git apply --ignore-whitespace {patches_dir}/DPMPP_2M_V2.patch\n",
" else:\n",
" !cd /content/sdw/ && git apply --ignore-whitespace -R {patches_dir}/DPMPP_2M_V2.patch\n",
"\n",
" # IGAF, get lost git ext checker thingy\n",
" # !cd /content/sdw/ && git apply --ignore-whitespace {patches_dir}/idgaf_about_git_ext.patch\n",
"\n",
" # Colab Optimizations modified to load_in_vram\n",
" if load_in_vram:\n",
" commandline_arguments += ' --lowram '\n",
"\n",
" # Merge in vram: self-explainotory\n",
" if merge_in_vram:\n",
" !sed -i \"s@'cpu'@'cuda'@\" /content/sdw/modules/extras.py\n",
" else:\n",
" !sed -i \"s@'cuda'@'cpu'@\" /content/sdw/modules/extras.py\n",
"\n",
" # Remove custom theme (since it's not for everyone)\n",
" if no_custom_theme:\n",
" !sed -i 's@\"gradio_theme\":.*@\"gradio_theme\": \"Default\",@' {config_dir}\n",
" else:\n",
" !sed -i 's@\"gradio_theme\":.*@\"gradio_theme\": \"NoCrypt/miku\",@' {config_dir}\n",
"\n",
"# Ngrok stuff goes here\n",
"if ngrok_token or ngrok_auto_save_load:\n",
" if ngrok_auto_save_load:\n",
" if not os.path.exists('/content/gdrive'):\n",
" drive.mount('/content/gdrive')\n",
" if ngrok_token:\n",
" if not os.path.exists(\"/content/gdrive/MyDrive/WebUI/ngrokToken.txt\"):\n",
" !mkdir -p /content/gdrive/MyDrive/WebUI/\n",
" !touch /content/gdrive/MyDrive/WebUI/ngrokToken.txt\n",
" f = open(\"/content/gdrive/MyDrive/WebUI/ngrokToken.txt\", \"w+\")\n",
" f.write(ngrok_token+\",\"+ngrok_region)\n",
" f.close()\n",
" elif os.path.exists('/content/gdrive/MyDrive/WebUI/ngrokToken.txt'):\n",
" ngrok_token,ngrok_region = getoutput(\"cat /content/gdrive/MyDrive/WebUI/ngrokToken.txt\").split(\",\",2)\n",
" else:\n",
" print(\"warning: ngrok token not detected\")\n",
" commandline_arguments += ' --ngrok ' + ngrok_token + ' --ngrok-region ' + ngrok_region\n",
" commandline_arguments = commandline_arguments.replace(\"--share\",\"\")\n",
"\n",
"# Configs in drive\n",
"if configs_in_drive:\n",
" config_dir = drive_config_dir+\"config.json\"\n",
" if not os.path.exists(drive_config_dir):\n",
" !mkdir -p {drive_config_dir}\n",
" !cp /content/sdw/styles.csv /content/sdw/ui-config.json /content/sdw/config.json {drive_config_dir}\n",
" commandline_arguments += ' --ui-config-file ' + drive_config_dir+\"ui-config.json\"\n",
" commandline_arguments += ' --ui-settings-file ' + drive_config_dir+\"config.json\"\n",
" commandline_arguments += ' --styles-file ' + drive_config_dir+\"styles.csv\"\n",
"\n",
"# Image outputs to drive (part 2)\n",
"if output_to_drive:\n",
" !sed -i 's@\"outdir_txt2img_samples\": \"outputs/txt2img-images\"@\"outdir_txt2img_samples\": \"/content/gdrive/MyDrive/WebUI/outputs/txt2img-images\"@' {config_dir}\n",
" !sed -i 's@\"outdir_img2img_samples\": \"outputs/img2img-images\"@\"outdir_img2img_samples\": \"/content/gdrive/MyDrive/WebUI/outputs/img2img-images\"@' {config_dir}\n",
" !sed -i 's@\"outdir_extras_samples\": \"outputs/extras-images\"@\"outdir_extras_samples\": \"/content/gdrive/MyDrive/WebUI/outputs/extras-images\"@' {config_dir}\n",
" !sed -i 's@\"outdir_txt2img_grids\": \"outputs/txt2img-grids\"@\"outdir_txt2img_grids\": \"/content/gdrive/MyDrive/WebUI/outputs/txt2img-grids\"@' {config_dir}\n",
" !sed -i 's@\"outdir_img2img_grids\": \"outputs/img2img-grids\"@\"outdir_img2img_grids\": \"/content/gdrive/MyDrive/WebUI/outputs/img2img-grids\"@' {config_dir}\n",
" !sed -i 's@\"outdir_save\": \"log/images\"@\"outdir_save\": \"/content/gdrive/MyDrive/WebUI/outputs/log/images\"@' {config_dir}\n",
"else:\n",
" if '/gdrive/' in getoutput('cat '+config_dir):\n",
" !sed -i 's@\"outdir_txt2img_samples\": \"outputs/txt2img-images\"@\"outdir_txt2img_samples\": \"outputs/txt2img-images\"@' {config_dir}\n",
" !sed -i 's@\"outdir_img2img_samples\": \"outputs/img2img-images\"@\"outdir_img2img_samples\": \"outputs/img2img-images\"@' {config_dir}\n",
" !sed -i 's@\"outdir_extras_samples\": \"outputs/extras-images\"@\"outdir_extras_samples\": \"outputs/extras-images\"@' {config_dir}\n",
" !sed -i 's@\"outdir_txt2img_grids\": \"outputs/txt2img-grids\"@\"outdir_txt2img_grids\": \"outputs/txt2img-grids\"@' {config_dir}\n",
" !sed -i 's@\"outdir_img2img_grids\": \"outputs/img2img-grids\"@\"outdir_img2img_grids\": \"outputs/img2img-grids\"@' {config_dir}\n",
" !sed -i 's@\"outdir_save\": \"log/images\"@\"outdir_save\": \"log/images\"@' {config_dir}\n",
"\n",
"\n",
"# Install models from model_url, oh boi it's getting bigger\n",
"extension_repo = []\n",
"prefixes = [\n",
" \"config:\",\n",
" \"ui-config:\",\n",
" \"styles:\",\n",
" \"lora:\",\n",
" \"hypernetwork:\",\n",
" \"locon:\",\n",
" \"lycoris:\",\n",
" \"model:\",\n",
" \"vae:\",\n",
" \"control:\",\n",
" \"clone:\",\n",
" \"gfpgan:\",\n",
" \"ersgan:\",\n",
" \"swinr:\",\n",
" \"ldsr:\",\n",
" \"repo:\",\n",
" \"embeddings:\",\n",
" \"sam:\"\n",
"]\n",
"token = optional_huggingface_token if optional_huggingface_token else \"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\"\n",
"user_header = f\"\\\"Authorization: Bearer {token}\\\"\"\n",
"print('📦 Downloading models and stuff...', end='')\n",
"def handle_manual(url):\n",
" if url.startswith(\"config:\"):\n",
" manual_download(url, \"/content/sdw/config.json\")\n",
" elif url.startswith(\"ui-config:\"):\n",
" manual_download(url, \"/content/sdw/ui-config.json\")\n",
" elif url.startswith(\"styles:\"):\n",
" manual_download(url, \"/content/sdw/styles.csv\")\n",
" elif url.startswith(\"sam:\"):\n",
" manual_download(url, sam_dir)\n",
" elif url.startswith(\"lora:\") or url.startswith(\"locon:\") or url.startswith(\"lycoris:\"):\n",
" manual_download(url, loras_dir)\n",
" elif url.startswith(\"hypernetwork:\"):\n",
" manual_download(url, hypernetworks_dir)\n",
" elif url.startswith(\"model:\"):\n",
" manual_download(url, models_dir)\n",
" elif url.startswith(\"vae:\"):\n",
" manual_download(url, vaes_dir)\n",
" elif url.startswith(\"control:\"):\n",
" manual_download(url, control_dir)\n",
" elif url.startswith(\"gfpgan:\"):\n",
" manual_download(url, \"/content/sdw/models/GFPGAN\")\n",
" elif url.startswith(\"esrgan:\"):\n",
" manual_download(url, \"/content/sdw/models/ESRGAN\")\n",
" elif url.startswith(\"swinr:\"):\n",
" manual_download(url, \"/content/sdw/models/SwinR\")\n",
" elif url.startswith(\"ldsr:\"):\n",
" manual_download(url, \"/content/sdw/models/LDSR\")\n",
" elif url.startswith(\"embeddings:\"):\n",
" manual_download(url, embeddings_dir)\n",
" elif url.startswith(\"extension:\"):\n",
" extension_repo.append(url)\n",
" elif url.startswith(\"clone:\") or url.startswith(\"repo:\"):\n",
" !cd /content/.downloaded && git clone $url\n",
"\n",
"def manual_download(url, dst):\n",
" url = url[url.find(':')+1:]\n",
" if \".json\" in url or \".csv\" in url:\n",
" !wget \"{url}\" -O {dst} -c\n",
" elif '.yaml' in url or '.yml' in url or 'discord' in url:\n",
" !wget \"{url}\" -P {dst} -c\n",
" elif 'drive.google' in url:\n",
" if 'folders' in url:\n",
" !gdown --folder \"{url}\" -O {dst} --fuzzy -c\n",
" else:\n",
" !gdown \"{url}\" -O {dst} --fuzzy -c\n",
" elif 'huggingface' in url:\n",
" if '/blob/' in url:\n",
" url = url.replace('/blob/', '/resolve/')\n",
" parsed_link = '\\n{}\\n\\tout={}'.format(url,unquote(url.split('/')[-1]))\n",
" !echo -e \"{parsed_link}\" | aria2c --header={user_header} --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d \"{dst}\"\n",
" elif 'http' in url or 'magnet' in url:\n",
" parsed_link = '\"{}\"'.format(url)\n",
" !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {dst} -Z {parsed_link}\n",
"\n",
"def download(url):\n",
" try:\n",
" have_drive_link\n",
" except:\n",
" if \"drive.google.com\" in url:\n",
" # I'm sorry drive ID enjoyer, this will make ID useless :(\n",
" !pip install -U gdown\n",
" have_drive_link = True\n",
" links_and_paths = url.split(',')\n",
" !mkdir -p {destination_dir} {models_dir} {vaes_dir} {hypernetworks_dir} {embeddings_dir} {loras_dir} {sam_dir}\n",
" http_links = []\n",
" huggingface_links = []\n",
" for link_or_path in links_and_paths:\n",
" link_or_path = link_or_path.strip()\n",
" if not link_or_path:\n",
" continue\n",
"\n",
" if any(link_or_path.startswith(prefix.lower()) for prefix in prefixes):\n",
" handle_manual(link_or_path)\n",
" continue\n",
"\n",
" if 'github.com' in link_or_path and ( '.git' in link_or_path or not '.' in link_or_path.split('/')[-1] ):\n",
" extension_repo.append(link_or_path)\n",
" continue\n",
"\n",
" if '.yaml' in link_or_path or '.yml' in link_or_path or 'discord' in link_or_path:\n",
" !wget {link_or_path} -P {destination_dir} -c\n",
" elif 'drive.google' in link_or_path:\n",
" if 'folders' in link_or_path:\n",
" !gdown --folder {link_or_path} -O {destination_dir} --fuzzy -c\n",
" else:\n",
" !gdown {link_or_path} -O {destination_dir} --fuzzy -c\n",
" elif 'huggingface' in link_or_path:\n",
" if '/blob/' in link_or_path:\n",
" link_or_path = link_or_path.replace('/blob/', '/resolve/')\n",
" huggingface_links.append(link_or_path)\n",
" elif 'http' in link_or_path or 'magnet' in link_or_path:\n",
" http_links.append(link_or_path)\n",
" elif '/' in link_or_path:\n",
" if not os.path.exists('/content/gdrive/MyDrive'):\n",
" print('Looks like there\\'s a path in your url. You need to mount your drive first.')\n",
" from google.colab import drive\n",
" drive.mount('/content/gdrive')\n",
" !rsync -avr --progress /content/gdrive/MyDrive/{link_or_path} {destination_dir}\n",
" else:\n",
" !gdown {link_or_path} -O {destination_dir} --fuzzy -c\n",
" if http_links:\n",
" links_string = ' '.join(['\"{}\"'.format(x) for x in http_links])\n",
" !aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -j5 -x16 -s16 -k1M -c -d {destination_dir} -Z {links_string}\n",
" del links_string\n",
" if huggingface_links:\n",
" # links_string = ' '.join(['\"{}\"'.format(x) for x in huggingface_links])\n",
" # !aria2c --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {destination_dir} -Z {links_string}\n",
" # for link in huggingface_links:\n",
" # !aria2c --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 -d {destination_dir} -o {link.split('/')[-1]} {link}\n",
" links_string = '\\n'.join(['{}\\n\\tout={}'.format(x,unquote(x.split('/')[-1])) for x in huggingface_links])\n",
" !echo -e \"{links_string}\" | aria2c --header={user_header} --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -i- -j5 -x16 -s16 -k1M -c -d {destination_dir}\n",
"\n",
"if verbose_download:\n",
" download(model_url)\n",
"else:\n",
" with capture.capture_output() as cap:\n",
" download(model_url)\n",
" del cap\n",
"\n",
"print('\\r🏁 Download finished.', flush=True)\n",
"\n",
"if len(extension_repo) > 0:\n",
" print('✨ Installing custom extensions...', end='')\n",
" with capture.capture_output() as cap:\n",
" for repo in extension_repo:\n",
" repo_name = repo.split('/')[-1]\n",
" !cd {extensions_dir} \\\n",
" && git clone \"{repo}\" \\\n",
" && cd {repo_name} \\\n",
" && git fetch\n",
" print('\\r🏁 Installed',len(extension_repo),'custom extensions.', flush=True)\n",
"\n",
"print('\\n')\n",
"# Link all files by filtering accoridng to their type\n",
"with capture.capture_output() as cap:\n",
" # files = os.listdir(destination_dir)\n",
" files = [os.path.join(dp,f) for dp, dn, fn in os.walk(destination_dir) for f in fn] # Thanks Aojiru!\n",
" for file in files:\n",
" name, file_extension = os.path.splitext(file)\n",
" if '.aria2' in file:\n",
" continue\n",
" file_path = os.path.join(destination_dir, file)\n",
" file_size = os.path.getsize(file_path)\n",
" if \"sam_\" in name and file_extension == \".pth\":\n",
" !ln \"{file_path}\" {sam_dir}\n",
" elif \"control_\" in name or \"t2iadapter_\" in name or file_extension == \".pth\":\n",
" !ln \"{file_path}\" {control_dir}\n",
" elif file_extension in ['.yaml', '.yml'] or file_size > 1_500_000_000:\n",
" !ln \"{file_path}\" {models_dir}\n",
" elif \"kl-f8\" in name or \"vae_\" in file or \"vae.\" in file or \"vae-\" in file or file_size > 380_000_000:\n",
" !ln \"{file_path}\" {vaes_dir}\n",
" elif getoutput('if rg -q -o \"lora_unet\" \"'+file_path+'\"; then echo 1; else echo 0; fi') == \"1\":\n",
" !ln \"{file_path}\" {loras_dir}\n",
" elif (file_extension == '.pt' or file_extension == '.safetensors') and file_size < 10_000_000:\n",
" !ln \"{file_path}\" {embeddings_dir}\n",
" else:\n",
" !ln \"{file_path}\" {hypernetworks_dir}\n",
" del cap\n",
"\n",
"# Automatically loads vae for first run, if it exists.\n",
"if auto_vae:\n",
" if '.vae.pt' in os.listdir(vaes_dir) or '/vae' in model_url:\n",
" commandline_arguments+=' --vae-path $(readlink -f $(find '+vaes_dir+' \\( -name \"*.vae.pt\" -or -name \"*.ckpt\" \\) -print -quit))'\n",
"\n",
"# Configure Alternatives Tunnels (Colab native, localtunnel, cloudflared, bore with auth)\n",
"if alternative_tunnels:\n",
" commandline_arguments = commandline_arguments.replace(\"--share\",\"\")\n",
" commandline_arguments += \" --multiple\"\n",
" print(\"⌚ \\033[95m\\033[1mGenerating alternative tunnels...\", end='')\n",
" with capture.capture_output() as cap:\n",
" %cd /content\n",
" if not os.path.exists('/tools/node/bin/lt'):\n",
" !npm install -g localtunnel\n",
" if not os.path.exists('/usr/bin/cloudflared'):\n",
" !curl -Lo /usr/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cloudflared\n",
" del cap\n",
" !true > /content/nohup.out\n",
" !nohup lt --port 7860 > /content/nohup.out 2>&1 &\n",
" !nohup cloudflared tunnel --url localhost:7860 > /content/nohup.out 2>&1 &\n",
" if with_bore:\n",
" if not os.path.exists('/usr/bin/bore'):\n",
" !curl -Ls https://github.com/ekzhang/bore/releases/download/v0.4.0/bore-v0.4.0-x86_64-unknown-linux-musl.tar.gz | tar zx -C /usr/bin\n",
" !nohup bore local 7860 --to bore.pub > /content/nohup.out 2>&1 &\n",
" if not \"--gradio-auth\" in commandline_arguments:\n",
" import random\n",
" import string\n",
" gradio_password = ''.join(random.choice(string.ascii_lowercase) for i in range(5))\n",
" commandline_arguments+=\" --gradio-auth {}:{}\".format(\"ncpt\", gradio_password)\n",
" else:\n",
" gradio_password = False\n",
" !sleep 4\n",
" print(\"\\r💡 \\033[95m\\033[1mUse one of these alternative tunnels after the loading is finished: \", flush=True)\n",
" from google.colab.output import serve_kernel_port_as_window\n",
" # serve_kernel_port_as_window(7860, anchor_text=\"https://th15f4k3l1nkofcn0tr34ll0l-7860-colab.googleusercontent.com/\")\n",
" !cat /content/nohup.out | rg -a -o \"https[^ ]*.*\\.trycloudflare\\.com|https[^ ]*.*\\.loca\\.lt|bore.pub:[^ ]*\" | sed 's@bore.pub@http://bore.pub@'\n",
" print(\"\\n\")\n",
" if with_bore:\n",
" if gradio_password:\n",
" print(\"\\r🔐 \\033[0m\\033[1mLooks like you're using bore without --gradio-auth huh... \")\n",
" print(\"For security, I've enforced to use gradio auth, so use this account to login:\")\n",
" print(\"👉⚠️ Username: ncpt\")\n",
" print(\"👉⚠️ Password:\", gradio_password,\"\\n\\n\")\n",
"\n",
"# If no xformers installed, remove --xformers from arg to avoid using old builtin xformers\n",
"# if not os.path.exists(\"/usr/local/lib/python3.10/dist-packages/xformers\"):\n",
"# commandline_arguments = commandline_arguments.replace(\"--xformers\",\"\")\n",
"\n",
"# Krita extension support (adding --api automatically) + toggleable.\n",
"with capture.capture_output() as cap:\n",
" if krita_paint_ext:\n",
" # Add api if no api (if lazy y'know)\n",
" if not \"--api\" in commandline_arguments:\n",
" commandline_arguments+=\" --api\"\n",
" %cd /content/sdw\n",
" if os.path.exists('/content/sdw/extensions/auto-sd-paint-ext'):\n",
" !cd ./extensions/auto-sd-paint-ext && git fetch && git merge # Deflecting FETCH_HEAD not found bug\n",
" else:\n",
" !git clone https://github.com/ashen-sensored/auto-sd-paint-ext extensions/auto-sd-paint-ext\n",
" else:\n",
" if os.path.exists('/content/sdw/extensions/auto-sd-paint-ext'):\n",
" !rm -rf /content/sdw/extensions/auto-sd-paint-ext\n",
" # Remove junks\n",
" !find /content/sdw/ -name \".ipynb_checkpoints\" -type d -exec rm -r {} \\;\n",
"\n",
"\n",
"# Print all files in every important directory\n",
"print(\"\\033[96mCan't see your files in here? Activate verbose_download to debug!\\n\")\n",
"print(\"\\033[92m\\033[1m╭-📦 Models + Configs\\033[96m\")\n",
"!find {models_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
"print(\"\\n\\033[92m\\033[1m╭-📦 VAEs\\033[96m\")\n",
"!find {vaes_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
"print(\"\\n\\033[92m\\033[1m╭-📦 Custom Embeddings (inbuilt is hidden)\\033[96m\")\n",
"!find {embeddings_dir}/ -mindepth 1 -maxdepth 1 -name '*.pt' -or -name '*.safetensors' -printf '%f\\n'\n",
"print(\"\\n\\033[92m\\033[1m╭-📦 LoRAs\\033[96m\")\n",
"!find {loras_dir}/ -mindepth 1 ! -name '*.keep' -printf '%f\\n'\n",
"# print(\"\\n\\033[92m\\033[1m╭-📦 LyCORIS\\033[96m\")\n",
"# !find {lycoris_dir}/ -mindepth 1 ! -name '*.keep' -printf '%f\\n'\n",
"print(\"\\n\\033[92m\\033[1m╭-📦 Hypernetworks\\033[96m\")\n",
"!find {hypernetworks_dir}/ -mindepth 1 ! -name '*.txt' -printf '%f\\n'\n",
"print(\"\\n\\033[92m\\033[1m╭-📦 Extensions\\033[96m\")\n",
"!find {extensions_dir}/ -mindepth 1 -maxdepth 1 ! -name '*.txt' -printf '%f\\n'\n",
"print(\"\\n\\n\\033[0m\")\n",
"\n",
"# HF OUT support!\n",
"if optional_huggingface_token:\n",
" commandline_arguments+=\" --hf-token-out \"+optional_huggingface_token\n",
"\n",
"# Start the weebui\n",
"%cd /content/sdw\n",
"\n",
"if null_model:\n",
" print(\"\\033[91m ⚠️ Null model will be loaded, if you don't understand please uncheck the model \\033[0m\")\n",
" !wget https://huggingface.co/ckpt/null/resolve/main/nullModelzeros.ckpt -P {models_dir} -c\n",
" commandline_arguments+=\" --ckpt \"+models_dir+\"/nullModelzeros.ckpt \"\n",
"\n",
"if fast_start:\n",
" # commandline_arguments += \" --skip-install\"\n",
" print(\"\\033[91m ⚠️ Fast start is active, please disable it if you have any problem! \\033[0m\")\n",
" !python webui.py $commandline_arguments\n",
"else:\n",
" !COMMANDLINE_ARGS=\"{commandline_arguments}\" REQS_FILE=\"requirements_versions.txt\" python launch.py\n",
"time_since_start = timedelta(seconds=time.time()-start_colab)\n",
"print(\"\\n\\n\\033[96m⌚ You've been running this colab for\",\"%02d:%02d:%02d\" % (time_since_start.seconds / 3600, (time_since_start.seconds / 60) % 60, time_since_start.seconds % 60))\n",
"print(\"\\n\\n\")"
]
},
{
"cell_type": "markdown",
"source": [
"---\n",
"# **Useful Utilities (Optional)**\n",
"\n",
"*Stuff that might be useful*"
],
"metadata": {
"id": "iLsO_riJrAEl"
}
},
{
"cell_type": "code",
"source": [
"#@markdown ## Colab Mobile Keep Alive\n",
"#@markdown Run this cell to keep the tab alive in mobile (before running the start cell)\n",
"\n",
"%%html\n",
"<b>Press play on the music player to keep the tab alive before running the start cell (Uses only 13MB of data)</b><br/>\n",
"<audio src=\"https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a\" controls>"
],
"metadata": {
"id": "ZIL7itnNaw5V",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@markdown ## Mass download outputs\n",
"#@markdown Zip all image outputs and downloads them\n",
"from google.colab import files\n",
"import os\n",
"%cd /content\n",
"if output_to_drive:\n",
" print(\"Your images already in google drive btw, this cell is basically useless but what ever\")\n",
"\n",
"if os.path.exists(\"/content/outputs.zip\"):\n",
" !rm -f /content/outputs.zip\n",
"!cd /content/sdw/outputs && zip -r /content/outputs.zip .\n",
"files.download('/content/outputs.zip')"
],
"metadata": {
"cellView": "form",
"id": "vcca4v99sBd6"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## XTerm Terminal\n",
"*Spins up a terminal*"
],
"metadata": {
"id": "QAvV1XNM3TxR"
}
},
{
"cell_type": "code",
"source": [
"#@title Install XTerm\n",
"!pip install colab-xterm\n",
"%load_ext colabxterm"
],
"metadata": {
"id": "xaIJuwU1f3k7",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title Run XTerm (Terminal)\n",
"%xterm"
],
"metadata": {
"id": "Umxr9M53f45V",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Upload stuff\n",
"*Quickly upload stuff like merged models to huggingface*\n",
"\n",
"Run cell `1,2,3`\n",
"\n",
"You only need to choose one between `3.1,3.2,and 3.3`\n",
"\n",
"<small>Forked from LYNN\n"
],
"metadata": {
"id": "EzbWAsEc2bAt"
}
},
{
"cell_type": "code",
"source": [
"#@title 1. Login to Huggingface hub\n",
"try:\n",
" hub_ok # My packaged dep didn't contains this (but stil have the folder)\n",
"except:\n",
" print(\"Setting up huggingface_hub...\")\n",
" !pip install --force-reinstall -qqqq huggingface_hub\n",
" hub_ok = True\n",
"from IPython.display import clear_output\n",
"from huggingface_hub import login\n",
"clear_output()\n",
"\n",
"#@markdown 1. Of course, you need a Huggingface account first.\n",
"#@markdown 2. To create a huggingface token, go to [this link](https://huggingface.co/settings/tokens), then `create new token` or copy available token with the `Write` role.\n",
"\n",
"write_token = \"\" #@param {type:\"string\"}\n",
"login(write_token, add_to_git_credential=True)"
],
"metadata": {
"cellView": "form",
"id": "HLPOBeoG2hIm"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title 2. Setup Repo\n",
"from huggingface_hub.utils import validate_repo_id, HfHubHTTPError\n",
"from huggingface_hub import HfApi\n",
"\n",
"\n",
"api = HfApi()\n",
"user = api.whoami(write_token)\n",
"\n",
"#@markdown #### If your model repo didn't exist, it will automatically create your repo.\n",
"repo_name = \"my_merged_models\" #@param{type:\"string\"}\n",
"make_this_repo_private_if_not_exist = False #@param{type:\"boolean\"}\n",
"clone_with_git = True #@param{type:\"boolean\"}\n",
"\n",
"model_repo = user['name']+\"/\"+repo_name.strip()\n",
"\n",
"validate_repo_id(model_repo)\n",
"\n",
"if repo_name != \"\":\n",
" try:\n",
" api.create_repo(repo_id=model_repo,\n",
" private=make_this_repo_private_if_not_exist)\n",
" print(\"Model Repo didn't exists, creating repo\")\n",
" print(\"Model Repo: \",model_repo,\"created!\\n\")\n",
"\n",
" except HfHubHTTPError as e:\n",
" print(f\"Model Repo: {model_repo} exists, skipping create repo\\n\")\n",
"\n",
"if clone_with_git:\n",
" !git lfs install --skip-smudge\n",
" !export GIT_LFS_SKIP_SMUDGE=1\n",
" !git clone https://huggingface.co/{model_repo} /content/{repo_name}"
],
"metadata": {
"cellView": "form",
"id": "3ecSNSOY3rKO"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "xSLziGY-sa89"
},
"outputs": [],
"source": [
"\n",
"import os\n",
"import sys\n",
"import ipywidgets as widgets\n",
"from IPython.display import clear_output\n",
"from huggingface_hub import HfApi, login\n",
"from huggingface_hub.utils import validate_repo_id, HfHubHTTPError\n",
"from IPython.utils import capture\n",
"\n",
"\n",
"paths_map = {\n",
" \"Models\" : \"/content/sdw/models/Stable-diffusion\",\n",
" \"VAEs\" : \"/content/sdw/models/VAE\",\n",
" \"LORAs\" : \"/content/sdw/models/Lora\",\n",
" \"Embeddings\" : \"/content/sdw/embeddings\",\n",
" \"Hypernetworks\" : \"/content/sdw/models/hypernetworks\",\n",
"}\n",
"\n",
"#@title 3.1 Upload via huggingface_hub (Fun way)\n",
"#@markdown ## **How to use this?**<br>\n",
"#@markdown 1. Run this cell after you ran the login cell\n",
"#@markdown 2. Select model you want to upload (use `ctrl/shift` for multiple selection)\n",
"#@markdown 3. Click on upload button\n",
"folder = \"Models\" #@param [\"Models\", \"VAEs\", \"LORAs\", \"Embeddings\", \"Hypernetworks\"]\n",
"commit_message = \"Upload with 🚀🤗 NoCrypt's nocrypt_colab_remastered\" #@param{type:\"string\"}\n",
"\n",
"models_path = paths_map[folder]\n",
"upload_path = '/content/upload_models'\n",
"\n",
"api = HfApi()\n",
"username_repo = user['name']+\"/\"+repo_name.strip()\n",
"validate_repo_id(username_repo)\n",
"\n",
"def get_file_list(path):\n",
" res = []\n",
" for (dir_path, dir_names, file_names) in os.walk(path):\n",
" res.extend(file_names)\n",
" return res\n",
"\n",
"selected = widgets.SelectMultiple(\n",
" options=get_file_list(models_path),\n",
" rows=10,\n",
" disabled=False,\n",
")\n",
"\n",
"button = widgets.Button(\n",
" description='Upload',\n",
" disabled=False,\n",
" button_style='success',\n",
" tooltip='Upload to huggingface',\n",
")\n",
"dropdown = widgets.Dropdown(\n",
" options=paths_map.keys(),\n",
" value=folder,\n",
" description='Folder',\n",
")\n",
"\n",
"out = widgets.Output()\n",
"\n",
"def on_folder_change(change):\n",
" if change['type'] == 'change' and change['name'] == 'value':\n",
" models_path = paths_map[change[\"new\"]]\n",
" selected.options = get_file_list(models_path)\n",
"\n",
"def upload_it(b):\n",
" with out:\n",
" if selected.value is not None:\n",
" clear_output()\n",
" !mkdir -p {upload_path}\n",
"\n",
"\n",
" #hard link each file\n",
" for selected_model in selected.value:\n",
" if not os.path.exists(os.path.join(upload_path,selected_model)):\n",
" os.link(os.path.join(paths_map[dropdown.value],selected_model),os.path.join(upload_path,selected_model)) #hardlinking to save colab's space\n",
"\n",
" #delete .ipynb_checkpoint\n",
" if os.path.exists(os.path.join(upload_path,\".ipynb_checkpoints\")):\n",
" !rm {upload_path}/.ipynb_checkpoints\n",
" print(\"Selected:\", \", \".join(selected.value))\n",
" print(\"Uploading to https://huggingface.co/\"+username_repo)\n",
" print(\"Please wait... Might look stuck, but it's not 👍\")\n",
"\n",
" # Comment this for file based upload\n",
" api.upload_folder(\n",
" folder_path=upload_path,\n",
" repo_id=username_repo,\n",
" commit_message=commit_message\n",
" )\n",
"\n",
" # Uncomment for file based upload\n",
" # for filename in os.listdir(upload_path):\n",
" # f = os.path.join(upload_path, filename)\n",
" # # checking if it is a file\n",
" # if os.path.isfile(f):\n",
" # api.upload_file(\n",
" # path_or_fileobj=f,\n",
" # path_in_repo=filename,\n",
" # repo_id=username_repo,\n",
" # commit_message=commit_message\n",
" # )\n",
"\n",
" print(\"Done!\")\n",
" #delete hardlink\n",
" !rm -rf {upload_path}/*\n",
" else:\n",
" print(\"Nothing is selected\")\n",
"\n",
"dropdown.observe(on_folder_change)\n",
"button.on_click(upload_it)\n",
"print(\"Upload target: https://huggingface.co/\"+username_repo)\n",
"print(\"👇 Select models you want to upload (use ctrl/shift for multiple selection) \")\n",
"display(dropdown,selected,button,out)"
]
},
{
"cell_type": "code",
"source": [
"#@title 3.2 Upload via huggingface_hub (Manual way)\n",
"\n",
"#@markdown All paths for easier access:<br>\n",
"#@markdown /content/sdw/models/Stable-diffusion<br>\n",
"#@markdown /content/sdw/models/VAE<br>\n",
"#@markdown /content/sdw/models/Lora<br>\n",
"#@markdown /content/sdw/embeddings<br>\n",
"#@markdown /content/sdw/models/hypernetwork<br>\n",
"from huggingface_hub import HfApi\n",
"from pathlib import Path\n",
"\n",
"api = HfApi()\n",
"file_path = \"/content/models/Anything-V3-vae-swapped.safetensors\" #@param {type :\"string\"}\n",
"commit_message = \"Upload with 🚀🤗 NoCrypt's nocrypt_colab_remastered\" #@param {type :\"string\"}\n",
"\n",
"if file_path != \"\":\n",
" path_obj = Path(file_path)\n",
" trained_model = path_obj.parts[-1]\n",
"\n",
" print(f\"Uploading {trained_model} to https://huggingface.co/\"+model_repo)\n",
" print(f\"Please wait...\")\n",
"\n",
" api.upload_file(\n",
" path_or_fileobj=file_path,\n",
" path_in_repo=trained_model,\n",
" repo_id=model_repo,\n",
" commit_message=commit_message,\n",
" )\n",
"\n",
" print(f\"Upload success, located at https://huggingface.co/\"+model_repo+\"/blob/main/\"+trained_model+\"\\n\")"
],
"metadata": {
"cellView": "form",
"id": "7Juh7N1c3ooM"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title 3.3 Upload via GIT (more stable)\n",
"%cd /content/\n",
"file_path = \"/content/models/Anything-V3-vae-swapped.safetensors\" #@param {type :\"string\"}\n",
"!ln {file_path} /content/{repo_name}/\n",
"#@markdown Set **git commit identity**\n",
"email = \"your-email\" #@param {'type': 'string'}\n",
"name = \"your-username\" #@param {'type': 'string'}\n",
"#@markdown Set **commit message**\n",
"commit_m = \"Upload with 🚀🤗 NoCrypt's nocrypt_colab_remastered\" #@param {'type': 'string'}\n",
"\n",
"%cd /content/{repo_name}\n",
"\n",
"!git lfs install --skip-smudge\n",
"!export GIT_LFS_SKIP_SMUDGE=1\n",
"!git pull -X theirs\n",
"\n",
"!git lfs install\n",
"!huggingface-cli lfs-enable-largefiles .\n",
"!git config --global user.email \"{email}\"\n",
"!git config --global user.name \"{name}\"\n",
"!git add .\n",
"!git commit -m \"{commit_m}\"\n",
"!git push"
],
"metadata": {
"cellView": "form",
"id": "C4sGvmEf1gIv"
},
"execution_count": null,
"outputs": []
}
]
} |