-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
433 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
# colab-stable-diffusion | ||
# CoLab-compatible version of stable-diffusion-webui | ||
Stable Diffusion webui scripts for Colab | ||
|
||
# Notebooks | ||
|
||
|Repository|CoLaboratory URL| | ||
|-|-| | ||
|[sd-webui](https://github.com/sd-webui/stable-diffusion-webui)|[![](https://img.shields.io/static/v1?message=Open%20in%20Colab&logo=googlecolab&labelColor=5c5c5c&color=0f80c1&label=%20&style=for-the-badge)](https://colab.research.google.com/github/ddPn08/stable-diffusion-webui-colab/blob/main/sd-webui.ipynb)| | ||
|
||
# Respect | ||
[stable-diffusion-webui](https://github.com/sd-webui/stable-diffusion-webui) | ||
[sd-webui-colab](https://github.com/altryne/sd-webui-colab) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,380 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "view-in-github" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/ddPn08/stable-diffusion-webui-colab/blob/main/sd-webui.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "jnXUwtACCHOy" | ||
}, | ||
"source": [ | ||
"# Stable Diffusion WebUI Colab by [ddPn08](https://github.com/ddpn08/)\n", | ||
"\n", | ||
"This colab runs from the repo [`sd-webui`](https://github.com/sd-webui/stable-diffusion-webui) \n", | ||
"このColabは[`sd-webui`](https://github.com/sd-webui/stable-diffusion-webui) を使用しています。\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "4eodrBxeCgOW" | ||
}, | ||
"source": [ | ||
"## 1 - Setup" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "RXasLtrYC9uj" | ||
}, | ||
"source": [ | ||
"### 1.1 Download repo and install\n", | ||
"\n", | ||
"Clone git repo and setup miniconda\n", | ||
"> Gitリポジトリをクローン、minicondaのセットアップ" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cellView": "form", | ||
"id": "LSCxESSsDGVh" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# @markdown ## Clone the stable-diffusion-webui repo\n", | ||
"\n", | ||
"webui_branch = \"master\" # @param {type: \"string\"}\n", | ||
"\n", | ||
"! git clone https://github.com/sd-webui/stable-diffusion-webui /content/stable-diffusion\n", | ||
"%cd /content/stable-diffusion\n", | ||
"! git checkout {webui_branch}\n", | ||
"\n", | ||
"import sys\n", | ||
"\n", | ||
"! curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh\n", | ||
"! chmod +x Miniconda3-latest-Linux-x86_64.sh\n", | ||
"! bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local\n", | ||
"sys.path.append(\"/usr/local/lib/python3.7/site-packages/\")\n", | ||
"! rm Miniconda3-latest-Linux-x86_64.sh\n", | ||
"\n", | ||
"# @markdown Set up conda environment - Takes a whilp\n", | ||
"# @markdown > conda環境をセットアップします (時間がかかります)\n", | ||
"! conda env update -n base -f /content/stable-diffusion/environment.yaml" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "vhZQqFGxEHcA" | ||
}, | ||
"source": [ | ||
"### 1.2 Setup GFPGAN and ESRGAN" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cellView": "form", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "M3o7slcTEQvp", | ||
"outputId": "4185e31a-afcd-4178-d355-cdc3dc84829a" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# @markdown **GFPGAN** Automatically correct distorted faces with a built-in GFPGAN option, fixes them in less than half a second\n", | ||
"# @markdown > **GFPGAN** オプションで歪んだ顔を自動的に修正し、0.5秒未満で修正します\n", | ||
"\n", | ||
"# @markdown **ESRGAN** Boosts the resolution of images with a built-in RealESRGAN option\n", | ||
"# @markdown > **ESRGAN** オプションで画像の解像度を向上させます\n", | ||
"\n", | ||
"add_CFP = True # @param {type:\"boolean\"}\n", | ||
"add_ESR = True # @param {type:\"boolean\"}\n", | ||
"add_LDSR = False # @param {type:\"boolean\"}\n", | ||
"# @markdown ⚠️ LDSR is 1.9GB and make take time to download\n", | ||
"# @markdown > ※LDSRは1.9GBあり、ダウンロードに時間がかかります\n", | ||
"\n", | ||
"if add_CFP:\n", | ||
" %cd /content/stable-diffusion/src/gfpgan/\n", | ||
" ! pip install basicsr facexlib yapf lmdb opencv-python pyyaml tb-nightly --no-deps\n", | ||
" ! python setup.py develop\n", | ||
" ! pip install realesrgan\n", | ||
" ! wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models\n", | ||
"if add_ESR:\n", | ||
" %cd /content/stable-diffusion/src/realesrgan/\n", | ||
" ! wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models\n", | ||
" ! wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P experiments/pretrained_models\n", | ||
"if add_LDSR:\n", | ||
" %cd /content/stable-diffusion/src\n", | ||
" ! git clone https://github.com/devilismyfriend/latent-diffusion\n", | ||
" %cd latent-diffusion\n", | ||
" %mkdir -p experiments/\n", | ||
" %cd experiments/\n", | ||
" %mkdir -p pretrained_models\n", | ||
" %cd pretrained_models\n", | ||
" # project.yaml download\n", | ||
" ! wget -O project.yaml https://heibox.uni-heidelberg.de/f/31a76b13ea27482981b4/?dl=1\n", | ||
" # model.ckpt model download\n", | ||
" ! wget -O model.ckpt https://heibox.uni-heidelberg.de/f/578df07c8fc04ffbadf3/?dl=1\n", | ||
"\n", | ||
"%cd /content/stable-diffusion/\n", | ||
"! wget https://github.com/matomo-org/travis-scripts/blob/master/fonts/Arial.ttf?raw=true -O arial.ttf" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "mBFOSYR91AeT" | ||
}, | ||
"source": [ | ||
"### 1.3 Setup model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cellView": "form", | ||
"id": "vkgBVo5OEpqn" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# @markdown # Load the stable-diffusion model\n", | ||
"# @markdown > ### stable-diffusionのモデルをロード\n", | ||
"\n", | ||
"# @markdown **Model Path Variables**\n", | ||
"# ask for the link\n", | ||
"print(\"Local Path Variables:\\n\")\n", | ||
"\n", | ||
"model_filename = \"sd-v1-4.ckpt\" # @param {type:\"string\"}\n", | ||
"models_path = \"/content/models\" # @param {type:\"string\"}\n", | ||
"output_path = \"/content/output\" # @param {type:\"string\"}\n", | ||
"\n", | ||
"# @markdown **Download the model if it isn't already in the `models_path` folder (Optional)**\n", | ||
"# @markdown > モデルが`models_path`フォルダーにない場合に、モデルをダウンロードする\n", | ||
"\n", | ||
"# @markdown To download the model, you need to have accepted the terms [HERE](https://huggingface.co/CompVis/stable-diffusion-v1-4)\n", | ||
"# @markdown and have copied a token from [HERE](https://huggingface.co/settings/tokens)\n", | ||
"\n", | ||
"# @markdown > モデルをダウンロードするには, [このページ](https://huggingface.co/CompVis/stable-diffusion-v1-4)で条件に同意する必要があります。\n", | ||
"# @markdown > また、[このページ](https://huggingface.co/settings/tokens)からトークンを取得する必要があります。\n", | ||
"download_if_missing = False # @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", | ||
"token = \"\" # @param {type:\"string\"}\n", | ||
"\n", | ||
"# @markdown **Google Drive Path Variables (Optional)**\n", | ||
"mount_google_drive = True # @param {type:\"boolean\"}\n", | ||
"force_remount = False\n", | ||
"\n", | ||
"%cd /content/\n", | ||
"import os\n", | ||
"\n", | ||
"mount_success = True\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/sd-webui/outputs\" # @param {type:\"string\"}\n", | ||
" models_path = models_path_gdrive\n", | ||
" output_path = output_path_gdrive\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", | ||
"os.makedirs(models_path, exist_ok=True)\n", | ||
"os.makedirs(output_path, exist_ok=True)\n", | ||
"\n", | ||
"if download_if_missing:\n", | ||
" if not mount_success:\n", | ||
" print(\"Downloading model to \" + models_path + \" due to gdrive mount error\")\n", | ||
" elif not os.path.exists(models_path + \"/\" + model_filename):\n", | ||
" ! mkdir sd-model\n", | ||
" %cd /content/sd-model/\n", | ||
" ! curl -LJ {model_url} -H {'\"Authorization: Bearer ' + token + '\"' if token else \"\"} -o {model_filename}\n", | ||
" ! mv /content/sd-model/{model_filename} {models_path}/\n", | ||
" else:\n", | ||
" print(\"Model already downloaded, moving to next step\")\n", | ||
"\n", | ||
"print(f\"models_path: {models_path}\")\n", | ||
"print(f\"output_path: {output_path}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "Wt_tzv_eJ9Qz" | ||
}, | ||
"source": [ | ||
"## 2 Optional - Set webUI settings and configs before running \n", | ||
"> オプション - 実行前にWebUIの設定を変更する。" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cellView": "form", | ||
"id": "3t1DaxIfRmSm" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# @markdown # Launch preferences - Advanced\n", | ||
"# @markdown # 詳細設定\n", | ||
"share_password = \"\" # @param {type:\"string\"}\n", | ||
"# @markdown * Add a password to your webui\n", | ||
"# @markdown > WebUI用のパスワード\n", | ||
"defaults = \"configs/webui/webui.yaml\" # @param {type:\"string\"}\n", | ||
"# @markdown * path to configuration file providing UI defaults, uses same format as cli parameter)\n", | ||
"# @markdown Edit this file if you want to change the default settings UI launches with\n", | ||
"# @markdown > デフォルトUIの構成ファイルへのパス。\n", | ||
"# @markdown UIのデフォルト設定を変更する場合は、このファイルを編集します\n", | ||
"\n", | ||
"# @markdown ---\n", | ||
"save_metadata = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Whether to embed the generation parameters in the sample images\n", | ||
"# @markdown > サンプル画像に生成パラメータを埋め込む\n", | ||
"skip_grid = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Do not save a grid, only individual samples. Helpful when evaluating lots of samples\n", | ||
"# @markdown > グリッドは保存せず、個々のサンプルだけを保存する。多くのサンプルを評価する際に便利です\n", | ||
"skip_save = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Do not save individual samples as files. For speed measurements\n", | ||
"# @markdown > 個々のサンプルはファイルとして保存しない。速度測定用\n", | ||
"optimized = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Load the model onto the device piecemeal instead of all at once to reduce VRAM usage at the cost of performance\n", | ||
"# @markdown > パフォーマンスを犠牲にしてVRAMの使用量を減らすために、モデルを一度に全部ではなく断片的に読み込む\n", | ||
"optimized_turbo = True # @param {type:\"boolean\"}\n", | ||
"# @markdown * Alternative optimization mode that does not save as much VRAM but runs siginificantly faster\n", | ||
"# @markdown > VRAMの節約はできないが、動作が大幅に高速化される代替最適化モード\n", | ||
"no_verify_input = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Do not verify input to check if it's too long\n", | ||
"# @markdown > プロンプトが長すぎるかどうかを確認しない\n", | ||
"no_half = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Do not switch the model to 16-bit floats\n", | ||
"# @markdown > モデルを16ビットfloatに切り替えない\n", | ||
"no_progressbar_hiding = True # @param {type:\"boolean\"}\n", | ||
"# @markdown * Do not hide progressbar in gradio UI\n", | ||
"# @markdown > プログレスバーを非表示にしない\n", | ||
"extra_models_cpu = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * Run extra models (GFGPAN/ESRGAN) on cpu\n", | ||
"# @markdown > 追加モデル(GFGPAN/ESRGAN)をCPUで実行する\n", | ||
"esrgan_cpu = True # @param {type:\"boolean\"}\n", | ||
"# @markdown * run ESRGAN on cpu\n", | ||
"# @markdown > ESRGANをCPUで実行する\n", | ||
"gfpgan_cpu = False # @param {type:\"boolean\"}\n", | ||
"# @markdown * run GFPGAN on cpu\n", | ||
"# @markdown > GFPGANをCPUで実行する\n", | ||
"\n", | ||
"\n", | ||
"run_string_with_variables = {\n", | ||
" \"--save-metadata\": f\"{save_metadata}\",\n", | ||
" \"--skip-grid\": f\"{skip_grid}\",\n", | ||
" \"--skip-save\": f\"{skip_save}\",\n", | ||
" \"--optimized\": f\"{optimized}\",\n", | ||
" \"--optimized-turbo\": f\"{optimized_turbo}\",\n", | ||
" \"--no-verify-input\": f\"{no_verify_input}\",\n", | ||
" \"--no-half\": f\"{no_half}\",\n", | ||
" \"--no-progressbar-hiding\": f\"{no_progressbar_hiding}\",\n", | ||
" \"--extra-models-cpu\": f\"{extra_models_cpu}\",\n", | ||
" \"--esrgan-cpu\": f\"{esrgan_cpu}\",\n", | ||
" \"--gfpgan-cpu\": f\"{gfpgan_cpu}\",\n", | ||
"}\n", | ||
"\n", | ||
"only_true_vars = {k for (k, v) in run_string_with_variables.items() if v == \"True\"}\n", | ||
"vars = \" \".join(only_true_vars)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "E1kYjBY9Rmi-" | ||
}, | ||
"source": [ | ||
"## 3 - Launch WebUI for stable diffusion" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"cellView": "form", | ||
"id": "BTH_drY9KZ4k" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#@markdown ** keep in mind that this script is set to run for ever, google will disconnect you after 90 minutes on free tiers\n", | ||
"#@markdown > ** ※注意 このスクリプトは永久に実行されます。Google は無料枠で 90 分後に接続を切断します\n", | ||
"\n", | ||
"#@markdown # Important - click the public URL to launch WebUI in another tab\n", | ||
"#@markdown > ### 重要 - 公開URLをクリックしてWebUIを起動してください\n", | ||
"\n", | ||
"#@markdown ![](https://user-images.githubusercontent.com/71378929/189563599-6df78bcf-133b-41e8-a55d-8ca3783cd933.png)\n", | ||
"\n", | ||
"#fix adding share_password to the launch params, and also changin {vars} to $vars as it was causing webui.py to fail.\n", | ||
"\n", | ||
"%cd /content/stable-diffusion\n", | ||
"\n", | ||
"if share_password == \"\":\n", | ||
" ! python scripts/webui.py \\\n", | ||
" --ckpt {models_path}/{model_filename} \\\n", | ||
" --outdir {output_path} \\\n", | ||
" --share $vars\n", | ||
"else:\n", | ||
" ! python scripts/webui.py \\\n", | ||
" --ckpt {models_path}/{model_filename} \\\n", | ||
" --outdir {output_path} \\\n", | ||
" --share-password {share_password} \\\n", | ||
" --share $vars\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"accelerator": "GPU", | ||
"colab": { | ||
"collapsed_sections": [ | ||
"RXasLtrYC9uj", | ||
"vhZQqFGxEHcA", | ||
"mBFOSYR91AeT", | ||
"Wt_tzv_eJ9Qz" | ||
], | ||
"include_colab_link": true, | ||
"machine_shape": "hm", | ||
"name": "stable-diffusion-webui-colab", | ||
"provenance": [] | ||
}, | ||
"gpuClass": "standard", | ||
"kernelspec": { | ||
"display_name": "Python 3.10.5 64-bit", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python", | ||
"version": "3.10.5" | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "a162c579ae611c46b3f917020f03078da6a8872353b51058912d08182f7284c9" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Oops, something went wrong.