{ "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": [] } ] }