├── Dockerfile ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | # build: docker build -t uberi/stable-diffusion . 2 | # run: docker run --rm -p 7860:7860 uberi/stable-diffusion 3 | 4 | FROM ubuntu:22.04 5 | 6 | ARG DEBIAN_FRONTEND=noninteractive 7 | RUN apt-get -y update 8 | RUN apt-get install -y wget git python3 python3-venv python3-pip 9 | 10 | RUN useradd -m dev 11 | USER dev 12 | WORKDIR /home/dev 13 | 14 | RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && cd stable-diffusion-webui && git reset --hard 53a3dc601fb734ce433505b1ca68770919106bad 15 | WORKDIR /home/dev/stable-diffusion-webui 16 | 17 | # these models get loaded at runtime when first used - download them now ahead of time so that we have them available 18 | # (determined by looking through the codebase for usages of load_models() from modules/modelloader.py) 19 | # since the official Stable Diffision model weights require signup to download, we found an alternative URL for `sd-v1-4.ckpt` from https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies 20 | RUN mkdir --parents models/Codeformer models/GFPGAN models/Stable-diffusion 21 | RUN wget -O models/Codeformer/codeformer-v0.1.0.pth 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth' 22 | RUN wget -O models/GFPGAN/GFPGANv1.4.pth 'https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth' 23 | RUN wget -O models/GFPGAN/detection_Resnet50_Final.pth 'https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth' 24 | RUN wget -O models/GFPGAN/parsing_parsenet.pth 'https://github.com/xinntao/facexlib/releases/download/v0.2.2/parsing_parsenet.pth' 25 | RUN wget -O models/Stable-diffusion/sd-v1-4.ckpt 'https://drive.yerf.org/wl/?id=EBfTrmcCCUAGaQBXVIj5lJmEhjoP1tgl&mode=grid&download=1' 26 | 27 | # install special CPU-oriented versions of torch and torchvision - much smaller because they don't include GPU support 28 | # the version numbers are taken from https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/53a3dc601fb734ce433505b1ca68770919106bad/launch.py#L13 29 | RUN pip3 install torch==1.12.1+cpu torchvision==0.13.1+cpu -f https://download.pytorch.org/whl/torch_stable.html 30 | 31 | # obtain most of the other dependencies needed for the model to run - this script clones some repos and installs their dependencies, as well as the dependencies of the web UI itself 32 | RUN COMMANDLINE_ARGS="--skip-torch-cuda-test --exit" python3 launch.py 33 | 34 | # install special non-graphical version of OpenCV - much smaller because they don't include graphics support 35 | RUN pip3 install opencv-python-headless==4.6.0.66 36 | 37 | # initialize CLIP since it downloads lots of files from the internet when first used 38 | RUN python3 -c 'from transformers import CLIPTokenizer, CLIPTextModel; version="openai/clip-vit-large-patch14"; CLIPTokenizer.from_pretrained(version); CLIPTextModel.from_pretrained(version)' 39 | 40 | # initialize Codeformers since it downloads lots of files from the internet when first used (mainly used for "Fix faces" option) 41 | RUN cd repositories/CodeFormer && python3 scripts/download_pretrained_models.py facelib 42 | 43 | EXPOSE 7860 44 | 45 | # start the web UI listening on 0.0.0.0:7860, disable half-size floats since we're running on CPUs that generally won't support those 46 | CMD [ "bash", "-c", "python3 webui.py --listen --port 7860 --no-half --precision full" ] 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Hypotenuse Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docker-stable-diffusion-webui 2 | ============================= 3 | 4 | A dockerized, CPU-only, self-contained version of AUTOMATIC1111's Stable Diffusion Web UI. 5 | 6 | Unlike other docker images out there, this one includes all necessary dependencies inside and weighs in at 9.7GiB - including the Stable Diffusion v1.4 weights! 7 | 8 | Quickstart: 9 | 10 | 1. Run `docker build -t uberi/stable-diffusion . && docker run --dns 0.0.0.0 --rm -t -p 7860:7860 uberi/stable-diffusion`. 11 | 2. The web UI should now be accessible at http://localhost:7860. 12 | 13 | Features: 14 | 15 | * Relatively small: we use the CPU-only versions of torch and torchvision, and the non-graphical version of OpenCV. 16 | * Self-contained: we pre-download the CLIP model, and retrieve the Stable Diffusion weights from an alternative source that doesn't login-wall the download. 17 | * CPU-only: can be run essentially anywhere, if you're willing to wait longer for the generation to happen. 18 | * Offline: all necessary models for the basic txt2img/img2img/upscale workflow are included in the image already, so we disable DNS to block telemetry (particularly from Gradio, which is used throughout the web UI). 19 | 20 | I also usually like to export an archive of the image locally with `docker save -o ../docker-stable-diffusion-webui.tar uberi/stable-diffusion`, so that it can be loaded later and on other computers using `docker load -i ../docker-stable-diffusion-webui.tar`. --------------------------------------------------------------------------------