File size: 7,730 Bytes
94445d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "grG2f8fRZI6V",
"tags": []
},
"source": [
"# **StableDiffusion SageMaker version by @marat_ai**\n",
"\n",
"\n",
"![youtube.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAJ1BMVEVHcEz/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/////mJj/wcH/jY3aUCqcAAAACHRSTlMA8czbELSvDrGIfzkAAABCSURBVBiVY2AgA7CwMTMycgABIyMzGztQgIkDCTABBThQAEyAixtNgIeTkwu/AIYWZEMxrGVhZWaE8BiZWVnI8RoAJWEEDt2WmW4AAAAASUVORK5CYII=) **[YouTube](https://www.youtube.com/watch?v=dQw4w9WgXcQ)** | ![youtube.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAA0lBMVEVHcEwASXEAVIIASXEAW40AW40AW40AW40AW40AW40ASXEARmwASXEAPV4ATnkAQGQAUoAAUn8AWowAQmYANFEANVIAQWUASXEAUHwAQmcAWowASXEAUX0AW40ASXGPscSPr8B/pLh/rcYMUXdJfZkDS3KlwtIqdqBWhqB9q8WZtsY/dpQzbY1Xh6GUs8MAWowAUHwAVoUqdp8AVIJ9pLkqZ4h9orelvsyJq70AWosAWYoATniNrb+kwM8ATHZ+oreBpbnF1t8DS3PI1+BbiaNbiqT25ex8AAAAHXRSTlMAmzOe3PvEmp3+3Ar+CjM0M/v7CgoKCsUzNNz7+yV3I4EAAACzSURBVBjTTY/XEoJADEUjbUEBezdrASxg7737/79kdmEcz9PeM5NsLgCRY5qua0yBmKJpocQyMyJXDPxhCGPiHyZAzcJBvy3pL9FSgCGOhlwyXC+QgYbYO/si+/suXzVAJ+Hdyfg3r8t5Kxbj12TyGAvRlCPR9Pl5B9OIRFouDQOxIwi3nKfApW8vHcluw+26POx45QkqXerQ6YdTnKtlUcahcrM5RVstJX1dphXy6VRWvL8EBRlO0i9n9wAAAABJRU5ErkJggg==) **[sdg.marat@gmail.com]** |\n",
"\n",
"\n",
"_That notebook creates a local instance that constantly saves to your Amazon storage, so you don't need to download all models and install all requirements every time. Only once._"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "RE1n8kLOZI6Y",
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# **STEP 1** (Runs only once!)\n",
"## Requirements π\n",
"* _Don't forget to specify your ngroc token_"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "A1p2bOziZI6Y",
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;32mDone!\n"
]
}
],
"source": [
"print('\u001b[1;32mInstalling requirements...')\n",
"\n",
"from IPython.display import clear_output\n",
"!conda install -c conda-forge libglib -y & conda update -n base conda -y\n",
"\n",
"!pip install tqdm\n",
"\n",
"clear_output()\n",
"print('\u001b[1;32mDone! Conda installed!')\n",
"\n",
"!git clone https://github.com/rocketpal/stable-diffusion-webui\n",
"%cd stable-diffusion-webui\n",
"\n",
"'''\n",
"%pip install -r requirements.txt --quiet\n",
"'''\n",
"\n",
"#ControlNet ext\n",
"\n",
"%cd /home/studio-lab-user/stable-diffusion-webui/extensions/\n",
"!git clone https://github.com/rocketpal/sd-webui-controlnet\n",
"%cd /home/studio-lab-user/stable-diffusion-webui\n",
"\n",
"clear_output()\n",
"print('\u001b[1;32mDone!')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7tJLpUoHZI6Z",
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# **STEP 2.1** (Runs only once!)\n",
"## Download Base models π\n",
"\n",
"* Don't forget to run the cell bellow!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "FQyXmO0fZI6a",
"tags": []
},
"outputs": [],
"source": [
"#Base models:\n",
"\n",
"model_link1 = 'https://huggingface.co/SG161222/Realistic_Vision_V5.1_noVAE/resolve/main/Realistic_Vision_V5.1.safetensors'\n",
"model_link2 = ''\n",
"model_link3 = ''\n",
"model_link4 = ''\n",
"model_link5 = ''\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"#Run this to download base models:\n",
"\n",
"import os\n",
"import requests\n",
"from tqdm import tqdm\n",
"\n",
"# Function to download a file with progress\n",
"def download_file(url, target_dir):\n",
" filename = url.split(\"/\")[-1] # Extract the filename from the URL\n",
" download_path = os.path.join(target_dir, filename)\n",
" response = requests.get(url, stream=True)\n",
" total_size = int(response.headers.get(\"content-length\", 0))\n",
" block_size = 1024 # 1 Kibibyte\n",
"\n",
" with open(download_path, \"wb\") as file, tqdm(\n",
" desc=filename,\n",
" total=total_size,\n",
" unit=\"B\",\n",
" unit_scale=True,\n",
" unit_divisor=1024,\n",
" ) as bar:\n",
" for data in response.iter_content(block_size):\n",
" file.write(data)\n",
" bar.update(len(data))\n",
"\n",
"\n",
"\n",
"#Base models\n",
"download_links = [model_link1,\n",
" model_link2,\n",
" model_link3,\n",
" model_link4,\n",
" model_link5\n",
" ]\n",
"\n",
"\n",
"target_dir = \"/home/studio-lab-user/stable-diffusion-webui/models/Stable-diffusion/\"\n",
"\n",
"# Loop through the download links and download files to the target directory\n",
"for link in download_links:\n",
" if link == '':\n",
" pass\n",
" else:\n",
" download_file(link, target_dir)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3wZXNNiHZI6c",
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# **STEP 3**\n",
"## Run StableDiffusion π\n",
"Don't forget to specify your ngroc token!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"_kg_hide-input": false,
"_kg_hide-output": false,
"id": "8af-hu-3ZI6c",
"tags": []
},
"outputs": [],
"source": [
"%cd ~/stable-diffusion-webui\n",
"!python launch.py --listen --xformers --enable-insecure-extension-access --gradio-queue --ngrok 2W3231xwzhftRMwLpIS0jiDd2lTNqs_6JmzFy51yhDQ85Q7NxeCT"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xMNePTxDZI6c",
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
"# **Maintenance**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "U3fphZyuZI6c",
"tags": []
},
"outputs": [],
"source": [
"#clean remove all env, cache and file\n",
"\n",
"!rm -r /home/studio-lab-user/.cache\n",
"!rm -r /home/studio-lab-user/.conda\n",
"!conda remove -n \"env_name\" --all\n",
"!rm -rf /home/studio-lab-user/*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YApy5h6TZI6d"
},
"outputs": [],
"source": [
"#Check the storage available\n",
"!df -h | grep -E 'Avail|home'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vwRdajvuZI6d",
"tags": []
},
"outputs": [],
"source": [
"#List all folders and sizes\n",
"!du -h --max-depth=1 /home/studio-lab-user"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [
"RE1n8kLOZI6Y",
"7tJLpUoHZI6Z",
"3wZXNNiHZI6c",
"xMNePTxDZI6c"
],
"provenance": []
},
"kernelspec": {
"display_name": "default:Python",
"language": "python",
"name": "conda-env-default-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|