File size: 17,980 Bytes
209132b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "gpuType": "T4"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# **SD COLAB BY YASHRAJ πŸ‘‡**"
      ],
      "metadata": {
        "id": "eN0YbpHXF5ld"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#@markdown **Mount your Drive if you Want Output Images in Drive**\n",
        "from IPython.display import clear_output, display, HTML\n",
        "from google.colab import drive\n",
        "import os\n",
        "import subprocess\n",
        "import shutil\n",
        "mount_drive = True # @param {type:\"boolean\"}\n",
        "%cd /content\n",
        "print('\u001b[1;92m')\n",
        "if mount_drive == True:\n",
        " drive.mount('/content/drive')\n",
        "else:\n",
        " print(\"No GDrive Found!!\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "_2b_FliL1kXz",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "3cd6350f-8b7b-4564-843f-cd59d4205012"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content\n",
            "\u001b[1;92m\n",
            "Mounted at /content/drive\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from IPython.display import clear_output, display, HTML\n",
        "import os\n",
        "import subprocess\n",
        "import shutil\n",
        "repo = 'AUTOMATIC1111' #@param [\"AUTOMATIC1111\", \"anapnoe\", \"automatic\"]\n",
        "commit_hash = \"\"  # @param {'type': 'string'}\n",
        "theme  = 'catppuccin' #@param [\"None\",\"lobe\", \"catppuccin\",\"kitchen-theme\"]\n",
        "%cd /content\n",
        "def exist():\n",
        " if os.path.isdir('/content/Repo'):\n",
        "   shutil.rmtree('/content/Repo', ignore_errors=False, onerror=None)\n",
        " else:\n",
        "   clear_output()\n",
        "exist()\n",
        "print('\u001b[1;92m')\n",
        "if repo == 'AUTOMATIC1111':\n",
        " !wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/a1111.py\n",
        " !python3 a1111.py\n",
        "elif repo == 'anapnoe':\n",
        " !wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/anapnoe.py\n",
        " !python3 anapnoe.py\n",
        "elif repo == 'automatic':\n",
        "  !wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/automatic.py\n",
        "  !python3 automatic.py\n",
        "clear_output()\n",
        "\n",
        "%cd /content/Repo/extensions\n",
        "print('\u001b[1;92m')\n",
        "!wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/Extensions.py\n",
        "!python3 Extensions.py\n",
        "\n",
        "def lobe():\n",
        "   print('\u001b[1;92m')\n",
        "   if repo == 'AUTOMATIC1111' and theme == 'lobe':\n",
        "     name_i = 'sd-webui'\n",
        "     !git clone https://github.com/lobehub/{name_i}-lobe-theme  /content/Repo/extensions/lobe-theme\n",
        "   elif repo == 'AUTOMATIC1111' and theme == 'catppuccin':\n",
        "     %cd /content/Repo/extensions/\n",
        "     !wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/catppucin.py\n",
        "     !python3 catppucin.py\n",
        "   elif repo == 'AUTOMATIC1111' and theme == 'kitchen-theme':\n",
        "      name_i = 'sd-webui'\n",
        "      !git clone https://github.com/canisminor1990/{name_i}-kitchen-theme-legacy /content/Repo/extensions/kitchen-theme\n",
        "   else :\n",
        "     print(\"Default theme\")\n",
        "lobe()\n",
        "\n",
        "%cd /content/Repo/models/\n",
        "!pip install -qq pyunpack\n",
        "!apt-get install aria2 -qq\n",
        "!mkdir -p Stable-diffusion\n",
        "print('\u001b[1;92m')\n",
        "%cd /content/Repo/models/Stable-diffusion/\n",
        "civitai_model_urls = \"https://civitai.com/api/download/models/138176?type=Model&format=SafeTensor&size=pruned&fp=fp32, https://civitai.com/api/download/models/44827?type=Model&format=SafeTensor&size=pruned&fp=fp16\"  # @param {'type': 'string'}\n",
        "url_list = civitai_model_urls.split(\", \")\n",
        "for url in url_list:\n",
        "    !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --content-disposition {url}\n",
        "print('\u001b[1;92m')\n",
        "%cd /content/Repo/models/Stable-diffusion/\n",
        "huggface_model_urls = \"\"   # @param {'type': 'string'}\n",
        "url_list = huggface_model_urls.split(\", \")\n",
        "for url in url_list:\n",
        "    !wget --content-disposition {url}\n",
        "\n",
        "clear_output()\n",
        "print(\"Done Successfully!✌️\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "zetu2t73c0MP"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from IPython.display import clear_output, display, HTML\n",
        "import os\n",
        "import subprocess\n",
        "import shutil\n",
        "repo = 'AUTOMATIC1111' #@param [\"AUTOMATIC1111\", \"anapnoe\", \"automatic\"]\n",
        "commit_hash = \"\"  # @param {'type': 'string'}\n",
        "theme  = 'None' #@param [\"None\",\"lobe\", \"catppuccin\",\"kitchen-theme\"]\n",
        "%cd /content\n",
        "def exist():\n",
        " if os.path.isdir('/content/Repo'):\n",
        "   shutil.rmtree('/content/Repo', ignore_errors=False, onerror=None)\n",
        " else:\n",
        "   clear_output()\n",
        "exist()\n",
        "\n",
        "!git clone https://github.com/Ysb321/a1111 Repo\n",
        "\n",
        "%cd /content/Repo/extensions/\n",
        "!git clone https://github.com/Ysb321/sd-controlnet.git\n",
        "!git clone https://github.com/Ysb321/roooop.git\n",
        "!git clone https://github.com/Bing-su/adetailer\n",
        "!git clone https://github.com/Ysb321/sd-infinite-image-browsing\n",
        "!git clone https://github.com/Iyashinouta/sd-model-downloader\n",
        "\n",
        "def lobe():\n",
        "   print('\u001b[1;92m')\n",
        "   if repo == 'AUTOMATIC1111' and theme == 'lobe':\n",
        "     name_i = 'sd-webui'\n",
        "     !git clone https://github.com/lobehub/{name_i}-lobe-theme  /content/Repo/extensions/lobe-theme\n",
        "   elif repo == 'AUTOMATIC1111' and theme == 'catppuccin':\n",
        "     %cd /content/Repo/extensions/\n",
        "     !wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/catppucin.py\n",
        "     !python3 catppucin.py\n",
        "   elif repo == 'AUTOMATIC1111' and theme == 'kitchen-theme':\n",
        "      name_i = 'sd-webui'\n",
        "      !git clone https://github.com/canisminor1990/{name_i}-kitchen-theme-legacy /content/Repo/extensions/kitchen-theme\n",
        "   else :\n",
        "     print(\"Default theme\")\n",
        "lobe()\n",
        "\n",
        "%cd /content/Repo/models/\n",
        "!pip install -qq pyunpack\n",
        "!apt-get install aria2 -qq\n",
        "!mkdir -p Stable-diffusion\n",
        "print('\u001b[1;92m')\n",
        "%cd /content/Repo/models/Stable-diffusion/\n",
        "civitai_model_urls = \"https://civitai.com/api/download/models/138176?type=Model&format=SafeTensor&size=pruned&fp=fp32, https://civitai.com/api/download/models/44827?type=Model&format=SafeTensor&size=pruned&fp=fp16\"  # @param {'type': 'string'}\n",
        "url_list = civitai_model_urls.split(\", \")\n",
        "for url in url_list:\n",
        "    !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --content-disposition {url}\n",
        "print('\u001b[1;92m')\n",
        "%cd /content/Repo/models/Stable-diffusion/\n",
        "huggface_model_urls = \"\"   # @param {'type': 'string'}\n",
        "url_list = huggface_model_urls.split(\", \")\n",
        "for url in url_list:\n",
        "    !wget --content-disposition {url}\n",
        "\n",
        "clear_output()\n",
        "print(\"Done Successfully!✌️\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "4esgMnLXS77M"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@markdown **ControlNet**\n",
        "def CN():\n",
        "    print('\u001b[1;92m')\n",
        "    Start_with_ControlNet = \"Download from urls\"  # @param [\"No\", \"Download from urls\", \"Download All\"]\n",
        "    if os.path.exists(\"/content/Repo/config.json\"):\n",
        "        os.remove(\"/content/Repo/config.json\")\n",
        "\n",
        "    if Start_with_ControlNet == \"No\":\n",
        "       name_i = 'sd-webui'\n",
        "       shutil.rmtree(f'/content/Repo/extensions/{name_i}-controlnet', ignore_errors=False, onerror=None)\n",
        "       print(\"No CN Models\")\n",
        "    elif Start_with_ControlNet == \"Download from urls\":\n",
        "        print('\u001b[1;92m')\n",
        "        name_i = 'sd-webui'\n",
        "        controlnet_url = 'https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors, https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors' # @param {'type': 'string'}\n",
        "        url_list = controlnet_url.split(\", \")\n",
        "        for url in url_list:\n",
        "          !wget --content-disposition -qq {url} -P /content/Repo/extensions/{name_i}-controlnet/models/\n",
        "    elif Start_with_ControlNet == \"Download All\":\n",
        "          name_i = 'sd-webui'\n",
        "          !wget --content-disposition -i /content/sd.net/DataFiles/CN.txt -P /content/Repo/extensions/{name_i}-controlnet/models/\n",
        "    else:\n",
        "        print(\"Invalid value for Start_with_ControlNet. Please choose either 'No' or 'Yes'.\")\n",
        "CN()\n",
        "clear_output()\n",
        "print(\"Done Successfully!✌️\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "Ko4nV3nb6dqh"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@markdown **LORA all in one zip**\n",
        "import os\n",
        "import subprocess\n",
        "from pyunpack import zipfile\n",
        "print('\u001b[1;92m')\n",
        "%cd /content/Repo/models/\n",
        "repo_url = 'https://huggingface.co/datasets/ysb123/yy'\n",
        "dest_path = './Lora'\n",
        "# Run the git clone command\n",
        "try:\n",
        "    subprocess.run(['git', 'clone', '--depth=1', repo_url, dest_path], check=True)\n",
        "    print('Clone operation completed successfully!')\n",
        "except subprocess.CalledProcessError:\n",
        "    print('Clone operation failed!')\n",
        "%cd /content/Repo/models/Lora/\n",
        "zip_directory = '/content/Repo/models/Lora/'\n",
        "\n",
        "# Loop through all the files in the zip directory\n",
        "for filename in os.listdir(zip_directory):\n",
        "    if filename.endswith('.zip'):\n",
        "        # Construct the full path of the zip file\n",
        "        zip_path = os.path.join(zip_directory, filename)\n",
        "\n",
        "        # Extract the zip file to the extract directory\n",
        "        shutil.unpack_archive(zip_path)\n",
        "!rm /content/Repo/models/Lora/*.zip\n",
        "clear_output()\n",
        "print(\"Done Successfully!✌️\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "H3shHFIKRcDp"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@markdown **VAE &**\n",
        "#@markdown **LORA**\n",
        "from IPython.display import clear_output, display, HTML\n",
        "import os\n",
        "import subprocess\n",
        "import shutil\n",
        "from pyunpack import zipfile\n",
        "print('\u001b[1;92m')\n",
        "%cd /content/Repo/models/\n",
        "!mkdir -p VAE\n",
        "%cd /content/Repo/models/VAE/\n",
        "!wget --content-disposition -qq https://github.com/Ysb321/supper/releases/download/vae/vae-ft-mse-840000-ema-pruned.vae.pt\n",
        "print('\u001b[1;92m')\n",
        "\n",
        "VAE_url = '' # @param {'type': 'string'}\n",
        "url_list = VAE_url.split(\", \")\n",
        "for url in url_list:\n",
        "    !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M {url}\n",
        "current_dir = os.getcwd()\n",
        "for entry in os.scandir(current_dir):\n",
        "     if entry.is_file() and entry.name.endswith('.zip'):\n",
        "        with zipfile.ZipFile(entry, 'r') as zip_ref:\n",
        "             zip_ref.extractall(current_dir)\n",
        "!rm *.zip\n",
        "%cd /content/Repo/models/\n",
        "!mkdir Lora\n",
        "%cd /content/Repo/models/Lora/\n",
        "lora_url = 'https://civitai.com/api/download/models/156831?type=Model&format=SafeTensor, https://civitai.com/api/download/models/21910?type=Model&format=SafeTensor&size=full&fp=fp16, https://civitai.com/api/download/models/112103' # @param {'type': 'string'}\n",
        "url_list = lora_url.split(\", \")\n",
        "for url in url_list:\n",
        "    !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --content-disposition {url}\n",
        "lora_zip_url = 'https://huggingface.co/datasets/ysb123/yy/resolve/main/Lora.zip, https://huggingface.co/datasets/ysb123/yy/resolve/main/ppp.zip, https://huggingface.co/datasets/ysb123/yy/resolve/main/ddd.zip' # @param {'type': 'string'}\n",
        "url_list = lora_zip_url.split(\", \")\n",
        "for url in url_list:\n",
        "    !aria2c -c -x 16 -s 16 -k 1M {url}\n",
        "directory = '/content/Repo/models/Lora'\n",
        "for filename in os.listdir(directory):\n",
        "    if '.' not in filename:\n",
        "        old_filepath = os.path.join(directory, filename)\n",
        "        new_filepath = os.path.join(directory, filename + '.zip')\n",
        "        os.rename(old_filepath, new_filepath)\n",
        "current_dir = os.getcwd()\n",
        "for entry in os.scandir(current_dir):\n",
        "     if entry.is_file() and entry.name.endswith('.zip'):\n",
        "        with zipfile.ZipFile(entry, 'r') as zip_ref:\n",
        "             zip_ref.extractall(current_dir)\n",
        "!rm *.zip\n",
        "clear_output()\n",
        "print(\"Done Successfully!✌️\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "QbHMAMwpqLjB"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@markdown **Run SD &  if you dont want to use gpu --skip-torch-cuda-test --no-half --no-half-vae paste in arrgu**\n",
        "from IPython.display import clear_output, display, HTML\n",
        "repo = 'AUTOMATIC1111' #@param [\"AUTOMATIC1111\", \"anapnoe\", \"automatic\"]\n",
        "commit_hash = \"\"  # @param {'type': 'string'}\n",
        "%cd /content/Repo/\n",
        "!wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/config.json\n",
        "!wget -qq https://huggingface.co/datasets/ysb123/repo/resolve/main/styles.csv\n",
        "print('\u001b[1;92m')\n",
        "def install_jemalloc():\n",
        "    !apt -y update -qq\n",
        "    !apt -y install libjemalloc-dev\n",
        "    %env LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2\n",
        "install_jemalloc()\n",
        "\n",
        "def new():\n",
        " !sed -i \"s@os.path.splitext(checkpoint_file)@os.path.splitext(checkpoint_file); map_location='cuda'@\" /content/Repo/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/Repo/webui.py\n",
        " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/Repo/modules/extras.py\n",
        " !cp /content/Repo/assets/blocks.py /usr/local/lib/python3.10/dist-packages/gradio/blocks.py\n",
        " !apt -y update -qq\n",
        " !wget https://github.com/camenduru/gperftools/releases/download/v1.0/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4\n",
        " %env LD_PRELOAD=/content/libtcmalloc_minimal.so.4\n",
        "new()\n",
        "\n",
        "clear_output()\n",
        "arrgu = '--lowram ' # @param {'type': 'string'}\n",
        "print('\u001b[1;92m')\n",
        "if repo == 'automatic':\n",
        "  !git reset --hard {commit_hash}\n",
        "  !mkdir /content/automatic\n",
        "  shutil.copy2('/content/Repo/styles.csv' , '/content/automatic')\n",
        "  new_i = 'sd-webui'\n",
        "  !python launch.py --multiple --lyco-dir /content/Repo/models/Lora/ --controlnet-dir /content/Repo/extensions/{name_i}-controlnet/\n",
        "else :\n",
        "  !git reset --hard {commit_hash}\n",
        "  !python launch.py {arrgu} --enable-insecure-extension-access --disable-console-progressbars --xformers --multiple --embeddings-dir /content/Repo/models/embeddings"
      ],
      "metadata": {
        "cellView": "form",
        "id": "k5grp_jrpCmD"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}