stable-diffusion-paperspace/StableDiffusionUI_Voldemort...

826 lines
31 KiB
Plaintext
Raw Normal View History

2022-09-08 13:02:54 -06:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "gfKvWAVnz8OB",
"tags": []
2022-09-08 13:02:54 -06:00
},
"source": [
"# AUTOMATIC1111's Stable Diffusion WebUI\n",
2022-09-08 13:02:54 -06:00
"\n",
"https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
"\n",
"Loosely based on https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl\n",
"\n",
"**Guides**\n",
"- [Getting started on Paperspace](https://github.com/Engineer-of-Stuff/stable-diffusion-paperspace/blob/main/Docs/Paperspace%20Guide%20for%20Retards.md)\n",
"- [Using the WebUI](https://rentry.org/voldy)\n",
"- [Using the Inpainter](https://rentry.org/drfar)\n",
"- [Textual Inversion](https://rentry.org/aikgx)\n",
"- [Crowd-Sourced Prompts](https://lexica.art/)\n",
"- [Artist Name Prompts](https://sgreens.notion.site/sgreens/4ca6f4e229e24da6845b6d49e6b08ae7?v=fdf861d1c65d456e98904fe3f3670bd3)\n",
"- [Stable Diffusion Models](https://cyberes.github.io/stable-diffusion-models)\n",
"- [Textual Inversion Models](https://cyberes.github.io/stable-diffusion-textual-inversion-models/)\n",
"- [Have I Been Trained?](https://haveibeentrained.com/)"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## Installation and Setup\n",
"\n",
"You must reinstall everything each time you restart the machine. If already downloaded, dependencies will be auto-updated."
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Where to store the models**\n",
"\n",
"`/storage/` is persistent storage shared across all machines on your account.\n",
"\n",
"`/notebooks/` is storage for this notebook only.\n",
"\n",
"`/tmp/` <mark style=\"background-color:lime\">is not a persistent directory, meaning your files there will be deleted when the machine turns off.</mark>\n",
"\n",
"<br>\n",
"\n",
"<mark style=\"background-color: #ff780082\">If you are having storage issues</mark>, set `repo_storage_dir` to `/tmp/stable-diffusion`.\n",
"\n",
"<br>\n",
"\n",
"<mark>You must uncomment the correct section and run the block below or else the notebook won't work!</mark>"
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
2022-09-08 13:02:54 -06:00
"outputs": [],
"source": [
"# Free tier\n",
"# free_tier = True # Enables the creation of symlinks back to /notebooks/\n",
"# model_storage_dir = '/tmp/stable-diffusion/models' # Where the models will be downloaded to\n",
"# repo_storage_dir = '/notebooks' # Where the repository will be downloaded to\n",
"\n",
"# Paid Tier\n",
"# free_tier = False\n",
"# model_storage_dir = '/storage/models'\n",
"# repo_storage_dir = '/notebooks'\n",
"\n",
"# Don't put a trailing slash on directory paths.\n",
"# To reset your storage directory, rerun this cell.\n",
"\n",
"# ===============================================================\n",
"# Save variables to Jupiter's temp storage so we can access it even if the kernel restarts.\n",
"%store free_tier model_storage_dir repo_storage_dir"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Don't forget, there's a script to update this notebook to [the latest version](https://github.com/Engineer-of-Stuff/stable-diffusion-paperspace/blob/main/StableDiffusionUI_Voldemort_paperspace.ipynb) on GitHub.**"
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Clone the central repository"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sBbcB4vwj_jm",
"tags": []
2022-09-08 13:02:54 -06:00
},
"outputs": [],
"source": [
"import os\n",
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"%cd /notebooks/\n",
"\n",
"def delete_broken_symlinks(path):\n",
" # make sure to pass this function a path without a trailing slash\n",
" for file in os.listdir(path):\n",
" if os.path.islink(f'{path}/{file}') and not os.path.exists(os.readlink(f'{path}/{file}')):\n",
" print(f'Symlink broken, removing: {file}')\n",
" os.unlink(f'{path}/{file}')\n",
"\n",
"def update_repo_if_not_exists(path, repo_clone_url, pre=None):\n",
" if pre is not None:\n",
" pre() \n",
" if not os.path.exists(path):\n",
" !git clone \"{repo_clone_url}\" \"{path}\"\n",
" else:\n",
" print(f'{repo_clone_url.split(\"/\")[-1]} already downloaded, updating...')\n",
" !cd \"{path}\" && git pull # no % so we don't interfere with the main process\n",
"\n",
"def init_free():\n",
" if (free_tier and repo_storage_dir != '/notebooks'):\n",
" delete_broken_symlinks('/notebooks/') # remove broken symlinks since it might have been installed in a non-persistent directory\n",
" if not os.path.exists(repo_storage_dir):\n",
" !mkdir -p \"{repo_storage_dir}\"\n",
" !ln -s \"{repo_storage_dir}\" /notebooks/\n",
" !ls -la /notebooks/stable-diffusion\n",
"update_repo_if_not_exists(f'{repo_storage_dir}/stable-diffusion-webui', 'https://github.com/AUTOMATIC1111/stable-diffusion-webui', init_free)"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "C68TUpkq0nj_",
"tags": []
},
"source": [
"### Install requirements and download repositories"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SaAJk33ppFw1",
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
2022-09-08 13:02:54 -06:00
"\n",
"# Import launch.py which will automatically run the install script but not launch the WebUI.\n",
"# They require a few specific external git repo commits so we have to do it their way. \n",
"import launch\n",
"\n",
"# Install requirements for this notebooks\n",
"!pip install requests validators\n",
"\n",
"# latent-diffusion is a requirement but launch.py isn't downloading it so we'll do it manually.\n",
"if not os.path.exists(f'{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion'):\n",
" !git clone https://github.com/crowsonkb/k-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/k-diffusion\"\n",
" !git clone https://github.com/Hafiidz/latent-diffusion.git \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion\"\n",
" # I don't think it's necessary to do this:\n",
" # %mkdir \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion/experiments/\"\n",
" # %mkdir \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion/experiments/pretrained_models\"\n",
" # !wget https://raw.githubusercontent.com/Engineer-of-Stuff/stable-diffusion-paperspace/main/lfs/latent-diffusion/project.yaml -O \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion/experiments/pretrained_models/project.yaml\"\n",
" # !wget https://github.com/Engineer-of-Stuff/stable-diffusion-paperspace/blob/main/lfs/latent-diffusion/model.ckpt?raw=true -O \"{repo_storage_dir}/stable-diffusion-webui/repositories/latent-diffusion/experiments/pretrained_models/model.ckpt\"\n",
"\n",
"# Download the GFPGAN face restorer.\n",
"if not os.path.exists(f'{repo_storage_dir}/stable-diffusion-webui/GFPGANv1.3.pth'):\n",
" !wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -O \"{repo_storage_dir}/stable-diffusion-webui/GFPGANv1.3.pth\"\n",
2022-09-08 13:02:54 -06:00
"else:\n",
2022-09-08 16:40:35 -06:00
" print('GFPGANv1.3.pth already downloaded')\n",
"\n",
"# Download popular custom scripts. This is basically remote code execution so be careful.\n",
"# See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts\n",
"import os\n",
"import shutil\n",
"import requests\n",
"!pip install moviepy==1.0.3\n",
"!apt update\n",
"!apt install -y potrace python3-tk\n",
"\n",
"def download_file_dir(url, output_dir):\n",
" # output_dir must have a trailing slash\n",
" local_filename = url.split('/')[-1]\n",
" with requests.get(url, stream=True) as r:\n",
" r.raise_for_status()\n",
" with open(f'{output_dir}{local_filename}', 'wb') as f:\n",
" for chunk in r.iter_content(chunk_size=8192):\n",
" f.write(chunk)\n",
" return local_filename\n",
"\n",
"custom_scripts = [\n",
" 'https://raw.githubusercontent.com/GRMrGecko/stable-diffusion-webui-automatic/advanced_matrix/scripts/advanced_prompt_matrix.py',\n",
" 'https://raw.githubusercontent.com/jtkelm2/stable-diffusion-webui-1/master/scripts/wildcards.py',\n",
" 'https://raw.githubusercontent.com/dfaker/stable-diffusion-webui-cv2-external-masking-script/main/external_masking.py',\n",
" 'https://raw.githubusercontent.com/memes-forever/Stable-diffusion-webui-video/main/videos.py',\n",
" 'https://raw.githubusercontent.com/yownas/seed_travel/main/scripts/seed_travel.py',\n",
" 'https://raw.githubusercontent.com/Animator-Anon/Animator/main/animation.py',\n",
" 'https://gist.githubusercontent.com/dfaker/f88aa62e3a14b559fe4e5f6b345db664/raw/791dabfa0ab26399aa2635bcbc1cf6267aa4ffc2/alternate_sampler_noise_schedules.py',\n",
" 'https://raw.githubusercontent.com/Filarius/stable-diffusion-webui/master/scripts/vid2vid.py',\n",
" 'https://raw.githubusercontent.com/GeorgLegato/Txt2Vectorgraphics/main/txt2vectorgfx.py',\n",
" 'https://raw.githubusercontent.com/yownas/shift-attention/main/scripts/shift_attention.py',\n",
" 'https://raw.githubusercontent.com/DiceOwl/StableDiffusionStuff/main/loopback_superimpose.py',\n",
" 'https://gist.githubusercontent.com/camenduru/9ec5f8141db9902e375967e93250860f/raw/c1a03eb447548adbef1858c0e69d3567a390d2f4/run_n_times.py',\n",
" 'https://raw.githubusercontent.com/Engineer-of-Stuff/stable-diffusion-paperspace/main/lfs/save_steps.py',\n",
" 'https://raw.githubusercontent.com/Pfaeff/sd-web-ui-scripts/main/moisaic.py'\n",
"]\n",
"for item in custom_scripts:\n",
" download_file_dir(item, f'{repo_storage_dir}/stable-diffusion-webui/scripts/')\n",
" print(f'{item.split(\"/\")[-1]} downloaded...')\n",
"\n",
"# Download and set up txt2img2img\n",
"update_repo_if_not_exists(f'{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root', 'https://github.com/ThereforeGames/txt2img2img.git')\n",
"!cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root/scripts\" \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"!cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root/txt2img2img\" \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"!cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2img2img_root/venv\" \"{repo_storage_dir}/stable-diffusion-webui\"\n",
" \n",
"# Download and set up txt2mask\n",
"update_repo_if_not_exists(f'{repo_storage_dir}/stable-diffusion-webui/txt2mask', 'https://github.com/ThereforeGames/txt2mask.git')\n",
"!cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2mask/repositories/clipseg\" \"{repo_storage_dir}/stable-diffusion-webui/repositories\"\n",
"!cp -r \"{repo_storage_dir}/stable-diffusion-webui/txt2mask/scripts/\" \"{repo_storage_dir}/stable-diffusion-webui/\"\n",
"\n",
"# Do the wildcard script\n",
"!mkdir -p \"{repo_storage_dir}/stable-diffusion-webui/scripts/wildcards\"\n",
"wildcard_lists = [\n",
" 'https://raw.githubusercontent.com/jtkelm2/stable-diffusion-webui-1/master/scripts/wildcards/adjective.txt',\n",
" 'https://raw.githubusercontent.com/jtkelm2/stable-diffusion-webui-1/master/scripts/wildcards/artist.txt',\n",
" 'https://raw.githubusercontent.com/jtkelm2/stable-diffusion-webui-1/master/scripts/wildcards/genre.txt',\n",
" 'https://raw.githubusercontent.com/jtkelm2/stable-diffusion-webui-1/master/scripts/wildcards/site.txt',\n",
" 'https://raw.githubusercontent.com/jtkelm2/stable-diffusion-webui-1/master/scripts/wildcards/style.txt'\n",
"]\n",
"for item in wildcard_lists:\n",
" download_file_dir(item, f'{repo_storage_dir}/stable-diffusion-webui/scripts/wildcards/')\n",
"\n",
"# Make sure your models storage directory exists\n",
"!mkdir -p \"{model_storage_dir}\"\n",
"\n",
"# Link the output folder to /notebooks/outputs\n",
"!mkdir -p \"{repo_storage_dir}/stable-diffusion-webui/outputs\"\n",
"!ln -s \"{repo_storage_dir}/stable-diffusion-webui/outputs\" /notebooks/"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
2022-09-08 15:49:49 -06:00
"id": "F0EINk5M0s-w",
"jp-MarkdownHeadingCollapsed": true,
2022-09-08 15:49:49 -06:00
"tags": []
2022-09-08 13:02:54 -06:00
},
"source": [
"### Download the Model"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I've provided a few different ways of aquiring the models. Try the torrent option first. You don't need to repeat this step if you've already downloaded the models.\n",
"\n",
"There are a few additional models available here: https://cyberes.github.io/stable-diffusion-models\n",
"\n",
"If you're interested in textual inversion, here's the database: https://cyberes.github.io/stable-diffusion-textual-inversion-models\n",
"\n",
"**Filesize and Storage Disclaimer**\n",
"\n",
"Paperspace free tier has only 5GB of storage space. If you're having storage issues, here's a few suggestions.\n",
"1. Download everything to `/tmp/`\n",
"2. Add a payment method to your account. Storage overages are billed at \\$0.29/GB and billing occurs monthly and runs at midnight on the first of each month. With a payment method on file, Paperspace will let you use more storage and if you time it right you shouldn't actually be charged for it.\n",
"3. Upgrade to a Pro account. They'll give you 15GB and you'll get longer runtimes and more powerful free GPUs.\n",
"4. Use my referral code `KQLRH37` You'll get \\$10 credit that you should be able to put towards the storage overage charges. Redeem the code at the bottom of the Billing page.\n",
"\n",
"If you're on free tier, only download one model.\n",
"\n",
"**Torrent Instructions**\n",
"\n",
"Aria2 may show some errors/warnings while downloading. Those are fine, when it eventually says \"Download Complete\" that means everything worked as it should."
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"#### Standard Model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Torrent**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!apt update\n",
"!apt install -y aria2\n",
"%cd $model_storage_dir\n",
"!aria2c --seed-time=0 --max-overall-upload-limit=1K \"magnet:?xt=urn:btih:3A4A612D75ED088EA542ACAC52F9F45987488D1C&tr=udp://tracker.opentrackr.org:1337/announce\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Web Download**\n",
"\n",
2022-09-08 13:02:54 -06:00
"Voldy provided an alternative download if you don't want to use HuggingFace.\n",
"\n",
"[https://drive.google.com/file/d/1wHFgl0ivCmIZv88hVZXkb8oy9qCuaBGA/view](https://drive.google.com/file/d/1wHFgl0ivCmIZv88hVZXkb8oy9qCuaBGA/view)\n",
"\n",
"Download it to your computer then upload it to your model storage directory (make sure it's named `sd-v1-4.ckpt`).\n",
2022-09-08 13:02:54 -06:00
"\n",
"HuggingFace is much faster and reliable but you need to get access to the repo and provide your user token."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "CT_J9L7oqLxG"
},
"outputs": [],
"source": [
"user_token = \"<put your user token here>\"\n",
2022-09-08 13:02:54 -06:00
"\n",
"# ===============================================================================================\n",
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!wget --header=\"Authorization: Bearer {user_token}\" https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt -O \"{model_storage_dir}/sd-v1-4.ckpt\""
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"#### Waifu Diffusion\n",
"\n",
"The original Stable Diffusion anime finetune."
2022-09-08 13:02:54 -06:00
]
},
2022-09-08 15:49:49 -06:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!apt update\n",
"!apt install -y aria2\n",
"%cd \"{model_storage_dir}\"\n",
"!aria2c --seed-time=0 --max-overall-upload-limit=1K \"magnet:?xt=urn:btih:153590FD7E93EE11D8DB951451056C362E3A9150&dn=wd-v1-2-full-ema-pruned.ckpt&tr=udp://tracker.opentrackr.org:1337/announce\""
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"#### trinart_stable_diffusion_v2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another anime finetune. Designed to nudge SD to an anime/manga style. Seems to be more \"stylized\" and \"artistic\" than Waifu Diffusion, if that makes any sense.\n",
"\n",
"The 60,000 steps version is the original, the 115,000 and 95,000 versions is the 60,000 with additional training. Use the 60,000 step version if the style nudging is too much.\n",
"\n",
"[See the comparison here.](https://cyberes.github.io/stable-diffusion-models/#model-comparison)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**60000**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!wget https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step60000.ckpt -O \"{model_storage_dir}/trinart2_step60000.ckpt\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**95000**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!wget https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step95000.ckpt -O \"{model_storage_dir}/trinart2_step95000.ckpt\""
2022-09-08 15:49:49 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**115000**"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!wget https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step115000.ckpt -O \"{model_storage_dir}/trinart2_step115000.ckpt\""
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Clean up and restart the kernel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"\n",
"# Get some storage back\n",
"!pip cache purge\n",
"!cd \"{model_storage_dir}\" && rm *.aria2\n",
"!apt remove --purge -y aria2 p7zip-full\n",
"!apt autoremove --purge -y\n",
"!apt clean\n",
"\n",
"# Restart the kernel\n",
"import os\n",
"os.kill(os.getpid(), 9)"
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "markdown",
"metadata": {},
2022-09-08 13:02:54 -06:00
"source": [
"### Link the models directory\n",
"\n",
"Create symlinks. The file will be stored in the models storage directory and linked to where the WebUI expects the files to be."
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-09-08 13:02:54 -06:00
"metadata": {},
"outputs": [],
2022-09-08 13:02:54 -06:00
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"import os\n",
"\n",
"# Check for broken symlinks and remove them\n",
"deleted = False\n",
"for file in os.listdir(f'{repo_storage_dir}/stable-diffusion-webui/models/Stable-diffusion/'):\n",
" path = f'{repo_storage_dir}/stable-diffusion-webui/models/Stable-diffusion/{file}'\n",
" if os.path.islink(path) and not os.path.exists(os.readlink(path)):\n",
" print(f'Symlink broken, removing: {file}')\n",
" os.unlink(path)\n",
" deleted = True\n",
"if deleted:\n",
" print('')\n",
"\n",
"# Make symlinks for new files\n",
"for file in os.listdir(model_storage_dir):\n",
" if file.endswith(\"ckpt\"):\n",
" path = f'{repo_storage_dir}/stable-diffusion-webui/models/Stable-diffusion/{file}'\n",
" if not os.path.exists(path):\n",
" print(f'New model: {file}')\n",
" !ln -s \"{model_storage_dir}/$file\" \"{repo_storage_dir}/stable-diffusion-webui/models/Stable-diffusion/$file\"\n",
" !ls -la --block-size=GB \"{repo_storage_dir}/stable-diffusion-webui/models/Stable-diffusion/$file\"\n",
" print('')"
2022-09-08 13:02:54 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xt8lbdmC04ox"
},
"source": [
"# Launch the WebUI"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"Run this block to launch the WebUI. You will get a link to nnn.gradio.app, that's your WebUI. Follow it.\n",
"\n",
"- See [webui.py](https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/modules/shared.py#L22) to view the code for the launch args. There's a lot of good info in here about exactly what the args do. If you aren't a programmer, [here's the wiki](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Run-with-Custom-Parameters).\n",
"- If you have a lot of VRAM and desire high generation speeds, add `--disable-opt-split-attention` to disable VRAM optimizations.\n",
"- If you have a decent about of VRAM and aren't generating large images you can remove `--medvram` for a speed boost.\n",
"\n",
"#### Troubleshooting\n",
"- If you have any issues, try restarting the kernel.\n",
"- `EOFError: Ran out of input` probably means you ran out of storage space and the model `.ckpt` file wasn't downloaded completely. Try cleaning up your files. There are some helpful scripts in the Tools section below.\n",
"- If you're having issues with your results not loading, that's a known bug. I used to suggest people use ngrok but apparently accounts were getting locked because tunneling proxies are against the terms of service even though the Paperspace terms of service doesn't mention anything like that. [More details in the Tools section below.](https://github.com/anderspitman/awesome-tunneling)"
]
},
2022-09-08 13:02:54 -06:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {
2022-09-08 15:49:49 -06:00
"id": "R-xAdMA5wxXd",
"tags": []
2022-09-08 13:02:54 -06:00
},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"\n",
"# Launch args go below:\n",
"!python webui.py --gradio-debug --share --medvram # --gradio-auth me:password1234"
]
},
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# Export Generations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This block will rename and compress the outputs with 7zip max compression. It expects you to have `log/` and `outputs/` in `/notebooks/stable-diffusion-webui/`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"!apt update\n",
"!apt install -y p7zip-full\n",
"from datetime import datetime\n",
"datetime_str = datetime.now().strftime('%m-%d-%Y_%H:%M:%S')\n",
"%cd /notebooks/\n",
"!mkdir \"{datetime_str}\"\n",
"!mv \"{repo_storage_dir}/stable-diffusion-webui/log\" \"/notebooks/{datetime_str}\"\n",
"!cd \"{repo_storage_dir}/stable-diffusion-webui/outputs/\" && mv * \"/notebooks/{datetime_str}\"\n",
"!TEMP=\"/notebooks/{datetime_str}\" # find command has issues with ipynb variables??\n",
"# !find $TEMP -name .ipynb_checkpoints -exec rm -rf \"{}\" +\n",
"!7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on \"{datetime_str}.7z\" \"/notebooks/{datetime_str}/\""
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Delete old output folder\n",
"\n",
"This block will delete the folder you just compressed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!rm -rf \"/notebooks/{datetime_str}/\"\n",
"!echo Deleted /notebooks/{datetime_str}/"
2022-09-08 15:49:49 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# Tools"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Show graphics card info"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!nvidia-smi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Download the latest version of this notebook from Github\n",
"\n",
"Run this and refresh the page (press F5). Don't save anything or you will overwrite the downloaded file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mv /notebooks/StableDiffusionUI_Voldemort_paperspace.ipynb /notebooks/StableDiffusionUI_Voldemort_paperspace.ipynb.backup # save your old notebook to a backup\n",
"!wget https://raw.githubusercontent.com/Engineer-of-Stuff/stable-diffusion-paperspace/main/StableDiffusionUI_Voldemort_paperspace.ipynb -O /notebooks/StableDiffusionUI_Voldemort_paperspace.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Reset Repository\n",
"\n",
"Sometimes AUTOMATIC1111 breaks something. Go to https://github.com/AUTOMATIC1111/stable-diffusion-webui/commits/master and choose a commit to revert to.\n",
"\n",
"**This shouldn't delete your outputs or any changes you've made to files, but I'd back up anything important just to be safe.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"%cd \"{repo_storage_dir}/stable-diffusion-webui\"\n",
"!git reset --hard <commit>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Delete .ipynb_checkpoints\n",
"\n",
"Jupyter stores temporary files in folders named `.ipynb_checkpoints`. It gets a little excessive sometimes so if you're running low on storage space or getting weird errors about a directory named `.ipynb_checkpoints`, run this block."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!find . -type d -name .ipynb_checkpoints -delete"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Reset storage\n",
"\n",
"This will delete ALL your files in `/notebooks/`, `/storage/`, `model_storage_dir`, and `repo_storage_dir`. Use if you're having issues with zero storage space and you don't want to delete your notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Uncomment the lines below to run this block. You can highlight the lines and do ctrl + /\n",
"# %store -r free_tier model_storage_dir repo_storage_dir\n",
"# !rm -rf /storage/*\n",
"# !mv /notebooks/*.ipynb / # move the notebook out of the directory before we nuke it\n",
"# !rm -rf /notebooks/*\n",
"# !mv /*.ipynb /notebooks/ # move it back\n",
"# !rm -rf {model_storage_dir}\n",
"# !rm -rf {repo_storage_dir}"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"### Download and Install Custom Scripts\n",
"\n",
"This block will prompt you to enter the URL of the script you want to download.\n",
"\n",
"See [https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts)\n",
"\n",
"<mark>This is basically remote code execution so be careful.</mark>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%store -r free_tier model_storage_dir repo_storage_dir\n",
"import validators\n",
"import requests\n",
"import sys\n",
"\n",
"def download_file(url, directory):\n",
" print('Checking if text...', end='\\r')\n",
" content_type = requests.head(url).headers['content-type'].split(';')[0]\n",
" if (content_type != 'text/plain'):\n",
" while True:\n",
" print(f'This is not a text file, it\\'s {content_type}! Continue? y/n', end='\\r')\n",
" ask = input().lower()\n",
" if (ask == 'y'):\n",
" break\n",
" if (ask == 'n'):\n",
" sys.exit(0)\n",
" print('\\033[F' + '\\033[K' + 'Downloading...', end='\\r')\n",
" local_filename = f'{directory}{url.split(\"/\")[-1]}'\n",
" with requests.get(url, stream=True) as r:\n",
" try:\n",
" r.raise_for_status()\n",
" except requests.exceptions.HTTPError as err:\n",
" print(err)\n",
" raise Exception(err)\n",
" with open(local_filename, 'wb') as f:\n",
" for chunk in r.iter_content(chunk_size=8192): \n",
" f.write(chunk)\n",
" print('Downloading... done!')\n",
" return local_filename\n",
"\n",
"print('URL to script then press ENTER: ')\n",
"i = input().strip()\n",
"valid_url = validators.url(i)\n",
"if not valid_url:\n",
" print('Not a valid URL')\n",
"else:\n",
" download_file(i, f'{repo_storage_dir}/stable-diffusion-webui/scripts/') # this will overwrite any existing files\n",
" print('\\nScripts folder content:')\n",
" !ls \"{repo_storage_dir}/stable-diffusion-webui/scripts\""
]
2022-09-08 13:02:54 -06:00
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [],
"private_outputs": true,
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}