-
-
Save vonvanzu/643dd5bff452368392788fa8427e3576 to your computer and use it in GitHub Desktop.
Config for running Automatic1111 Stable Diffusion WebUI on an AWS SageMaker Notebook
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Stable Diffusion WebUI (AUTOMATIC1111) for SageMaker Studio Lab\n", | |
"\n", | |
"This notebook will install and run the [stable-diffusion-webui repository by AUTOMATIC1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) on SageMaker Studio Lab\n", | |
"\n", | |
"With the default model you can run textual inversion training, hypernetwork training and image generation, but no native training\n", | |
"\n", | |
"You will need a ngrok (reverse proxy) auth token to run it, as gradio sharing doesn't work on SageMaker Studio Lab\n", | |
"\n", | |
"If you don't have a ngrok account yet, create one here: https://dashboard.ngrok.com/signup\n", | |
"\n", | |
"It's free for non-commercial use\n", | |
"\n", | |
"If you use the default model, you will also need a Huggingface user token. Alternatively you can download a model from Google Drive or MEGA, without needing a Huggingface token" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "OHCtG9MT0jLq" | |
}, | |
"source": [ | |
"# Installation: Clone webui repository\n", | |
"***You only need to do this once on your SageMaker SL account***" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"id": "sBbcB4vwj_jm" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"%cd ~/SageMaker/\n", | |
"!git clone --depth 1 https://github.com/AUTOMATIC1111/stable-diffusion-webui\n", | |
"#create softlink to /tmp/outputs for storing images\n", | |
"#contents of /tmp folder will be deleted when each session ends\n", | |
"!ln -vs /tmp/outputs stable-diffusion-webui/outputs\n", | |
"#create softlink to /tmp in ~/SageMaker/\n", | |
"!ln -vs /tmp ~/SageMaker/tmp\n", | |
"#create softlink to /tmp/models in stable-diffusion-webui/models/Stable-diffusion/\n", | |
"!ln -vs /tmp/models stable-diffusion-webui/models/Stable-diffusion/tmp_models\n", | |
"\n", | |
"# change default settings (not necessary)\n", | |
"%cd stable-diffusion-webui\n", | |
"!wget https://raw.githubusercontent.com/Miraculix200/StableDiffusionUI_Colab/main/config.json\n", | |
"!wget https://raw.githubusercontent.com/Miraculix200/StableDiffusionUI_Colab/main/ui-config.json\n", | |
"learning_rate = \"5e-5:100, 5e-6:1500, 5e-7:2000, 5e-5:2100, 5e-7:3000, 5e-5:3100, 5e-7:4000, 5e-5:4100, 5e-7:5000, 5e-5:5100, 5e-7:6000, 5e-5:6100, 5e-7:7000, 5e-5:7100, 5e-7:8000, 5e-5:8100, 5e-7:9000, 5e-5:9100, 5e-7:10000, 5e-6:10100, 5e-8:11000, 5e-6:11100, 5e-8:12000, 5e-6:12100, 5e-8:13000, 5e-6:13100, 5e-8:14000, 5e-6:14100, 5e-8:15000, 5e-6:15100, 5e-8:16000, 5e-6:16100, 5e-8:17000, 5e-6:17100, 5e-8:18000, 5e-6:18100, 5e-8:19000, 5e-6:19100, 5e-8:20000, 5e-5:20100, 5e-7:21000, 5e-5:21100, 5e-7:22000, 5e-5:22100, 5e-7:23000, 5e-5:23100, 5e-7:24000, 5e-5:24100, 5e-7:25000, 5e-5:25100, 5e-7:26000, 5e-5:26100, 5e-7:27000, 5e-5:27100, 5e-7:28000, 5e-5:28100, 5e-7:29000, 5e-5:29100, 5e-7:30000, 5e-6:30100, 5e-8:31000, 5e-6:31100, 5e-8:32000, 5e-6:32100, 5e-8:33000, 5e-6:33100, 5e-8:34000, 5e-6:34100, 5e-8:35000, 5e-6:35100, 5e-8:36000, 5e-6:36100, 5e-8:37000, 5e-6:37100, 5e-8:38000, 5e-6:38100, 5e-8:39000, 5e-6:39100, 5e-8:40000\"\n", | |
"!echo \"a photo of a [filewords]\" >textual_inversion_templates/hypernetwork2.txt\n", | |
"#!sed -i 's/label=\"Use dropout\"/value=\"True\",label=\"Use dropout\"/' modules/ui.py\n", | |
"#!sed -i 's/value=\"0.00001\"/value=\"{learning_rate}\"/' modules/ui.py\n", | |
"#!sed -i -E 's/dataset_directory = gr.Textbox\\(/dataset_directory = gr.Textbox\\(value=\\\"\\/tmp\\/processed\\\", /' modules/ui.py\n", | |
"#!sed -i 's/style_filewords.txt/hypernetwork2.txt/' modules/ui.py\n", | |
"\n", | |
"# install extensions (not necessary)\n", | |
"%cd extensions\n", | |
"!git clone --depth 1 https://github.com/yfszzx/stable-diffusion-webui-images-browser\n", | |
"!git clone --depth 1 https://github.com/toshiaki1729/stable-diffusion-webui-dataset-tag-editor.git" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "F0EINk5M0s-w" | |
}, | |
"source": [ | |
"# Installation: Download model(s) from Huggingface\n", | |
"***You only need to do this once on your SageMaker SL account***\n", | |
"\n", | |
"Alternatively you can use the JupyterLab file browser to upload one or more .ckpt files to the `~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/` folder\n", | |
"\n", | |
"There are optional model downloads below this cell, where a Huggingface token is not necessary\n", | |
"\n", | |
"To save disk space, you can move models to `/tmp/models` and restart the webui. These models will be deleted when the runtime ends" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"tags": [] | |
}, | |
"source": [ | |
"### Download model(s)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Check free disk space" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"!df -h | grep -E 'Avail|home'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Huggingface token\n", | |
"You only have to enter this once, as the token will persist in ~/.huggingface/token across sessions" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "d044b4111e8a49d5aa2f72f919c65095", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Text(value='HUGGING_FACE_TOKEN', description='Token:')" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import ipywidgets as widgets\n", | |
"\n", | |
"token_textbox = widgets.Text(\n", | |
" value='HUGGING_FACE_TOKEN',\n", | |
" description='Token:',\n", | |
")\n", | |
"token_textbox" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The next cell will download model `v1-5-pruned-emaonly.ckpt` (4GB) \n", | |
"\n", | |
"This model can be used for training textual inversion embeddings and hypernetworks\n", | |
"\n", | |
"Comment out and uncomment lines in the next cell to download different models\n", | |
"\n", | |
"Go to these pages and ***accept the licenses*** before running the next cell:\n", | |
"\n", | |
"https://huggingface.co/runwayml/stable-diffusion-v1-5\n", | |
"\n", | |
"https://huggingface.co/CompVis/stable-diffusion-v-1-4-original\n", | |
"\n", | |
"https://huggingface.co/runwayml/stable-diffusion-inpainting" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"id": "CT_J9L7oqLxG", | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"huggingface_token = \"\"\n", | |
"\n", | |
"import os\n", | |
"\n", | |
"token_path = os.path.expanduser('~/.huggingface/token')\n", | |
"\n", | |
"if os.path.isfile(token_path):\n", | |
" with open(token_path) as f:\n", | |
" lines = f.readlines()\n", | |
" huggingface_token = lines[0]\n", | |
"else:\n", | |
" try:\n", | |
" token_textbox\n", | |
" except NameError:\n", | |
" raise RuntimeError(\"Enter Huggingface token\")\n", | |
" else:\n", | |
" !mkdir -p ~/.huggingface\n", | |
" !echo -n \"{token_textbox.value}\" > ~/.huggingface/token\n", | |
" huggingface_token = token_textbox.value\n", | |
"\n", | |
"user_header = f\"\\\"Authorization: Bearer {huggingface_token}\\\"\"\n", | |
"\n", | |
"%cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n", | |
"\n", | |
"# Choose here which model(s) to download #############################################################################\n", | |
"\n", | |
"# Model 1.4\n", | |
"#!wget --header={user_header} https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt\n", | |
"\n", | |
"# Model 1.5 (8GB) - only necessary for native training, not for embeddings/hypernetworks\n", | |
"#!wget --header={user_header} https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.ckpt \n", | |
"\n", | |
"# Model 1.5 (4GB)\n", | |
"!wget --header={user_header} https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt \n", | |
"\n", | |
"# Inpainting model 1.5 (4GB)\n", | |
"#!wget --header={user_header} https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Recommended Optional: Download variational autoencoder (VAE)\n", | |
"\n", | |
"Doing so can improve the quality of generated images, if you select the VAE in the webui settings\n", | |
"\n", | |
"Go to these pages and ***accept the licenses*** before running the next cell:\n", | |
"\n", | |
"https://huggingface.co/stabilityai/sd-vae-ft-ema-original\n", | |
"\n", | |
"https://huggingface.co/stabilityai/sd-vae-ft-mse-original" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"# sd-vae-ft-ema-original\n", | |
"#%cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n", | |
"#!wget --header={user_header} https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.ckpt\n", | |
"\n", | |
"# sd-vae-ft-mse-original\n", | |
"#%cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n", | |
"#!wget --header={user_header} https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt\n", | |
"\n", | |
"# sd-vae-ft-mse-original\n", | |
"# Use this if you downloaded v1-5-pruned-emaonly.ckpt above and want to autoselect the VAE every time you load this model in the webui\n", | |
"%cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n", | |
"!wget --header={user_header} https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt -O v1-5-pruned-emaonly.vae.pt \n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"jp-MarkdownHeadingCollapsed": true, | |
"tags": [] | |
}, | |
"source": [ | |
"### Optional: Download various models\n", | |
"\n", | |
"Change values from False to True to download a model\n", | |
"\n", | |
"A Huggingface token is not necessary for these downloads" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"############################################################\n", | |
"\n", | |
"download_to_temp_folder = True # models will be deleted when the SageMaker session ends \n", | |
"\n", | |
"anything_v3 = True # Anything V3 model with VAE\n", | |
"anything_xtron = False # AnythingXtron model\n", | |
"gigachad = False # Gigachad model\n", | |
"midjourney_v4 = False # Midjourney V4 Diffusion\n", | |
"waifu = False # Waifu Division with Anime VAE\n", | |
"modidi = False # Modern Disney Diffusion\n", | |
"nitrodiffusion = False # Multi-Style Model trained from scratch\n", | |
"sd15_cloned = False # Cloned version of model 1.5 (not token necessary)\n", | |
"secret_ai = False # Anime/furry model with VAE and hypernetworks\n", | |
"\n", | |
"############################################################\n", | |
"\n", | |
"if download_to_temp_folder:\n", | |
" !mkdir -p /tmp/models\n", | |
" %cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/tmp_models\n", | |
"else:\n", | |
" %cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n", | |
"\n", | |
"if anything_v3:\n", | |
" !wget https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/Anything-V3.0-pruned.ckpt\n", | |
" !wget https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/Anything-V3.0.vae.pt -O Anything-V3.0-pruned.vae.pt\n", | |
"\n", | |
"if anything_xtron:\n", | |
" !wget https://huggingface.co/CrasHthe2nd2/anything-tron/resolve/main/anythingXtron.ckpt\n", | |
" !wget https://huggingface.co/CrasHthe2nd2/anything-tron/resolve/main/Anything-V3.0.vae.pt -O anythingXtron.vae.pt\n", | |
"\n", | |
"if gigachad:\n", | |
" !wget https://huggingface.co/SpiteAnon/gigachad-diffusion/resolve/main/gigachad_2000.ckpt\n", | |
"\n", | |
"if midjourney_v4:\n", | |
" !wget https://huggingface.co/prompthero/midjourney-v4-diffusion/resolve/main/mdjrny-v4.ckpt\n", | |
"\n", | |
"if modidi:\n", | |
" !wget https://huggingface.co/nitrosocke/mo-di-diffusion/resolve/main/moDi-v1-pruned.ckpt\n", | |
"\n", | |
"if nitrodiffusion:\n", | |
" !wget https://huggingface.co/nitrosocke/Nitro-Diffusion/resolve/main/nitroDiffusion-v1.ckpt\n", | |
"\n", | |
"if sd15_cloned:\n", | |
" !wget https://huggingface.co/acheong08/SD-V1-5-cloned/resolve/main/v1-5-pruned-emaonly.ckpt\n", | |
"\n", | |
"if secret_ai:\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/animefull-final-pruned/model.ckpt -O secret_ai.ckpt\n", | |
" %cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/animevae.pt\n", | |
" !mkdir -p ~/SageMaker/stable-diffusion-webui/models/hypernetworks/\n", | |
" %cd ~/SageMaker/stable-diffusion-webui/models/hypernetworks/\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/aini.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/anime.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/anime_2.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/anime_3.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_2.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_3.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_kemono.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_protogen.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_scalie.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/furry_transformation.pt\n", | |
" !wget https://huggingface.co/acheong08/secretAI/resolve/main/stableckpt/modules/modules/pony.pt\n", | |
"\n", | |
"# waifu division\n", | |
"if waifu:\n", | |
" %cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n", | |
" !wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/models/wd-1-3-penultimate-ucg-cont.ckpt\n", | |
"\n", | |
" %cd ~/SageMaker/stable-diffusion-webui/models/VAE/\n", | |
" !wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime.ckpt\n", | |
" !wget https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Sources: \n", | |
"\n", | |
"https://huggingface.co/SpiteAnon/gigachad-diffusion\n", | |
"\n", | |
"https://huggingface.co/CrasHthe2nd2/anything-tron\n", | |
"\n", | |
"https://huggingface.co/Linaqruf/anything-v3.0\n", | |
"\n", | |
"https://huggingface.co/prompthero/midjourney-v4-diffusion\n", | |
"\n", | |
"https://huggingface.co/hakurei/waifu-diffusion-v1-4\n", | |
"\n", | |
"https://huggingface.co/nitrosocke/mo-di-diffusion\n", | |
"\n", | |
"https://huggingface.co/nitrosocke/Nitro-Diffusion\n", | |
"\n", | |
"https://huggingface.co/acheong08" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"jp-MarkdownHeadingCollapsed": true, | |
"tags": [] | |
}, | |
"source": [ | |
"### Optional: Download a model from Google Drive" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Copy the file ID from your URL and paste it into the `GOOGLE_FILE_ID` variable below, before running this cell" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%pip install gdown" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"###########################################################\n", | |
"GOOGLE_FILE_ID = \"1wHFgl0ivCmIZv88hVZXkb8oy9qCuaBGA\"\n", | |
"###########################################################\n", | |
"\n", | |
"# above file ID is Stable Diffusion model 1.4. Replace it with the file ID of the model you want to download from Google Drive\n", | |
"\n", | |
"import gdown\n", | |
"\n", | |
"%cd /content/stable-diffusion-webui/models/Stable-diffusion/\n", | |
"url = \"https://drive.google.com/u/0/uc?id=\" + GOOGLE_FILE_ID + \"&export=download&confirm=t\"\n", | |
"print(\"Downloading \" + url)\n", | |
"gdown.download(url)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"jp-MarkdownHeadingCollapsed": true, | |
"tags": [] | |
}, | |
"source": [ | |
"### Optional: Download a model from MEGA" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Change `MEGA_DOWNLOAD_URL` to the URL of the model, then run the cell\n", | |
"\n", | |
"Download can be very slow (>30 minutes for a 4GB model)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"##########################################################\n", | |
"MEGA_DOWNLOAD_URL = \"https://mega.nz/file/mdcVARhL#FUq5TL2xp7FuzzgMS4B20sOYYnPZsyPMw93sPMHeQ78\"\n", | |
"##########################################################\n", | |
"\n", | |
"%cd ~/SageMaker/stable-diffusion-webui/models/Stable-diffusion/\n", | |
"\n", | |
"%pip install mega.py\n", | |
"from mega import Mega\n", | |
"\n", | |
"mega = Mega()\n", | |
"print(\"Connecting to MEGA\")\n", | |
"m = mega.login()\n", | |
"print(\"Downloading file (no progress display available)\")\n", | |
"m.download_url(MEGA_DOWNLOAD_URL)\n", | |
"print(\"Download complete\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Installation: Install glib to prevent libgthread error when starting webui\n", | |
"\n", | |
"***You only need to do this once on your SageMaker SL account***" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"!conda install glib=2.51.0 -y" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "S8nvm5f6AfaL" | |
}, | |
"source": [ | |
"# Update: Change into Web UI directory and download updates\n", | |
"This is not strictly necessary. You can run this every time before you start the webui" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"%cd ~/SageMaker/stable-diffusion-webui\n", | |
"!git pull" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Update: Install webui requirements.txt\n", | |
"This is necessary sometimes after you did a `!git pull` above" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"%cd ~/SageMaker/stable-diffusion-webui\n", | |
"%pip install -r requirements.txt" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Run: Enter ngrok auth token\n", | |
"You only need to run this once, until you delete your auth token on ngrok.com" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "d0a6d68849bd4ccf8ac8840e5f87c86d", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Text(value='YOUR_NGROK_TOKEN', description='Token:')" | |
] | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import ipywidgets as widgets\n", | |
"\n", | |
"ngrok_token_textbox = widgets.Text(\n", | |
" value='YOUR_NGROK_TOKEN',\n", | |
" description='Token:',\n", | |
")\n", | |
"ngrok_token_textbox" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "xt8lbdmC04ox" | |
}, | |
"source": [ | |
"# Run: Launch web ui\n", | |
"\n", | |
"You will get a ngrok.io link. Follow it and enter the username and password shown below. You may want to change username and password for security reasons.\n", | |
"\n", | |
"Note that every time you stop the SageMaker Studio Lab runtime the generated images will be lost, as they are stored in the /tmp folder" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"id": "R-xAdMA5wxXd" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [] | |
} | |
], | |
"source": [ | |
"##################################\n", | |
"\n", | |
"WEBUI_USERNAME=\"\"\n", | |
"WEBUI_PASSWORD=\"\"\n", | |
"\n", | |
"##################################\n", | |
"\n", | |
"import subprocess\n", | |
"import os\n", | |
"import sys\n", | |
"\n", | |
"ngrok_token = \"\"\n", | |
"\n", | |
"# Check if ngrok token exists\n", | |
"if 'ngrok_token_textbox' in locals():\n", | |
" print(\"Saving ngrok auth token to ~/.ngrok_token\")\n", | |
" !echo -n \"{ngrok_token_textbox.value}\" > ~/.ngrok_token\n", | |
" ngrok_token = ngrok_token_textbox.value\n", | |
"\n", | |
"else:\n", | |
" full_path = os.path.expanduser('~/.ngrok_token')\n", | |
" if not os.path.exists(full_path):\n", | |
" #print('\u001b[1;31mNo ngrok auth token found')\n", | |
" sys.exit(\"No ngrok auth token found\")\n", | |
" else:\n", | |
" with open(full_path) as f:\n", | |
" ngrok_token = f.readline()\n", | |
" print(\"Using ngrok auth token from ~/.ngrok_token\")\n", | |
"\n", | |
"# create /tmp/outputs folder for storing generated images for this session\n", | |
"!mkdir -p /tmp/outputs\n", | |
"!mkdir -p /tmp/models\n", | |
"\n", | |
"# show free disk space\n", | |
"# print(\"Free disk space:\")\n", | |
"# print(subprocess.check_output('df -h | grep Avail', shell=True))\n", | |
"# print(subprocess.check_output('df -h | grep home', shell=True))\n", | |
"# print(subprocess.check_output('df -h | grep overlay', shell=True))\n", | |
"# print(\" \")\n", | |
"# print(\" \")\n", | |
"# print(\" \")\n", | |
"\n", | |
"# launch webui\n", | |
"%cd ~/SageMaker/stable-diffusion-webui\n", | |
"ARGS = \"\\\"--disable-console-progressbars --gradio-debug --gradio-auth \" + WEBUI_USERNAME + \":\" + WEBUI_PASSWORD + \" --ngrok \" + ngrok_token + \"\\\"\"\n", | |
"!COMMANDLINE_ARGS=$ARGS REQS_FILE=\"requirements.txt\" python launch.py\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Commandline arguments are:\n", | |
" - `--share` - create online gradio.app link (currently this doesn't work on SageMaker SL)\n", | |
" - `--gradio-debug` - print outputs to console\n", | |
" - `--ngrok` - start ngrok reverse proxy with supplied auth token" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "9qrpRUJpno7L", | |
"tags": [] | |
}, | |
"source": [ | |
"End: Commands for ***after*** you're done with a session\n", | |
"============================================================================\n", | |
"Click the square stop button before running these cells" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "zB-L8JpElKp-" | |
}, | |
"source": [ | |
"### Create .tar.gz archive of images for downloading \n", | |
"\n", | |
"Location will be `~/SageMaker/tmp/outputs.tar.gz` and `/tmp/outputs.tar.gz`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%cd /tmp\n", | |
"!echo \"Creating archive. Please wait...\"\n", | |
"!tar -czf /tmp/outputs.tar.gz outputs\n", | |
"!echo \"You can now download the archive with generated images\"" | |
] | |
} | |
], | |
"metadata": { | |
"accelerator": "GPU", | |
"colab": { | |
"collapsed_sections": [ | |
"9qrpRUJpno7L" | |
], | |
"provenance": [] | |
}, | |
"gpuClass": "standard", | |
"kernelspec": { | |
"display_name": "Python 3.9.16 ('codeserver_py39': conda)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.16" | |
}, | |
"vscode": { | |
"interpreter": { | |
"hash": "aca522a4f3a95a8cc19c0c49aa2b52717208ab4d9caac282bf163cf809ab5536" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment