From 01ac53874c813f06f864c00cfd08d7462fc50971 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:17:42 +0800 Subject: [PATCH 01/34] Add files via upload --- fast_stable_diffusion_ReForge.ipynb | 717 ++++++++++++++++++++++++++++ 1 file changed, 717 insertions(+) create mode 100644 fast_stable_diffusion_ReForge.ipynb diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb new file mode 100644 index 00000000..c52f01b4 --- /dev/null +++ b/fast_stable_diffusion_ReForge.ipynb @@ -0,0 +1,717 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "47kV9o1Ni8GH" + }, + "source": [ + "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Y9EBc437WDOs" + }, + "outputs": [], + "source": [ + "#@markdown # Connect Google Drive\n", + "from google.colab import drive\n", + "from IPython.display import clear_output\n", + "import ipywidgets as widgets\n", + "import os\n", + "\n", + "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + "Shared_Drive = \"\" #@param {type:\"string\"}\n", + "#@markdown - Leave empty if you're not using a shared drive\n", + "\n", + "print(\"\u001b[0;33mConnecting...\")\n", + "drive.mount('/content/gdrive')\n", + "\n", + "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " mainpth=\"Shareddrives/\"+Shared_Drive\n", + "else:\n", + " mainpth=\"MyDrive\"\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "CFWtw-6EPrKi" + }, + "outputs": [], + "source": [ + "#@markdown # Install/Update Panchovix repo\n", + "from IPython.utils import capture\n", + "from IPython.display import clear_output\n", + "from subprocess import getoutput\n", + "import ipywidgets as widgets\n", + "import sys\n", + "import fileinput\n", + "import os\n", + "import time\n", + "import base64\n", + "import requests\n", + "from urllib.request import urlopen, Request\n", + "from urllib.parse import urlparse, parse_qs, unquote\n", + "from tqdm import tqdm\n", + "import six\n", + "\n", + "\n", + "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", + "\n", + "if not os.path.exists(\"/content/gdrive\"):\n", + " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", + " time.sleep(4)\n", + " mainpth=\"MyDrive\"\n", + " !mkdir -p /content/gdrive/$mainpth\n", + " Shared_Drive=\"\"\n", + "\n", + "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", + " mainpth=\"MyDrive\"\n", + "\n", + "with capture.capture_output() as cap:\n", + " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + " fgitclone = \"git clone --depth 1\"\n", + " %mkdir -p /content/gdrive/$mainpth/sd\n", + " %cd /content/gdrive/$mainpth/sd\n", + " !git clone -q --branch master https://github.com/Panchovix/stable-diffusion-w$blsaphemy\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", + " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", + " !git clone https://github.com/Panchovix/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " !git reset --hard\n", + " !git checkout master\n", + " time.sleep(1)\n", + " !rm webui.sh\n", + " !git pull\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ZGV_5H4xrOSp" + }, + "outputs": [], + "source": [ + "#@markdown # Requirements\n", + "\n", + "print('\u001b[1;32mInstalling requirements...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/\n", + " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", + " !dpkg -i *.deb\n", + " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", + " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", + " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", + " !rm *.deb | rm *.zst | rm *.txt\n", + " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", + " %env CXXFLAGS=-std=c++14\n", + " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", + " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/Patch\n", + " %cd /content/gperftools\n", + " !patch -p1 < /content/Patch\n", + " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", + " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + " %cd /content\n", + " !rm *.tar.gz Patch && rm -r /content/gperftools\n", + " else:\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + "\n", + " !pip install controlnet_aux -qq --no-deps\n", + " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", + " os.environ['PYTHONWARNINGS'] = 'ignore'\n", + " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "p4wj_txjP3TC" + }, + "outputs": [], + "source": [ + "#@markdown # Model Download/Load\n", + "\n", + "import gdown\n", + "from gdown.download import get_url_from_gdrive_confirmation\n", + "import re\n", + "\n", + "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", + "#@markdown - If not, make sure you have enough space on your gdrive\n", + "\n", + "#@markdown ---\n", + "\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", + "\n", + "#@markdown Or\n", + "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", + "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", + "\n", + "#@markdown Or\n", + "MODEL_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "\n", + "def getsrc(url):\n", + " parsed_url = urlparse(url)\n", + " if parsed_url.netloc == 'civitai.com':\n", + " src='civitai'\n", + " elif parsed_url.netloc == 'drive.google.com':\n", + " src='gdrive'\n", + " elif parsed_url.netloc == 'huggingface.co':\n", + " src='huggingface'\n", + " else:\n", + " src='others'\n", + " return src\n", + "\n", + "src=getsrc(MODEL_LINK)\n", + "\n", + "def get_name(url, gdrive):\n", + " if not gdrive:\n", + " response = requests.get(url, allow_redirects=False)\n", + " if \"Location\" in response.headers:\n", + " redirected_url = response.headers[\"Location\"]\n", + " quer = parse_qs(urlparse(redirected_url).query)\n", + " if \"response-content-disposition\" in quer:\n", + " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", + " for vals in disp_val:\n", + " if vals.strip().startswith(\"filename=\"):\n", + " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", + " return filenm.replace(\"\\\"\",\"\")\n", + " else:\n", + " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", + " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", + " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", + " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", + " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", + " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", + " return filenm\n", + "\n", + "\n", + "def dwn(url, dst, msg):\n", + " file_size = None\n", + " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", + " u = urlopen(req)\n", + " meta = u.info()\n", + " if hasattr(meta, 'getheaders'):\n", + " content_length = meta.getheaders(\"Content-Length\")\n", + " else:\n", + " content_length = meta.get_all(\"Content-Length\")\n", + " if content_length is not None and len(content_length) > 0:\n", + " file_size = int(content_length[0])\n", + "\n", + " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", + " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", + " with open(dst, \"wb\") as f:\n", + " while True:\n", + " buffer = u.read(8192)\n", + " if len(buffer) == 0:\n", + " break\n", + " f.write(buffer)\n", + " pbar.update(len(buffer))\n", + " f.close()\n", + "\n", + "\n", + "def sdmdls(ver, Use_Temp_Storage):\n", + "\n", + " if ver=='1.5':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", + " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", + " elif ver=='V2.1-768px':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", + " elif ver=='v1.5 Inpainting':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", + " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", + " elif ver=='SDXL':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", + " elif ver=='Pony Diffusion V6 XL Turbo DPO':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", + " link='https://huggingface.co/Bakanayatsu/ponyDiffusion-V6-XL-Turbo-DPO/resolve/main/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", + " elif ver=='CommonCanvas-XL-C':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/commoncanvas_xl_c.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_xl_c.safetensors'\n", + " link='https://huggingface.co/common-canvas/CommonCanvas-XL-C/resolve/main/commoncanvas_xl_c.safetensors'\n", + " elif ver=='CommonCanvas-S-C':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/commoncanvas_s_c.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_s_c.safetensors'\n", + " link='https://huggingface.co/common-canvas/CommonCanvas-S-C/resolve/main/commoncanvas_s_c.safetensors'\n", + " elif ver=='CC0 Rebild Attempt':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/cc0_atempt_microcosmos-20240709.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/cc0_atempt_microcosmos-20240709.safetensors'\n", + " link='https://huggingface.co/Pixel-Dust/CC0_rebild_attempt/resolve/main/cc0_atempt_microcosmos-20240709.safetensors'\n", + "\n", + " if not os.path.exists(model):\n", + " !gdown --fuzzy -O $model $link\n", + " if os.path.exists(model):\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + " else:\n", + " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", + " else:\n", + " clear_output()\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + "\n", + " return model\n", + "\n", + "\n", + "if (PATH_to_MODEL !=''):\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the trained model.','success', '200px')\n", + "\n", + " else:\n", + " while not os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", + " PATH_to_MODEL=input()\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the custom model.','success', '200px')\n", + "\n", + " model=PATH_to_MODEL\n", + "\n", + "elif MODEL_LINK != \"\":\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(MODEL_LINK, False)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(MODEL_LINK, True)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " else:\n", + " modelname=os.path.basename(MODEL_LINK)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '700px')\n", + "\n", + " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", + " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", + " else:\n", + " !rm model\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "else:\n", + " model=sdmdls(Model_Version, Use_Temp_Storage)\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Svx6Hx0iUPd1" + }, + "outputs": [], + "source": [ + "#@markdown # Download LoRA\n", + "\n", + "LoRA_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "if LoRA_LINK == \"\":\n", + " inf('\\u2714 Nothing to do','primary', '200px')\n", + "else:\n", + " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", + "\n", + " src=getsrc(LoRA_LINK)\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(LoRA_LINK, False)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(LoRA_LINK, True)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " else:\n", + " modelname=os.path.basename(LoRA_LINK)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + "\n", + " if os.path.exists(loramodel) :\n", + " inf('\\u2714 LoRA downloaded','success', '200px')\n", + " else:\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "zC3Rz1b2TBcB" + }, + "outputs": [], + "source": [ + "#@markdown # ControlNet\n", + "from torch.hub import download_url_to_file\n", + "from urllib.parse import urlparse\n", + "import re\n", + "from subprocess import run\n", + "\n", + "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", + "\n", + "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", + "\n", + "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", + "\n", + "#@markdown - Download/update ControlNet extension and its models\n", + "\n", + "def download(url, model_dir):\n", + "\n", + " filename = os.path.basename(urlparse(url).path)\n", + " pth = os.path.abspath(os.path.join(model_dir, filename))\n", + " if not os.path.exists(pth):\n", + " print('Downloading: '+os.path.basename(url))\n", + " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", + " else:\n", + " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", + "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", + "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", + "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", + "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", + " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", + " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", + " %cd /content\n", + " else:\n", + " %cd sd-w$blsaphemy-controlnet\n", + " !git reset --hard\n", + " !git pull\n", + " %cd /content\n", + "\n", + "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", + "for filename in os.listdir(mdldir):\n", + " if \"_sd14v1\" in filename:\n", + " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", + " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", + "\n", + "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/CN_models.txt\n", + "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/CN_models_v2.txt\n", + "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/CN_models_XL.txt\n", + "\n", + "\n", + "with open(\"CN_models.txt\", 'r') as f:\n", + " mdllnk = f.read().splitlines()\n", + "with open(\"CN_models_v2.txt\", 'r') as d:\n", + " mdllnk_v2 = d.read().splitlines()\n", + "with open(\"CN_models_XL.txt\", 'r') as d:\n", + " mdllnk_XL = d.read().splitlines()\n", + "\n", + "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", + "\n", + "\n", + "if XL_Model == \"All\":\n", + " for lnk_XL in mdllnk_XL:\n", + " download(lnk_XL, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif XL_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[XL_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", + "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", + "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", + "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", + "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", + "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", + "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", + "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", + "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", + "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", + "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", + "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", + "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", + "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", + " for name in cfgnames:\n", + " run(['cp', 'cldm_v21.yaml', name])\n", + " %cd /content\n", + "\n", + "if v1_Model == \"All (21GB)\":\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"T2iadapter_Models\":\n", + " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + "\n", + "else:\n", + " download(globals()[v1_Model], mdldir)\n", + " clear_output()\n", + "\n", + "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", + "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", + "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", + "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", + "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", + "\n", + "\n", + "if v2_Model == \"All\":\n", + " for lnk_v2 in mdllnk_v2:\n", + " download(lnk_v2, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif v2_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[v2_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + " #@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "PjzwxTkPSPHf" + }, + "outputs": [], + "source": [ + "#@markdown # Start Stable-Diffusion\n", + "from IPython.utils import capture\n", + "import time\n", + "import sys\n", + "import fileinput\n", + "from pyngrok import ngrok, conf\n", + "import re\n", + "\n", + "\n", + "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", + "#@markdown - Offers better gradio responsivity\n", + "\n", + "Ngrok_token = \"\" #@param {type:\"string\"}\n", + "\n", + "#@markdown - Input your ngrok token if you want to use ngrok server\n", + "\n", + "User = \"\" #@param {type:\"string\"}\n", + "Password= \"\" #@param {type:\"string\"}\n", + "#@markdown - Add credentials to your Gradio interface (optional)\n", + "\n", + "auth=f\"--gradio-auth {User}:{Password}\"\n", + "if User ==\"\" or Password==\"\":\n", + " auth=\"\"\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", + " !wget -q -O extras.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", + " !wget -q -O sd_models.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", + " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Panchovix_files/blocks.py\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " \n", + " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", + " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", + " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", + "\n", + " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + "\n", + " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", + " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", + "\n", + "share=''\n", + "if Ngrok_token!=\"\":\n", + " ngrok.kill()\n", + " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + "elif Use_Cloudflare_Tunnel:\n", + " with capture.capture_output() as cap:\n", + " !pkill cloudflared\n", + " time.sleep(4)\n", + " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", + " time.sleep(4)\n", + " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", + " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + " !rm /content/srv.txt\n", + "\n", + "else:\n", + " share='--share'\n", + "\n", + "ckptdir=''\n", + "if os.path.exists('/content/temp_models'):\n", + " ckptdir='--ckpt-dir /content/temp_models'\n", + "\n", + "try:\n", + " model\n", + " if os.path.isfile(model):\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", + " else:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", + "except:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "provenance": [] + }, + "gpuClass": "standard", + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From e64b74c2185d1992415bd01c5ae6a090f9d81a35 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:23:23 +0800 Subject: [PATCH 02/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index c52f01b4..fbb32633 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -172,7 +172,7 @@ "\n", "#@markdown ---\n", "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", "\n", "#@markdown Or\n", "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", @@ -272,7 +272,7 @@ " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - " elif ver=='Pony Diffusion V6 XL Turbo DPO':\n", + " elif ver=='Pony-Diffusion-V6-XL-Turbo-DPO':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", " model='/content/temp_models/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", @@ -293,7 +293,7 @@ " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_s_c.safetensors'\n", " link='https://huggingface.co/common-canvas/CommonCanvas-S-C/resolve/main/commoncanvas_s_c.safetensors'\n", - " elif ver=='CC0 Rebild Attempt':\n", + " elif ver=='CC0-Rebild-Attempt':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", " model='/content/temp_models/cc0_atempt_microcosmos-20240709.safetensors'\n", From 6125a83c4d64b59ef2d35259c7a3b98a4af48ed8 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:34:27 +0800 Subject: [PATCH 03/34] Add files via upload --- fast_stable_diffusion_ReForge.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index fbb32633..52e9ec7b 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -130,7 +130,7 @@ " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", " %env CXXFLAGS=-std=c++14\n", " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", - " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/Patch\n", + " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", " %cd /content/gperftools\n", " !patch -p1 < /content/Patch\n", " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", @@ -490,9 +490,9 @@ " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", "\n", - "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/CN_models.txt\n", - "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/CN_models_v2.txt\n", - "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Panchovix_files/CN_models_XL.txt\n", + "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", + "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", + "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", "\n", "\n", "with open(\"CN_models.txt\", 'r') as f:\n", @@ -628,7 +628,7 @@ " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", " !wget -q -O extras.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", " !wget -q -O sd_models.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", - " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Panchovix_files/blocks.py\n", + " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", " \n", " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", From 288b85209ebe8d1b3f17b3b48bcc17300fd4fd02 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:34:57 +0800 Subject: [PATCH 04/34] Create SECURITY.md --- SECURITY.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..034e8480 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 5.1.x | :white_check_mark: | +| 5.0.x | :x: | +| 4.0.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. From c14f1ace1e14a139e5153693e851d7e0fa9aee5e Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:35:31 +0800 Subject: [PATCH 05/34] Delete SECURITY.md --- SECURITY.md | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 034e8480..00000000 --- a/SECURITY.md +++ /dev/null @@ -1,21 +0,0 @@ -# Security Policy - -## Supported Versions - -Use this section to tell people about which versions of your project are -currently being supported with security updates. - -| Version | Supported | -| ------- | ------------------ | -| 5.1.x | :white_check_mark: | -| 5.0.x | :x: | -| 4.0.x | :white_check_mark: | -| < 4.0 | :x: | - -## Reporting a Vulnerability - -Use this section to tell people how to report a vulnerability. - -Tell them where to go, how often they can expect to get an update on a -reported vulnerability, what to expect if the vulnerability is accepted or -declined, etc. From b79baf7bb85e6a9da816dd1b808c13448cdda6e5 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:58:03 +0800 Subject: [PATCH 06/34] Add files via upload --- fast_stable_diffusion_ReForge.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index 52e9ec7b..d08fcf0b 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -91,7 +91,7 @@ " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", - " !git clone https://github.com/Panchovix/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", + " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", "\n", "with capture.capture_output() as cap:\n", " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", From a2d649c22aa625f7a21a45eef3928b65383e4aa6 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:11:32 +0800 Subject: [PATCH 07/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index d08fcf0b..91d74d30 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -145,6 +145,7 @@ " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", " os.environ['PYTHONWARNINGS'] = 'ignore'\n", " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + " !pip install Pillow==9.5.0\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From b57a813e14f86710152dcfdcb2295bbc1754928d Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:15:53 +0800 Subject: [PATCH 08/34] Add files via upload --- fast_stable_diffusion_ReForge.ipynb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index 91d74d30..605eeb29 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -173,7 +173,7 @@ "\n", "#@markdown ---\n", "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"Pony-Diffusion-V6-XL\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", "\n", "#@markdown Or\n", "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", @@ -273,6 +273,13 @@ " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", + " elif ver=='Pony-Diffusion-V6-XL':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v6.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v6.safetensors'\n", + " link='https://huggingface.co/AstraliteHeart/pony-diffusion-v6/resolve/main/v6.safetensors'\n", " elif ver=='Pony-Diffusion-V6-XL-Turbo-DPO':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", From 421f4b72754f3f1a0fd890561fe52ab361c55de0 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:36:07 +0800 Subject: [PATCH 09/34] Add files via upload --- fast_stable_diffusion_ReForge.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index 605eeb29..33e26e03 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -173,7 +173,7 @@ "\n", "#@markdown ---\n", "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"Pony-Diffusion-V6-XL\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"AutismMix-Lighting-8steps\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", "\n", "#@markdown Or\n", "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", @@ -273,13 +273,13 @@ " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - " elif ver=='Pony-Diffusion-V6-XL':\n", + " elif ver=='AutismMix-Lighting-8steps':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v6.safetensors'\n", + " model='/content/temp_models/autismmixSDXL_autismmixLightning.safetensors'\n", " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v6.safetensors'\n", - " link='https://huggingface.co/AstraliteHeart/pony-diffusion-v6/resolve/main/v6.safetensors'\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/autismmixSDXL_autismmixLightning.safetensors'\n", + " link='https://huggingface.co/JoaoBarosa/AutismXL_Pony/resolve/main/autismmixSDXL_autismmixLightning.safetensors'\n", " elif ver=='Pony-Diffusion-V6-XL-Turbo-DPO':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", From 12a38db4e52359d8e9d48ee553fc85ee98940ddd Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:35:22 +0800 Subject: [PATCH 10/34] Add files via upload --- fast_stable_diffusion_Forge.ipynb | 725 ++++++++++++++++++++++++++++++ 1 file changed, 725 insertions(+) create mode 100644 fast_stable_diffusion_Forge.ipynb diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb new file mode 100644 index 00000000..b7e6b3df --- /dev/null +++ b/fast_stable_diffusion_Forge.ipynb @@ -0,0 +1,725 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "47kV9o1Ni8GH" + }, + "source": [ + "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Y9EBc437WDOs" + }, + "outputs": [], + "source": [ + "#@markdown # Connect Google Drive\n", + "from google.colab import drive\n", + "from IPython.display import clear_output\n", + "import ipywidgets as widgets\n", + "import os\n", + "\n", + "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + "Shared_Drive = \"\" #@param {type:\"string\"}\n", + "#@markdown - Leave empty if you're not using a shared drive\n", + "\n", + "print(\"\u001b[0;33mConnecting...\")\n", + "drive.mount('/content/gdrive')\n", + "\n", + "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " mainpth=\"Shareddrives/\"+Shared_Drive\n", + "else:\n", + " mainpth=\"MyDrive\"\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "CFWtw-6EPrKi" + }, + "outputs": [], + "source": [ + "#@markdown # Install/Update lllyasviel repo\n", + "from IPython.utils import capture\n", + "from IPython.display import clear_output\n", + "from subprocess import getoutput\n", + "import ipywidgets as widgets\n", + "import sys\n", + "import fileinput\n", + "import os\n", + "import time\n", + "import base64\n", + "import requests\n", + "from urllib.request import urlopen, Request\n", + "from urllib.parse import urlparse, parse_qs, unquote\n", + "from tqdm import tqdm\n", + "import six\n", + "\n", + "\n", + "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", + "\n", + "if not os.path.exists(\"/content/gdrive\"):\n", + " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", + " time.sleep(4)\n", + " mainpth=\"MyDrive\"\n", + " !mkdir -p /content/gdrive/$mainpth\n", + " Shared_Drive=\"\"\n", + "\n", + "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", + " mainpth=\"MyDrive\"\n", + "\n", + "with capture.capture_output() as cap:\n", + " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + " fgitclone = \"git clone --depth 1\"\n", + " %mkdir -p /content/gdrive/$mainpth/sd\n", + " %cd /content/gdrive/$mainpth/sd\n", + " !git clone -q --branch master https://github.com/lllyasviel/stable-diffusion-w$blsaphemy\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", + " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", + " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " !git reset --hard\n", + " !git checkout master\n", + " time.sleep(1)\n", + " !rm webui.sh\n", + " !git pull\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ZGV_5H4xrOSp" + }, + "outputs": [], + "source": [ + "#@markdown # Requirements\n", + "\n", + "print('\u001b[1;32mInstalling requirements...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/\n", + " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", + " !dpkg -i *.deb\n", + " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", + " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", + " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", + " !rm *.deb | rm *.zst | rm *.txt\n", + " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", + " %env CXXFLAGS=-std=c++14\n", + " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", + " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", + " %cd /content/gperftools\n", + " !patch -p1 < /content/Patch\n", + " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", + " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + " %cd /content\n", + " !rm *.tar.gz Patch && rm -r /content/gperftools\n", + " else:\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + "\n", + " !pip install controlnet_aux -qq --no-deps\n", + " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", + " os.environ['PYTHONWARNINGS'] = 'ignore'\n", + " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + " !pip install Pillow==9.5.0\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "p4wj_txjP3TC" + }, + "outputs": [], + "source": [ + "#@markdown # Model Download/Load\n", + "\n", + "import gdown\n", + "from gdown.download import get_url_from_gdrive_confirmation\n", + "import re\n", + "\n", + "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", + "#@markdown - If not, make sure you have enough space on your gdrive\n", + "\n", + "#@markdown ---\n", + "\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"AutismMix-Lighting-8steps\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", + "\n", + "#@markdown Or\n", + "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", + "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", + "\n", + "#@markdown Or\n", + "MODEL_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "\n", + "def getsrc(url):\n", + " parsed_url = urlparse(url)\n", + " if parsed_url.netloc == 'civitai.com':\n", + " src='civitai'\n", + " elif parsed_url.netloc == 'drive.google.com':\n", + " src='gdrive'\n", + " elif parsed_url.netloc == 'huggingface.co':\n", + " src='huggingface'\n", + " else:\n", + " src='others'\n", + " return src\n", + "\n", + "src=getsrc(MODEL_LINK)\n", + "\n", + "def get_name(url, gdrive):\n", + " if not gdrive:\n", + " response = requests.get(url, allow_redirects=False)\n", + " if \"Location\" in response.headers:\n", + " redirected_url = response.headers[\"Location\"]\n", + " quer = parse_qs(urlparse(redirected_url).query)\n", + " if \"response-content-disposition\" in quer:\n", + " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", + " for vals in disp_val:\n", + " if vals.strip().startswith(\"filename=\"):\n", + " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", + " return filenm.replace(\"\\\"\",\"\")\n", + " else:\n", + " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", + " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", + " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", + " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", + " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", + " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", + " return filenm\n", + "\n", + "\n", + "def dwn(url, dst, msg):\n", + " file_size = None\n", + " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", + " u = urlopen(req)\n", + " meta = u.info()\n", + " if hasattr(meta, 'getheaders'):\n", + " content_length = meta.getheaders(\"Content-Length\")\n", + " else:\n", + " content_length = meta.get_all(\"Content-Length\")\n", + " if content_length is not None and len(content_length) > 0:\n", + " file_size = int(content_length[0])\n", + "\n", + " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", + " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", + " with open(dst, \"wb\") as f:\n", + " while True:\n", + " buffer = u.read(8192)\n", + " if len(buffer) == 0:\n", + " break\n", + " f.write(buffer)\n", + " pbar.update(len(buffer))\n", + " f.close()\n", + "\n", + "\n", + "def sdmdls(ver, Use_Temp_Storage):\n", + "\n", + " if ver=='1.5':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", + " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", + " elif ver=='V2.1-768px':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", + " elif ver=='v1.5 Inpainting':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", + " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", + " elif ver=='SDXL':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", + " elif ver=='AutismMix-Lighting-8steps':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/autismmixSDXL_autismmixLightning.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/autismmixSDXL_autismmixLightning.safetensors'\n", + " link='https://huggingface.co/JoaoBarosa/AutismXL_Pony/resolve/main/autismmixSDXL_autismmixLightning.safetensors'\n", + " elif ver=='Pony-Diffusion-V6-XL-Turbo-DPO':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", + " link='https://huggingface.co/Bakanayatsu/ponyDiffusion-V6-XL-Turbo-DPO/resolve/main/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", + " elif ver=='CommonCanvas-XL-C':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/commoncanvas_xl_c.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_xl_c.safetensors'\n", + " link='https://huggingface.co/common-canvas/CommonCanvas-XL-C/resolve/main/commoncanvas_xl_c.safetensors'\n", + " elif ver=='CommonCanvas-S-C':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/commoncanvas_s_c.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_s_c.safetensors'\n", + " link='https://huggingface.co/common-canvas/CommonCanvas-S-C/resolve/main/commoncanvas_s_c.safetensors'\n", + " elif ver=='CC0-Rebild-Attempt':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/cc0_atempt_microcosmos-20240709.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/cc0_atempt_microcosmos-20240709.safetensors'\n", + " link='https://huggingface.co/Pixel-Dust/CC0_rebild_attempt/resolve/main/cc0_atempt_microcosmos-20240709.safetensors'\n", + "\n", + " if not os.path.exists(model):\n", + " !gdown --fuzzy -O $model $link\n", + " if os.path.exists(model):\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + " else:\n", + " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", + " else:\n", + " clear_output()\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + "\n", + " return model\n", + "\n", + "\n", + "if (PATH_to_MODEL !=''):\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the trained model.','success', '200px')\n", + "\n", + " else:\n", + " while not os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", + " PATH_to_MODEL=input()\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the custom model.','success', '200px')\n", + "\n", + " model=PATH_to_MODEL\n", + "\n", + "elif MODEL_LINK != \"\":\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(MODEL_LINK, False)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(MODEL_LINK, True)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " else:\n", + " modelname=os.path.basename(MODEL_LINK)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '700px')\n", + "\n", + " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", + " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", + " else:\n", + " !rm model\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "else:\n", + " model=sdmdls(Model_Version, Use_Temp_Storage)\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Svx6Hx0iUPd1" + }, + "outputs": [], + "source": [ + "#@markdown # Download LoRA\n", + "\n", + "LoRA_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "if LoRA_LINK == \"\":\n", + " inf('\\u2714 Nothing to do','primary', '200px')\n", + "else:\n", + " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", + "\n", + " src=getsrc(LoRA_LINK)\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(LoRA_LINK, False)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(LoRA_LINK, True)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " else:\n", + " modelname=os.path.basename(LoRA_LINK)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + "\n", + " if os.path.exists(loramodel) :\n", + " inf('\\u2714 LoRA downloaded','success', '200px')\n", + " else:\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "zC3Rz1b2TBcB" + }, + "outputs": [], + "source": [ + "#@markdown # ControlNet\n", + "from torch.hub import download_url_to_file\n", + "from urllib.parse import urlparse\n", + "import re\n", + "from subprocess import run\n", + "\n", + "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", + "\n", + "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", + "\n", + "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", + "\n", + "#@markdown - Download/update ControlNet extension and its models\n", + "\n", + "def download(url, model_dir):\n", + "\n", + " filename = os.path.basename(urlparse(url).path)\n", + " pth = os.path.abspath(os.path.join(model_dir, filename))\n", + " if not os.path.exists(pth):\n", + " print('Downloading: '+os.path.basename(url))\n", + " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", + " else:\n", + " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", + "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", + "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", + "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", + "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", + " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", + " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", + " %cd /content\n", + " else:\n", + " %cd sd-w$blsaphemy-controlnet\n", + " !git reset --hard\n", + " !git pull\n", + " %cd /content\n", + "\n", + "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", + "for filename in os.listdir(mdldir):\n", + " if \"_sd14v1\" in filename:\n", + " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", + " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", + "\n", + "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", + "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", + "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", + "\n", + "\n", + "with open(\"CN_models.txt\", 'r') as f:\n", + " mdllnk = f.read().splitlines()\n", + "with open(\"CN_models_v2.txt\", 'r') as d:\n", + " mdllnk_v2 = d.read().splitlines()\n", + "with open(\"CN_models_XL.txt\", 'r') as d:\n", + " mdllnk_XL = d.read().splitlines()\n", + "\n", + "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", + "\n", + "\n", + "if XL_Model == \"All\":\n", + " for lnk_XL in mdllnk_XL:\n", + " download(lnk_XL, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif XL_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[XL_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", + "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", + "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", + "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", + "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", + "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", + "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", + "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", + "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", + "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", + "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", + "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", + "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", + "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", + " for name in cfgnames:\n", + " run(['cp', 'cldm_v21.yaml', name])\n", + " %cd /content\n", + "\n", + "if v1_Model == \"All (21GB)\":\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"T2iadapter_Models\":\n", + " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + "\n", + "else:\n", + " download(globals()[v1_Model], mdldir)\n", + " clear_output()\n", + "\n", + "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", + "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", + "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", + "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", + "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", + "\n", + "\n", + "if v2_Model == \"All\":\n", + " for lnk_v2 in mdllnk_v2:\n", + " download(lnk_v2, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif v2_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[v2_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + " #@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "PjzwxTkPSPHf" + }, + "outputs": [], + "source": [ + "#@markdown # Start Stable-Diffusion\n", + "from IPython.utils import capture\n", + "import time\n", + "import sys\n", + "import fileinput\n", + "from pyngrok import ngrok, conf\n", + "import re\n", + "\n", + "\n", + "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", + "#@markdown - Offers better gradio responsivity\n", + "\n", + "Ngrok_token = \"\" #@param {type:\"string\"}\n", + "\n", + "#@markdown - Input your ngrok token if you want to use ngrok server\n", + "\n", + "User = \"\" #@param {type:\"string\"}\n", + "Password= \"\" #@param {type:\"string\"}\n", + "#@markdown - Add credentials to your Gradio interface (optional)\n", + "\n", + "auth=f\"--gradio-auth {User}:{Password}\"\n", + "if User ==\"\" or Password==\"\":\n", + " auth=\"\"\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", + " !wget -q -O extras.py https://raw.githubusercontent.com/lllyasviel/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", + " !wget -q -O sd_models.py https://raw.githubusercontent.com/lllyasviel/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", + " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " \n", + " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", + " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", + " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", + "\n", + " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + "\n", + " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", + " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", + "\n", + "share=''\n", + "if Ngrok_token!=\"\":\n", + " ngrok.kill()\n", + " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + "elif Use_Cloudflare_Tunnel:\n", + " with capture.capture_output() as cap:\n", + " !pkill cloudflared\n", + " time.sleep(4)\n", + " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", + " time.sleep(4)\n", + " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", + " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + " !rm /content/srv.txt\n", + "\n", + "else:\n", + " share='--share'\n", + "\n", + "ckptdir=''\n", + "if os.path.exists('/content/temp_models'):\n", + " ckptdir='--ckpt-dir /content/temp_models'\n", + "\n", + "try:\n", + " model\n", + " if os.path.isfile(model):\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", + " else:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", + "except:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "provenance": [] + }, + "gpuClass": "standard", + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 40b2f023c6a5d96e6e5be9a3278eddb33a0fd9d1 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:24:33 +0800 Subject: [PATCH 11/34] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 5c83a0b5..c91cbb28 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -145,6 +145,7 @@ " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", " os.environ['PYTHONWARNINGS'] = 'ignore'\n", " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + " !pip install Pillow==9.5.0\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", @@ -250,7 +251,7 @@ " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", - " link='https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", + " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", " elif ver=='V2.1-768px':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", @@ -264,7 +265,7 @@ " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", - " link='https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", + " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", " elif ver=='SDXL':\n", " if Use_Temp_Storage:\n", " os.makedirs('/content/temp_models', exist_ok=True)\n", From 39514f2054d53a8b801ab30d8191eac1193783d4 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:28:18 +0800 Subject: [PATCH 12/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 37 +------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index b7e6b3df..9d7828b3 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -173,7 +173,7 @@ "\n", "#@markdown ---\n", "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"AutismMix-Lighting-8steps\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\""]\n", "\n", "#@markdown Or\n", "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", @@ -273,41 +273,6 @@ " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - " elif ver=='AutismMix-Lighting-8steps':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/autismmixSDXL_autismmixLightning.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/autismmixSDXL_autismmixLightning.safetensors'\n", - " link='https://huggingface.co/JoaoBarosa/AutismXL_Pony/resolve/main/autismmixSDXL_autismmixLightning.safetensors'\n", - " elif ver=='Pony-Diffusion-V6-XL-Turbo-DPO':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", - " link='https://huggingface.co/Bakanayatsu/ponyDiffusion-V6-XL-Turbo-DPO/resolve/main/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", - " elif ver=='CommonCanvas-XL-C':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/commoncanvas_xl_c.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_xl_c.safetensors'\n", - " link='https://huggingface.co/common-canvas/CommonCanvas-XL-C/resolve/main/commoncanvas_xl_c.safetensors'\n", - " elif ver=='CommonCanvas-S-C':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/commoncanvas_s_c.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_s_c.safetensors'\n", - " link='https://huggingface.co/common-canvas/CommonCanvas-S-C/resolve/main/commoncanvas_s_c.safetensors'\n", - " elif ver=='CC0-Rebild-Attempt':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/cc0_atempt_microcosmos-20240709.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/cc0_atempt_microcosmos-20240709.safetensors'\n", - " link='https://huggingface.co/Pixel-Dust/CC0_rebild_attempt/resolve/main/cc0_atempt_microcosmos-20240709.safetensors'\n", "\n", " if not os.path.exists(model):\n", " !gdown --fuzzy -O $model $link\n", From 54879348e66f3c86f3791d64dfd0c5d0830fbcce Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:29:03 +0800 Subject: [PATCH 13/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index 9d7828b3..a7ef3d7c 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -173,7 +173,7 @@ "\n", "#@markdown ---\n", "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\""]\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", "\n", "#@markdown Or\n", "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", From 7d101fa7ec818516142e2898b48b8f615ee85e83 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:30:18 +0800 Subject: [PATCH 14/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 37 +---------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index 33e26e03..b291d559 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -173,7 +173,7 @@ "\n", "#@markdown ---\n", "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\", \"AutismMix-Lighting-8steps\", \"Pony-Diffusion-V6-XL-Turbo-DPO\", \"CommonCanvas-XL-C\", \"CommonCanvas-S-C\", \"CC0-Rebild-Attempt\"]\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", "\n", "#@markdown Or\n", "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", @@ -273,41 +273,6 @@ " else:\n", " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - " elif ver=='AutismMix-Lighting-8steps':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/autismmixSDXL_autismmixLightning.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/autismmixSDXL_autismmixLightning.safetensors'\n", - " link='https://huggingface.co/JoaoBarosa/AutismXL_Pony/resolve/main/autismmixSDXL_autismmixLightning.safetensors'\n", - " elif ver=='Pony-Diffusion-V6-XL-Turbo-DPO':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", - " link='https://huggingface.co/Bakanayatsu/ponyDiffusion-V6-XL-Turbo-DPO/resolve/main/ponyDiffusionV6XL_v6TurboDPOMerge.safetensors'\n", - " elif ver=='CommonCanvas-XL-C':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/commoncanvas_xl_c.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_xl_c.safetensors'\n", - " link='https://huggingface.co/common-canvas/CommonCanvas-XL-C/resolve/main/commoncanvas_xl_c.safetensors'\n", - " elif ver=='CommonCanvas-S-C':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/commoncanvas_s_c.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/commoncanvas_s_c.safetensors'\n", - " link='https://huggingface.co/common-canvas/CommonCanvas-S-C/resolve/main/commoncanvas_s_c.safetensors'\n", - " elif ver=='CC0-Rebild-Attempt':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/cc0_atempt_microcosmos-20240709.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/cc0_atempt_microcosmos-20240709.safetensors'\n", - " link='https://huggingface.co/Pixel-Dust/CC0_rebild_attempt/resolve/main/cc0_atempt_microcosmos-20240709.safetensors'\n", "\n", " if not os.path.exists(model):\n", " !gdown --fuzzy -O $model $link\n", From 09e7f4cde93723ccea0b23fd419014778b654082 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:08:13 +0800 Subject: [PATCH 15/34] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index c91cbb28..aa0ab10b 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -146,6 +146,7 @@ " os.environ['PYTHONWARNINGS'] = 'ignore'\n", " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", + " !pip install protobuf==3.20.3\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From f0c3291a83eae5876d4922f262095e47f3e18c5b Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:08:36 +0800 Subject: [PATCH 16/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index a7ef3d7c..a0a9e9ed 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -146,6 +146,7 @@ " os.environ['PYTHONWARNINGS'] = 'ignore'\n", " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", + " !pip install protobuf==3.20.3\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From 7aa7e467d568f80fc146cef13c53f01f46ddf83a Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:08:51 +0800 Subject: [PATCH 17/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index b291d559..86839b35 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -146,6 +146,7 @@ " os.environ['PYTHONWARNINGS'] = 'ignore'\n", " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", + " !pip install protobuf==3.20.3\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From da0b17d7d2ae2e883ab0e129617a3e2669a2b1c9 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:49:53 +0800 Subject: [PATCH 18/34] Rename fast_stable_diffusion_AUTOMATIC1111.ipynb to fast_stable_diffusion_AUTOMATIC1111-old.ipynb --- ...TIC1111.ipynb => fast_stable_diffusion_AUTOMATIC1111-old.ipynb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fast_stable_diffusion_AUTOMATIC1111.ipynb => fast_stable_diffusion_AUTOMATIC1111-old.ipynb (100%) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111-old.ipynb similarity index 100% rename from fast_stable_diffusion_AUTOMATIC1111.ipynb rename to fast_stable_diffusion_AUTOMATIC1111-old.ipynb From 8a53b9af149d8a7af8d6f5f864bca4c1c597d1e4 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:50:08 +0800 Subject: [PATCH 19/34] Add files via upload --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 690 ++++++++++++++++++++++ 1 file changed, 690 insertions(+) create mode 100644 fast_stable_diffusion_AUTOMATIC1111.ipynb diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb new file mode 100644 index 00000000..4478dfd3 --- /dev/null +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -0,0 +1,690 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "47kV9o1Ni8GH" + }, + "source": [ + "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Y9EBc437WDOs" + }, + "outputs": [], + "source": [ + "#@markdown # Connect Google Drive\n", + "from google.colab import drive\n", + "from IPython.display import clear_output\n", + "import ipywidgets as widgets\n", + "import os\n", + "\n", + "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + "Shared_Drive = \"\" #@param {type:\"string\"}\n", + "#@markdown - Leave empty if you're not using a shared drive\n", + "\n", + "print(\"\u001b[0;33mConnecting...\")\n", + "drive.mount('/content/gdrive')\n", + "\n", + "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " mainpth=\"Shareddrives/\"+Shared_Drive\n", + "else:\n", + " mainpth=\"MyDrive\"\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "CFWtw-6EPrKi" + }, + "outputs": [], + "source": [ + "#@markdown # Install/Update AUTOMATIC1111 repo\n", + "from IPython.utils import capture\n", + "from IPython.display import clear_output\n", + "from subprocess import getoutput\n", + "import ipywidgets as widgets\n", + "import sys\n", + "import fileinput\n", + "import os\n", + "import time\n", + "import base64\n", + "import requests\n", + "from urllib.request import urlopen, Request\n", + "from urllib.parse import urlparse, parse_qs, unquote\n", + "from tqdm import tqdm\n", + "import six\n", + "\n", + "\n", + "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", + "\n", + "if not os.path.exists(\"/content/gdrive\"):\n", + " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", + " time.sleep(4)\n", + " mainpth=\"MyDrive\"\n", + " !mkdir -p /content/gdrive/$mainpth\n", + " Shared_Drive=\"\"\n", + "\n", + "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", + " mainpth=\"MyDrive\"\n", + "\n", + "with capture.capture_output() as cap:\n", + " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + " fgitclone = \"git clone --depth 1\"\n", + " %mkdir -p /content/gdrive/$mainpth/sd\n", + " %cd /content/gdrive/$mainpth/sd\n", + " !git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", + " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", + " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " !git reset --hard\n", + " !git checkout master\n", + " time.sleep(1)\n", + " !rm webui.sh\n", + " !git pull\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ZGV_5H4xrOSp" + }, + "outputs": [], + "source": [ + "#@markdown # Requirements\n", + "\n", + "print('\u001b[1;32mInstalling requirements...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/\n", + " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", + " !dpkg -i *.deb\n", + " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", + " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", + " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", + " !rm *.deb | rm *.zst | rm *.txt\n", + " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", + " %env CXXFLAGS=-std=c++14\n", + " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", + " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", + " %cd /content/gperftools\n", + " !patch -p1 < /content/Patch\n", + " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", + " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + " %cd /content\n", + " !rm *.tar.gz Patch && rm -r /content/gperftools\n", + " else:\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + "\n", + " !pip install controlnet_aux -qq --no-deps\n", + " !rm -r /usr/local/lib/python3.10/dist-packages/google/_upb\n", + " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", + " os.environ['PYTHONWARNINGS'] = 'ignore'\n", + " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "p4wj_txjP3TC" + }, + "outputs": [], + "source": [ + "#@markdown # Model Download/Load\n", + "\n", + "import gdown\n", + "from gdown.download import get_url_from_gdrive_confirmation\n", + "import re\n", + "\n", + "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", + "#@markdown - If not, make sure you have enough space on your gdrive\n", + "\n", + "#@markdown ---\n", + "\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", + "\n", + "#@markdown Or\n", + "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", + "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", + "\n", + "#@markdown Or\n", + "MODEL_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "\n", + "def getsrc(url):\n", + " parsed_url = urlparse(url)\n", + " if parsed_url.netloc == 'civitai.com':\n", + " src='civitai'\n", + " elif parsed_url.netloc == 'drive.google.com':\n", + " src='gdrive'\n", + " elif parsed_url.netloc == 'huggingface.co':\n", + " src='huggingface'\n", + " else:\n", + " src='others'\n", + " return src\n", + "\n", + "src=getsrc(MODEL_LINK)\n", + "\n", + "def get_name(url, gdrive):\n", + " if not gdrive:\n", + " response = requests.get(url, allow_redirects=False)\n", + " if \"Location\" in response.headers:\n", + " redirected_url = response.headers[\"Location\"]\n", + " quer = parse_qs(urlparse(redirected_url).query)\n", + " if \"response-content-disposition\" in quer:\n", + " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", + " for vals in disp_val:\n", + " if vals.strip().startswith(\"filename=\"):\n", + " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", + " return filenm.replace(\"\\\"\",\"\")\n", + " else:\n", + " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", + " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", + " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", + " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", + " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", + " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", + " return filenm\n", + "\n", + "\n", + "def dwn(url, dst, msg):\n", + " file_size = None\n", + " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", + " u = urlopen(req)\n", + " meta = u.info()\n", + " if hasattr(meta, 'getheaders'):\n", + " content_length = meta.getheaders(\"Content-Length\")\n", + " else:\n", + " content_length = meta.get_all(\"Content-Length\")\n", + " if content_length is not None and len(content_length) > 0:\n", + " file_size = int(content_length[0])\n", + "\n", + " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", + " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", + " with open(dst, \"wb\") as f:\n", + " while True:\n", + " buffer = u.read(8192)\n", + " if len(buffer) == 0:\n", + " break\n", + " f.write(buffer)\n", + " pbar.update(len(buffer))\n", + " f.close()\n", + "\n", + "\n", + "def sdmdls(ver, Use_Temp_Storage):\n", + "\n", + " if ver=='1.5':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", + " link='https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", + " elif ver=='V2.1-768px':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", + " elif ver=='v1.5 Inpainting':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", + " link='https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", + " elif ver=='SDXL':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", + "\n", + " if not os.path.exists(model):\n", + " !gdown --fuzzy -O $model $link\n", + " if os.path.exists(model):\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + " else:\n", + " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", + " else:\n", + " clear_output()\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + "\n", + " return model\n", + "\n", + "\n", + "if (PATH_to_MODEL !=''):\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the trained model.','success', '200px')\n", + "\n", + " else:\n", + " while not os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", + " PATH_to_MODEL=input()\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the custom model.','success', '200px')\n", + "\n", + " model=PATH_to_MODEL\n", + "\n", + "elif MODEL_LINK != \"\":\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(MODEL_LINK, False)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(MODEL_LINK, True)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " else:\n", + " modelname=os.path.basename(MODEL_LINK)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '700px')\n", + "\n", + " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", + " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", + " else:\n", + " !rm model\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "else:\n", + " model=sdmdls(Model_Version, Use_Temp_Storage)\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Svx6Hx0iUPd1" + }, + "outputs": [], + "source": [ + "#@markdown # Download LoRA\n", + "\n", + "LoRA_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "if LoRA_LINK == \"\":\n", + " inf('\\u2714 Nothing to do','primary', '200px')\n", + "else:\n", + " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", + "\n", + " src=getsrc(LoRA_LINK)\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(LoRA_LINK, False)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(LoRA_LINK, True)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " else:\n", + " modelname=os.path.basename(LoRA_LINK)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + "\n", + " if os.path.exists(loramodel) :\n", + " inf('\\u2714 LoRA downloaded','success', '200px')\n", + " else:\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "zC3Rz1b2TBcB" + }, + "outputs": [], + "source": [ + "#@markdown # ControlNet\n", + "from torch.hub import download_url_to_file\n", + "from urllib.parse import urlparse\n", + "import re\n", + "from subprocess import run\n", + "\n", + "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", + "\n", + "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", + "\n", + "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", + "\n", + "#@markdown - Download/update ControlNet extension and its models\n", + "\n", + "def download(url, model_dir):\n", + "\n", + " filename = os.path.basename(urlparse(url).path)\n", + " pth = os.path.abspath(os.path.join(model_dir, filename))\n", + " if not os.path.exists(pth):\n", + " print('Downloading: '+os.path.basename(url))\n", + " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", + " else:\n", + " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", + "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", + "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", + "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", + "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", + " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", + " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", + " %cd /content\n", + " else:\n", + " %cd sd-w$blsaphemy-controlnet\n", + " !git reset --hard\n", + " !git pull\n", + " %cd /content\n", + "\n", + "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", + "for filename in os.listdir(mdldir):\n", + " if \"_sd14v1\" in filename:\n", + " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", + " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", + "\n", + "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", + "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", + "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", + "\n", + "\n", + "with open(\"CN_models.txt\", 'r') as f:\n", + " mdllnk = f.read().splitlines()\n", + "with open(\"CN_models_v2.txt\", 'r') as d:\n", + " mdllnk_v2 = d.read().splitlines()\n", + "with open(\"CN_models_XL.txt\", 'r') as d:\n", + " mdllnk_XL = d.read().splitlines()\n", + "\n", + "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", + "\n", + "\n", + "if XL_Model == \"All\":\n", + " for lnk_XL in mdllnk_XL:\n", + " download(lnk_XL, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif XL_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[XL_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", + "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", + "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", + "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", + "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", + "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", + "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", + "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", + "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", + "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", + "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", + "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", + "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", + "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", + " for name in cfgnames:\n", + " run(['cp', 'cldm_v21.yaml', name])\n", + " %cd /content\n", + "\n", + "if v1_Model == \"All (21GB)\":\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"T2iadapter_Models\":\n", + " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + "\n", + "else:\n", + " download(globals()[v1_Model], mdldir)\n", + " clear_output()\n", + "\n", + "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", + "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", + "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", + "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", + "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", + "\n", + "\n", + "if v2_Model == \"All\":\n", + " for lnk_v2 in mdllnk_v2:\n", + " download(lnk_v2, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif v2_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[v2_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + " #@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "PjzwxTkPSPHf" + }, + "outputs": [], + "source": [ + "#@markdown # Start Stable-Diffusion\n", + "from IPython.utils import capture\n", + "import time\n", + "import sys\n", + "import fileinput\n", + "from pyngrok import ngrok, conf\n", + "import re\n", + "\n", + "\n", + "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", + "#@markdown - Offers better gradio responsivity\n", + "\n", + "Ngrok_token = \"\" #@param {type:\"string\"}\n", + "\n", + "#@markdown - Input your ngrok token if you want to use ngrok server\n", + "\n", + "User = \"\" #@param {type:\"string\"}\n", + "Password= \"\" #@param {type:\"string\"}\n", + "#@markdown - Add credentials to your Gradio interface (optional)\n", + "\n", + "auth=f\"--gradio-auth {User}:{Password}\"\n", + "if User ==\"\" or Password==\"\":\n", + " auth=\"\"\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", + " !wget -q -O extras.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", + " !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", + " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " \n", + " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", + " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", + " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", + "\n", + " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + "\n", + " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", + " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", + "\n", + "share=''\n", + "if Ngrok_token!=\"\":\n", + " ngrok.kill()\n", + " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + "elif Use_Cloudflare_Tunnel:\n", + " with capture.capture_output() as cap:\n", + " !pkill cloudflared\n", + " time.sleep(4)\n", + " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", + " time.sleep(4)\n", + " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", + " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + " !rm /content/srv.txt\n", + "\n", + "else:\n", + " share='--share'\n", + "\n", + "ckptdir=''\n", + "if os.path.exists('/content/temp_models'):\n", + " ckptdir='--ckpt-dir /content/temp_models'\n", + "\n", + "try:\n", + " model\n", + " if os.path.isfile(model):\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", + " else:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", + "except:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "provenance": [] + }, + "gpuClass": "standard", + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From e2d03df3f0c8c289eed69d83c02ffea74dc54b7a Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:55:31 +0800 Subject: [PATCH 20/34] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 4478dfd3..08394dd5 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -146,6 +146,8 @@ " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", " os.environ['PYTHONWARNINGS'] = 'ignore'\n", " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + " !pip install Pillow==9.5.0\n", + " !pip install protobuf==3.20.3\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From 315c1ef3d36097b2a56e63a8918b918359ffe296 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:56:01 +0800 Subject: [PATCH 21/34] Delete fast_stable_diffusion_AUTOMATIC1111-old.ipynb --- fast_stable_diffusion_AUTOMATIC1111-old.ipynb | 691 ------------------ 1 file changed, 691 deletions(-) delete mode 100644 fast_stable_diffusion_AUTOMATIC1111-old.ipynb diff --git a/fast_stable_diffusion_AUTOMATIC1111-old.ipynb b/fast_stable_diffusion_AUTOMATIC1111-old.ipynb deleted file mode 100644 index aa0ab10b..00000000 --- a/fast_stable_diffusion_AUTOMATIC1111-old.ipynb +++ /dev/null @@ -1,691 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "47kV9o1Ni8GH" - }, - "source": [ - "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "Y9EBc437WDOs" - }, - "outputs": [], - "source": [ - "#@markdown # Connect Google Drive\n", - "from google.colab import drive\n", - "from IPython.display import clear_output\n", - "import ipywidgets as widgets\n", - "import os\n", - "\n", - "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", - "Shared_Drive = \"\" #@param {type:\"string\"}\n", - "#@markdown - Leave empty if you're not using a shared drive\n", - "\n", - "print(\"\u001b[0;33mConnecting...\")\n", - "drive.mount('/content/gdrive')\n", - "\n", - "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", - " mainpth=\"Shareddrives/\"+Shared_Drive\n", - "else:\n", - " mainpth=\"MyDrive\"\n", - "\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "CFWtw-6EPrKi" - }, - "outputs": [], - "source": [ - "#@markdown # Install/Update AUTOMATIC1111 repo\n", - "from IPython.utils import capture\n", - "from IPython.display import clear_output\n", - "from subprocess import getoutput\n", - "import ipywidgets as widgets\n", - "import sys\n", - "import fileinput\n", - "import os\n", - "import time\n", - "import base64\n", - "import requests\n", - "from urllib.request import urlopen, Request\n", - "from urllib.parse import urlparse, parse_qs, unquote\n", - "from tqdm import tqdm\n", - "import six\n", - "\n", - "\n", - "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", - "\n", - "if not os.path.exists(\"/content/gdrive\"):\n", - " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", - " time.sleep(4)\n", - " mainpth=\"MyDrive\"\n", - " !mkdir -p /content/gdrive/$mainpth\n", - " Shared_Drive=\"\"\n", - "\n", - "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", - " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", - " mainpth=\"MyDrive\"\n", - "\n", - "with capture.capture_output() as cap:\n", - " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", - " fgitclone = \"git clone --depth 1\"\n", - " %mkdir -p /content/gdrive/$mainpth/sd\n", - " %cd /content/gdrive/$mainpth/sd\n", - " !git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy\n", - " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", - " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", - " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", - " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", - " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", - " !git reset --hard\n", - " !git checkout master\n", - " time.sleep(1)\n", - " !rm webui.sh\n", - " !git pull\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "ZGV_5H4xrOSp" - }, - "outputs": [], - "source": [ - "#@markdown # Requirements\n", - "\n", - "print('\u001b[1;32mInstalling requirements...')\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/\n", - " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", - " !dpkg -i *.deb\n", - " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", - " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", - " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", - " !rm *.deb | rm *.zst | rm *.txt\n", - " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", - " %env CXXFLAGS=-std=c++14\n", - " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", - " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", - " %cd /content/gperftools\n", - " !patch -p1 < /content/Patch\n", - " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", - " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", - " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", - " %cd /content\n", - " !rm *.tar.gz Patch && rm -r /content/gperftools\n", - " else:\n", - " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", - "\n", - " !pip install controlnet_aux -qq --no-deps\n", - " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", - " os.environ['PYTHONWARNINGS'] = 'ignore'\n", - " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", - " !pip install Pillow==9.5.0\n", - " !pip install protobuf==3.20.3\n", - "\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "p4wj_txjP3TC" - }, - "outputs": [], - "source": [ - "#@markdown # Model Download/Load\n", - "\n", - "import gdown\n", - "from gdown.download import get_url_from_gdrive_confirmation\n", - "import re\n", - "\n", - "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", - "#@markdown - If not, make sure you have enough space on your gdrive\n", - "\n", - "#@markdown ---\n", - "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", - "\n", - "#@markdown Or\n", - "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", - "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", - "\n", - "#@markdown Or\n", - "MODEL_LINK = \"\" #@param {type:\"string\"}\n", - "\n", - "\n", - "def getsrc(url):\n", - " parsed_url = urlparse(url)\n", - " if parsed_url.netloc == 'civitai.com':\n", - " src='civitai'\n", - " elif parsed_url.netloc == 'drive.google.com':\n", - " src='gdrive'\n", - " elif parsed_url.netloc == 'huggingface.co':\n", - " src='huggingface'\n", - " else:\n", - " src='others'\n", - " return src\n", - "\n", - "src=getsrc(MODEL_LINK)\n", - "\n", - "def get_name(url, gdrive):\n", - " if not gdrive:\n", - " response = requests.get(url, allow_redirects=False)\n", - " if \"Location\" in response.headers:\n", - " redirected_url = response.headers[\"Location\"]\n", - " quer = parse_qs(urlparse(redirected_url).query)\n", - " if \"response-content-disposition\" in quer:\n", - " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", - " for vals in disp_val:\n", - " if vals.strip().startswith(\"filename=\"):\n", - " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", - " return filenm.replace(\"\\\"\",\"\")\n", - " else:\n", - " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", - " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", - " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", - " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", - " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", - " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", - " return filenm\n", - "\n", - "\n", - "def dwn(url, dst, msg):\n", - " file_size = None\n", - " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", - " u = urlopen(req)\n", - " meta = u.info()\n", - " if hasattr(meta, 'getheaders'):\n", - " content_length = meta.getheaders(\"Content-Length\")\n", - " else:\n", - " content_length = meta.get_all(\"Content-Length\")\n", - " if content_length is not None and len(content_length) > 0:\n", - " file_size = int(content_length[0])\n", - "\n", - " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", - " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", - " with open(dst, \"wb\") as f:\n", - " while True:\n", - " buffer = u.read(8192)\n", - " if len(buffer) == 0:\n", - " break\n", - " f.write(buffer)\n", - " pbar.update(len(buffer))\n", - " f.close()\n", - "\n", - "\n", - "def sdmdls(ver, Use_Temp_Storage):\n", - "\n", - " if ver=='1.5':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", - " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", - " elif ver=='V2.1-768px':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", - " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", - " elif ver=='v1.5 Inpainting':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", - " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", - " elif ver=='SDXL':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", - " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - "\n", - " if not os.path.exists(model):\n", - " !gdown --fuzzy -O $model $link\n", - " if os.path.exists(model):\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - " else:\n", - " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", - " else:\n", - " clear_output()\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - "\n", - " return model\n", - "\n", - "\n", - "if (PATH_to_MODEL !=''):\n", - " if os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2714 Using the trained model.','success', '200px')\n", - "\n", - " else:\n", - " while not os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", - " PATH_to_MODEL=input()\n", - " if os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2714 Using the custom model.','success', '200px')\n", - "\n", - " model=PATH_to_MODEL\n", - "\n", - "elif MODEL_LINK != \"\":\n", - "\n", - " if src=='civitai':\n", - " modelname=get_name(MODEL_LINK, False)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - " elif src=='gdrive':\n", - " modelname=get_name(MODEL_LINK, True)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - " else:\n", - " modelname=os.path.basename(MODEL_LINK)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '700px')\n", - "\n", - " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", - " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", - " else:\n", - " !rm model\n", - " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", - "\n", - "else:\n", - " model=sdmdls(Model_Version, Use_Temp_Storage)\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "Svx6Hx0iUPd1" - }, - "outputs": [], - "source": [ - "#@markdown # Download LoRA\n", - "\n", - "LoRA_LINK = \"\" #@param {type:\"string\"}\n", - "\n", - "if LoRA_LINK == \"\":\n", - " inf('\\u2714 Nothing to do','primary', '200px')\n", - "else:\n", - " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", - "\n", - " src=getsrc(LoRA_LINK)\n", - "\n", - " if src=='civitai':\n", - " modelname=get_name(LoRA_LINK, False)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - " elif src=='gdrive':\n", - " modelname=get_name(LoRA_LINK, True)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - " else:\n", - " modelname=os.path.basename(LoRA_LINK)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - "\n", - " if os.path.exists(loramodel) :\n", - " inf('\\u2714 LoRA downloaded','success', '200px')\n", - " else:\n", - " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "zC3Rz1b2TBcB" - }, - "outputs": [], - "source": [ - "#@markdown # ControlNet\n", - "from torch.hub import download_url_to_file\n", - "from urllib.parse import urlparse\n", - "import re\n", - "from subprocess import run\n", - "\n", - "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", - "\n", - "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", - "\n", - "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", - "\n", - "#@markdown - Download/update ControlNet extension and its models\n", - "\n", - "def download(url, model_dir):\n", - "\n", - " filename = os.path.basename(urlparse(url).path)\n", - " pth = os.path.abspath(os.path.join(model_dir, filename))\n", - " if not os.path.exists(pth):\n", - " print('Downloading: '+os.path.basename(url))\n", - " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", - " else:\n", - " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", - "\n", - "\n", - "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", - "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", - "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", - "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", - "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", - " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", - " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", - " %cd /content\n", - " else:\n", - " %cd sd-w$blsaphemy-controlnet\n", - " !git reset --hard\n", - " !git pull\n", - " %cd /content\n", - "\n", - "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", - "for filename in os.listdir(mdldir):\n", - " if \"_sd14v1\" in filename:\n", - " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", - " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", - "\n", - "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", - "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", - "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", - "\n", - "\n", - "with open(\"CN_models.txt\", 'r') as f:\n", - " mdllnk = f.read().splitlines()\n", - "with open(\"CN_models_v2.txt\", 'r') as d:\n", - " mdllnk_v2 = d.read().splitlines()\n", - "with open(\"CN_models_XL.txt\", 'r') as d:\n", - " mdllnk_XL = d.read().splitlines()\n", - "\n", - "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", - "\n", - "\n", - "if XL_Model == \"All\":\n", - " for lnk_XL in mdllnk_XL:\n", - " download(lnk_XL, mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "elif XL_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "else:\n", - " download(globals()[XL_Model], mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "\n", - "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", - "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", - "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", - "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", - "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", - "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", - "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", - "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", - "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", - "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", - "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", - "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", - "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", - "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", - " for name in cfgnames:\n", - " run(['cp', 'cldm_v21.yaml', name])\n", - " %cd /content\n", - "\n", - "if v1_Model == \"All (21GB)\":\n", - " for lnk in mdllnk:\n", - " download(lnk, mdldir)\n", - " clear_output()\n", - "\n", - "elif v1_Model == \"T2iadapter_Models\":\n", - " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", - " for lnk in mdllnk:\n", - " download(lnk, mdldir)\n", - " clear_output()\n", - "\n", - "elif v1_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - "\n", - "else:\n", - " download(globals()[v1_Model], mdldir)\n", - " clear_output()\n", - "\n", - "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", - "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", - "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", - "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", - "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", - "\n", - "\n", - "if v2_Model == \"All\":\n", - " for lnk_v2 in mdllnk_v2:\n", - " download(lnk_v2, mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "elif v2_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "else:\n", - " download(globals()[v2_Model], mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - " #@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "PjzwxTkPSPHf" - }, - "outputs": [], - "source": [ - "#@markdown # Start Stable-Diffusion\n", - "from IPython.utils import capture\n", - "import time\n", - "import sys\n", - "import fileinput\n", - "from pyngrok import ngrok, conf\n", - "import re\n", - "\n", - "\n", - "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", - "#@markdown - Offers better gradio responsivity\n", - "\n", - "Ngrok_token = \"\" #@param {type:\"string\"}\n", - "\n", - "#@markdown - Input your ngrok token if you want to use ngrok server\n", - "\n", - "User = \"\" #@param {type:\"string\"}\n", - "Password= \"\" #@param {type:\"string\"}\n", - "#@markdown - Add credentials to your Gradio interface (optional)\n", - "\n", - "auth=f\"--gradio-auth {User}:{Password}\"\n", - "if User ==\"\" or Password==\"\":\n", - " auth=\"\"\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", - " !wget -q -O extras.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", - " !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", - " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", - " \n", - " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", - " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", - " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", - "\n", - " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - "\n", - " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", - " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", - "\n", - "share=''\n", - "if Ngrok_token!=\"\":\n", - " ngrok.kill()\n", - " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", - "\n", - " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", - " if line.strip().startswith('self.server_name ='):\n", - " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", - " if line.strip().startswith('self.protocol = \"https\"'):\n", - " line = ' self.protocol = \"https\"\\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", - " line = ''\n", - " if line.strip().startswith('else \"http\"'):\n", - " line = ''\n", - " sys.stdout.write(line)\n", - "\n", - "elif Use_Cloudflare_Tunnel:\n", - " with capture.capture_output() as cap:\n", - " !pkill cloudflared\n", - " time.sleep(4)\n", - " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", - " time.sleep(4)\n", - " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", - " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", - "\n", - " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", - " if line.strip().startswith('self.server_name ='):\n", - " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", - " if line.strip().startswith('self.protocol = \"https\"'):\n", - " line = ' self.protocol = \"https\"\\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", - " line = ''\n", - " if line.strip().startswith('else \"http\"'):\n", - " line = ''\n", - " sys.stdout.write(line)\n", - "\n", - " !rm /content/srv.txt\n", - "\n", - "else:\n", - " share='--share'\n", - "\n", - "ckptdir=''\n", - "if os.path.exists('/content/temp_models'):\n", - " ckptdir='--ckpt-dir /content/temp_models'\n", - "\n", - "try:\n", - " model\n", - " if os.path.isfile(model):\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", - " else:\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", - "except:\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "provenance": [] - }, - "gpuClass": "standard", - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} From cb6bb8ff7304a91efc20897e3d706a417ab6e185 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:03:48 +0800 Subject: [PATCH 22/34] Add files via upload --- fast_stable_diffusion_Forge.ipynb | 1377 ++++++++++++++------------- fast_stable_diffusion_ReForge.ipynb | 1377 ++++++++++++++------------- 2 files changed, 1378 insertions(+), 1376 deletions(-) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index a0a9e9ed..355747cb 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -1,691 +1,692 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "47kV9o1Ni8GH" - }, - "source": [ - "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "Y9EBc437WDOs" - }, - "outputs": [], - "source": [ - "#@markdown # Connect Google Drive\n", - "from google.colab import drive\n", - "from IPython.display import clear_output\n", - "import ipywidgets as widgets\n", - "import os\n", - "\n", - "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", - "Shared_Drive = \"\" #@param {type:\"string\"}\n", - "#@markdown - Leave empty if you're not using a shared drive\n", - "\n", - "print(\"\u001b[0;33mConnecting...\")\n", - "drive.mount('/content/gdrive')\n", - "\n", - "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", - " mainpth=\"Shareddrives/\"+Shared_Drive\n", - "else:\n", - " mainpth=\"MyDrive\"\n", - "\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "CFWtw-6EPrKi" - }, - "outputs": [], - "source": [ - "#@markdown # Install/Update lllyasviel repo\n", - "from IPython.utils import capture\n", - "from IPython.display import clear_output\n", - "from subprocess import getoutput\n", - "import ipywidgets as widgets\n", - "import sys\n", - "import fileinput\n", - "import os\n", - "import time\n", - "import base64\n", - "import requests\n", - "from urllib.request import urlopen, Request\n", - "from urllib.parse import urlparse, parse_qs, unquote\n", - "from tqdm import tqdm\n", - "import six\n", - "\n", - "\n", - "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", - "\n", - "if not os.path.exists(\"/content/gdrive\"):\n", - " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", - " time.sleep(4)\n", - " mainpth=\"MyDrive\"\n", - " !mkdir -p /content/gdrive/$mainpth\n", - " Shared_Drive=\"\"\n", - "\n", - "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", - " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", - " mainpth=\"MyDrive\"\n", - "\n", - "with capture.capture_output() as cap:\n", - " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", - " fgitclone = \"git clone --depth 1\"\n", - " %mkdir -p /content/gdrive/$mainpth/sd\n", - " %cd /content/gdrive/$mainpth/sd\n", - " !git clone -q --branch master https://github.com/lllyasviel/stable-diffusion-w$blsaphemy\n", - " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", - " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", - " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", - " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", - " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", - " !git reset --hard\n", - " !git checkout master\n", - " time.sleep(1)\n", - " !rm webui.sh\n", - " !git pull\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "ZGV_5H4xrOSp" - }, - "outputs": [], - "source": [ - "#@markdown # Requirements\n", - "\n", - "print('\u001b[1;32mInstalling requirements...')\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/\n", - " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", - " !dpkg -i *.deb\n", - " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", - " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", - " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", - " !rm *.deb | rm *.zst | rm *.txt\n", - " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", - " %env CXXFLAGS=-std=c++14\n", - " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", - " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", - " %cd /content/gperftools\n", - " !patch -p1 < /content/Patch\n", - " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", - " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", - " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", - " %cd /content\n", - " !rm *.tar.gz Patch && rm -r /content/gperftools\n", - " else:\n", - " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", - "\n", - " !pip install controlnet_aux -qq --no-deps\n", - " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", - " os.environ['PYTHONWARNINGS'] = 'ignore'\n", - " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", - " !pip install Pillow==9.5.0\n", - " !pip install protobuf==3.20.3\n", - "\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "p4wj_txjP3TC" - }, - "outputs": [], - "source": [ - "#@markdown # Model Download/Load\n", - "\n", - "import gdown\n", - "from gdown.download import get_url_from_gdrive_confirmation\n", - "import re\n", - "\n", - "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", - "#@markdown - If not, make sure you have enough space on your gdrive\n", - "\n", - "#@markdown ---\n", - "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", - "\n", - "#@markdown Or\n", - "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", - "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", - "\n", - "#@markdown Or\n", - "MODEL_LINK = \"\" #@param {type:\"string\"}\n", - "\n", - "\n", - "def getsrc(url):\n", - " parsed_url = urlparse(url)\n", - " if parsed_url.netloc == 'civitai.com':\n", - " src='civitai'\n", - " elif parsed_url.netloc == 'drive.google.com':\n", - " src='gdrive'\n", - " elif parsed_url.netloc == 'huggingface.co':\n", - " src='huggingface'\n", - " else:\n", - " src='others'\n", - " return src\n", - "\n", - "src=getsrc(MODEL_LINK)\n", - "\n", - "def get_name(url, gdrive):\n", - " if not gdrive:\n", - " response = requests.get(url, allow_redirects=False)\n", - " if \"Location\" in response.headers:\n", - " redirected_url = response.headers[\"Location\"]\n", - " quer = parse_qs(urlparse(redirected_url).query)\n", - " if \"response-content-disposition\" in quer:\n", - " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", - " for vals in disp_val:\n", - " if vals.strip().startswith(\"filename=\"):\n", - " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", - " return filenm.replace(\"\\\"\",\"\")\n", - " else:\n", - " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", - " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", - " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", - " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", - " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", - " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", - " return filenm\n", - "\n", - "\n", - "def dwn(url, dst, msg):\n", - " file_size = None\n", - " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", - " u = urlopen(req)\n", - " meta = u.info()\n", - " if hasattr(meta, 'getheaders'):\n", - " content_length = meta.getheaders(\"Content-Length\")\n", - " else:\n", - " content_length = meta.get_all(\"Content-Length\")\n", - " if content_length is not None and len(content_length) > 0:\n", - " file_size = int(content_length[0])\n", - "\n", - " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", - " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", - " with open(dst, \"wb\") as f:\n", - " while True:\n", - " buffer = u.read(8192)\n", - " if len(buffer) == 0:\n", - " break\n", - " f.write(buffer)\n", - " pbar.update(len(buffer))\n", - " f.close()\n", - "\n", - "\n", - "def sdmdls(ver, Use_Temp_Storage):\n", - "\n", - " if ver=='1.5':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", - " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", - " elif ver=='V2.1-768px':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", - " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", - " elif ver=='v1.5 Inpainting':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", - " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", - " elif ver=='SDXL':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", - " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - "\n", - " if not os.path.exists(model):\n", - " !gdown --fuzzy -O $model $link\n", - " if os.path.exists(model):\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - " else:\n", - " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", - " else:\n", - " clear_output()\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - "\n", - " return model\n", - "\n", - "\n", - "if (PATH_to_MODEL !=''):\n", - " if os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2714 Using the trained model.','success', '200px')\n", - "\n", - " else:\n", - " while not os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", - " PATH_to_MODEL=input()\n", - " if os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2714 Using the custom model.','success', '200px')\n", - "\n", - " model=PATH_to_MODEL\n", - "\n", - "elif MODEL_LINK != \"\":\n", - "\n", - " if src=='civitai':\n", - " modelname=get_name(MODEL_LINK, False)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - " elif src=='gdrive':\n", - " modelname=get_name(MODEL_LINK, True)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - " else:\n", - " modelname=os.path.basename(MODEL_LINK)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '700px')\n", - "\n", - " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", - " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", - " else:\n", - " !rm model\n", - " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", - "\n", - "else:\n", - " model=sdmdls(Model_Version, Use_Temp_Storage)\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "Svx6Hx0iUPd1" - }, - "outputs": [], - "source": [ - "#@markdown # Download LoRA\n", - "\n", - "LoRA_LINK = \"\" #@param {type:\"string\"}\n", - "\n", - "if LoRA_LINK == \"\":\n", - " inf('\\u2714 Nothing to do','primary', '200px')\n", - "else:\n", - " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", - "\n", - " src=getsrc(LoRA_LINK)\n", - "\n", - " if src=='civitai':\n", - " modelname=get_name(LoRA_LINK, False)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - " elif src=='gdrive':\n", - " modelname=get_name(LoRA_LINK, True)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - " else:\n", - " modelname=os.path.basename(LoRA_LINK)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - "\n", - " if os.path.exists(loramodel) :\n", - " inf('\\u2714 LoRA downloaded','success', '200px')\n", - " else:\n", - " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "zC3Rz1b2TBcB" - }, - "outputs": [], - "source": [ - "#@markdown # ControlNet\n", - "from torch.hub import download_url_to_file\n", - "from urllib.parse import urlparse\n", - "import re\n", - "from subprocess import run\n", - "\n", - "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", - "\n", - "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", - "\n", - "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", - "\n", - "#@markdown - Download/update ControlNet extension and its models\n", - "\n", - "def download(url, model_dir):\n", - "\n", - " filename = os.path.basename(urlparse(url).path)\n", - " pth = os.path.abspath(os.path.join(model_dir, filename))\n", - " if not os.path.exists(pth):\n", - " print('Downloading: '+os.path.basename(url))\n", - " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", - " else:\n", - " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", - "\n", - "\n", - "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", - "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", - "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", - "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", - "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", - " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", - " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", - " %cd /content\n", - " else:\n", - " %cd sd-w$blsaphemy-controlnet\n", - " !git reset --hard\n", - " !git pull\n", - " %cd /content\n", - "\n", - "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", - "for filename in os.listdir(mdldir):\n", - " if \"_sd14v1\" in filename:\n", - " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", - " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", - "\n", - "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", - "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", - "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", - "\n", - "\n", - "with open(\"CN_models.txt\", 'r') as f:\n", - " mdllnk = f.read().splitlines()\n", - "with open(\"CN_models_v2.txt\", 'r') as d:\n", - " mdllnk_v2 = d.read().splitlines()\n", - "with open(\"CN_models_XL.txt\", 'r') as d:\n", - " mdllnk_XL = d.read().splitlines()\n", - "\n", - "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", - "\n", - "\n", - "if XL_Model == \"All\":\n", - " for lnk_XL in mdllnk_XL:\n", - " download(lnk_XL, mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "elif XL_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "else:\n", - " download(globals()[XL_Model], mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "\n", - "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", - "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", - "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", - "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", - "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", - "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", - "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", - "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", - "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", - "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", - "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", - "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", - "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", - "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", - " for name in cfgnames:\n", - " run(['cp', 'cldm_v21.yaml', name])\n", - " %cd /content\n", - "\n", - "if v1_Model == \"All (21GB)\":\n", - " for lnk in mdllnk:\n", - " download(lnk, mdldir)\n", - " clear_output()\n", - "\n", - "elif v1_Model == \"T2iadapter_Models\":\n", - " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", - " for lnk in mdllnk:\n", - " download(lnk, mdldir)\n", - " clear_output()\n", - "\n", - "elif v1_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - "\n", - "else:\n", - " download(globals()[v1_Model], mdldir)\n", - " clear_output()\n", - "\n", - "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", - "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", - "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", - "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", - "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", - "\n", - "\n", - "if v2_Model == \"All\":\n", - " for lnk_v2 in mdllnk_v2:\n", - " download(lnk_v2, mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "elif v2_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "else:\n", - " download(globals()[v2_Model], mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - " #@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "PjzwxTkPSPHf" - }, - "outputs": [], - "source": [ - "#@markdown # Start Stable-Diffusion\n", - "from IPython.utils import capture\n", - "import time\n", - "import sys\n", - "import fileinput\n", - "from pyngrok import ngrok, conf\n", - "import re\n", - "\n", - "\n", - "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", - "#@markdown - Offers better gradio responsivity\n", - "\n", - "Ngrok_token = \"\" #@param {type:\"string\"}\n", - "\n", - "#@markdown - Input your ngrok token if you want to use ngrok server\n", - "\n", - "User = \"\" #@param {type:\"string\"}\n", - "Password= \"\" #@param {type:\"string\"}\n", - "#@markdown - Add credentials to your Gradio interface (optional)\n", - "\n", - "auth=f\"--gradio-auth {User}:{Password}\"\n", - "if User ==\"\" or Password==\"\":\n", - " auth=\"\"\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", - " !wget -q -O extras.py https://raw.githubusercontent.com/lllyasviel/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", - " !wget -q -O sd_models.py https://raw.githubusercontent.com/lllyasviel/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", - " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", - " \n", - " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", - " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", - " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", - "\n", - " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - "\n", - " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", - " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", - "\n", - "share=''\n", - "if Ngrok_token!=\"\":\n", - " ngrok.kill()\n", - " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", - "\n", - " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", - " if line.strip().startswith('self.server_name ='):\n", - " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", - " if line.strip().startswith('self.protocol = \"https\"'):\n", - " line = ' self.protocol = \"https\"\\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", - " line = ''\n", - " if line.strip().startswith('else \"http\"'):\n", - " line = ''\n", - " sys.stdout.write(line)\n", - "\n", - "elif Use_Cloudflare_Tunnel:\n", - " with capture.capture_output() as cap:\n", - " !pkill cloudflared\n", - " time.sleep(4)\n", - " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", - " time.sleep(4)\n", - " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", - " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", - "\n", - " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", - " if line.strip().startswith('self.server_name ='):\n", - " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", - " if line.strip().startswith('self.protocol = \"https\"'):\n", - " line = ' self.protocol = \"https\"\\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", - " line = ''\n", - " if line.strip().startswith('else \"http\"'):\n", - " line = ''\n", - " sys.stdout.write(line)\n", - "\n", - " !rm /content/srv.txt\n", - "\n", - "else:\n", - " share='--share'\n", - "\n", - "ckptdir=''\n", - "if os.path.exists('/content/temp_models'):\n", - " ckptdir='--ckpt-dir /content/temp_models'\n", - "\n", - "try:\n", - " model\n", - " if os.path.isfile(model):\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", - " else:\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", - "except:\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "provenance": [] - }, - "gpuClass": "standard", - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "47kV9o1Ni8GH" + }, + "source": [ + "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" + ] }, - "nbformat": 4, - "nbformat_minor": 0 + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Y9EBc437WDOs" + }, + "outputs": [], + "source": [ + "#@markdown # Connect Google Drive\n", + "from google.colab import drive\n", + "from IPython.display import clear_output\n", + "import ipywidgets as widgets\n", + "import os\n", + "\n", + "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + "Shared_Drive = \"\" #@param {type:\"string\"}\n", + "#@markdown - Leave empty if you're not using a shared drive\n", + "\n", + "print(\"\u001b[0;33mConnecting...\")\n", + "drive.mount('/content/gdrive')\n", + "\n", + "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " mainpth=\"Shareddrives/\"+Shared_Drive\n", + "else:\n", + " mainpth=\"MyDrive\"\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "CFWtw-6EPrKi" + }, + "outputs": [], + "source": [ + "#@markdown # Install/Update lllyasviel and AUTOMATIC1111 repos\n", + "from IPython.utils import capture\n", + "from IPython.display import clear_output\n", + "from subprocess import getoutput\n", + "import ipywidgets as widgets\n", + "import sys\n", + "import fileinput\n", + "import os\n", + "import time\n", + "import base64\n", + "import requests\n", + "from urllib.request import urlopen, Request\n", + "from urllib.parse import urlparse, parse_qs, unquote\n", + "from tqdm import tqdm\n", + "import six\n", + "\n", + "\n", + "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", + "\n", + "if not os.path.exists(\"/content/gdrive\"):\n", + " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", + " time.sleep(4)\n", + " mainpth=\"MyDrive\"\n", + " !mkdir -p /content/gdrive/$mainpth\n", + " Shared_Drive=\"\"\n", + "\n", + "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", + " mainpth=\"MyDrive\"\n", + "\n", + "with capture.capture_output() as cap:\n", + " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + " fgitclone = \"git clone --depth 1\"\n", + " %mkdir -p /content/gdrive/$mainpth/sd\n", + " %cd /content/gdrive/$mainpth/sd\n", + " !git clone -q --branch master https://github.com/lllyasviel/stable-diffusion-w$blsaphemy\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", + " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", + " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " !git reset --hard\n", + " !git checkout master\n", + " time.sleep(1)\n", + " !rm webui.sh\n", + " !git pull\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ZGV_5H4xrOSp" + }, + "outputs": [], + "source": [ + "#@markdown # Requirements\n", + "\n", + "print('\u001b[1;32mInstalling requirements...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/\n", + " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", + " !dpkg -i *.deb\n", + " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", + " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", + " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", + " !rm *.deb | rm *.zst | rm *.txt\n", + " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", + " %env CXXFLAGS=-std=c++14\n", + " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", + " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", + " %cd /content/gperftools\n", + " !patch -p1 < /content/Patch\n", + " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", + " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + " %cd /content\n", + " !rm *.tar.gz Patch && rm -r /content/gperftools\n", + " else:\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + "\n", + " !pip install controlnet_aux -qq --no-deps\n", + " !rm -r /usr/local/lib/python3.10/dist-packages/google/_upb\n", + " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", + " os.environ['PYTHONWARNINGS'] = 'ignore'\n", + " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + " !pip install Pillow==9.5.0\n", + " !pip install protobuf==3.20.3\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "p4wj_txjP3TC" + }, + "outputs": [], + "source": [ + "#@markdown # Model Download/Load\n", + "\n", + "import gdown\n", + "from gdown.download import get_url_from_gdrive_confirmation\n", + "import re\n", + "\n", + "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", + "#@markdown - If not, make sure you have enough space on your gdrive\n", + "\n", + "#@markdown ---\n", + "\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", + "\n", + "#@markdown Or\n", + "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", + "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", + "\n", + "#@markdown Or\n", + "MODEL_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "\n", + "def getsrc(url):\n", + " parsed_url = urlparse(url)\n", + " if parsed_url.netloc == 'civitai.com':\n", + " src='civitai'\n", + " elif parsed_url.netloc == 'drive.google.com':\n", + " src='gdrive'\n", + " elif parsed_url.netloc == 'huggingface.co':\n", + " src='huggingface'\n", + " else:\n", + " src='others'\n", + " return src\n", + "\n", + "src=getsrc(MODEL_LINK)\n", + "\n", + "def get_name(url, gdrive):\n", + " if not gdrive:\n", + " response = requests.get(url, allow_redirects=False)\n", + " if \"Location\" in response.headers:\n", + " redirected_url = response.headers[\"Location\"]\n", + " quer = parse_qs(urlparse(redirected_url).query)\n", + " if \"response-content-disposition\" in quer:\n", + " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", + " for vals in disp_val:\n", + " if vals.strip().startswith(\"filename=\"):\n", + " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", + " return filenm.replace(\"\\\"\",\"\")\n", + " else:\n", + " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", + " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", + " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", + " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", + " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", + " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", + " return filenm\n", + "\n", + "\n", + "def dwn(url, dst, msg):\n", + " file_size = None\n", + " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", + " u = urlopen(req)\n", + " meta = u.info()\n", + " if hasattr(meta, 'getheaders'):\n", + " content_length = meta.getheaders(\"Content-Length\")\n", + " else:\n", + " content_length = meta.get_all(\"Content-Length\")\n", + " if content_length is not None and len(content_length) > 0:\n", + " file_size = int(content_length[0])\n", + "\n", + " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", + " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", + " with open(dst, \"wb\") as f:\n", + " while True:\n", + " buffer = u.read(8192)\n", + " if len(buffer) == 0:\n", + " break\n", + " f.write(buffer)\n", + " pbar.update(len(buffer))\n", + " f.close()\n", + "\n", + "\n", + "def sdmdls(ver, Use_Temp_Storage):\n", + "\n", + " if ver=='1.5':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", + " link='https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", + " elif ver=='V2.1-768px':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", + " elif ver=='v1.5 Inpainting':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", + " link='https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", + " elif ver=='SDXL':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", + "\n", + " if not os.path.exists(model):\n", + " !gdown --fuzzy -O $model $link\n", + " if os.path.exists(model):\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + " else:\n", + " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", + " else:\n", + " clear_output()\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + "\n", + " return model\n", + "\n", + "\n", + "if (PATH_to_MODEL !=''):\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the trained model.','success', '200px')\n", + "\n", + " else:\n", + " while not os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", + " PATH_to_MODEL=input()\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the custom model.','success', '200px')\n", + "\n", + " model=PATH_to_MODEL\n", + "\n", + "elif MODEL_LINK != \"\":\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(MODEL_LINK, False)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(MODEL_LINK, True)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " else:\n", + " modelname=os.path.basename(MODEL_LINK)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '700px')\n", + "\n", + " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", + " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", + " else:\n", + " !rm model\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "else:\n", + " model=sdmdls(Model_Version, Use_Temp_Storage)\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Svx6Hx0iUPd1" + }, + "outputs": [], + "source": [ + "#@markdown # Download LoRA\n", + "\n", + "LoRA_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "if LoRA_LINK == \"\":\n", + " inf('\\u2714 Nothing to do','primary', '200px')\n", + "else:\n", + " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", + "\n", + " src=getsrc(LoRA_LINK)\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(LoRA_LINK, False)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(LoRA_LINK, True)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " else:\n", + " modelname=os.path.basename(LoRA_LINK)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + "\n", + " if os.path.exists(loramodel) :\n", + " inf('\\u2714 LoRA downloaded','success', '200px')\n", + " else:\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "zC3Rz1b2TBcB" + }, + "outputs": [], + "source": [ + "#@markdown # ControlNet\n", + "from torch.hub import download_url_to_file\n", + "from urllib.parse import urlparse\n", + "import re\n", + "from subprocess import run\n", + "\n", + "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", + "\n", + "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", + "\n", + "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", + "\n", + "#@markdown - Download/update ControlNet extension and its models\n", + "\n", + "def download(url, model_dir):\n", + "\n", + " filename = os.path.basename(urlparse(url).path)\n", + " pth = os.path.abspath(os.path.join(model_dir, filename))\n", + " if not os.path.exists(pth):\n", + " print('Downloading: '+os.path.basename(url))\n", + " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", + " else:\n", + " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", + "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", + "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", + "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", + "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", + " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", + " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", + " %cd /content\n", + " else:\n", + " %cd sd-w$blsaphemy-controlnet\n", + " !git reset --hard\n", + " !git pull\n", + " %cd /content\n", + "\n", + "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", + "for filename in os.listdir(mdldir):\n", + " if \"_sd14v1\" in filename:\n", + " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", + " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", + "\n", + "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", + "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", + "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", + "\n", + "\n", + "with open(\"CN_models.txt\", 'r') as f:\n", + " mdllnk = f.read().splitlines()\n", + "with open(\"CN_models_v2.txt\", 'r') as d:\n", + " mdllnk_v2 = d.read().splitlines()\n", + "with open(\"CN_models_XL.txt\", 'r') as d:\n", + " mdllnk_XL = d.read().splitlines()\n", + "\n", + "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", + "\n", + "\n", + "if XL_Model == \"All\":\n", + " for lnk_XL in mdllnk_XL:\n", + " download(lnk_XL, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif XL_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[XL_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", + "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", + "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", + "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", + "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", + "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", + "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", + "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", + "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", + "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", + "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", + "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", + "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", + "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", + " for name in cfgnames:\n", + " run(['cp', 'cldm_v21.yaml', name])\n", + " %cd /content\n", + "\n", + "if v1_Model == \"All (21GB)\":\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"T2iadapter_Models\":\n", + " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + "\n", + "else:\n", + " download(globals()[v1_Model], mdldir)\n", + " clear_output()\n", + "\n", + "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", + "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", + "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", + "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", + "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", + "\n", + "\n", + "if v2_Model == \"All\":\n", + " for lnk_v2 in mdllnk_v2:\n", + " download(lnk_v2, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif v2_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[v2_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + " #@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "PjzwxTkPSPHf" + }, + "outputs": [], + "source": [ + "#@markdown # Start Stable-Diffusion\n", + "from IPython.utils import capture\n", + "import time\n", + "import sys\n", + "import fileinput\n", + "from pyngrok import ngrok, conf\n", + "import re\n", + "\n", + "\n", + "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", + "#@markdown - Offers better gradio responsivity\n", + "\n", + "Ngrok_token = \"\" #@param {type:\"string\"}\n", + "\n", + "#@markdown - Input your ngrok token if you want to use ngrok server\n", + "\n", + "User = \"\" #@param {type:\"string\"}\n", + "Password= \"\" #@param {type:\"string\"}\n", + "#@markdown - Add credentials to your Gradio interface (optional)\n", + "\n", + "auth=f\"--gradio-auth {User}:{Password}\"\n", + "if User ==\"\" or Password==\"\":\n", + " auth=\"\"\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", + " !wget -q -O extras.py https://raw.githubusercontent.com/lllyasviel/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", + " !wget -q -O sd_models.py https://raw.githubusercontent.com/lllyasviel/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", + " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " \n", + " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", + " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", + " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", + "\n", + " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + "\n", + " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", + " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", + "\n", + "share=''\n", + "if Ngrok_token!=\"\":\n", + " ngrok.kill()\n", + " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + "elif Use_Cloudflare_Tunnel:\n", + " with capture.capture_output() as cap:\n", + " !pkill cloudflared\n", + " time.sleep(4)\n", + " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", + " time.sleep(4)\n", + " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", + " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + " !rm /content/srv.txt\n", + "\n", + "else:\n", + " share='--share'\n", + "\n", + "ckptdir=''\n", + "if os.path.exists('/content/temp_models'):\n", + " ckptdir='--ckpt-dir /content/temp_models'\n", + "\n", + "try:\n", + " model\n", + " if os.path.isfile(model):\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", + " else:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", + "except:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "provenance": [] + }, + "gpuClass": "standard", + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index 86839b35..f3049e5d 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -1,691 +1,692 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "47kV9o1Ni8GH" - }, - "source": [ - "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "Y9EBc437WDOs" - }, - "outputs": [], - "source": [ - "#@markdown # Connect Google Drive\n", - "from google.colab import drive\n", - "from IPython.display import clear_output\n", - "import ipywidgets as widgets\n", - "import os\n", - "\n", - "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", - "Shared_Drive = \"\" #@param {type:\"string\"}\n", - "#@markdown - Leave empty if you're not using a shared drive\n", - "\n", - "print(\"\u001b[0;33mConnecting...\")\n", - "drive.mount('/content/gdrive')\n", - "\n", - "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", - " mainpth=\"Shareddrives/\"+Shared_Drive\n", - "else:\n", - " mainpth=\"MyDrive\"\n", - "\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "CFWtw-6EPrKi" - }, - "outputs": [], - "source": [ - "#@markdown # Install/Update Panchovix repo\n", - "from IPython.utils import capture\n", - "from IPython.display import clear_output\n", - "from subprocess import getoutput\n", - "import ipywidgets as widgets\n", - "import sys\n", - "import fileinput\n", - "import os\n", - "import time\n", - "import base64\n", - "import requests\n", - "from urllib.request import urlopen, Request\n", - "from urllib.parse import urlparse, parse_qs, unquote\n", - "from tqdm import tqdm\n", - "import six\n", - "\n", - "\n", - "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", - "\n", - "if not os.path.exists(\"/content/gdrive\"):\n", - " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", - " time.sleep(4)\n", - " mainpth=\"MyDrive\"\n", - " !mkdir -p /content/gdrive/$mainpth\n", - " Shared_Drive=\"\"\n", - "\n", - "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", - " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", - " mainpth=\"MyDrive\"\n", - "\n", - "with capture.capture_output() as cap:\n", - " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", - " fgitclone = \"git clone --depth 1\"\n", - " %mkdir -p /content/gdrive/$mainpth/sd\n", - " %cd /content/gdrive/$mainpth/sd\n", - " !git clone -q --branch master https://github.com/Panchovix/stable-diffusion-w$blsaphemy\n", - " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", - " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", - " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", - " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", - " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", - " !git reset --hard\n", - " !git checkout master\n", - " time.sleep(1)\n", - " !rm webui.sh\n", - " !git pull\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "ZGV_5H4xrOSp" - }, - "outputs": [], - "source": [ - "#@markdown # Requirements\n", - "\n", - "print('\u001b[1;32mInstalling requirements...')\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/\n", - " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", - " !dpkg -i *.deb\n", - " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", - " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", - " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", - " !rm *.deb | rm *.zst | rm *.txt\n", - " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", - " %env CXXFLAGS=-std=c++14\n", - " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", - " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", - " %cd /content/gperftools\n", - " !patch -p1 < /content/Patch\n", - " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", - " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", - " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", - " %cd /content\n", - " !rm *.tar.gz Patch && rm -r /content/gperftools\n", - " else:\n", - " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", - "\n", - " !pip install controlnet_aux -qq --no-deps\n", - " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", - " os.environ['PYTHONWARNINGS'] = 'ignore'\n", - " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", - " !pip install Pillow==9.5.0\n", - " !pip install protobuf==3.20.3\n", - "\n", - "clear_output()\n", - "inf('\\u2714 Done','success', '50px')\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "p4wj_txjP3TC" - }, - "outputs": [], - "source": [ - "#@markdown # Model Download/Load\n", - "\n", - "import gdown\n", - "from gdown.download import get_url_from_gdrive_confirmation\n", - "import re\n", - "\n", - "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", - "#@markdown - If not, make sure you have enough space on your gdrive\n", - "\n", - "#@markdown ---\n", - "\n", - "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", - "\n", - "#@markdown Or\n", - "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", - "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", - "\n", - "#@markdown Or\n", - "MODEL_LINK = \"\" #@param {type:\"string\"}\n", - "\n", - "\n", - "def getsrc(url):\n", - " parsed_url = urlparse(url)\n", - " if parsed_url.netloc == 'civitai.com':\n", - " src='civitai'\n", - " elif parsed_url.netloc == 'drive.google.com':\n", - " src='gdrive'\n", - " elif parsed_url.netloc == 'huggingface.co':\n", - " src='huggingface'\n", - " else:\n", - " src='others'\n", - " return src\n", - "\n", - "src=getsrc(MODEL_LINK)\n", - "\n", - "def get_name(url, gdrive):\n", - " if not gdrive:\n", - " response = requests.get(url, allow_redirects=False)\n", - " if \"Location\" in response.headers:\n", - " redirected_url = response.headers[\"Location\"]\n", - " quer = parse_qs(urlparse(redirected_url).query)\n", - " if \"response-content-disposition\" in quer:\n", - " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", - " for vals in disp_val:\n", - " if vals.strip().startswith(\"filename=\"):\n", - " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", - " return filenm.replace(\"\\\"\",\"\")\n", - " else:\n", - " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", - " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", - " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", - " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", - " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", - " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", - " return filenm\n", - "\n", - "\n", - "def dwn(url, dst, msg):\n", - " file_size = None\n", - " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", - " u = urlopen(req)\n", - " meta = u.info()\n", - " if hasattr(meta, 'getheaders'):\n", - " content_length = meta.getheaders(\"Content-Length\")\n", - " else:\n", - " content_length = meta.get_all(\"Content-Length\")\n", - " if content_length is not None and len(content_length) > 0:\n", - " file_size = int(content_length[0])\n", - "\n", - " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", - " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", - " with open(dst, \"wb\") as f:\n", - " while True:\n", - " buffer = u.read(8192)\n", - " if len(buffer) == 0:\n", - " break\n", - " f.write(buffer)\n", - " pbar.update(len(buffer))\n", - " f.close()\n", - "\n", - "\n", - "def sdmdls(ver, Use_Temp_Storage):\n", - "\n", - " if ver=='1.5':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", - " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", - " elif ver=='V2.1-768px':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", - " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", - " elif ver=='v1.5 Inpainting':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", - " link='https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", - " elif ver=='SDXL':\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", - " else:\n", - " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", - " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", - "\n", - " if not os.path.exists(model):\n", - " !gdown --fuzzy -O $model $link\n", - " if os.path.exists(model):\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - " else:\n", - " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", - " else:\n", - " clear_output()\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - "\n", - " return model\n", - "\n", - "\n", - "if (PATH_to_MODEL !=''):\n", - " if os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2714 Using the trained model.','success', '200px')\n", - "\n", - " else:\n", - " while not os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", - " PATH_to_MODEL=input()\n", - " if os.path.exists(str(PATH_to_MODEL)):\n", - " inf('\\u2714 Using the custom model.','success', '200px')\n", - "\n", - " model=PATH_to_MODEL\n", - "\n", - "elif MODEL_LINK != \"\":\n", - "\n", - " if src=='civitai':\n", - " modelname=get_name(MODEL_LINK, False)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - " elif src=='gdrive':\n", - " modelname=get_name(MODEL_LINK, True)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '300px')\n", - " else:\n", - " modelname=os.path.basename(MODEL_LINK)\n", - " if Use_Temp_Storage:\n", - " os.makedirs('/content/temp_models', exist_ok=True)\n", - " model=f'/content/temp_models/{modelname}'\n", - " else:\n", - " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", - " if not os.path.exists(model):\n", - " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '700px')\n", - "\n", - " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", - " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", - " else:\n", - " !rm model\n", - " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", - "\n", - "else:\n", - " model=sdmdls(Model_Version, Use_Temp_Storage)\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "Svx6Hx0iUPd1" - }, - "outputs": [], - "source": [ - "#@markdown # Download LoRA\n", - "\n", - "LoRA_LINK = \"\" #@param {type:\"string\"}\n", - "\n", - "if LoRA_LINK == \"\":\n", - " inf('\\u2714 Nothing to do','primary', '200px')\n", - "else:\n", - " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", - "\n", - " src=getsrc(LoRA_LINK)\n", - "\n", - " if src=='civitai':\n", - " modelname=get_name(LoRA_LINK, False)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - " elif src=='gdrive':\n", - " modelname=get_name(LoRA_LINK, True)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - " else:\n", - " modelname=os.path.basename(LoRA_LINK)\n", - " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", - " if not os.path.exists(loramodel):\n", - " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", - " clear_output()\n", - " else:\n", - " inf('\\u2714 Model already exists','primary', '200px')\n", - "\n", - " if os.path.exists(loramodel) :\n", - " inf('\\u2714 LoRA downloaded','success', '200px')\n", - " else:\n", - " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", - "\n", - "#@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "zC3Rz1b2TBcB" - }, - "outputs": [], - "source": [ - "#@markdown # ControlNet\n", - "from torch.hub import download_url_to_file\n", - "from urllib.parse import urlparse\n", - "import re\n", - "from subprocess import run\n", - "\n", - "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", - "\n", - "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", - "\n", - "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", - "\n", - "#@markdown - Download/update ControlNet extension and its models\n", - "\n", - "def download(url, model_dir):\n", - "\n", - " filename = os.path.basename(urlparse(url).path)\n", - " pth = os.path.abspath(os.path.join(model_dir, filename))\n", - " if not os.path.exists(pth):\n", - " print('Downloading: '+os.path.basename(url))\n", - " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", - " else:\n", - " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", - "\n", - "\n", - "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", - "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", - "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", - "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", - "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", - " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", - " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", - " %cd /content\n", - " else:\n", - " %cd sd-w$blsaphemy-controlnet\n", - " !git reset --hard\n", - " !git pull\n", - " %cd /content\n", - "\n", - "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", - "for filename in os.listdir(mdldir):\n", - " if \"_sd14v1\" in filename:\n", - " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", - " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", - "\n", - "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", - "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", - "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", - "\n", - "\n", - "with open(\"CN_models.txt\", 'r') as f:\n", - " mdllnk = f.read().splitlines()\n", - "with open(\"CN_models_v2.txt\", 'r') as d:\n", - " mdllnk_v2 = d.read().splitlines()\n", - "with open(\"CN_models_XL.txt\", 'r') as d:\n", - " mdllnk_XL = d.read().splitlines()\n", - "\n", - "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", - "\n", - "\n", - "if XL_Model == \"All\":\n", - " for lnk_XL in mdllnk_XL:\n", - " download(lnk_XL, mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "elif XL_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "else:\n", - " download(globals()[XL_Model], mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "\n", - "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", - "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", - "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", - "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", - "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", - "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", - "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", - "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", - "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", - "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", - "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", - "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", - "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", - "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", - " for name in cfgnames:\n", - " run(['cp', 'cldm_v21.yaml', name])\n", - " %cd /content\n", - "\n", - "if v1_Model == \"All (21GB)\":\n", - " for lnk in mdllnk:\n", - " download(lnk, mdldir)\n", - " clear_output()\n", - "\n", - "elif v1_Model == \"T2iadapter_Models\":\n", - " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", - " for lnk in mdllnk:\n", - " download(lnk, mdldir)\n", - " clear_output()\n", - "\n", - "elif v1_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - "\n", - "else:\n", - " download(globals()[v1_Model], mdldir)\n", - " clear_output()\n", - "\n", - "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", - "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", - "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", - "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", - "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", - "\n", - "\n", - "if v2_Model == \"All\":\n", - " for lnk_v2 in mdllnk_v2:\n", - " download(lnk_v2, mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "elif v2_Model == \"None\":\n", - " pass\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - "else:\n", - " download(globals()[v2_Model], mdldir)\n", - " clear_output()\n", - " inf('\\u2714 Done','success', '50px')\n", - "\n", - " #@markdown ---" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "PjzwxTkPSPHf" - }, - "outputs": [], - "source": [ - "#@markdown # Start Stable-Diffusion\n", - "from IPython.utils import capture\n", - "import time\n", - "import sys\n", - "import fileinput\n", - "from pyngrok import ngrok, conf\n", - "import re\n", - "\n", - "\n", - "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", - "#@markdown - Offers better gradio responsivity\n", - "\n", - "Ngrok_token = \"\" #@param {type:\"string\"}\n", - "\n", - "#@markdown - Input your ngrok token if you want to use ngrok server\n", - "\n", - "User = \"\" #@param {type:\"string\"}\n", - "Password= \"\" #@param {type:\"string\"}\n", - "#@markdown - Add credentials to your Gradio interface (optional)\n", - "\n", - "auth=f\"--gradio-auth {User}:{Password}\"\n", - "if User ==\"\" or Password==\"\":\n", - " auth=\"\"\n", - "\n", - "\n", - "with capture.capture_output() as cap:\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", - " !wget -q -O extras.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", - " !wget -q -O sd_models.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", - " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", - " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", - " \n", - " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", - " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", - " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", - "\n", - " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", - "\n", - " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", - " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", - "\n", - "share=''\n", - "if Ngrok_token!=\"\":\n", - " ngrok.kill()\n", - " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", - "\n", - " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", - " if line.strip().startswith('self.server_name ='):\n", - " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", - " if line.strip().startswith('self.protocol = \"https\"'):\n", - " line = ' self.protocol = \"https\"\\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", - " line = ''\n", - " if line.strip().startswith('else \"http\"'):\n", - " line = ''\n", - " sys.stdout.write(line)\n", - "\n", - "elif Use_Cloudflare_Tunnel:\n", - " with capture.capture_output() as cap:\n", - " !pkill cloudflared\n", - " time.sleep(4)\n", - " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", - " time.sleep(4)\n", - " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", - " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", - "\n", - " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", - " if line.strip().startswith('self.server_name ='):\n", - " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", - " if line.strip().startswith('self.protocol = \"https\"'):\n", - " line = ' self.protocol = \"https\"\\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", - " line = ''\n", - " if line.strip().startswith('else \"http\"'):\n", - " line = ''\n", - " sys.stdout.write(line)\n", - "\n", - " !rm /content/srv.txt\n", - "\n", - "else:\n", - " share='--share'\n", - "\n", - "ckptdir=''\n", - "if os.path.exists('/content/temp_models'):\n", - " ckptdir='--ckpt-dir /content/temp_models'\n", - "\n", - "try:\n", - " model\n", - " if os.path.isfile(model):\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", - " else:\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", - "except:\n", - " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "provenance": [] - }, - "gpuClass": "standard", - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "47kV9o1Ni8GH" + }, + "source": [ + "# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*" + ] }, - "nbformat": 4, - "nbformat_minor": 0 + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Y9EBc437WDOs" + }, + "outputs": [], + "source": [ + "#@markdown # Connect Google Drive\n", + "from google.colab import drive\n", + "from IPython.display import clear_output\n", + "import ipywidgets as widgets\n", + "import os\n", + "\n", + "def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + "Shared_Drive = \"\" #@param {type:\"string\"}\n", + "#@markdown - Leave empty if you're not using a shared drive\n", + "\n", + "print(\"\u001b[0;33mConnecting...\")\n", + "drive.mount('/content/gdrive')\n", + "\n", + "if Shared_Drive!=\"\" and os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " mainpth=\"Shareddrives/\"+Shared_Drive\n", + "else:\n", + " mainpth=\"MyDrive\"\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "CFWtw-6EPrKi" + }, + "outputs": [], + "source": [ + "#@markdown # Install/Update Panchovix and AUTOMATIC1111 repos\n", + "from IPython.utils import capture\n", + "from IPython.display import clear_output\n", + "from subprocess import getoutput\n", + "import ipywidgets as widgets\n", + "import sys\n", + "import fileinput\n", + "import os\n", + "import time\n", + "import base64\n", + "import requests\n", + "from urllib.request import urlopen, Request\n", + "from urllib.parse import urlparse, parse_qs, unquote\n", + "from tqdm import tqdm\n", + "import six\n", + "\n", + "\n", + "blsaphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n", + "\n", + "if not os.path.exists(\"/content/gdrive\"):\n", + " print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n", + " time.sleep(4)\n", + " mainpth=\"MyDrive\"\n", + " !mkdir -p /content/gdrive/$mainpth\n", + " Shared_Drive=\"\"\n", + "\n", + "if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n", + " print('\u001b[1;31mShared drive not detected, using default MyDrive')\n", + " mainpth=\"MyDrive\"\n", + "\n", + "with capture.capture_output() as cap:\n", + " def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n", + " fgitclone = \"git clone --depth 1\"\n", + " %mkdir -p /content/gdrive/$mainpth/sd\n", + " %cd /content/gdrive/$mainpth/sd\n", + " !git clone -q --branch master https://github.com/Panchovix/stable-diffusion-w$blsaphemy\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/cache/\n", + " os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blsaphemy+\"/cache\"\n", + " !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories\n", + " !git clone https://github.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy-assets /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/repositories/stable-diffusion-webui-assets\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " !git reset --hard\n", + " !git checkout master\n", + " time.sleep(1)\n", + " !rm webui.sh\n", + " !git pull\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ZGV_5H4xrOSp" + }, + "outputs": [], + "source": [ + "#@markdown # Requirements\n", + "\n", + "print('\u001b[1;32mInstalling requirements...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/\n", + " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", + " !dpkg -i *.deb\n", + " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", + " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", + " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", + " !rm *.deb | rm *.zst | rm *.txt\n", + " if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", + " %env CXXFLAGS=-std=c++14\n", + " !wget -q https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz && tar zxf gperftools-2.5.tar.gz && mv gperftools-2.5 gperftools\n", + " !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n", + " %cd /content/gperftools\n", + " !patch -p1 < /content/Patch\n", + " !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n", + " !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + " %cd /content\n", + " !rm *.tar.gz Patch && rm -r /content/gperftools\n", + " else:\n", + " %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n", + "\n", + " !pip install controlnet_aux -qq --no-deps\n", + " !rm -r /usr/local/lib/python3.10/dist-packages/google/_upb\n", + " os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n", + " os.environ['PYTHONWARNINGS'] = 'ignore'\n", + " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", + " !pip install Pillow==9.5.0\n", + " !pip install protobuf==3.20.3\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "p4wj_txjP3TC" + }, + "outputs": [], + "source": [ + "#@markdown # Model Download/Load\n", + "\n", + "import gdown\n", + "from gdown.download import get_url_from_gdrive_confirmation\n", + "import re\n", + "\n", + "Use_Temp_Storage = False #@param {type:\"boolean\"}\n", + "#@markdown - If not, make sure you have enough space on your gdrive\n", + "\n", + "#@markdown ---\n", + "\n", + "Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n", + "\n", + "#@markdown Or\n", + "PATH_to_MODEL = \"\" #@param {type:\"string\"}\n", + "#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n", + "\n", + "#@markdown Or\n", + "MODEL_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "\n", + "def getsrc(url):\n", + " parsed_url = urlparse(url)\n", + " if parsed_url.netloc == 'civitai.com':\n", + " src='civitai'\n", + " elif parsed_url.netloc == 'drive.google.com':\n", + " src='gdrive'\n", + " elif parsed_url.netloc == 'huggingface.co':\n", + " src='huggingface'\n", + " else:\n", + " src='others'\n", + " return src\n", + "\n", + "src=getsrc(MODEL_LINK)\n", + "\n", + "def get_name(url, gdrive):\n", + " if not gdrive:\n", + " response = requests.get(url, allow_redirects=False)\n", + " if \"Location\" in response.headers:\n", + " redirected_url = response.headers[\"Location\"]\n", + " quer = parse_qs(urlparse(redirected_url).query)\n", + " if \"response-content-disposition\" in quer:\n", + " disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n", + " for vals in disp_val:\n", + " if vals.strip().startswith(\"filename=\"):\n", + " filenm=unquote(vals.split(\"=\", 1)[1].strip())\n", + " return filenm.replace(\"\\\"\",\"\")\n", + " else:\n", + " headers = {\"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"}\n", + " lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n", + " res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n", + " res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n", + " content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n", + " filenm = re.search('attachment; filename=\"(.*?)\"', content_disposition).groups()[0]\n", + " return filenm\n", + "\n", + "\n", + "def dwn(url, dst, msg):\n", + " file_size = None\n", + " req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n", + " u = urlopen(req)\n", + " meta = u.info()\n", + " if hasattr(meta, 'getheaders'):\n", + " content_length = meta.getheaders(\"Content-Length\")\n", + " else:\n", + " content_length = meta.get_all(\"Content-Length\")\n", + " if content_length is not None and len(content_length) > 0:\n", + " file_size = int(content_length[0])\n", + "\n", + " with tqdm(total=file_size, disable=False, mininterval=0.5,\n", + " bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n", + " with open(dst, \"wb\") as f:\n", + " while True:\n", + " buffer = u.read(8192)\n", + " if len(buffer) == 0:\n", + " break\n", + " f.write(buffer)\n", + " pbar.update(len(buffer))\n", + " f.close()\n", + "\n", + "\n", + "def sdmdls(ver, Use_Temp_Storage):\n", + "\n", + " if ver=='1.5':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n", + " link='https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n", + " elif ver=='V2.1-768px':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n", + " elif ver=='v1.5 Inpainting':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n", + " link='https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n", + " elif ver=='SDXL':\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model='/content/temp_models/sd_xl_base_1.0.safetensors'\n", + " else:\n", + " model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n", + " link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n", + "\n", + " if not os.path.exists(model):\n", + " !gdown --fuzzy -O $model $link\n", + " if os.path.exists(model):\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + " else:\n", + " inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n", + " else:\n", + " clear_output()\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + "\n", + " return model\n", + "\n", + "\n", + "if (PATH_to_MODEL !=''):\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the trained model.','success', '200px')\n", + "\n", + " else:\n", + " while not os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n", + " PATH_to_MODEL=input()\n", + " if os.path.exists(str(PATH_to_MODEL)):\n", + " inf('\\u2714 Using the custom model.','success', '200px')\n", + "\n", + " model=PATH_to_MODEL\n", + "\n", + "elif MODEL_LINK != \"\":\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(MODEL_LINK, False)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " dwn(MODEL_LINK, model, 'Downloading the custom model')\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(MODEL_LINK, True)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '300px')\n", + " else:\n", + " modelname=os.path.basename(MODEL_LINK)\n", + " if Use_Temp_Storage:\n", + " os.makedirs('/content/temp_models', exist_ok=True)\n", + " model=f'/content/temp_models/{modelname}'\n", + " else:\n", + " model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Stable-diffusion/{modelname}'\n", + " if not os.path.exists(model):\n", + " gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '700px')\n", + "\n", + " if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n", + " inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n", + " else:\n", + " !rm model\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "else:\n", + " model=sdmdls(Model_Version, Use_Temp_Storage)\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "Svx6Hx0iUPd1" + }, + "outputs": [], + "source": [ + "#@markdown # Download LoRA\n", + "\n", + "LoRA_LINK = \"\" #@param {type:\"string\"}\n", + "\n", + "if LoRA_LINK == \"\":\n", + " inf('\\u2714 Nothing to do','primary', '200px')\n", + "else:\n", + " os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/models/Lora', exist_ok=True)\n", + "\n", + " src=getsrc(LoRA_LINK)\n", + "\n", + " if src=='civitai':\n", + " modelname=get_name(LoRA_LINK, False)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " elif src=='gdrive':\n", + " modelname=get_name(LoRA_LINK, True)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + " else:\n", + " modelname=os.path.basename(LoRA_LINK)\n", + " loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blsaphemy}/models/Lora/{modelname}'\n", + " if not os.path.exists(loramodel):\n", + " gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n", + " clear_output()\n", + " else:\n", + " inf('\\u2714 Model already exists','primary', '200px')\n", + "\n", + " if os.path.exists(loramodel) :\n", + " inf('\\u2714 LoRA downloaded','success', '200px')\n", + " else:\n", + " inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n", + "\n", + "#@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "zC3Rz1b2TBcB" + }, + "outputs": [], + "source": [ + "#@markdown # ControlNet\n", + "from torch.hub import download_url_to_file\n", + "from urllib.parse import urlparse\n", + "import re\n", + "from subprocess import run\n", + "\n", + "XL_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"Sketch\", \"OpenPose\", \"Recolor\"]\n", + "\n", + "v1_Model = \"None\" #@param [ \"None\", \"All (21GB)\", \"Canny\", \"Depth\", \"Lineart\", \"MLSD\", \"Normal\", \"OpenPose\", \"Scribble\", \"Seg\", \"ip2p\", \"Shuffle\", \"Inpaint\", \"Softedge\", \"Lineart_Anime\", \"Tile\", \"T2iadapter_Models\"]\n", + "\n", + "v2_Model = \"None\" #@param [ \"None\", \"All\", \"Canny\", \"Depth\", \"HED\", \"OpenPose\", \"Scribble\"]\n", + "\n", + "#@markdown - Download/update ControlNet extension and its models\n", + "\n", + "def download(url, model_dir):\n", + "\n", + " filename = os.path.basename(urlparse(url).path)\n", + " pth = os.path.abspath(os.path.join(model_dir, filename))\n", + " if not os.path.exists(pth):\n", + " print('Downloading: '+os.path.basename(url))\n", + " download_url_to_file(url, pth, hash_prefix=None, progress=True)\n", + " else:\n", + " print(f\"\u001b[1;32mThe model {filename} already exists\u001b[0m\")\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_mid.safetensors'\n", + "Depth='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_mid.safetensors'\n", + "Sketch='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors'\n", + "OpenPose='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose_256lora.safetensors'\n", + "Recolor='https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_128lora.safetensors'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions\n", + " if not os.path.exists('sd-w'+blsaphemy+'-controlnet'):\n", + " !git clone https://github.com/Mikubill/sd-w$blsaphemy-controlnet.git\n", + " %cd /content\n", + " else:\n", + " %cd sd-w$blsaphemy-controlnet\n", + " !git reset --hard\n", + " !git pull\n", + " %cd /content\n", + "\n", + "mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blsaphemy+'/extensions/sd-w'+blsaphemy+'-controlnet/models'\n", + "for filename in os.listdir(mdldir):\n", + " if \"_sd14v1\" in filename:\n", + " renamed = re.sub(\"_sd14v1\", \"-fp16\", filename)\n", + " os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))\n", + "\n", + "!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt\n", + "!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt\n", + "!wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt\n", + "\n", + "\n", + "with open(\"CN_models.txt\", 'r') as f:\n", + " mdllnk = f.read().splitlines()\n", + "with open(\"CN_models_v2.txt\", 'r') as d:\n", + " mdllnk_v2 = d.read().splitlines()\n", + "with open(\"CN_models_XL.txt\", 'r') as d:\n", + " mdllnk_XL = d.read().splitlines()\n", + "\n", + "!rm CN_models.txt CN_models_v2.txt CN_models_XL.txt\n", + "\n", + "\n", + "if XL_Model == \"All\":\n", + " for lnk_XL in mdllnk_XL:\n", + " download(lnk_XL, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif XL_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[XL_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "\n", + "Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'\n", + "Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'\n", + "Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'\n", + "MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'\n", + "Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'\n", + "OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'\n", + "Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'\n", + "Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'\n", + "ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'\n", + "Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'\n", + "Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'\n", + "Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'\n", + "Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'\n", + "Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/extensions/sd-w$blsaphemy-controlnet/models\n", + " for name in cfgnames:\n", + " run(['cp', 'cldm_v21.yaml', name])\n", + " %cd /content\n", + "\n", + "if v1_Model == \"All (21GB)\":\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"T2iadapter_Models\":\n", + " mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))\n", + " for lnk in mdllnk:\n", + " download(lnk, mdldir)\n", + " clear_output()\n", + "\n", + "elif v1_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + "\n", + "else:\n", + " download(globals()[v1_Model], mdldir)\n", + " clear_output()\n", + "\n", + "Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'\n", + "Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'\n", + "HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'\n", + "OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'\n", + "Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'\n", + "\n", + "\n", + "if v2_Model == \"All\":\n", + " for lnk_v2 in mdllnk_v2:\n", + " download(lnk_v2, mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "elif v2_Model == \"None\":\n", + " pass\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + "else:\n", + " download(globals()[v2_Model], mdldir)\n", + " clear_output()\n", + " inf('\\u2714 Done','success', '50px')\n", + "\n", + " #@markdown ---" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "PjzwxTkPSPHf" + }, + "outputs": [], + "source": [ + "#@markdown # Start Stable-Diffusion\n", + "from IPython.utils import capture\n", + "import time\n", + "import sys\n", + "import fileinput\n", + "from pyngrok import ngrok, conf\n", + "import re\n", + "\n", + "\n", + "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", + "#@markdown - Offers better gradio responsivity\n", + "\n", + "Ngrok_token = \"\" #@param {type:\"string\"}\n", + "\n", + "#@markdown - Input your ngrok token if you want to use ngrok server\n", + "\n", + "User = \"\" #@param {type:\"string\"}\n", + "Password= \"\" #@param {type:\"string\"}\n", + "#@markdown - Add credentials to your Gradio interface (optional)\n", + "\n", + "auth=f\"--gradio-auth {User}:{Password}\"\n", + "if User ==\"\" or Password==\"\":\n", + " auth=\"\"\n", + "\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", + " !wget -q -O extras.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", + " !wget -q -O sd_models.py https://raw.githubusercontent.com/Panchovix/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", + " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", + " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", + " \n", + " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", + " #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", + " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", + "\n", + " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", + "\n", + " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", + " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", + "\n", + "share=''\n", + "if Ngrok_token!=\"\":\n", + " ngrok.kill()\n", + " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + "elif Use_Cloudflare_Tunnel:\n", + " with capture.capture_output() as cap:\n", + " !pkill cloudflared\n", + " time.sleep(4)\n", + " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", + " time.sleep(4)\n", + " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", + " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", + "\n", + " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", + " if line.strip().startswith('self.protocol = \"https\"'):\n", + " line = ' self.protocol = \"https\"\\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", + " line = ''\n", + " if line.strip().startswith('else \"http\"'):\n", + " line = ''\n", + " sys.stdout.write(line)\n", + "\n", + " !rm /content/srv.txt\n", + "\n", + "else:\n", + " share='--share'\n", + "\n", + "ckptdir=''\n", + "if os.path.exists('/content/temp_models'):\n", + " ckptdir='--ckpt-dir /content/temp_models'\n", + "\n", + "try:\n", + " model\n", + " if os.path.isfile(model):\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir\n", + " else:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --skip-version-check\n", + "except:\n", + " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --skip-version-check $ckptdir" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "provenance": [] + }, + "gpuClass": "standard", + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } From b11f8ecf459c7814d56c0e6ee58ad01eef2d9779 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:48:40 +0800 Subject: [PATCH 23/34] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 08394dd5..216ab15c 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -148,6 +148,7 @@ " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", " !pip install protobuf==3.20.3\n", + " !pip install --upgrade torch tensorboard\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From b5821b135747014ca86984a75d4c6153e7098b34 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:48:58 +0800 Subject: [PATCH 24/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index 355747cb..56593a91 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -148,6 +148,7 @@ " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", " !pip install protobuf==3.20.3\n", + " !pip install --upgrade torch tensorboard\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From 5b8cdb8276512699271c13d540123dbeb9c1c870 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:49:15 +0800 Subject: [PATCH 25/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index f3049e5d..55913b12 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -148,6 +148,7 @@ " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", " !pip install protobuf==3.20.3\n", + " !pip install --upgrade torch tensorboard\n", "\n", "clear_output()\n", "inf('\\u2714 Done','success', '50px')\n", From 8ac5c1e5d2ed35c4443a5163c16ffd0b10cab030 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Sun, 22 Dec 2024 19:25:25 +0800 Subject: [PATCH 26/34] Update fast_stable_diffusion_AUTOMATIC1111.ipynb --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 216ab15c..17327e87 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -148,6 +148,7 @@ " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", " !pip install protobuf==3.20.3\n", + " !pip install wandb==0.15.12\n", " !pip install --upgrade torch tensorboard\n", "\n", "clear_output()\n", From 9f31d3501b65b8e0a03dbc848bf5da023445c0fb Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Sun, 22 Dec 2024 19:25:48 +0800 Subject: [PATCH 27/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index 56593a91..ef4f80b7 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -148,6 +148,7 @@ " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", " !pip install protobuf==3.20.3\n", + " !pip install wandb==0.15.12\n", " !pip install --upgrade torch tensorboard\n", "\n", "clear_output()\n", From 6a0aa461f859feb4eaf8db93b4374c80482b83f1 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Sun, 22 Dec 2024 19:26:03 +0800 Subject: [PATCH 28/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index 55913b12..f61209ce 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -148,6 +148,7 @@ " !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n", " !pip install Pillow==9.5.0\n", " !pip install protobuf==3.20.3\n", + " !pip install wandb==0.15.12\n", " !pip install --upgrade torch tensorboard\n", "\n", "clear_output()\n", From 1049a27ccf662b0bde56d6e724b974adc90f116c Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Mon, 30 Dec 2024 18:02:13 +0800 Subject: [PATCH 29/34] Update fast-DreamBooth.ipynb --- fast-DreamBooth.ipynb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fast-DreamBooth.ipynb b/fast-DreamBooth.ipynb index 9c80180a..4e6062be 100644 --- a/fast-DreamBooth.ipynb +++ b/fast-DreamBooth.ipynb @@ -49,6 +49,11 @@ " !git clone -q --depth 1 --branch main https://github.com/TheLastBen/diffusers\n", " !pip install gradio==3.16.2 --no-deps -qq\n", " !rm -r /usr/local/lib/python3.10/dist-packages/google/_upb\n", + " !pip install --upgrade torch tensorboard\n", + " !pip uninstall protobuf -y\n", + " !pip install protobuf==3.20.3\n", + " !pip uninstall wandb -y\n", + " !pip install wandb==0.15.12\n", "\n", " if not os.path.exists('gdrive/MyDrive/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n", " %env CXXFLAGS=-std=c++14\n", From b7913263bc23b961f286f98bd797ed0a3770ea02 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Mon, 30 Dec 2024 20:55:40 +0800 Subject: [PATCH 30/34] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd07df31..fd5080eb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Shoutout to for sponsoring the project -# fast-stable-diffusion Notebooks, A1111 + ComfyUI + DreamBooth -Paperspace adaptations AUTOMATIC1111 Webui, ComfyUI and Dreambooth. +# fast-stable-diffusion Notebooks, A1111 + Forge + ReForge + ComfyUI + DreamBooth +Paperspace adaptations AUTOMATIC1111 Webui(Original A111, Forge and ReForge), ComfyUI and Dreambooth.
                                                                               Paperspace From 869bc4744eb5875d920e16e63862b913d2fead81 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Mon, 30 Dec 2024 20:56:20 +0800 Subject: [PATCH 31/34] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd5080eb..f8ba6bd6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Shoutout to for sponsoring the project # fast-stable-diffusion Notebooks, A1111 + Forge + ReForge + ComfyUI + DreamBooth -Paperspace adaptations AUTOMATIC1111 Webui(Original A111, Forge and ReForge), ComfyUI and Dreambooth. +Paperspace adaptations AUTOMATIC1111 Webui(Original A1111, Forge and ReForge), ComfyUI and Dreambooth.
                                                                               Paperspace From d77d6a4682675964be33ed21cb4d1b03f30ad7f8 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:08:10 +0800 Subject: [PATCH 32/34] Update fast_stable_diffusion_ReForge.ipynb --- fast_stable_diffusion_ReForge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_ReForge.ipynb b/fast_stable_diffusion_ReForge.ipynb index f61209ce..3a6ccce4 100644 --- a/fast_stable_diffusion_ReForge.ipynb +++ b/fast_stable_diffusion_ReForge.ipynb @@ -123,6 +123,7 @@ " %cd /content/\n", " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", " !dpkg -i *.deb\n", + " !rm -r /usr/local/lib/python3.10/dist-packages/wandb*\n", " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", From f4e77cad0dec3757aab516b12f487447647c287b Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:08:52 +0800 Subject: [PATCH 33/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index ef4f80b7..15019413 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -123,6 +123,7 @@ " %cd /content/\n", " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", " !dpkg -i *.deb\n", + " !rm -r /usr/local/lib/python3.10/dist-packages/wandb*\n", " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", " !tar -C / --zstd -xf gcolabdeps.tar.zst\n", From 856521d9a8044ec69d1020d02db2638971ae3a51 Mon Sep 17 00:00:00 2001 From: LOLSALT <174792819+LOLSALT@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:10:16 +0800 Subject: [PATCH 34/34] Update fast_stable_diffusion_Forge.ipynb --- fast_stable_diffusion_Forge.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fast_stable_diffusion_Forge.ipynb b/fast_stable_diffusion_Forge.ipynb index 15019413..57a2c604 100644 --- a/fast_stable_diffusion_Forge.ipynb +++ b/fast_stable_diffusion_Forge.ipynb @@ -123,7 +123,7 @@ " %cd /content/\n", " !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n", " !dpkg -i *.deb\n", - " !rm -r /usr/local/lib/python3.10/dist-packages/wandb*\n", + " !rm -r /usr/local/lib/python3.10/dist-packages/wandb*\n", " if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusion'):\n", " !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n", " !tar -C / --zstd -xf gcolabdeps.tar.zst\n",