Created
March 13, 2023 13:20
-
-
Save morsoli/666a3f92b44e9b4b327d4b7af4ca2e30 to your computer and use it in GitHub Desktop.
stable_diffusion_1_5_webui_colab.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/morsoli/666a3f92b44e9b4b327d4b7af4ca2e30/stable_diffusion_1_5_webui_colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "zeXxRrmEugM6" | |
| }, | |
| "source": [ | |
| "1. 挂载 Google Drive 时会弹出授权窗口,然后允许授权账号即可。" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "aoebT0vXuhVr", | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "outputId": "4361eea3-319e-4683-bd6d-be7f6de4c9fa" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "from google.colab import drive\n", | |
| "drive.mount('/content/drive')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "IB-aJtZ5urG6" | |
| }, | |
| "source": [ | |
| "2. 运行时环境依赖包下载" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "29R0yWyvuvtT" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "!apt-get -y install -qq aria2\n", | |
| "!pip install -q https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+814314d.d20230118-cp38-cp38-linux_x86_64.whl\n", | |
| "!pip install -q --pre triton" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "KQ1JX4riwI2G" | |
| }, | |
| "source": [ | |
| "3. 安装Stable Diffusion Web UI Colab依赖的模型下载(只执行一次)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "f7O3-GlfwE0O" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "%cd /content/drive/MyDrive/\n", | |
| "!git clone -b v2.0 https://github.com/camenduru/stable-diffusion-webui\n", | |
| "!wget https://raw.githubusercontent.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O /content/drive/MyDrive/stable-diffusion-webui/scripts/run_n_times.py\n", | |
| "!git clone https://github.com/deforum-art/deforum-for-automatic1111-webui /content/drive/MyDrive/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui\n", | |
| "!git clone https://github.com/AlUlkesh/stable-diffusion-webui-images-browser /content/drive/MyDrive/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser\n", | |
| "!git clone https://github.com/camenduru/stable-diffusion-webui-huggingface /content/drive/MyDrive/stable-diffusion-webui/extensions/stable-diffusion-webui-huggingface\n", | |
| "!git clone -b v2.0 https://github.com/camenduru/sd-civitai-browser /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-civitai-browser\n", | |
| "!git clone https://github.com/kohya-ss/sd-webui-additional-networks /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-additional-networks\n", | |
| "!git clone https://github.com/Mikubill/sd-webui-controlnet /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet\n", | |
| "!git clone https://github.com/camenduru/openpose-editor /content/drive/MyDrive/stable-diffusion-webui/extensions/openpose-editor\n", | |
| "\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_canny-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_canny-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_depth-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_depth-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_hed-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_hed-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_mlsd-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_mlsd-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_normal-fp16.safetensors -d //content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_normal-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_openpose-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_openpose-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_scribble-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_scribble-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/webui/ControlNet-modules-safetensors/resolve/main/control_seg-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_seg-fp16.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/hand_pose_model.pth -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/openpose -o hand_pose_model.pth\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/body_pose_model.pth -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/openpose -o body_pose_model.pth\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/dpt_hybrid-midas-501f0c75.pt -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/midas -o dpt_hybrid-midas-501f0c75.pt\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_large_512_fp32.pth -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/mlsd -o mlsd_large_512_fp32.pth\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_tiny_512_fp32.pth -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/mlsd -o mlsd_tiny_512_fp32.pth\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/network-bsds500.pth -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/hed -o network-bsds500.pth\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/upernet_global_small.pth -d /content/drive/MyDrive/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/uniformer -o upernet_global_small.pth" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "bWCcLcyC3Wyz" | |
| }, | |
| "source": [ | |
| "4. 下载自定义模型(按需执行)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "TmSbUoyn3Wyz", | |
| "outputId": "261d118e-67da-4028-acfc-ab15ca15b032" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\u001b[0m\n", | |
| "Download Results:\n", | |
| "gid |stat|avg speed |path/URI\n", | |
| "======+====+===========+=======================================================\n", | |
| "52865c|\u001b[1;32mOK\u001b[0m | 42MiB/s|/content/drive/MyDrive/stable-diffusion-webui/models/Lora//chinesedolllikeness.safetensors\n", | |
| "\n", | |
| "Status Legend:\n", | |
| "(OK):download completed.\n", | |
| "\u001b[0m\n", | |
| "Download Results:\n", | |
| "gid |stat|avg speed |path/URI\n", | |
| "======+====+===========+=======================================================\n", | |
| "297c02|\u001b[1;32mOK\u001b[0m | 129MiB/s|/content/drive/MyDrive/stable-diffusion-webui/models/Stable-diffusion//Chilloutmix-Ni-pruned-fp32-fix.safetensors\n", | |
| "\n", | |
| "Status Legend:\n", | |
| "(OK):download completed.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!mkdir -p /content/drive/MyDrive/stable-diffusion-webui/models/Lora\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/11195 -d /content/drive/MyDrive/stable-diffusion-webui/models/Lora/ -o chinesedolllikeness.safetensors\n", | |
| "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/11745 -d /content/drive/MyDrive/stable-diffusion-webui/models/Stable-diffusion/ -o Chilloutmix-Ni-pruned-fp32-fix.safetensors" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "MA7gAljGw2Bt" | |
| }, | |
| "source": [ | |
| "5. Launch Web UI\n", | |
| "当你需要 启动 或者 重启 Web UI 时,可以运行下面的代码来启动。" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "1pby8a2uxGjp" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# Launch\n", | |
| "%cd /content/drive/MyDrive/stable-diffusion-webui\n", | |
| "!python launch.py --share --xformers --enable-insecure-extension-access --gradio-queue" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "119-MeSqxKyW" | |
| }, | |
| "source": [ | |
| "6. 保存产物\n", | |
| "使用 zip 来打包产物,并保存到 Google Drive。" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "J1YpuUBDxOXx" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# Zip images and save to Google Drive\n", | |
| "%cd /content/drive/MyDrive/stable-diffusion-webui/outputs \n", | |
| "!zip -r /content/drive/MyDrive/images.zip txt2img-images" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "accelerator": "GPU", | |
| "colab": { | |
| "provenance": [], | |
| "include_colab_link": true | |
| }, | |
| "gpuClass": "standard", | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment