Skip to content

Web-based UI for Stable Diffusion

Stable Diffusion Web UI

Features

  • Gradio GUI : txt2img, img2img
  • 프롬프트만 입력하고 나머지는 슬라이더로 조정
  • GFPGAN 얼굴 보정 + RealESRGAN 업스케일링 + Textual Inversion
  • 고급 img2img 에디터
  • Mask & Crop 지원
  • 여러개의 txt2img, imig2img 샘플러들
  • 윈도우/리눅스/Colab 설치 가이드 제공

Stable Diffusion WebUI Docker

Easy Docker setup for Stable Diffusion with user-friendly UI

docker와 nvidia-docker가 설치되어 있어야 한다.

해당 repo 간단한 사용 방법

git clone https://github.com/AbdBarho/stable-diffusion-webui-docker
cd stable-diffusion-webui-docker

# Data Download
cd services/download/
docker build --tag download .
cd ../../
docker run --rm -it -v $PWD/data:/data download

# Service Start
cd services/hlky/
docker build --tag hlky .
cd ../../
docker run --rm -it -v $PWD/data:/data -v $PWD/output:/output -p 7860:7860 -e CLI_ARGS=--optimized-turbo -e USE_STREAMLIT=0 --gpus all hlky

hlky 이미지 만드는 단계에서 문법 에러가 발생된다면 하단의, 서비스 항목의 Dockerfile 을 복사하여 사용하자.

데이터 다운로드 관련 파일들

checksums.sha256 file

fe4efff1e174c627256e44ec2991ba279b3816e364b49f9be2abc0b3ff3f8556  /data/StableDiffusion/model.ckpt
e2cd4703ab14f4d01fd1383a8a8b266f9a5833dacee8e6a79d3bf21a1b6be5ad  /data/GFPGAN/GFPGANv1.4.pth
4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1  /data/RealESRGAN/RealESRGAN_x4plus.pth
f872d837d3c90ed2e05227bed711af5671a6fd1c9f7d7e91c911a61f155e99da  /data/RealESRGAN/RealESRGAN_x4plus_anime_6B.pth
c209caecac2f97b4bb8f4d726b70ac2ac9b35904b7fc99801e1f5e61f9210c13  /data/LDSR/model.ckpt
9d6ad53c5dafeb07200fb712db14b813b527edd262bc80ea136777bdb41be2ba  /data/LDSR/project.yaml

Dockerfile

FROM bash:alpine3.15

RUN apk add parallel aria2
COPY . /docker
RUN chmod +x /docker/download.sh
ENTRYPOINT ["/docker/download.sh"]

download.sh

#!/usr/bin/env bash
set -Eeuo pipefail
mkdir -p /data/.cache /data/StableDiffusion /data/Codeformer /data/GFPGAN /data/ESRGAN /data/BSRGAN /data/RealESRGAN /data/SwinIR /data/LDSR /data/ScuNET /data/embeddings
echo "Downloading, this might take a while..."
aria2c --input-file /docker/links.txt --dir /data --continue
echo "Checking SHAs..."
parallel --will-cite -a /docker/checksums.sha256 "echo -n {} | sha256sum -c"
# aria2c already does hash check
# cc6cb27103417325ff94f52b7a5d2dde45a7515b25c255d8e396c90014281516  /data/StableDiffusion/v1-5-pruned-emaonly.ckpt
cat <<EOF
By using this software, you agree to the following licenses:
https://github.com/CompVis/stable-diffusion/blob/main/LICENSE
https://github.com/AbdBarho/stable-diffusion-webui-docker/blob/master/LICENSE
https://github.com/sd-webui/stable-diffusion-webui/blob/master/LICENSE
https://github.com/invoke-ai/InvokeAI/blob/main/LICENSE
https://github.com/cszn/BSRGAN/blob/main/LICENSE
https://github.com/sczhou/CodeFormer/blob/master/LICENSE
https://github.com/TencentARC/GFPGAN/blob/master/LICENSE
https://github.com/xinntao/Real-ESRGAN/blob/master/LICENSE
https://github.com/xinntao/ESRGAN/blob/master/LICENSE
https://github.com/cszn/SCUNet/blob/main/LICENSE
EOF

links.txt

magnet:?xt=urn:btih:2daef5b5f63a16a9af9169a529b1a773fc452637&dn=v1-5-pruned-emaonly.ckpt&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&tr=udp%3a%2f%2f9.rarbg.com%3a2810%2fannounce&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a6969%2fannounce&tr=udp%3a%2f%2fopentracker.i2p.rocks%3a6969%2fannounce&tr=https%3a%2f%2fopentracker.i2p.rocks%3a443%2fannounce&tr=http%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&tr=udp%3a%2f%2ftracker.torrent.eu.org%3a451%2fannounce&tr=udp%3a%2f%2fopen.stealth.si%3a80%2fannounce&tr=udp%3a%2f%2fvibe.sleepyinternetfun.xyz%3a1738%2fannounce&tr=udp%3a%2f%2ftracker2.dler.org%3a80%2fannounce&tr=udp%3a%2f%2ftracker1.bt.moack.co.kr%3a80%2fannounce&tr=udp%3a%2f%2ftracker.zemoj.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.tiny-vps.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.theoks.net%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.publictracker.xyz%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.monitorit4.me%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.moeking.me%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.lelux.fi%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.dler.org%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.army%3a6969%2fannounce
  select-file=1
  index-out=1=StableDiffusion/v1-5-pruned-emaonly.ckpt
  follow-torrent=mem
  follow-metalink=mem
  seed-time=0
  # this is the only way aria2c won't fail if the file already exists
  check-integrity=true
https://drive.yerf.org/wl/?id=EBfTrmcCCUAGaQBXVIj5lJmEhjoP1tgl&mode=grid&download=1
  out=StableDiffusion/model.ckpt
https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth
  out=GFPGAN/GFPGANv1.4.pth
https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth
  out=RealESRGAN/RealESRGAN_x4plus.pth
https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth
  out=RealESRGAN/RealESRGAN_x4plus_anime_6B.pth
https://heibox.uni-heidelberg.de/f/31a76b13ea27482981b4/?dl=1
  out=LDSR/project.yaml
https://heibox.uni-heidelberg.de/f/578df07c8fc04ffbadf3/?dl=1
  out=LDSR/model.ckpt

Run

docker build --tag download .
docker run --rm -it -v $PWD/data:/data download

서비스 실행 관련 파일들

Dockerfile

EOF 관련 문법 에러가 발생된다면 하단의 내용으로 사용한다.

# syntax=docker/dockerfile:1

FROM continuumio/miniconda3:4.12.0

SHELL ["/bin/bash", "-ceuxo", "pipefail"]

ENV DEBIAN_FRONTEND=noninteractive

RUN conda install python=3.8.5 && conda clean -a -y
RUN conda install pytorch==1.11.0 torchvision==0.12.0 cudatoolkit=11.3 -c pytorch && conda clean -a -y

RUN apt-get update && apt install fonts-dejavu-core rsync gcc -y && apt-get clean


RUN git config --global http.postBuffer 1048576000 && \
    git clone https://github.com/sd-webui/stable-diffusion-webui.git stable-diffusion && \
    cd stable-diffusion && \
    git reset --hard 1a9c053cb7b6832695771db2555c0adc9b41e95f && \
    conda env update --file environment.yaml -n base && \
    conda clean -a -y


ARG BRANCH=dev SHA=bb7fce1a871cc434145d5a2114e5d70cbdafa34d
RUN cd stable-diffusion && \
    git fetch && \
    git checkout ${BRANCH} && \
    git reset --hard ${SHA} && \
    conda env update --file environment.yaml -n base && \
    conda clean -a -y

# add info
COPY . /docker/
RUN python /docker/info.py /stable-diffusion/frontend/frontend.py && \
    chmod +x /docker/mount.sh /docker/run.sh && \
    sed -i -- 's/8501/7860/g' /stable-diffusion/.streamlit/config.toml

WORKDIR /stable-diffusion
ENV PYTHONPATH="${PYTHONPATH}:${PWD}" STREAMLIT_SERVER_HEADLESS=true USE_STREAMLIT=0 CLI_ARGS=""
EXPOSE 7860

CMD /docker/mount.sh && /docker/run.sh

info.py

import sys
from pathlib import Path

file = Path(sys.argv[1])
file.write_text(
  file.read_text()\
  .replace('<p>For help and advanced usage guides,', """
  <p>
    Created using <a href="https://github.com/AbdBarho/stable-diffusion-webui-docker">stable-diffusion-webui-docker</a>.
  </p>
  <p>For help and advanced usage guides,
""", 1)
)

mount.sh

#!/bin/bash

set -Eeuo pipefail

declare -A MOUNTS

ROOT=/stable-diffusion/src

# cache
MOUNTS["/root/.cache"]=/data/.cache
# ui specific
MOUNTS["${PWD}/models/realesrgan"]=/data/RealESRGAN
MOUNTS["${PWD}/models/ldsr"]=/data/LDSR
MOUNTS["${PWD}/models/custom"]=/data/StableDiffusion

# hack
MOUNTS["${PWD}/models/gfpgan/GFPGANv1.3.pth"]=/data/GFPGAN/GFPGANv1.4.pth
MOUNTS["${PWD}/models/gfpgan/GFPGANv1.4.pth"]=/data/GFPGAN/GFPGANv1.4.pth

for to_path in "${!MOUNTS[@]}"; do
  set -Eeuo pipefail
  from_path="${MOUNTS[${to_path}]}"
  rm -rf "${to_path}"
  mkdir -p "$(dirname "${to_path}")"
  ln -sT "${from_path}" "${to_path}"
  echo Mounted $(basename "${from_path}")
done

# streamlit config
ln -sf /docker/userconfig_streamlit.yaml /stable-diffusion/configs/webui/userconfig_streamlit.yaml

run.sh

#!/bin/bash

set -Eeuo pipefail

echo "USE_STREAMLIT = ${USE_STREAMLIT}"
if [ "${USE_STREAMLIT}" == "1" ]; then
  python -u -m streamlit run scripts/webui_streamlit.py
else
  python3 -u scripts/webui.py --outdir /output --ckpt /data/StableDiffusion/v1-5-pruned-emaonly.ckpt ${CLI_ARGS}
fi

userconfig_streamlit.yaml

general:
  version: 1.24.6
  outdir: /output
  default_model: "Stable Diffusion v1.5"
  default_model_path: /data/StableDiffusion/v1-5-pruned-emaonly.ckpt
  outdir_txt2img: /output/txt2img-samples
  outdir_img2img: /output/img2img-samples
  outdir_img2txt: /output/img2txt
  optimized_turbo: True

Run

GPU에서 구동해야 하므로 nvidia-docker는 반드시 필요하다.

docker build --tag hlky .
docker run --rm -it -v $PWD/data:/data -v $PWD/output:/output -p 7860:7860 -e CLI_ARGS=--optimized-turbo -e USE_STREAMLIT=0 --gpus all hlky

필요하다면 특정 GPU 만 선택해도 된다: --gpus '"device=0,1"'

최신버전 (2023-03-02) Docker Container 에서 실행 방법

아래 명령을 Dockerfile로 잘 매꾸면 된다.

sudo apt install curl git python3 python3-venv

## 'ImportError: libGL.so.1: cannot open shared object file: No such file or directory' 에러 방지용
sudo apt install libgl1-mesa-glx

## ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
sudo apt install libglib2.0-0

curl -O "https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh"
mkdir /home/root
bash /webui.sh -f

수동 실행 방법 (sdweb)

초기화 스크립트:

#!/usr/bin/env bash

REPOS=stable-diffusion-webui/repositories

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui/ ./stable-diffusion-webui
git -C ./stable-diffusion-webui checkout 0cc0ee1bcb4c24a8c9715f66cede06601bfc00c8

./python -m pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
./python -m pip install --prefer-binary "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379"
./python -m pip install --prefer-binary "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379"
./python -m pip install --prefer-binary "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1"
./python -m pip install --prefer-binary "git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b"
./python -m pip install --prefer-binary xformers==0.0.16rc425
./python -m pip install --prefer-binary pyngrok

mkdir -vp "$REPOS"

git clone "https://github.com/Stability-AI/stablediffusion.git" "$REPOS/stable-diffusion-stability-ai"
git -C "$REPOS/stable-diffusion-stability-ai" checkout 47b6b607fdd31875c9279cd2f4f16b92e4ea958e

git clone "https://github.com/CompVis/taming-transformers.git" "$REPOS/taming-transformers"
git -C "$REPOS/taming-transformers" checkout 24268930bf1dce879235a7fddd0b2355b84d7ea6

git clone "https://github.com/crowsonkb/k-diffusion.git" "$REPOS/k-diffusion"
git -C "$REPOS/k-diffusion" checkout 5b3af030dd83e0297272d861c19477735d0317ec

git clone "https://github.com/sczhou/CodeFormer.git" "$REPOS/CodeFormer"
git -C "$REPOS/CodeFormer" checkout c5b4593074ba6214284d6acd5f1719b6c5d739af

git clone "https://github.com/salesforce/BLIP.git" "$REPOS/BLIP"
git -C "$REPOS/BLIP" checkout 48211a1594f1321b00f14c9f7a5b4813144b2fb9

./python -m pip install -r "$REPOS/CodeFormer/requirements.txt"
./python -m pip install -r stable-diffusion-webui/requirements_versions.txt

# list_extensions
# ./python -m pip {extensions}/install.py"

# Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors" to /home/your/Project/sdweb/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors

실행 스크립트:

#!/usr/bin/env bash

cd stable-diffusion-webui && ../python launch.py --listen

See also

Favorite site

YuoTube

Extensions

Models

Prompt