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
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {
|
| 6 |
+
"id": "47kV9o1Ni8GH"
|
| 7 |
+
},
|
| 8 |
+
"source": [
|
| 9 |
+
"# **Colab Pro notebook from https://github.com/TheLastBen/fast-stable-diffusion** *Alternatives : [RunPod](https://www.runpod.io/console/gpu-browse?template=runpod-stable-unified) | [Paperspace](https://console.paperspace.com/github/TheLastBen/PPS?machine=Free-GPU)*\n",
|
| 10 |
+
"##**[Support](https://ko-fi.com/thelastben)**"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"cell_type": "code",
|
| 15 |
+
"execution_count": null,
|
| 16 |
+
"metadata": {
|
| 17 |
+
"cellView": "form",
|
| 18 |
+
"id": "CFWtw-6EPrKi"
|
| 19 |
+
},
|
| 20 |
+
"outputs": [],
|
| 21 |
+
"source": [
|
| 22 |
+
"#@markdown # Install/Update AUTOMATIC1111 repo\n",
|
| 23 |
+
"from IPython.utils import capture\n",
|
| 24 |
+
"from IPython.display import clear_output\n",
|
| 25 |
+
"from subprocess import getoutput\n",
|
| 26 |
+
"import ipywidgets as widgets\n",
|
| 27 |
+
"import sys\n",
|
| 28 |
+
"import fileinput\n",
|
| 29 |
+
"import os\n",
|
| 30 |
+
"import time\n",
|
| 31 |
+
"import base64\n",
|
| 32 |
+
"import gdown\n",
|
| 33 |
+
"from gdown.download import get_url_from_gdrive_confirmation\n",
|
| 34 |
+
"import requests\n",
|
| 35 |
+
"from urllib.request import urlopen, Request\n",
|
| 36 |
+
"from urllib.parse import urlparse, parse_qs, unquote\n",
|
| 37 |
+
"from tqdm import tqdm\n",
|
| 38 |
+
"import six\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"blasphemy=base64.b64decode((\"ZWJ1aQ==\").encode('ascii')).decode('ascii')\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"if not os.path.exists(\"/content/gdrive\"):\n",
|
| 44 |
+
" print('\u001b[1;31mGdrive not connected, using temporary colab storage ...')\n",
|
| 45 |
+
" time.sleep(4)\n",
|
| 46 |
+
" mainpth=\"MyDrive\"\n",
|
| 47 |
+
" !mkdir -p /content/gdrive/$mainpth\n",
|
| 48 |
+
" Shared_Drive=\"\"\n",
|
| 49 |
+
"\n",
|
| 50 |
+
"if Shared_Drive!=\"\" and not os.path.exists(\"/content/gdrive/Shareddrives\"):\n",
|
| 51 |
+
" print('\u001b[1;31mShared drive not detected, using default MyDrive')\n",
|
| 52 |
+
" mainpth=\"MyDrive\"\n",
|
| 53 |
+
"\n",
|
| 54 |
+
"with capture.capture_output() as cap:\n",
|
| 55 |
+
" def inf(msg, style, wdth): inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth));display(inf)\n",
|
| 56 |
+
" fgitclone = \"git clone --depth 1\"\n",
|
| 57 |
+
" %mkdir -p /content/gdrive/$mainpth/sd\n",
|
| 58 |
+
" %cd /content/gdrive/$mainpth/sd\n",
|
| 59 |
+
" !git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-w$blasphemy\n",
|
| 60 |
+
" !mkdir -p /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/cache/\n",
|
| 61 |
+
" os.environ['TRANSFORMERS_CACHE']=f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blasphemy+\"/cache\"\n",
|
| 62 |
+
" os.environ['TORCH_HOME'] = f\"/content/gdrive/{mainpth}/sd/stable-diffusion-w\"+blasphemy+\"/cache\"\n",
|
| 63 |
+
"\n",
|
| 64 |
+
"with capture.capture_output() as cap:\n",
|
| 65 |
+
" %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/\n",
|
| 66 |
+
" !git reset --hard\n",
|
| 67 |
+
" !git checkout master\n",
|
| 68 |
+
" time.sleep(1)\n",
|
| 69 |
+
" !rm webui.sh\n",
|
| 70 |
+
" !git pull\n",
|
| 71 |
+
"clear_output()\n",
|
| 72 |
+
"inf('\\u2714 Done','success', '50px')\n",
|
| 73 |
+
"\n",
|
| 74 |
+
"#@markdown ---"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"cell_type": "code",
|
| 79 |
+
"execution_count": null,
|
| 80 |
+
"metadata": {
|
| 81 |
+
"cellView": "form",
|
| 82 |
+
"id": "ZGV_5H4xrOSp"
|
| 83 |
+
},
|
| 84 |
+
"outputs": [],
|
| 85 |
+
"source": [
|
| 86 |
+
"#@markdown # Requirements\n",
|
| 87 |
+
"\n",
|
| 88 |
+
"print('\u001b[1;32mInstalling requirements...')\n",
|
| 89 |
+
"\n",
|
| 90 |
+
"with capture.capture_output() as cap:\n",
|
| 91 |
+
" %cd /content/\n",
|
| 92 |
+
" !wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/A1111.txt\n",
|
| 93 |
+
" !dpkg -i *.deb\n",
|
| 94 |
+
" if not os.path.exists('/content/gdrive/'+mainpth+'/sd/stablediffusiond'): #restore later\n",
|
| 95 |
+
" !tar -C /content/gdrive/$mainpth --zstd -xf sd_mrep.tar.zst\n",
|
| 96 |
+
" !tar -C / --zstd -xf gcolabdeps.tar.zst\n",
|
| 97 |
+
" !rm *.deb | rm *.zst | rm *.txt\n",
|
| 98 |
+
" if not os.path.exists('gdrive/'+mainpth+'/sd/libtcmalloc/libtcmalloc_minimal.so.4'):\n",
|
| 99 |
+
" %env CXXFLAGS=-std=c++14\n",
|
| 100 |
+
" !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",
|
| 101 |
+
" !wget -q https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/Patch\n",
|
| 102 |
+
" %cd /content/gperftools\n",
|
| 103 |
+
" !patch -p1 < /content/Patch\n",
|
| 104 |
+
" !./configure --enable-minimal --enable-libunwind --enable-frame-pointers --enable-dynamic-sized-delete-support --enable-sized-delete --enable-emergency-malloc; make -j4\n",
|
| 105 |
+
" !mkdir -p /content/gdrive/$mainpth/sd/libtcmalloc && cp .libs/libtcmalloc*.so* /content/gdrive/$mainpth/sd/libtcmalloc\n",
|
| 106 |
+
" %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n",
|
| 107 |
+
" %cd /content\n",
|
| 108 |
+
" !rm *.tar.gz Patch && rm -r /content/gperftools\n",
|
| 109 |
+
" else:\n",
|
| 110 |
+
" %env LD_PRELOAD=/content/gdrive/$mainpth/sd/libtcmalloc/libtcmalloc_minimal.so.4\n",
|
| 111 |
+
" os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n",
|
| 112 |
+
" os.environ['PYTHONWARNINGS'] = 'ignore'\n",
|
| 113 |
+
" !sed -i 's@text = _formatwarnmsg(msg)@text =\\\"\\\"@g' /usr/lib/python3.10/warnings.py\n",
|
| 114 |
+
"\n",
|
| 115 |
+
"clear_output()\n",
|
| 116 |
+
"inf('\\u2714 Done','success', '50px')\n",
|
| 117 |
+
"\n",
|
| 118 |
+
"#@markdown ---"
|
| 119 |
+
]
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"cell_type": "code",
|
| 123 |
+
"execution_count": null,
|
| 124 |
+
"metadata": {
|
| 125 |
+
"cellView": "form",
|
| 126 |
+
"id": "p4wj_txjP3TC"
|
| 127 |
+
},
|
| 128 |
+
"outputs": [],
|
| 129 |
+
"source": [
|
| 130 |
+
"#@markdown # Model Download/Load\n",
|
| 131 |
+
"\n",
|
| 132 |
+
"Use_Temp_Storage = False #@param {type:\"boolean\"}\n",
|
| 133 |
+
"#@markdown - If not, make sure you have enough space on your gdrive\n",
|
| 134 |
+
"\n",
|
| 135 |
+
"#@markdown ---\n",
|
| 136 |
+
"\n",
|
| 137 |
+
"Model_Version = \"SDXL\" #@param [\"SDXL\", \"1.5\", \"v1.5 Inpainting\", \"V2.1-768px\"]\n",
|
| 138 |
+
"\n",
|
| 139 |
+
"#@markdown Or\n",
|
| 140 |
+
"PATH_to_MODEL = \"\" #@param {type:\"string\"}\n",
|
| 141 |
+
"#@markdown - Insert the full path of your custom model or to a folder containing multiple models\n",
|
| 142 |
+
"\n",
|
| 143 |
+
"#@markdown Or\n",
|
| 144 |
+
"MODEL_LINK = \"https://civitai.com/api/download/models/133462\" #@param {type:\"string\"}\n",
|
| 145 |
+
"\n",
|
| 146 |
+
"\n",
|
| 147 |
+
"def getsrc(url):\n",
|
| 148 |
+
" parsed_url = urlparse(url)\n",
|
| 149 |
+
" if parsed_url.netloc == 'civitai.com':\n",
|
| 150 |
+
" src='civitai'\n",
|
| 151 |
+
" elif parsed_url.netloc == 'drive.google.com':\n",
|
| 152 |
+
" src='gdrive'\n",
|
| 153 |
+
" elif parsed_url.netloc == 'huggingface.co':\n",
|
| 154 |
+
" src='huggingface'\n",
|
| 155 |
+
" else:\n",
|
| 156 |
+
" src='others'\n",
|
| 157 |
+
" return src\n",
|
| 158 |
+
"\n",
|
| 159 |
+
"src=getsrc(MODEL_LINK)\n",
|
| 160 |
+
"\n",
|
| 161 |
+
"def get_name(url, gdrive):\n",
|
| 162 |
+
" if not gdrive:\n",
|
| 163 |
+
" response = requests.get(url, allow_redirects=False)\n",
|
| 164 |
+
" if \"Location\" in response.headers:\n",
|
| 165 |
+
" redirected_url = response.headers[\"Location\"]\n",
|
| 166 |
+
" quer = parse_qs(urlparse(redirected_url).query)\n",
|
| 167 |
+
" if \"response-content-disposition\" in quer:\n",
|
| 168 |
+
" disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n",
|
| 169 |
+
" for vals in disp_val:\n",
|
| 170 |
+
" if vals.strip().startswith(\"filename=\"):\n",
|
| 171 |
+
" filenm=unquote(vals.split(\"=\", 1)[1].strip())\n",
|
| 172 |
+
" return filenm.replace(\"\\\"\",\"\")\n",
|
| 173 |
+
" else:\n",
|
| 174 |
+
" 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",
|
| 175 |
+
" lnk=\"https://drive.google.com/uc?id={id}&export=download\".format(id=url[url.find(\"/d/\")+3:url.find(\"/view\")])\n",
|
| 176 |
+
" res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n",
|
| 177 |
+
" res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)\n",
|
| 178 |
+
" content_disposition = six.moves.urllib_parse.unquote(res.headers[\"Content-Disposition\"])\n",
|
| 179 |
+
" filenm = re.search(r\"filename\\*=UTF-8''(.*)\", content_disposition).groups()[0].replace(os.path.sep, \"_\")\n",
|
| 180 |
+
" return filenm\n",
|
| 181 |
+
"\n",
|
| 182 |
+
"\n",
|
| 183 |
+
"def dwn(url, dst, msg):\n",
|
| 184 |
+
" file_size = None\n",
|
| 185 |
+
" req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n",
|
| 186 |
+
" u = urlopen(req)\n",
|
| 187 |
+
" meta = u.info()\n",
|
| 188 |
+
" if hasattr(meta, 'getheaders'):\n",
|
| 189 |
+
" content_length = meta.getheaders(\"Content-Length\")\n",
|
| 190 |
+
" else:\n",
|
| 191 |
+
" content_length = meta.get_all(\"Content-Length\")\n",
|
| 192 |
+
" if content_length is not None and len(content_length) > 0:\n",
|
| 193 |
+
" file_size = int(content_length[0])\n",
|
| 194 |
+
"\n",
|
| 195 |
+
" with tqdm(total=file_size, disable=False, mininterval=0.5,\n",
|
| 196 |
+
" bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:\n",
|
| 197 |
+
" with open(dst, \"wb\") as f:\n",
|
| 198 |
+
" while True:\n",
|
| 199 |
+
" buffer = u.read(8192)\n",
|
| 200 |
+
" if len(buffer) == 0:\n",
|
| 201 |
+
" break\n",
|
| 202 |
+
" f.write(buffer)\n",
|
| 203 |
+
" pbar.update(len(buffer))\n",
|
| 204 |
+
" f.close()\n",
|
| 205 |
+
"\n",
|
| 206 |
+
"\n",
|
| 207 |
+
"def sdmdls(ver, Use_Temp_Storage):\n",
|
| 208 |
+
"\n",
|
| 209 |
+
" if ver=='1.5':\n",
|
| 210 |
+
" if Use_Temp_Storage:\n",
|
| 211 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 212 |
+
" model='/content/temp_models/v1-5-pruned-emaonly.safetensors'\n",
|
| 213 |
+
" else:\n",
|
| 214 |
+
" model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blasphemy+'/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors'\n",
|
| 215 |
+
" link='https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors'\n",
|
| 216 |
+
" elif ver=='V2.1-768px':\n",
|
| 217 |
+
" if Use_Temp_Storage:\n",
|
| 218 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 219 |
+
" model='/content/temp_models/v2-1_768-ema-pruned.safetensors'\n",
|
| 220 |
+
" else:\n",
|
| 221 |
+
" model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blasphemy+'/models/Stable-diffusion/v2-1_768-ema-pruned.safetensors'\n",
|
| 222 |
+
" link='https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors'\n",
|
| 223 |
+
" elif ver=='v1.5 Inpainting':\n",
|
| 224 |
+
" if Use_Temp_Storage:\n",
|
| 225 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 226 |
+
" model='/content/temp_models/sd-v1-5-inpainting.ckpt'\n",
|
| 227 |
+
" else:\n",
|
| 228 |
+
" model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blasphemy+'/models/Stable-diffusion/sd-v1-5-inpainting.ckpt'\n",
|
| 229 |
+
" link='https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt'\n",
|
| 230 |
+
" elif ver=='SDXL':\n",
|
| 231 |
+
" if Use_Temp_Storage:\n",
|
| 232 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 233 |
+
" model='/content/temp_models/sd_xl_base_1.0.safetensors'\n",
|
| 234 |
+
" else:\n",
|
| 235 |
+
" model='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blasphemy+'/models/Stable-diffusion/sd_xl_base_1.0.safetensors'\n",
|
| 236 |
+
" link='https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'\n",
|
| 237 |
+
"\n",
|
| 238 |
+
" if not os.path.exists(model):\n",
|
| 239 |
+
" !gdown --fuzzy -O $model $link\n",
|
| 240 |
+
" if os.path.exists(model):\n",
|
| 241 |
+
" clear_output()\n",
|
| 242 |
+
" inf('\\u2714 Done','success', '50px')\n",
|
| 243 |
+
" else:\n",
|
| 244 |
+
" inf('\\u2718 Something went wrong, try again','danger', \"250px\")\n",
|
| 245 |
+
" else:\n",
|
| 246 |
+
" clear_output()\n",
|
| 247 |
+
" inf('\\u2714 Model already exists','primary', '300px')\n",
|
| 248 |
+
"\n",
|
| 249 |
+
" return model\n",
|
| 250 |
+
"\n",
|
| 251 |
+
"\n",
|
| 252 |
+
"if (PATH_to_MODEL !=''):\n",
|
| 253 |
+
" if os.path.exists(str(PATH_to_MODEL)):\n",
|
| 254 |
+
" inf('\\u2714 Using the trained model.','success', '200px')\n",
|
| 255 |
+
"\n",
|
| 256 |
+
" else:\n",
|
| 257 |
+
" while not os.path.exists(str(PATH_to_MODEL)):\n",
|
| 258 |
+
" inf('\\u2718 Wrong path, use the colab file explorer to copy the path : ','danger', \"400px\")\n",
|
| 259 |
+
" PATH_to_MODEL=input()\n",
|
| 260 |
+
" if os.path.exists(str(PATH_to_MODEL)):\n",
|
| 261 |
+
" inf('\\u2714 Using the custom model.','success', '200px')\n",
|
| 262 |
+
"\n",
|
| 263 |
+
" model=PATH_to_MODEL\n",
|
| 264 |
+
"\n",
|
| 265 |
+
"elif MODEL_LINK != \"\":\n",
|
| 266 |
+
"\n",
|
| 267 |
+
" if src=='civitai':\n",
|
| 268 |
+
" modelname=get_name(MODEL_LINK, False)\n",
|
| 269 |
+
" if Use_Temp_Storage:\n",
|
| 270 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 271 |
+
" model=f'/content/temp_models/{modelname}'\n",
|
| 272 |
+
" else:\n",
|
| 273 |
+
" model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blasphemy}/models/Stable-diffusion/{modelname}'\n",
|
| 274 |
+
" if not os.path.exists(model):\n",
|
| 275 |
+
" dwn(MODEL_LINK, model, 'Downloading the custom model')\n",
|
| 276 |
+
" clear_output()\n",
|
| 277 |
+
" else:\n",
|
| 278 |
+
" inf('\\u2714 Model already exists','primary', '300px')\n",
|
| 279 |
+
" elif src=='gdrive':\n",
|
| 280 |
+
" modelname=get_name(MODEL_LINK, True)\n",
|
| 281 |
+
" if Use_Temp_Storage:\n",
|
| 282 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 283 |
+
" model=f'/content/temp_models/{modelname}'\n",
|
| 284 |
+
" else:\n",
|
| 285 |
+
" model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blasphemy}/models/Stable-diffusion/{modelname}'\n",
|
| 286 |
+
" if not os.path.exists(model):\n",
|
| 287 |
+
" gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n",
|
| 288 |
+
" clear_output()\n",
|
| 289 |
+
" else:\n",
|
| 290 |
+
" inf('\\u2714 Model already exists','primary', '300px')\n",
|
| 291 |
+
" else:\n",
|
| 292 |
+
" modelname=os.path.basename(MODEL_LINK)\n",
|
| 293 |
+
" if Use_Temp_Storage:\n",
|
| 294 |
+
" os.makedirs('/content/temp_models', exist_ok=True)\n",
|
| 295 |
+
" model=f'/content/temp_models/{modelname}'\n",
|
| 296 |
+
" else:\n",
|
| 297 |
+
" model=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blasphemy}/models/Stable-diffusion/{modelname}'\n",
|
| 298 |
+
" if not os.path.exists(model):\n",
|
| 299 |
+
" gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)\n",
|
| 300 |
+
" clear_output()\n",
|
| 301 |
+
" else:\n",
|
| 302 |
+
" inf('\\u2714 Model already exists','primary', '700px')\n",
|
| 303 |
+
"\n",
|
| 304 |
+
" if os.path.exists(model) and os.path.getsize(model) > 1810671599:\n",
|
| 305 |
+
" inf('\\u2714 Model downloaded, using the custom model.','success', '300px')\n",
|
| 306 |
+
" else:\n",
|
| 307 |
+
" !rm model\n",
|
| 308 |
+
" inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n",
|
| 309 |
+
"\n",
|
| 310 |
+
"else:\n",
|
| 311 |
+
" model=sdmdls(Model_Version, Use_Temp_Storage)\n",
|
| 312 |
+
"\n",
|
| 313 |
+
"#@markdown ---"
|
| 314 |
+
]
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"cell_type": "code",
|
| 318 |
+
"execution_count": null,
|
| 319 |
+
"metadata": {
|
| 320 |
+
"cellView": "form",
|
| 321 |
+
"id": "Svx6Hx0iUPd1"
|
| 322 |
+
},
|
| 323 |
+
"outputs": [],
|
| 324 |
+
"source": [
|
| 325 |
+
"#@markdown # Download LoRA\n",
|
| 326 |
+
"\n",
|
| 327 |
+
"LoRA_LINK = \"https://civitai.com/api/download/models/161948\" #@param {type:\"string\"}\n",
|
| 328 |
+
"\n",
|
| 329 |
+
"os.makedirs('/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blasphemy+'/models/Lora', exist_ok=True)\n",
|
| 330 |
+
"\n",
|
| 331 |
+
"src=getsrc(LoRA_LINK)\n",
|
| 332 |
+
"\n",
|
| 333 |
+
"if src=='civitai':\n",
|
| 334 |
+
" modelname=get_name(LoRA_LINK, False)\n",
|
| 335 |
+
" loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blasphemy}/models/Lora/{modelname}'\n",
|
| 336 |
+
" if not os.path.exists(loramodel):\n",
|
| 337 |
+
" dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model '+modelname)\n",
|
| 338 |
+
" clear_output()\n",
|
| 339 |
+
" else:\n",
|
| 340 |
+
" inf('\\u2714 Model already exists','primary', '300px')\n",
|
| 341 |
+
"elif src=='gdrive':\n",
|
| 342 |
+
" modelname=get_name(LoRA_LINK, True)\n",
|
| 343 |
+
" loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blasphemy}/models/Lora/{modelname}'\n",
|
| 344 |
+
" if not os.path.exists(loramodel):\n",
|
| 345 |
+
" gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n",
|
| 346 |
+
" clear_output()\n",
|
| 347 |
+
" else:\n",
|
| 348 |
+
" inf('\\u2714 Model already exists','primary', '300px')\n",
|
| 349 |
+
"else:\n",
|
| 350 |
+
" modelname=os.path.basename(LoRA_LINK)\n",
|
| 351 |
+
" loramodel=f'/content/gdrive/{mainpth}/sd/stable-diffusion-w{blasphemy}/models/Lora/{modelname}'\n",
|
| 352 |
+
" if not os.path.exists(loramodel):\n",
|
| 353 |
+
" gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)\n",
|
| 354 |
+
" clear_output()\n",
|
| 355 |
+
" else:\n",
|
| 356 |
+
" inf('\\u2714 Model already exists','primary', '700px')\n",
|
| 357 |
+
"\n",
|
| 358 |
+
"if os.path.exists(loramodel) :\n",
|
| 359 |
+
" inf('\\u2714 LoRA downloaded','success', '300px')\n",
|
| 360 |
+
"else:\n",
|
| 361 |
+
" inf('\\u2718 Wrong link, check that the link is valid','danger', \"300px\")\n",
|
| 362 |
+
"\n",
|
| 363 |
+
"#@markdown ---"
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"cell_type": "code",
|
| 368 |
+
"source": [
|
| 369 |
+
"!git clone https://github.com/AIrjen/OneButtonPrompt /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/OneButtonPrompt"
|
| 370 |
+
],
|
| 371 |
+
"metadata": {
|
| 372 |
+
"id": "WZYOPI0iVlXV"
|
| 373 |
+
},
|
| 374 |
+
"execution_count": null,
|
| 375 |
+
"outputs": []
|
| 376 |
+
},
|
| 377 |
+
{
|
| 378 |
+
"cell_type": "code",
|
| 379 |
+
"execution_count": null,
|
| 380 |
+
"metadata": {
|
| 381 |
+
"cellView": "form",
|
| 382 |
+
"id": "PjzwxTkPSPHf"
|
| 383 |
+
},
|
| 384 |
+
"outputs": [],
|
| 385 |
+
"source": [
|
| 386 |
+
"#@markdown # Start Stable-Diffusion\n",
|
| 387 |
+
"from IPython.utils import capture\n",
|
| 388 |
+
"import time\n",
|
| 389 |
+
"import sys\n",
|
| 390 |
+
"import fileinput\n",
|
| 391 |
+
"from pyngrok import ngrok, conf\n",
|
| 392 |
+
"import re\n",
|
| 393 |
+
"\n",
|
| 394 |
+
"\n",
|
| 395 |
+
"Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n",
|
| 396 |
+
"#@markdown - Offers better gradio responsivity\n",
|
| 397 |
+
"\n",
|
| 398 |
+
"Ngrok_token = \"2Lc4gkhRYt3qQBJdcJIDGgclNrb_M3RiJdXAB2fot3r7AT6y\" #@param {type:\"string\"}\n",
|
| 399 |
+
"\n",
|
| 400 |
+
"#@markdown - Input your ngrok token if you want to use ngrok server\n",
|
| 401 |
+
"\n",
|
| 402 |
+
"User = \"\" #@param {type:\"string\"}\n",
|
| 403 |
+
"Password= \"\" #@param {type:\"string\"}\n",
|
| 404 |
+
"#@markdown - Add credentials to your Gradio interface (optional)\n",
|
| 405 |
+
"\n",
|
| 406 |
+
"auth=f\"--gradio-auth {User}:{Password}\"\n",
|
| 407 |
+
"if User ==\"\" or Password==\"\":\n",
|
| 408 |
+
" auth=\"\"\n",
|
| 409 |
+
"\n",
|
| 410 |
+
"\n",
|
| 411 |
+
"with capture.capture_output() as cap:\n",
|
| 412 |
+
" %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/modules/\n",
|
| 413 |
+
" !wget -q -O extras.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blasphemy/master/modules/extras.py\n",
|
| 414 |
+
" !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blasphemy/master/modules/sd_models.py\n",
|
| 415 |
+
" !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",
|
| 416 |
+
" %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/\n",
|
| 417 |
+
"\n",
|
| 418 |
+
" !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$blasphemy/modules/sd_models.py\n",
|
| 419 |
+
" !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$blasphemy/webui.py\n",
|
| 420 |
+
" !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/modules/extras.py\n",
|
| 421 |
+
"\n",
|
| 422 |
+
" !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/modules/paths.py\n",
|
| 423 |
+
" !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/modules/paths.py\n",
|
| 424 |
+
" !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/modules/paths.py\n",
|
| 425 |
+
"\n",
|
| 426 |
+
" !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n",
|
| 427 |
+
" !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$blasphemy/modules/shared.py\n",
|
| 428 |
+
"\n",
|
| 429 |
+
"share=''\n",
|
| 430 |
+
"if Ngrok_token!=\"\":\n",
|
| 431 |
+
" ngrok.kill()\n",
|
| 432 |
+
" srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n",
|
| 433 |
+
"\n",
|
| 434 |
+
" for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n",
|
| 435 |
+
" if line.strip().startswith('self.server_name ='):\n",
|
| 436 |
+
" line = f' self.server_name = \"{srv[8:]}\"\\n'\n",
|
| 437 |
+
" if line.strip().startswith('self.protocol = \"https\"'):\n",
|
| 438 |
+
" line = ' self.protocol = \"https\"\\n'\n",
|
| 439 |
+
" if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n",
|
| 440 |
+
" line = ''\n",
|
| 441 |
+
" if line.strip().startswith('else \"http\"'):\n",
|
| 442 |
+
" line = ''\n",
|
| 443 |
+
" sys.stdout.write(line)\n",
|
| 444 |
+
"\n",
|
| 445 |
+
"elif Use_Cloudflare_Tunnel:\n",
|
| 446 |
+
" with capture.capture_output() as cap:\n",
|
| 447 |
+
" !pkill cloudflared\n",
|
| 448 |
+
" time.sleep(4)\n",
|
| 449 |
+
" !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n",
|
| 450 |
+
" time.sleep(4)\n",
|
| 451 |
+
" with open('/content/srv.txt', \"r\") as file: text = file.read()\n",
|
| 452 |
+
" srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n",
|
| 453 |
+
"\n",
|
| 454 |
+
" for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n",
|
| 455 |
+
" if line.strip().startswith('self.server_name ='):\n",
|
| 456 |
+
" line = f' self.server_name = \"{srv[8:]}\"\\n'\n",
|
| 457 |
+
" if line.strip().startswith('self.protocol = \"https\"'):\n",
|
| 458 |
+
" line = ' self.protocol = \"https\"\\n'\n",
|
| 459 |
+
" if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n",
|
| 460 |
+
" line = ''\n",
|
| 461 |
+
" if line.strip().startswith('else \"http\"'):\n",
|
| 462 |
+
" line = ''\n",
|
| 463 |
+
" sys.stdout.write(line)\n",
|
| 464 |
+
"\n",
|
| 465 |
+
" !rm /content/srv.txt\n",
|
| 466 |
+
"\n",
|
| 467 |
+
"else:\n",
|
| 468 |
+
" share='--share'\n",
|
| 469 |
+
"\n",
|
| 470 |
+
"ckptdir=''\n",
|
| 471 |
+
"if os.path.exists('/content/temp_models'):\n",
|
| 472 |
+
" ckptdir='--ckpt-dir /content/temp_models'\n",
|
| 473 |
+
"\n",
|
| 474 |
+
"try:\n",
|
| 475 |
+
" model\n",
|
| 476 |
+
" if os.path.isfile(model):\n",
|
| 477 |
+
" !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/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 --upcast-sampling $ckptdir\n",
|
| 478 |
+
" else:\n",
|
| 479 |
+
" !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/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 --upcast-sampling\n",
|
| 480 |
+
"except:\n",
|
| 481 |
+
" !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --upcast-sampling $ckptdir"
|
| 482 |
+
]
|
| 483 |
+
}
|
| 484 |
+
],
|
| 485 |
+
"metadata": {
|
| 486 |
+
"accelerator": "GPU",
|
| 487 |
+
"colab": {
|
| 488 |
+
"provenance": []
|
| 489 |
+
},
|
| 490 |
+
"gpuClass": "standard",
|
| 491 |
+
"kernelspec": {
|
| 492 |
+
"display_name": "Python 3",
|
| 493 |
+
"name": "python3"
|
| 494 |
+
},
|
| 495 |
+
"language_info": {
|
| 496 |
+
"name": "python"
|
| 497 |
+
}
|
| 498 |
+
},
|
| 499 |
+
"nbformat": 4,
|
| 500 |
+
"nbformat_minor": 0
|
| 501 |
+
}
|