Last active
October 27, 2022 21:27
-
-
Save inu-ai/c12d82b065b3d70e28feb6e3f358e1e0 to your computer and use it in GitHub Desktop.
stablediffusionui_free_tier.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"private_outputs": true, | |
"provenance": [], | |
"collapsed_sections": [], | |
"name": "stablediffusionui_free_tier.ipynb", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
}, | |
"accelerator": "GPU", | |
"gpuClass": "standard" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/thx-pw/c12d82b065b3d70e28feb6e3f358e1e0/stablediffusionui_voldemort_autocast_improvements.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"It runs and moves in order from the top.\n", | |
"Settings include model changes.\n", | |
">上から順に実行して動きます。\n", | |
">設定はモデル変更などがあります。" | |
], | |
"metadata": { | |
"id": "urkXwu2KwQn0" | |
} | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"Adapted from(参考元): \n", | |
"\n", | |
"\n", | |
"https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl\n", | |
"https://colab.research.google.com/github/TheLastBen/fast-stable-diffusion/blob/main/fast_stable_diffusion_AUTOMATIC1111.ipynb" | |
], | |
"metadata": { | |
"id": "gfKvWAVnz8OB" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Clone webUI repository.(webUIリポジトリのクローン)\n", | |
"!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui --quiet\n", | |
"%cd /content/stable-diffusion-webui" | |
], | |
"metadata": { | |
"id": "sBbcB4vwj_jm", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Download the model from Hugging Face.(Hugging Faceからモデルをダウンロード)\n", | |
"\n", | |
"models_dict = {\n", | |
" \"trinart_characters_19m\" : \"https://huggingface.co/naclbit/trinart_characters_19.2m_stable_diffusion_v1/blob/main/trinart_characters_it4_v1.ckpt\",\n", | |
" \"trinart2_step115000\" : \"https://huggingface.co/naclbit/trinart_stable_diffusion_v2/blob/main/trinart2_step115000.ckpt\",\n", | |
" \"trinart2_step95000\" : \"https://huggingface.co/naclbit/trinart_stable_diffusion_v2/blob/main/trinart2_step95000.ckpt\",\n", | |
" \"trinart2_step60000\" : \"https://huggingface.co/naclbit/trinart_stable_diffusion_v2/blob/main/trinart2_step60000.ckpt\",\n", | |
" \"waifu-v13-float32\" : \"https://huggingface.co/hakurei/waifu-diffusion-v1-3/blob/main/wd-v1-3-float32.ckpt\",\n", | |
" \"waifu-v13-float16\" : \"https://huggingface.co/hakurei/waifu-diffusion-v1-3/blob/main/wd-v1-3-float16.ckpt\",\n", | |
" \"waifu-v12-prune\" : \"https://huggingface.co/crumb/pruned-waifu-diffusion/blob/main/model-pruned.ckpt\",\n", | |
" \"stable-v15\" : \"https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.ckpt\",\n", | |
" \"stable-v15-inpainting\" : \"https://huggingface.co/runwayml/stable-diffusion-inpainting/blob/main/sd-v1-5-inpainting.ckpt\",\n", | |
" \"stable-v14\" : \"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/blob/main/sd-v1-4.ckpt\",\n", | |
" \"tohoku-v1\" : \"https://huggingface.co/shirayu/sd-tohoku-v1/blob/main/sd-tohoku-v1.model.ckpt\", \n", | |
" \"robo-v1\" : \"https://huggingface.co/nousr/robo-diffusion/blob/main/models/robo-diffusion-v1.ckpt\",\n", | |
" \"eva-v22-notHD\" : \"https://huggingface.co/crumb/eva-model-ckpt/blob/main/eva-fusion-v2.22-notHD.ckpt\",\n", | |
" \"eva-v21\" : \"https://huggingface.co/crumb/eva-model-ckpt/blob/main/eva-fusion-v2.1.ckpt\",\n", | |
" \"icon\" : \"https://huggingface.co/crumb/icon-diffusion-ckpt/blob/main/icon-diffusion.ckpt\",\n", | |
" \"arcane-v3\" : \"https://huggingface.co/nitrosocke/Arcane-Diffusion/blob/main/arcane-diffusion-v3.ckpt\",\n", | |
" \"arcane-v2\" : \"https://huggingface.co/nitrosocke/Arcane-Diffusion/blob/main/arcane-diffusion-v2.ckpt\",\n", | |
" \"eldenring-v2\" : \"https://huggingface.co/nitrosocke/elden-ring-diffusion/blob/main/eldenring-v2-pruned.ckpt\",\n", | |
" \"eldenring-v1\" : \"https://huggingface.co/nitrosocke/elden-ring-diffusion/blob/main/eldenring-v1-pruned.ckpt\",\n", | |
" \"hiten_girl_anime_8k_wallpaper_4k\" : \"https://huggingface.co/BumblingOrange/Hiten/blob/main/Hiten%20girl_anime_8k_wallpaper_4k.ckpt\",\n", | |
"}\n", | |
"\n", | |
"vaes_dict = {\n", | |
" \"trinart_characters_19m\" : \"https://huggingface.co/naclbit/trinart_characters_19.2m_stable_diffusion_v1/blob/main/autoencoder_kl-f8-trinart_characters.ckpt\",\n", | |
" \"waifu-v14-anime2\" : \"https://huggingface.co/hakurei/waifu-diffusion-v1-4/blob/main/vae/kl-f8-anime2.ckpt\",\n", | |
" \"waifu-v14-anime1\" : \"https://huggingface.co/hakurei/waifu-diffusion-v1-4/blob/main/vae/kl-f8-anime.ckpt\",\n", | |
" \"sd-vae-ft-mse\" : \"https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.ckpt\",\n", | |
" \"sd-vae-ft-ema\" : \"https://huggingface.co/stabilityai/sd-vae-ft-ema-original/blob/main/vae-ft-ema-560000-ema-pruned.ckpt\",\n", | |
"}\n", | |
"\n", | |
"hypernetworks_dict = {\n", | |
" \"zelda\" : \"https://huggingface.co/wavymulder/zelda-diffusion-HN/blob/main/zeldaBOTW.pt\",\n", | |
"}\n", | |
"\n", | |
"model = \"trinart_characters_19m\" #@param ['trinart_characters_19m', 'trinart2_step115000', 'trinart2_step95000', 'trinart2_step60000', 'waifu-v13-float32', 'waifu-v13-float16', 'waifu-v12-prune', 'stable-v15', 'stable-v15-inpainting', 'stable-v14', 'tohoku-v1', 'robo-v1', 'eva-v22-notHD', 'eva-v21', 'icon', 'arcane-v3', 'arcane-v2', 'eldenring-v2', 'eldenring-v1', 'hiten_girl_anime_8k_wallpaper_4k']\n", | |
"#@markdown get a token from Hugging Face. https://huggingface.co/settings/tokens (Hugging Faceからトークンを取得)\n", | |
"user_token = \"\" #@param {type:\"string\"}\n", | |
"download_vae = True #@param {type:\"boolean\"}\n", | |
"vae = \"trinart_characters_19m\" #@param ['trinart_characters_19m', 'waifu-v14-anime2', 'waifu-v14-anime1', 'sd-vae-ft-mse', 'sd-vae-ft-ema']\n", | |
"download_hypernetwork = False #@param {type:\"boolean\"}\n", | |
"hypernetwork = \"zelda\" #@param ['zelda']\n", | |
"if user_token != \"\":\n", | |
" user_header = f\"\\\"Authorization: Bearer {user_token}\\\"\"\n", | |
"else:\n", | |
" user_header = \"\"\n", | |
"\n", | |
"model_url = models_dict[model].replace(\"/blob/\", \"/resolve/\")\n", | |
"!wget --header={user_header} {model_url} -O /content/stable-diffusion-webui/models/Stable-diffusion/{model}.ckpt\n", | |
"\n", | |
"vae_url = vaes_dict[vae].replace(\"/blob/\", \"/resolve/\")\n", | |
"#vae_config_url = vae_url.rsplit(\"/\", 1)[0] + \"/config.yaml\"\n", | |
"if download_vae:\n", | |
" !wget --header={user_header} {vae_url} -O /content/stable-diffusion-webui/models/Stable-diffusion/{model}.vae.pt\n", | |
"# !wget --header={user_header} {vae_config_url} -O /content/stable-diffusion-webui/models/Stable-diffusion/{model}.yaml\n", | |
"\n", | |
"hypernetwork_url = hypernetworks_dict[hypernetwork].replace(\"/blob/\", \"/resolve/\")\n", | |
"if download_hypernetwork:\n", | |
" import os\n", | |
" os.makedirs(\"/content/stable-diffusion-webui/models/hypernetworks/\", exist_ok=True)\n", | |
" !wget --header={user_header} {hypernetwork_url} -O /content/stable-diffusion-webui/models/hypernetworks/{hypernetwork}.pt\n", | |
" \n", | |
"!wget -q https://gist.githubusercontent.com/thx-pw/7489e7ffe873519bfa18498f68a98564/raw/e14a5b35293f7f66fa926dbc715cfa4ceae11c55/styles.csv -O /content/stable-diffusion-webui/styles.csv\n", | |
"\n", | |
"localization = \"ja_JP\" #@param ['None', 'ar_AR', 'es_ES', 'fr-FR', 'ja_JP', 'ko_KR', 'ru_RU', 'tr_TR', 'zh_CN']\n", | |
"!echo '{\"localization\":' > \"/content/stable-diffusion-webui/config.json\"\n", | |
"!echo '\"'{localization}'\"' >> \"/content/stable-diffusion-webui/config.json\"\n", | |
"!echo '}' >> \"/content/stable-diffusion-webui/config.json\"" | |
], | |
"metadata": { | |
"id": "CT_J9L7oqLxG", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Download the model from Google Drive.(Google Driveからモデルをダウンロード)\n", | |
"\n", | |
"import os\n", | |
"import glob\n", | |
"from google.colab import drive # type: ignore\n", | |
"\n", | |
"use_google_drive = False #@param {type:\"boolean\"}\n", | |
"sd_webui_gdrive = \"/content/drive/MyDrive/sd/stable-diffusion-webui\" #@param {type:\"string\"}\n", | |
"sd_webui_colab = \"/content/stable-diffusion-webui\"\n", | |
"\n", | |
"create_directory_gdrive = False #@param {type:\"boolean\"}\n", | |
"#@markdown Find and copy the following files from the stable-diffusion-webui(sd_webui_gdrive) directory.\n", | |
"#@markdown > stable-diffusion-webui(sd_webui_gdrive)ディレクトリから以下のファイルを見つけてコピーします。\n", | |
"\n", | |
"#@markdown + models/Stable-diffusion/\\*.ckpt\n", | |
"#@markdown + models/Stable-diffusion/\\*.vae.pt\n", | |
"#@markdown + embeddings/\\*.pt\n", | |
"#@markdown + embeddings/\\*.bin\n", | |
"#@markdown + models/hypernetworks/*.pt\n", | |
"#@markdown + styles.csv\n", | |
"#@markdown + config.json\n", | |
"#@markdown + ui-config.json\n", | |
"#@markdown + /content/drive/MyDrive/model.ckpt\n", | |
"#@markdown + /content/drive/MyDrive/AI/models/*.ckpt\n", | |
"\n", | |
"model_checkpoints = \"models/Stable-diffusion\"\n", | |
"model_vaes = \"models/Stable-diffusion\"\n", | |
"textual_inversion_embeddings = \"embeddings\"\n", | |
"hypernetworks = \"models/hypernetworks\"\n", | |
"config_list = [\"styles.csv\", \"config.json\", \"ui-config.json\"]\n", | |
"\n", | |
"model_checkpoints_gdrive = os.path.join(sd_webui_gdrive, model_checkpoints)\n", | |
"model_vaes_gdrive = os.path.join(sd_webui_gdrive, model_vaes)\n", | |
"textual_inversion_embeddings_gdrive = os.path.join(sd_webui_gdrive, textual_inversion_embeddings)\n", | |
"hypernetworks_gdrive = os.path.join(sd_webui_gdrive, hypernetworks)\n", | |
"\n", | |
"model_checkpoints_colab = os.path.join(sd_webui_colab, model_checkpoints)\n", | |
"model_vaes_colab = os.path.join(sd_webui_colab, model_vaes)\n", | |
"textual_inversion_embeddings_colab = os.path.join(sd_webui_colab, textual_inversion_embeddings)\n", | |
"hypernetworks_colab = os.path.join(sd_webui_colab, hypernetworks)\n", | |
"\n", | |
"if use_google_drive:\n", | |
" drive.mount(\"/content/drive\")\n", | |
"\n", | |
" ckpt_path = \"/content/drive/MyDrive/model.ckpt\"\n", | |
" if os.path.exists(ckpt_path):\n", | |
" !cp {ckpt_path} {model_checkpoints_colab}\n", | |
" for model_checkpoint in glob.glob(f\"/content/drive/MyDrive/AI/models/*.ckpt\"):\n", | |
" !cp {model_checkpoint} {model_checkpoints_colab}\n", | |
" \n", | |
" for config in config_list:\n", | |
" config_gdrive = os.path.join(sd_webui_gdrive, config)\n", | |
" if os.path.exists(config_gdrive):\n", | |
" !cp {config_gdrive} {sd_webui_colab}\n", | |
"\n", | |
" if create_directory_gdrive:\n", | |
" os.makedirs(model_checkpoints_gdrive, exist_ok=True)\n", | |
" os.makedirs(model_vaes_gdrive, exist_ok=True)\n", | |
" os.makedirs(textual_inversion_embeddings_gdrive, exist_ok=True)\n", | |
" os.makedirs(hypernetworks_gdrive, exist_ok=True)\n", | |
" os.makedirs(hypernetworks_colab, exist_ok=True)\n", | |
"\n", | |
" for model_checkpoint in glob.glob(f\"{model_checkpoints_gdrive}/*.ckpt\"):\n", | |
" !cp {model_checkpoint} {model_checkpoints_colab}\n", | |
"\n", | |
" for model_vae in glob.glob(f\"{model_vaes_gdrive}/*.vae.pt\"):\n", | |
" !cp {model_vae} {model_vaes_colab}\n", | |
"\n", | |
" files = glob.glob(f\"{textual_inversion_embeddings_gdrive}/*.pt\")\n", | |
" files.extend(glob.glob(f\"{textual_inversion_embeddings_gdrive}/*.bin\"))\n", | |
" for textual_inversion_embedding in files:\n", | |
" !cp {textual_inversion_embedding} {textual_inversion_embeddings_colab}\n", | |
"\n", | |
" for hypernetwork in glob.glob(f\"{hypernetworks_gdrive}/*.pt\"):\n", | |
" !cp {hypernetwork} {hypernetworks_colab}\n", | |
" " | |
], | |
"metadata": { | |
"cellView": "form", | |
"id": "EpphvH4Hubl_" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Installing Requirements from https://colab.research.google.com/github/TheLastBen/fast-stable-diffusion/blob/main/fast_stable_diffusion_AUTOMATIC1111.ipynb\n", | |
"!COMMANDLINE_ARGS=\"--exit\" REQS_FILE=\"requirements.txt\" python launch.py\n", | |
"!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-aesthetic-gradients extensions/aesthetic-gradients --quiet\n", | |
"!git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser extensions/images-browser --quiet\n", | |
"!git clone https://github.com/deforum-art/deforum-for-automatic1111-webui/ extensions/deforum\n", | |
"\n", | |
"!git clone https://github.com/timojl/clipseg repositories/clipseg\n", | |
"!wget -q -O scripts/txt2mask.py https://raw.githubusercontent.com/ThereforeGames/txt2mask/main/scripts/txt2mask.py\n", | |
"\n", | |
"!wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dependencies/Dependencies_AUT.1\n", | |
"!wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dependencies/Dependencies_AUT.2\n", | |
"!mv Dependencies_AUT.1 Dependencies_AUT.7z.001\n", | |
"!mv Dependencies_AUT.2 Dependencies_AUT.7z.002\n", | |
"!7z x Dependencies_AUT.7z.001\n", | |
"\n", | |
"!cp -r ./usr/local/lib/python3.7/dist-packages /usr/local/lib/python3.7/\n", | |
"!rm -r ./usr\n", | |
"!rm Dependencies_AUT.7z.001\n", | |
"!rm Dependencies_AUT.7z.002\n", | |
" \n", | |
"!wget -q -O repositories/stable-diffusion/ldm/modules/attention.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/precompiled/attention.py\n", | |
"\n", | |
"!pip install -qq scikit-image --upgrade\n", | |
"!pip install -qq tensorflow tensorflow-io\n", | |
"!pip install -qq git+https://github.com/KichangKim/DeepDanbooru.git@edf73df4cdaeea2cf00e9ac08bd8a9026b7a7b26#egg=deepdanbooru\n", | |
"\n", | |
"import time\n", | |
"from subprocess import getoutput\n", | |
"from IPython.display import clear_output\n", | |
"\n", | |
"def xformers():\n", | |
" s = getoutput('nvidia-smi')\n", | |
" if 'T4' in s:\n", | |
" gpu = 'T4'\n", | |
" elif 'P100' in s:\n", | |
" gpu = 'P100'\n", | |
" elif 'V100' in s:\n", | |
" gpu = 'V100'\n", | |
" elif 'A100' in s:\n", | |
" gpu = 'A100'\n", | |
"\n", | |
" while True:\n", | |
" try: \n", | |
" gpu=='T4'or gpu=='P100'or gpu=='V100'or gpu=='A100'\n", | |
" break\n", | |
" except:\n", | |
" pass\n", | |
" print('it seems that your GPU is not supported at the moment')\n", | |
" time.sleep(5)\n", | |
"\n", | |
" if (gpu=='T4'):\n", | |
" %pip install -qq https://github.com/TheLastBen/fast-stable-diffusion/raw/main/precompiled/T4/xformers-0.0.13.dev0-py3-none-any.whl\n", | |
" \n", | |
" elif (gpu=='P100'):\n", | |
" %pip install -qq https://github.com/TheLastBen/fast-stable-diffusion/raw/main/precompiled/P100/xformers-0.0.13.dev0-py3-none-any.whl\n", | |
"\n", | |
" elif (gpu=='V100'):\n", | |
" %pip install -qq https://github.com/TheLastBen/fast-stable-diffusion/raw/main/precompiled/V100/xformers-0.0.13.dev0-py3-none-any.whl\n", | |
"\n", | |
" elif (gpu=='A100'):\n", | |
" %pip install -qq https://github.com/TheLastBen/fast-stable-diffusion/raw/main/precompiled/A100/xformers-0.0.13.dev0-py3-none-any.whl\n", | |
"\n", | |
" clear_output()\n", | |
" print('\u001b[1;32mDone!')\n", | |
"\n", | |
"xformers()\n" | |
], | |
"metadata": { | |
"cellView": "form", | |
"id": "xzGnq4uoi__n" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Launch the webUI.(webUIの起動)\n", | |
"\n", | |
"username = \"user\" #@param {type:\"string\"}\n", | |
"password = \"pass\" #@param {type:\"string\"}\n", | |
"tunnel = \"gradio\" #@param [\"ngrok\", \"gradio\"]\n", | |
"#@markdown get a token from for ngrok. https://dashboard.ngrok.com/get-started/your-authtoken (ngrokからトークンを取得)\n", | |
"ngrok_authtoken = \"\" #@param {type:\"string\"}\n", | |
"ngrok_region = \"jp\" #@param [\"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n", | |
"\n", | |
"\n", | |
"common_args = f\"--disable-safe-unpickle --update-check --deepdanbooru --gradio-debug --gradio-auth {username}:{password}\"\n", | |
"if tunnel == \"ngrok\":\n", | |
" !COMMANDLINE_ARGS=\"{common_args} --ngrok {ngrok_authtoken} --ngrok-region {ngrok_region}\" REQS_FILE=\"requirements.txt\" python launch.py\n", | |
"else:\n", | |
" !COMMANDLINE_ARGS=\"{common_args} --share\" REQS_FILE=\"requirements.txt\" python launch.py\n" | |
], | |
"metadata": { | |
"id": "R-xAdMA5wxXd", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Save to zip file with same password as cell above. (上のセルと同じパスワードでzipファイルに保存)\n", | |
"\n", | |
"%cd /content/stable-diffusion-webui\n", | |
"!zip -er --password={password} outputs.zip outputs " | |
], | |
"metadata": { | |
"id": "gBt5g_Dn0NFo", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title Save the zip file to Google Drive. (Google Driveにzipファイルを保存)\n", | |
"from google.colab import drive \n", | |
"drive_path = \"/content/drive\"\n", | |
"drive.mount(drive_path, force_remount=False)\n", | |
"\n", | |
"!cp \"/content/stable-diffusion-webui/outputs.zip\" \"/content/drive/MyDrive\"" | |
], | |
"metadata": { | |
"id": "zNEgJfbhDwI6", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment