Skip to content

Commit

Permalink
change directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ddPn08 committed Dec 18, 2022
1 parent ea75a3d commit 6b06652
Showing 1 changed file with 68 additions and 78 deletions.
146 changes: 68 additions & 78 deletions automatic1111.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
"\n",
"Wiki -> https://github.com/ddPn08/automatic1111-colab/wiki\n",
"\n",
"If you have any questions, please refer to the Wiki link for each step.\n",
"If you run into any issues, please create an issue [here](https://github.com/ddPn08/automatic1111-colab/issues/new).\n",
"<br />\n",
"\n",
"わからないことがあった場合、各項目にあるWikiリンクを参照してください。\n",
"問題が発生した場合は[こちら](https://github.com/ddPn08/automatic1111-colab/issues/new)からIssueを作成してください。\n"
"# Troubleshooting (不具合が発生したら)\n",
"1. First, check the wiki and changelog. (まずは、Wikiと変更ログを確認してください。)\n",
" - [Wiki](https://github.com/ddPn08/automatic1111-colab/wiki)\n",
" - [CHANGELOG | 変更ログ](#scrollTo=moDR3lrJVsE8)\n",
"\n",
"2. If you still can't figure it out, open a Github issue. (それでもわからない場合はGithubのIssueを立ててください。)\n",
" - [Github Issue](https://github.com/ddPn08/automatic1111-colab/issues/new)."
]
},
{
Expand Down Expand Up @@ -91,8 +95,8 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "Mls4_48XOrTd"
"id": "Mls4_48XOrTd",
"cellView": "form"
},
"outputs": [],
"source": [
Expand All @@ -101,76 +105,62 @@
"# @markdown **Model Path Variables**\n",
"%cd /content/\n",
"\n",
"models_path = \"/content/models\" # @param {type:\"string\"}\n",
"output_path = \"/content/output\" # @param {type:\"string\"}\n",
"config_path = \"/content/config\" # @param {type:\"string\"}\n",
"extensions_file_path = \"\"\n",
"data_dir = \"/content/data\" # @param {type:\"string\"}\n",
"\n",
"# @markdown **Optional | Download the model if it isn't already in the `models_path` folder**\n",
"# @markdown **Optional | Download the model if it isn't already in the `{data_dir}/models` folder**\n",
"download_if_missing = True # @param {type:\"boolean\"}\n",
"model_url = \"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt\" # @param {type:\"string\"}\n",
"model_filename = \"\" # @param {type:\"string\"}\n",
"auth_token = \"\" # @param {type:\"string\"}\n",
"\n",
"# @markdown **Optional | Use Google Drive**\n",
"mount_google_drive = True # @param {type:\"boolean\"}\n",
"force_remount = False\n",
"force_remount = False # @param {type:\"boolean\"}\n",
"\n",
"import os\n",
"\n",
"mount_success = True\n",
"mount_success = False\n",
"if mount_google_drive:\n",
" from google.colab import drive\n",
"\n",
" try:\n",
" drive_path = \"/content/drive\"\n",
" drive.mount(drive_path, force_remount=force_remount)\n",
" models_path_gdrive = \"/content/drive/MyDrive/AI/models\" # @param {type:\"string\"}\n",
" output_path_gdrive = \"/content/drive/MyDrive/AI/automatic1111/outputs\" # @param {type:\"string\"}\n",
" config_path_gdrive = \"/content/drive/MyDrive/AI/automatic1111/config\" # @param {type:\"string\"}\n",
" extensions_file_path_gdrive = \"/content/drive/MyDrive/AI/automatic1111/extensions.txt\" # @param {type:\"string\"}\n",
"\n",
" models_path = models_path_gdrive\n",
" output_path = output_path_gdrive\n",
" config_path = config_path_gdrive\n",
" extensions_file_path = extensions_file_path_gdrive\n",
" data_dir_gdrive = \"/content/drive/MyDrive/AI/automatic1111\" # @param {type:\"string\"}\n",
" data_dir = data_dir_gdrive\n",
" mount_success = True\n",
" except:\n",
" print(\"...error mounting drive or with drive path variables\")\n",
" print(\"...reverting to default path variables\")\n",
" mount_success = False\n",
"\n",
"if os.path.exists(f\"{data_dir}/script.pre.sh\"):\n",
" ! {data_dir}/script.pre.sh\n",
"\n",
"models_path = f\"{data_dir}/models\"\n",
"output_path = f\"{data_dir}/outputs\"\n",
"config_path = f\"{data_dir}/config\"\n",
"extensions_file_path = f\"{data_dir}/extensions.txt\"\n",
"\n",
"os.makedirs(models_path, exist_ok=True)\n",
"os.makedirs(output_path, exist_ok=True)\n",
"os.makedirs(config_path, exist_ok=True)\n",
"os.makedirs(f\"{models_path}/embeddings\", exist_ok=True)\n",
"os.makedirs(f\"{models_path}/VAE\", exist_ok=True)\n",
"os.makedirs(f\"{models_path}/hypernetworks\", exist_ok=True)\n",
"\n",
"! rm -Rf stable-diffusion-webui/embeddings && ln -s {models_path}/embeddings stable-diffusion-webui/embeddings\n",
"! rm -Rf stable-diffusion-webui/models/VAE && ln -s {models_path}/VAE stable-diffusion-webui/models/VAE\n",
"! rm -Rf stable-diffusion-webui/models/hypernetworks && ln -s {models_path}/hypernetworks stable-diffusion-webui/models/hypernetworks\n",
"for dir in os.listdir(models_path):\n",
" ! rm -Rf stable-diffusion-webui/models/{dir} && ln -s {models_path}/{dir} stable-diffusion-webui/models/{dir}\n",
"\n",
"if os.path.exists(\"stable-diffusion-webui/extensions/stable-diffusion-webui-aesthetic-gradients\"):\n",
" os.makedirs(f\"{models_path}/aesthetic_embeddings\", exist_ok=True)\n",
" ! rm -Rf stable-diffusion-webui/extensions/stable-diffusion-webui-aesthetic-gradients/aesthetic_embeddings \\\n",
" && ln -sf {models_path}/aesthetic_embeddings stable-diffusion-webui/extensions/stable-diffusion-webui-aesthetic-gradients/aesthetic_embeddings\n",
"! rm -f stable-diffusion-webui/outputs && ln -s {config_path}/outputs stable-diffusion-webui/outputs\n",
"! rm -f stable-diffusion-webui/config.json && ln -s {config_path}/config.json stable-diffusion-webui/config.json\n",
"! rm -f stable-diffusion-webui/ui-config.json && ln -s {config_path}/ui-config.json stable-diffusion-webui/ui-config.json\n",
"\n",
"if download_if_missing:\n",
" if not model_filename:\n",
" model_filename = model_url.split(\"/\")[-1]\n",
" if not mount_success:\n",
" print(\"Downloading model to \" + models_path + \" due to gdrive mount error\")\n",
" elif not model_filename or not os.path.exists(models_path + \"/\" + model_filename):\n",
" if mount_google_drive and not mount_success:\n",
" print(f\"Downloading model to {models_path} due to gdrive mount error\")\n",
" elif not model_filename or not os.path.exists(f\"{data_dir}/models/{model_filename}\"):\n",
" ! curl -LJ {model_url} -o {models_path}/{model_filename} {'-H \"Authorization: Bearer ' + auth_token + '\"' if auth_token else \"\"}\n",
" else:\n",
" print(\"Model already downloaded, moving to next step\")\n",
"\n",
"%cd /content/stable-diffusion-webui\n",
"! curl -LOJ https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth\n",
"\n",
"print(f\"models_path: {models_path}\")\n",
"print(f\"output_path: {output_path}\")\n",
"print(f\"config_path: {config_path}\")"
" print(\"Model already downloaded, moving to next step\")"
]
},
{
Expand Down Expand Up @@ -210,7 +200,6 @@
"# @markdown &nbsp;\n",
"# @markdown ## Command line arguments\n",
"\n",
"\n",
"no_half = False # @param {type:\"boolean\"}\n",
"no_half_vae = False # @param {type:\"boolean\"}\n",
"allow_code = False # @param {type:\"boolean\"}\n",
Expand Down Expand Up @@ -274,14 +263,7 @@
"\n",
"import os\n",
"\n",
"os.environ['COMMANDLINE_ARGS'] = f\"\"\"\n",
"--ckpt-dir {models_path} \\\n",
"--ui-config-file {config_path}/ui-config.json \\\n",
"--ui-settings-file {config_path}/config.json \\\n",
"--styles-file {config_path}/styles.csv \\\n",
"{vars} \\\n",
"{custom_arguments}\n",
"\"\"\"\n"
"os.environ['COMMANDLINE_ARGS'] = f\"{vars} {custom_arguments}\"\n"
]
},
{
Expand All @@ -298,29 +280,30 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "Ao2t5h5qG9HD"
"id": "Ao2t5h5qG9HD",
"cellView": "form"
},
"outputs": [],
"source": [
"# @markdown ## Setup environment\n",
"# @markdown This may take up to 10 minutes\n",
"\n",
"store_env_gdrive = False # @param{type:\"boolean\"}\n",
"gdrive_env_directory = \"/content/drive/MyDrive/AI/automatic1111/conda-env\" # @param{type:\"string\"}\n",
"gdrive_env_directory = f\"{data_dir}/conda-env\" # @param{type:\"string\"}\n",
"force_reinstall_environmemt = False # @param{type:\"boolean\"}\n",
"gdrive_env_file = f\"{gdrive_env_directory}/env.tar.zst\"\n",
"\n",
"%cd /content/stable-diffusion-webui/extensions\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"for extension in extensions:\n",
" ! git clone {extension}\n",
" extension_name = extension.split(\"/\")[-1]\n",
" ! cd {extension_name} && git fetch\n",
"\n",
"%cd /content\n",
"import os\n",
"import sys\n",
"\n",
"! curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/bionic.gpg | sudo apt-key add -\n",
"! curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/bionic.list | sudo tee /etc/apt/sources.list.d/tailscale.list\n",
Expand All @@ -342,31 +325,26 @@
" ! bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local\n",
" ! rm Miniconda3-latest-Linux-x86_64.sh\n",
"\n",
"install_script = \"\"\"#!/bin/bash\n",
"eval \"$(conda shell.bash hook)\"\n",
"cd stable-diffusion-webui\n",
"conda env create -f ./environment-wsl2.yaml\n",
"conda activate automatic\n",
"conda install -y xformers -c xformers/label/dev\n",
"python3 -m pip install --upgrade tensorrt\n",
"python -c 'from launch import prepare_environment; prepare_environment()'\"\"\"\n",
"\n",
"if os.path.exists(gdrive_env_file) and not os.path.exists(\"/usr/local/envs/automatic\") and not force_reinstall_environmemt:\n",
" os.makedirs(\"/usr/local/envs/automatic\", exist_ok=True)\n",
" ! zstd -dc {gdrive_env_file} | tar -xf - -C /usr/local/envs/automatic\n",
" update_script = \"\"\"#!/bin/bash\n",
" eval \"$(conda shell.bash hook)\"\n",
" cd stable-diffusion-webui\n",
" conda env update -n automatic -f ./environment-wsl2.yaml\n",
" conda activate automatic\n",
" conda install -y xformers -c xformers/label/dev\n",
" python3 -m pip install --upgrade tensorrt\n",
" python -c 'from launch import prepare_environment; prepare_environment()'\"\"\"\n",
" ! {update_script}\n",
"elif not os.path.exists(\"/usr/local/envs/automatic\"):\n",
" install_script = \"\"\"#!/bin/bash\n",
" eval \"$(conda shell.bash hook)\"\n",
" cd stable-diffusion-webui\n",
" conda env create -f ./environment-wsl2.yaml\n",
" conda activate automatic\n",
" conda install -y xformers -c xformers/label/dev\n",
" python3 -m pip install --upgrade tensorrt\n",
" python -c 'from launch import prepare_environment; prepare_environment()'\"\"\"\n",
" ! {install_script}\n",
"\n",
"! {install_script}\n",
"\n",
"os.environ[\"LD_LIBRARY_PATH\"] = f\"{os.environ['LD_LIBRARY_PATH']}:/usr/local/envs/automatic/lib\"\n",
"\n",
"if os.path.exists(f\"{data_dir}/script.post.sh\"):\n",
" ! {data_dir}/script.post.sh\n",
"\n",
"if store_env_gdrive and mount_google_drive and mount_success:\n",
" import threading\n",
" def pack():\n",
Expand Down Expand Up @@ -407,14 +385,26 @@
"python launch.py\"\"\"\n",
"! {run_script}"
]
},
{
"cell_type": "markdown",
"source": [
"# CHANGELOG (変更ログ)\n",
"\n",
"## 2022/12/18 BREAKING CHANGE\n",
"モデル等のディレクトリの構造を変更しました。くわしくは[こちら](https://github.com/ddPn08/automatic1111-colab/wiki/Data-directory-%7C-JP) \n",
"Changed the directory structure of models etc. For details [here](https://github.com/ddPn08/automatic1111-colab/wiki/Data-directory-%7C-EN) "
],
"metadata": {
"id": "moDR3lrJVsE8"
}
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"machine_shape": "hm",
"provenance": [],
"toc_visible": true,
"include_colab_link": true
},
"kernelspec": {
Expand Down

0 comments on commit 6b06652

Please sign in to comment.