{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xsrWOeo55N9b"
      },
      "outputs": [],
      "source": [
        "!apt update\n",
        "!yes | apt install libgoogle-perftools-dev\n",
        "!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
        "%cd /content/stable-diffusion-webui\n",
        "\n",
        "!pip3 uninstall torch torchvision torchaudio --yes\n",
        "!pip3 install torch==2.3.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "dE2epWSSNcbV"
      },
      "outputs": [],
      "source": [
        "# run below cell to install after detailer (adetailer) extension\n",
        "%cd /content/stable-diffusion-webui/extensions\n",
        "!git clone https://github.com/Bing-su/adetailer\n",
        "%cd /content/stable-diffusion-webui"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "o_AbGHOe579l"
      },
      "outputs": [],
      "source": [
        "# downloads SDXL base model\n",
        "!wget https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors\n",
        "# downloads SDXL refiner model\n",
        "!wget https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/sd_xl_refiner_1.0.safetensors\n",
        "# downloads SDXL best VAE file\n",
        "!wget https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors -O /kaggle/working/stable-diffusion-webui/models/VAE/sdxl_vae.safetensors\n",
        "\n",
        "# downloads realistic vision v 5.1 into models folder - SD 1.5 based model\n",
        "!wget https://huggingface.co/SG161222/Realistic_Vision_V5.1_noVAE/resolve/main/Realistic_Vision_V5.1.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/Realistic_Vision_V5.1.safetensors\n",
        "#downloads best VAE for SD 1.5 based models into VAE folder\n",
        "!wget https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -O /content/stable-diffusion-webui/models/VAE/vae-ft-mse-840000-ema-pruned.safetensors\n",
        "# downloads base SD 1.5 model - the weakest one\n",
        "!wget https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned.safetensors\n",
        "\n",
        "# downloads 4x_NMKD-Superscale-SP_178000_G  upscaler into the RESGRAN folder\n",
        "!wget https://huggingface.co/gemasai/4x_NMKD-Superscale-SP_178000_G/resolve/main/4x_NMKD-Superscale-SP_178000_G.pth -O /content/stable-diffusion-webui/models/ESRGAN/4x_NMKD-Superscale-SP_178000_G.pth\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "O3z7d-O06daO"
      },
      "outputs": [],
      "source": [
        "# this below code will clone and install controlnet with all of its models for SDXL\n",
        "# dont download both SDXL and SD 1.5 Controlnet Models at the same - you would get out of disk space\n",
        "# execute this line before starting the automatic1111 web ui via webui.sh\n",
        "%cd /content/stable-diffusion-webui/extensions\n",
        "!git clone https://github.com/Mikubill/sd-webui-controlnet\n",
        "%cd /content/stable-diffusion-webui\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_blur.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_blur.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_blur_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_blur_anime.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_blur_anime_beta.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_blur_anime_beta.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_canny.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_canny.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_depth.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_depth.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_diffusers_xl_canny.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_canny.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_diffusers_xl_depth_midas.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_depth_midas.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_diffusers_xl_depth_zoe.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_depth_zoe.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_diffusers_xl_lineart.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_lineart.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_diffusers_xl_openpose.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_openpose.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_diffusers_xl_sketch.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_sketch.safetensors\"\n",
        "\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/diffusers_xl_canny_full.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_full.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/diffusers_xl_depth_full.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_full.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/ioclab_sd15_recolor.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/ioclab_sd15_recolor.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/ip-adapter_sd15_plus.pth \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/ip-adapter_sd15_plus.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/ip-adapter_xl.pth \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/ip-adapter_xl.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_canny_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_canny_anime.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_depth_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_depth_anime.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_openpose_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_openpose_anime.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_openpose_anime_v2.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_openpose_anime_v2.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/kohya_controllllite_xl_scribble_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_scribble_anime.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sai_xl_canny_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_canny_256lora.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sai_xl_depth_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_depth_256lora.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sai_xl_recolor_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_256lora.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sai_xl_sketch_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sargezt_xl_depth.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_depth.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sargezt_xl_depth_faid_vidit.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_depth_faid_vidit.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sargezt_xl_depth_zeed.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_depth_zeed.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/sargezt_xl_softedge.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_softedge.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_xl_canny.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_xl_canny.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_xl_openpose.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_xl_openpose.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2i-adapter_xl_sketch.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_xl_sketch.safetensors\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/thibaud_xl_openpose.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose.safetensors\"\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "-C9yw9dF-6zE"
      },
      "outputs": [],
      "source": [
        "# this below code will clone and install controlnet with all of its models For SD 1.5 based models\n",
        "# execute this line before starting the automatic1111 web ui via webui.sh\n",
        "%cd /content/stable-diffusion-webui/extensions\n",
        "!git clone https://github.com/Mikubill/sd-webui-controlnet\n",
        "%cd /content/stable-diffusion-webui\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11e_sd15_ip2p.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11e_sd15_shuffle.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11f1e_sd15_tile.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11f1p_sd15_depth.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_canny.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_inpaint.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_lineart.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_mlsd.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_normalbae.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_openpose.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_scribble.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_seg.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15_softedge.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/control_v11p_sd15s2_lineart_anime.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth\"\n",
        "\n",
        "!wget -O /content/stable-diffusion-webui/extensions/sd-webui-controlnet/models/t2iadapter_style_sd14v1.pth \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_style_sd14v1.pth\"\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Cap1Y_ye7Zh_"
      },
      "outputs": [],
      "source": [
        "# this below code will download pixel art SDXL lora from civit AI. this is the format to download others\n",
        "# right click download button and copy link and replace yours as below\n",
        "!mkdir -p /content/stable-diffusion-webui/models/Lora\n",
        "!wget https://civitai.com/api/download/models/135931 -O /content/stable-diffusion-webui/models/Lora/Pixel_Art_XL_1_1.safetensors"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "fs9AboTq7oP3"
      },
      "outputs": [],
      "source": [
        "%cd /content/stable-diffusion-webui\n",
        "!wget https://huggingface.co/MonsterMMORPG/SECourses/resolve/main/webui_colab.sh -O \"webui.sh\"\n",
        "!chmod +x webui.sh\n",
        "# If you turn off your session or restart it will delete everything\n",
        "# this below code will start Automatic1111 Web UI. You can stop and start this cell again to restart Web UI\n",
        "# remove --no-half-vae if you use SD 1.5 based models - use only if SDXL\n",
        "!./webui.sh \\\n",
        "    -f \\\n",
        "    --share \\\n",
        "    --enable-insecure-extension-access \\\n",
        "    --no-half-vae\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Dr2nvRzG80Kp"
      },
      "outputs": [],
      "source": [
        "!rm -r /content/generated_images.zip\n",
        "%cd /content/stable-diffusion-webui/outputs/\n",
        "!zip -r /content/generated_images.zip *\n",
        "%cd -\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ZeY6X67nCX1W"
      },
      "outputs": [],
      "source": [
        "#patron requested models\n",
        "#this way you can download any civitAI models\n",
        "!wget \"https://civitai.com/api/download/models/130072?type=Model&format=SafeTensor&size=full&fp=fp16\" -O \"/content/stable-diffusion-webui/models/Stable-diffusion/Realistic_Vision_V5.1.safetensors\"\n",
        "\n",
        "!wget \"https://civitai.com/api/download/models/138176?type=Model&format=SafeTensor&size=full&fp=fp32\" -O \"/content/stable-diffusion-webui/models/Stable-diffusion/CyberRealistic_v3_3.safetensors\"\n",
        "\n",
        "!wget \"https://civitai.com/api/download/models/132760?type=Model&format=SafeTensor&size=pruned&fp=fp16\" -O \"/content/stable-diffusion-webui/models/Stable-diffusion/AbsoluteReality_v181.safetensors\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "DEruJ86OChUO"
      },
      "outputs": [],
      "source": [
        "#patron requested models\n",
        "#this way you can download any civitAI models\n",
        "!wget \"https://civitai.com/api/download/models/157603\" -O \"/content/stable-diffusion-webui/models/Stable-diffusion/AlbedoBase_XL.safetensors\""
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
