├── .devscripts ├── chmod.sh ├── migratev1tov2.sh ├── migratev3tov4.sh └── migratev7tov8.sh ├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug.md │ └── config.yml ├── pull_request_template.md └── workflows │ ├── docker.yml │ └── stale.yml ├── .gitignore ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── data └── .gitignore ├── docker-compose.yml ├── output └── .gitignore └── services ├── AUTOMATIC1111 ├── Dockerfile ├── clone.sh ├── config.py └── entrypoint.sh ├── comfy ├── Dockerfile ├── entrypoint.sh └── extra_model_paths.yaml └── download ├── Dockerfile ├── checksums.sha256 ├── download.sh └── links.txt /.devscripts/chmod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuo pipefail 4 | 5 | find services -name "*.sh" -exec git update-index --chmod=+x {} \; 6 | find .devscripts -name "*.sh" -exec git update-index --chmod=+x {} \; 7 | -------------------------------------------------------------------------------- /.devscripts/migratev1tov2.sh: -------------------------------------------------------------------------------- 1 | mkdir -p data/.cache data/StableDiffusion data/Codeformer data/GFPGAN data/ESRGAN data/BSRGAN data/RealESRGAN data/SwinIR data/LDSR data/embeddings 2 | 3 | cp -vf cache/models/model.ckpt data/StableDiffusion/model.ckpt 4 | 5 | cp -vf cache/models/LDSR.ckpt data/LDSR/model.ckpt 6 | cp -vf cache/models/LDSR.yaml data/LDSR/project.yaml 7 | 8 | cp -vf cache/models/RealESRGAN_x4plus.pth data/RealESRGAN/ 9 | cp -vf cache/models/RealESRGAN_x4plus_anime_6B.pth data/RealESRGAN/ 10 | 11 | cp -vrf cache/torch data/.cache/ 12 | 13 | mkdir -p data/.cache/huggingface/transformers/ 14 | cp -vrf cache/transformers/* data/.cache/huggingface/transformers/ 15 | 16 | cp -v cache/custom-models/* data/StableDiffusion/ 17 | 18 | mkdir -p data/.cache/clip/ 19 | cp -vf cache/weights/ViT-L-14.pt data/.cache/clip/ 20 | 21 | cp -vf cache/weights/codeformer.pth data/Codeformer/codeformer-v0.1.0.pth 22 | 23 | cp -vf cache/weights/detection_Resnet50_Final.pth data/.cache/ 24 | cp -vf cache/weights/parsing_parsenet.pth data/.cache/ 25 | 26 | cp -v embeddings/* data/embeddings/ 27 | 28 | echo this script was created 10/2022 29 | echo Dont forget to run: docker compose --profile download up --build 30 | echo the cache and embeddings folders can be deleted, but its not necessary. 31 | -------------------------------------------------------------------------------- /.devscripts/migratev3tov4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuo pipefail 4 | 5 | echo "Moving everything in output to output/old..." 6 | mv output old 7 | mkdir output 8 | mv old/.gitignore output 9 | mv old output 10 | -------------------------------------------------------------------------------- /.devscripts/migratev7tov8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuo pipefail 4 | 5 | echo "Renaming..." 6 | 7 | # compatible with default auto-names 8 | mv -v ./data/StableDiffusion ./data/Stable-diffusion 9 | mv -v ./data/Deepdanbooru ./data/torch_deepdanbooru 10 | 11 | # casing problem on windows 12 | mv -v ./data/Hypernetworks ./data/hypernetworks1 13 | mv -v ./data/hypernetworks1 ./data/hypernetworks 14 | 15 | mv -v ./data/MiDaS ./data/midas1 16 | mv -v ./data/midas1 ./data/midas 17 | 18 | 19 | echo "Moving folders..." 20 | 21 | mkdir -pv ./final 22 | 23 | mv -v ./data/config ./final/config 24 | mv -v ./data/.cache ./final/.cache 25 | mv -v ./data/embeddings ./final/embeddings 26 | mv -v ./data ./final/models 27 | 28 | mv -v ./final ./data 29 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug 3 | about: Report a bug 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | 10 | 11 | **Has this issue been opened before?** 12 | 13 | - [ ] It is not in the [FAQ](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/FAQ), I checked. 14 | - [ ] It is not in the [issues](https://github.com/AbdBarho/stable-diffusion-webui-docker/issues?q=), I searched. 15 | 16 | **Describe the bug** 17 | 18 | 19 | 20 | **Which UI** 21 | 22 | auto or auto-cpu or invoke or comfy? 23 | 24 | **Hardware / Software** 25 | 26 | - OS: [e.g. Windows 10 / Ubuntu 22.04] 27 | - OS version: 28 | - WSL version (if applicable): 29 | - Docker Version: 30 | - Docker compose version: 31 | - Repo version: 32 | - RAM: 33 | - GPU/VRAM: 34 | 35 | **Steps to Reproduce** 36 | 37 | 1. Go to '...' 38 | 2. Click on '....' 39 | 3. Scroll down to '....' 40 | 4. See error 41 | 42 | **Additional context** 43 | Any other context about the problem here. If applicable, add screenshots to help explain your problem. 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Feature request? Questions regarding some extension? 4 | url: https://github.com/AbdBarho/stable-diffusion-webui-docker/discussions 5 | about: Please use the discussions tab 6 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | Closes issue # 8 | 9 | ### Update versions 10 | 11 | - auto: https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ 12 | - invoke: https://github.com/invoke-ai/InvokeAI/commit/ 13 | - comfy: https://github.com/comfyanonymous/ComfyUI/commit/ 14 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Build Images 2 | 3 | on: 4 | push: 5 | branches: master 6 | pull_request: 7 | paths: 8 | - docker-compose.yml 9 | - services 10 | 11 | jobs: 12 | build: 13 | strategy: 14 | matrix: 15 | profile: 16 | - auto 17 | - comfy 18 | - download 19 | runs-on: ubuntu-latest 20 | name: ${{ matrix.profile }} 21 | steps: 22 | - uses: actions/checkout@v3 23 | - run: docker compose --profile ${{ matrix.profile }} build --progress plain 24 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | on: 3 | schedule: 4 | - cron: '0 0 * * *' 5 | 6 | jobs: 7 | stale: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/stale@v6 11 | with: 12 | only-labels: awaiting-response 13 | stale-issue-message: This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. 14 | stale-pr-message: This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. 15 | close-issue-message: This issue was closed because it has been stalled for 7 days with no activity. 16 | close-pr-message: This PR was closed because it has been stalled for 7 days with no activity. 17 | days-before-issue-stale: 14 18 | days-before-pr-stale: 14 19 | days-before-issue-close: 7 20 | days-before-pr-close: 7 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.devcontainer 2 | /docker-compose.override.yml 3 | 4 | # VSCode specific 5 | *.code-workspace 6 | /.vscode 7 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "WebUI", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "${file}", 12 | "cwd": "/stable-diffusion", 13 | "args": ["--ckpt", "${workspaceFolder}/models/model.ckpt", "--gfpgan-dir", "${workspaceFolder}/models/", "--extra-models-cpu"], 14 | "env": { 15 | "TRANSFORMERS_CACHE":"${workspaceFolder}/cache/transformers", 16 | "TORCH_HOME":"${workspaceFolder}/cache/torch" 17 | }, 18 | "console": "integratedTerminal", 19 | "justMyCode": false 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | License 2 | 3 | Copyright (c) 2022 4 | 5 | Section I 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | The person obtaining a copy of the Software meets the Use-based restrictions 18 | as referenced in Section II paragraph 1. 19 | 20 | The person obtaining a copy of the Software accepts that the Model or 21 | Derivatives of the Model (as defined in the "CreativeML Open RAIL-M" license 22 | accompanying this License) are subject to Section II paragraph 1. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 | SOFTWARE. 31 | 32 | Section II 33 | 34 | 1. Use-based restrictions. The restrictions set forth in Attachment A are 35 | considered Use-based restrictions. Therefore the person obtaining a copy of the 36 | Software cannot use the Software for the specified restricted uses. The person 37 | obtaining a copy of the Software may use the Software only for lawful purposes. 38 | 39 | 2. Except as set forth herein, the authors or copyright holders claim no rights 40 | in the results of operating the Software. The person obtaining a copy of the 41 | Software is accountable for the results of operating the Software and its 42 | subsequent uses. 43 | 44 | 3. If any provision of this License is held to be invalid, illegal or 45 | unenforceable, the remaining provisions shall be unaffected thereby and 46 | remain valid as if such provision had not been set forth herein. 47 | 48 | END OF TERMS AND CONDITIONS 49 | 50 | 51 | 52 | 53 | 54 | Attachment A 55 | 56 | Use Restrictions 57 | 58 | The person obtaining a copy of the Software agrees not to use the Software: 59 | - In any way that violates any applicable national, federal, state, local 60 | or international law or regulation; 61 | - For the purpose of exploiting, harming or attempting to exploit or harm 62 | minors in any way; 63 | - To generate or disseminate verifiably false information and/or content 64 | with the purpose of harming others; 65 | - To generate or disseminate personal identifiable information that can 66 | be used to harm an individual; 67 | - To defame, disparage or otherwise harass others; 68 | - For fully automated decision making that adversely impacts an 69 | individual’s legal rights or otherwise creates or modifies a binding, 70 | enforceable obligation; 71 | - For any use intended to or which has the effect of discriminating 72 | against or harming individuals or groups based on online or offline 73 | social behavior or known or predicted personal or personality 74 | characteristics; 75 | - To exploit any of the vulnerabilities of a specific group of persons 76 | based on their age, social, physical or mental characteristics, in order 77 | to materially distort the behavior of a person pertaining to that group 78 | in a manner that causes or is likely to cause that person or another 79 | person physical or psychological harm; 80 | - For any use intended to or which has the effect of discriminating 81 | against individuals or groups based on legally protected characteristics 82 | or categories; 83 | - To provide medical advice and medical results interpretation; 84 | - To generate or disseminate information for the purpose to be used for 85 | administration of justice, law enforcement, immigration or asylum 86 | processes, such as predicting an individual will commit fraud/crime 87 | commitment (e.g. by text profiling, drawing causal relationships between 88 | assertions made in documents, indiscriminate and arbitrarily-targeted 89 | use). 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stable Diffusion WebUI Docker 2 | 3 | Run Stable Diffusion on your machine with a nice UI without any hassle! 4 | 5 | ## Setup & Usage 6 | 7 | Visit the wiki for [Setup](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Setup) and [Usage](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Usage) instructions, checkout the [FAQ](https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/FAQ) page if you face any problems, or create a new issue! 8 | 9 | ## Features 10 | 11 | This repository provides multiple UIs for you to play around with stable diffusion: 12 | 13 | ### [AUTOMATIC1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 14 | 15 | [Full feature list here](https://github.com/AUTOMATIC1111/stable-diffusion-webui-feature-showcase), Screenshots: 16 | 17 | | Text to image | Image to image | Extras | 18 | | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | 19 | | ![](https://user-images.githubusercontent.com/24505302/189541954-46afd772-d0c8-4005-874c-e2eca40c02f2.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541956-5b528de7-1b5d-479f-a1db-d3f5a53afc59.jpg) | ![](https://user-images.githubusercontent.com/24505302/189541957-cf78b352-a071-486d-8889-f26952779a61.jpg) | 20 | 21 | ### [ComfyUI](https://github.com/comfyanonymous/ComfyUI) 22 | 23 | [Full feature list here](https://github.com/comfyanonymous/ComfyUI#features), Screenshot: 24 | 25 | | Workflow | 26 | | -------------------------------------------------------------------------------- | 27 | | ![](https://github.com/comfyanonymous/ComfyUI/raw/master/comfyui_screenshot.png) | 28 | 29 | ## Contributing 30 | 31 | Contributions are welcome! **Create a discussion first of what the problem is and what you want to contribute (before you implement anything)** 32 | 33 | ## Disclaimer 34 | 35 | The authors of this project are not responsible for any content generated using this interface. 36 | 37 | This license of this software forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please read [the license](./LICENSE). 38 | 39 | ## Thanks 40 | 41 | Special thanks to everyone behind these awesome projects, without them, none of this would have been possible: 42 | 43 | - [AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 44 | - [InvokeAI](https://github.com/invoke-ai/InvokeAI) 45 | - [ComfyUI](https://github.com/comfyanonymous/ComfyUI) 46 | - [CompVis/stable-diffusion](https://github.com/CompVis/stable-diffusion) 47 | - [Sygil-webui](https://github.com/Sygil-Dev/sygil-webui) 48 | - and many many more. 49 | -------------------------------------------------------------------------------- /data/.gitignore: -------------------------------------------------------------------------------- 1 | /.cache 2 | /config 3 | /embeddings 4 | /models 5 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | x-base_service: &base_service 2 | ports: 3 | - "${WEBUI_PORT:-7860}:7860" 4 | volumes: 5 | - &v1 ./data:/data 6 | - &v2 ./output:/output 7 | stop_signal: SIGKILL 8 | tty: true 9 | deploy: 10 | resources: 11 | reservations: 12 | devices: 13 | - driver: nvidia 14 | device_ids: ['0'] 15 | capabilities: [compute, utility] 16 | 17 | name: webui-docker 18 | 19 | services: 20 | download: 21 | build: ./services/download/ 22 | profiles: ["download"] 23 | volumes: 24 | - *v1 25 | 26 | auto: &automatic 27 | <<: *base_service 28 | profiles: ["auto"] 29 | build: ./services/AUTOMATIC1111 30 | image: sd-auto:78 31 | environment: 32 | - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api 33 | 34 | auto-cpu: 35 | <<: *automatic 36 | profiles: ["auto-cpu"] 37 | deploy: {} 38 | environment: 39 | - CLI_ARGS=--no-half --precision full --allow-code --enable-insecure-extension-access --api 40 | 41 | comfy: &comfy 42 | <<: *base_service 43 | profiles: ["comfy"] 44 | build: ./services/comfy/ 45 | image: sd-comfy:7 46 | environment: 47 | - CLI_ARGS= 48 | 49 | 50 | comfy-cpu: 51 | <<: *comfy 52 | profiles: ["comfy-cpu"] 53 | deploy: {} 54 | environment: 55 | - CLI_ARGS=--cpu 56 | -------------------------------------------------------------------------------- /output/.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !/.gitignore -------------------------------------------------------------------------------- /services/AUTOMATIC1111/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine/git:2.36.2 as download 2 | 3 | COPY clone.sh /clone.sh 4 | 5 | RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git 6f7db241d2f8ba7457bac5ca9753331f0c266917 6 | 7 | RUN . /clone.sh stable-diffusion-stability-ai https://github.com/Stability-AI/stablediffusion.git cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf \ 8 | && rm -rf assets data/**/*.png data/**/*.jpg data/**/*.gif 9 | 10 | RUN . /clone.sh BLIP https://github.com/salesforce/BLIP.git 48211a1594f1321b00f14c9f7a5b4813144b2fb9 11 | RUN . /clone.sh k-diffusion https://github.com/crowsonkb/k-diffusion.git ab527a9a6d347f364e3d185ba6d714e22d80cb3c 12 | RUN . /clone.sh clip-interrogator https://github.com/pharmapsychotic/clip-interrogator 2cf03aaf6e704197fd0dae7c7f96aa59cf1b11c9 13 | RUN . /clone.sh generative-models https://github.com/Stability-AI/generative-models 45c443b316737a4ab6e40413d7794a7f5657c19f 14 | RUN . /clone.sh stable-diffusion-webui-assets https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets 6f7db241d2f8ba7457bac5ca9753331f0c266917 15 | 16 | 17 | FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime 18 | 19 | ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 20 | 21 | RUN --mount=type=cache,target=/var/cache/apt \ 22 | apt-get update && \ 23 | # we need those 24 | apt-get install -y fonts-dejavu-core rsync git jq moreutils aria2 \ 25 | # extensions needs those 26 | ffmpeg libglfw3-dev libgles2-mesa-dev pkg-config libcairo2 libcairo2-dev build-essential 27 | 28 | 29 | WORKDIR / 30 | RUN --mount=type=cache,target=/root/.cache/pip \ 31 | git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \ 32 | cd stable-diffusion-webui && \ 33 | git reset --hard v1.9.4 && \ 34 | pip install -r requirements_versions.txt 35 | 36 | 37 | ENV ROOT=/stable-diffusion-webui 38 | 39 | COPY --from=download /repositories/ ${ROOT}/repositories/ 40 | RUN mkdir ${ROOT}/interrogate && cp ${ROOT}/repositories/clip-interrogator/clip_interrogator/data/* ${ROOT}/interrogate 41 | 42 | RUN --mount=type=cache,target=/root/.cache/pip \ 43 | pip install pyngrok xformers==0.0.26.post1 \ 44 | git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 \ 45 | git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 \ 46 | git+https://github.com/mlfoundations/open_clip.git@v2.20.0 47 | 48 | # there seems to be a memory leak (or maybe just memory not being freed fast enough) that is fixed by this version of malloc 49 | # maybe move this up to the dependencies list. 50 | RUN apt-get -y install libgoogle-perftools-dev && apt-get clean 51 | ENV LD_PRELOAD=libtcmalloc.so 52 | 53 | COPY . /docker 54 | 55 | RUN \ 56 | # mv ${ROOT}/style.css ${ROOT}/user.css && \ 57 | # one of the ugliest hacks I ever wrote \ 58 | sed -i 's/in_app_dir = .*/in_app_dir = True/g' /opt/conda/lib/python3.10/site-packages/gradio/routes.py && \ 59 | git config --global --add safe.directory '*' 60 | 61 | WORKDIR ${ROOT} 62 | ENV NVIDIA_VISIBLE_DEVICES=all 63 | ENV CLI_ARGS="" 64 | EXPOSE 7860 65 | ENTRYPOINT ["/docker/entrypoint.sh"] 66 | CMD python -u webui.py --listen --port 7860 ${CLI_ARGS} 67 | -------------------------------------------------------------------------------- /services/AUTOMATIC1111/clone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuox pipefail 4 | 5 | mkdir -p /repositories/"$1" 6 | cd /repositories/"$1" 7 | git init 8 | git remote add origin "$2" 9 | git fetch origin "$3" --depth=1 10 | git reset --hard "$3" 11 | rm -rf .git 12 | -------------------------------------------------------------------------------- /services/AUTOMATIC1111/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """Checks and sets default values for config.json before starting the container.""" 4 | 5 | import json 6 | import re 7 | import os.path 8 | import sys 9 | 10 | DEFAULT_FILEPATH = '/data/config/auto/config.json' 11 | 12 | DEFAULT_OUTDIRS = { 13 | "outdir_samples": "", 14 | "outdir_txt2img_samples": "/output/txt2img", 15 | "outdir_img2img_samples": "/output/img2img", 16 | "outdir_extras_samples": "/output/extras", 17 | "outdir_grids": "", 18 | "outdir_txt2img_grids": "/output/txt2img-grids", 19 | "outdir_img2img_grids": "/output/img2img-grids", 20 | "outdir_save": "/output/saved", 21 | "outdir_init_images": "/output/init-images", 22 | } 23 | RE_VALID_OUTDIR = re.compile(r"(^/output(/\.?[\w\-\_]+)+/?$)|(^\s?$)") 24 | 25 | DEFAULT_OTHER = { 26 | "font": "DejaVuSans.ttf", 27 | } 28 | 29 | def dict_to_json_file(target_file: str, data: dict): 30 | """Write dictionary to specified json file""" 31 | 32 | with open(target_file, 'w') as f: 33 | json.dump(data, f) 34 | 35 | def json_file_to_dict(config_file: str) -> dict|None: 36 | """Load json file into a dictionary. Return None if file does not exist.""" 37 | 38 | if os.path.isfile(config_file): 39 | with open(config_file, 'r') as f: 40 | return json.load(f) 41 | else: 42 | return None 43 | 44 | def replace_if_invalid(value: str, replacement: str, pattern: str|re.Pattern[str]) -> str: 45 | """Returns original value if valid, fallback value if invalid""" 46 | 47 | if re.match(pattern, value): 48 | return value 49 | else: 50 | return replacement 51 | 52 | def check_and_replace_config(config_file: str, target_file: str = None): 53 | """Checks given file for invalid values. Replaces those with fallback values (default: overwrites file).""" 54 | 55 | # Get current user config, or empty if file does not exists 56 | data = json_file_to_dict(config_file) or {} 57 | 58 | # Check and fix output directories 59 | for k, def_val in DEFAULT_OUTDIRS.items(): 60 | if k not in data: 61 | data[k] = def_val 62 | else: 63 | data[k] = replace_if_invalid(value=data[k], replacement=def_val, pattern=RE_VALID_OUTDIR) 64 | 65 | # Check and fix other default settings 66 | for k, def_val in DEFAULT_OTHER.items(): 67 | if k not in data: 68 | data[k] = def_val 69 | 70 | # Write results to file 71 | dict_to_json_file(target_file or config_file, data) 72 | 73 | if __name__ == '__main__': 74 | if len(sys.argv) > 1: 75 | check_and_replace_config(*sys.argv[1:]) 76 | else: 77 | check_and_replace_config(DEFAULT_FILEPATH) 78 | 79 | -------------------------------------------------------------------------------- /services/AUTOMATIC1111/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuo pipefail 4 | 5 | # TODO: move all mkdir -p ? 6 | mkdir -p /data/config/auto/scripts/ 7 | # mount scripts individually 8 | 9 | echo $ROOT 10 | ls -lha $ROOT 11 | 12 | find "${ROOT}/scripts/" -maxdepth 1 -type l -delete 13 | cp -vrfTs /data/config/auto/scripts/ "${ROOT}/scripts/" 14 | 15 | # Set up config file 16 | python /docker/config.py /data/config/auto/config.json 17 | 18 | if [ ! -f /data/config/auto/ui-config.json ]; then 19 | echo '{}' >/data/config/auto/ui-config.json 20 | fi 21 | 22 | if [ ! -f /data/config/auto/styles.csv ]; then 23 | touch /data/config/auto/styles.csv 24 | fi 25 | 26 | # copy models from original models folder 27 | mkdir -p /data/models/VAE-approx/ /data/models/karlo/ 28 | 29 | rsync -a --info=NAME ${ROOT}/models/VAE-approx/ /data/models/VAE-approx/ 30 | rsync -a --info=NAME ${ROOT}/models/karlo/ /data/models/karlo/ 31 | 32 | declare -A MOUNTS 33 | 34 | MOUNTS["/root/.cache"]="/data/.cache" 35 | MOUNTS["${ROOT}/models"]="/data/models" 36 | 37 | MOUNTS["${ROOT}/embeddings"]="/data/embeddings" 38 | MOUNTS["${ROOT}/config.json"]="/data/config/auto/config.json" 39 | MOUNTS["${ROOT}/ui-config.json"]="/data/config/auto/ui-config.json" 40 | MOUNTS["${ROOT}/styles.csv"]="/data/config/auto/styles.csv" 41 | MOUNTS["${ROOT}/extensions"]="/data/config/auto/extensions" 42 | MOUNTS["${ROOT}/config_states"]="/data/config/auto/config_states" 43 | 44 | # extra hacks 45 | MOUNTS["${ROOT}/repositories/CodeFormer/weights/facelib"]="/data/.cache" 46 | 47 | for to_path in "${!MOUNTS[@]}"; do 48 | set -Eeuo pipefail 49 | from_path="${MOUNTS[${to_path}]}" 50 | rm -rf "${to_path}" 51 | if [ ! -f "$from_path" ]; then 52 | mkdir -vp "$from_path" 53 | fi 54 | mkdir -vp "$(dirname "${to_path}")" 55 | ln -sT "${from_path}" "${to_path}" 56 | echo Mounted $(basename "${from_path}") 57 | done 58 | 59 | echo "Installing extension dependencies (if any)" 60 | 61 | # because we build our container as root: 62 | chown -R root ~/.cache/ 63 | chmod 766 ~/.cache/ 64 | 65 | shopt -s nullglob 66 | # For install.py, please refer to https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions#installpy 67 | list=(./extensions/*/install.py) 68 | for installscript in "${list[@]}"; do 69 | EXTNAME=$(echo $installscript | cut -d '/' -f 3) 70 | # Skip installing dependencies if extension is disabled in config 71 | if $(jq -e ".disabled_extensions|any(. == \"$EXTNAME\")" config.json); then 72 | echo "Skipping disabled extension ($EXTNAME)" 73 | continue 74 | fi 75 | PYTHONPATH=${ROOT} python "$installscript" 76 | done 77 | 78 | if [ -f "/data/config/auto/startup.sh" ]; then 79 | pushd ${ROOT} 80 | echo "Running startup script" 81 | . /data/config/auto/startup.sh 82 | popd 83 | fi 84 | 85 | exec "$@" 86 | -------------------------------------------------------------------------------- /services/comfy/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 4 | 5 | RUN apt-get update && apt-get install -y git && apt-get clean 6 | 7 | ENV ROOT=/stable-diffusion 8 | RUN --mount=type=cache,target=/root/.cache/pip \ 9 | git clone https://github.com/comfyanonymous/ComfyUI.git ${ROOT} && \ 10 | cd ${ROOT} && \ 11 | git checkout master && \ 12 | git reset --hard 276f8fce9f5a80b500947fb5745a4dde9e84622d && \ 13 | pip install -r requirements.txt 14 | 15 | WORKDIR ${ROOT} 16 | COPY . /docker/ 17 | RUN chmod u+x /docker/entrypoint.sh && cp /docker/extra_model_paths.yaml ${ROOT} 18 | 19 | ENV NVIDIA_VISIBLE_DEVICES=all PYTHONPATH="${PYTHONPATH}:${PWD}" CLI_ARGS="" 20 | EXPOSE 7860 21 | ENTRYPOINT ["/docker/entrypoint.sh"] 22 | CMD python -u main.py --listen --port 7860 ${CLI_ARGS} 23 | -------------------------------------------------------------------------------- /services/comfy/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -Eeuo pipefail 4 | 5 | mkdir -vp /data/config/comfy/custom_nodes 6 | 7 | declare -A MOUNTS 8 | 9 | MOUNTS["/root/.cache"]="/data/.cache" 10 | MOUNTS["${ROOT}/input"]="/data/config/comfy/input" 11 | MOUNTS["${ROOT}/output"]="/output/comfy" 12 | 13 | for to_path in "${!MOUNTS[@]}"; do 14 | set -Eeuo pipefail 15 | from_path="${MOUNTS[${to_path}]}" 16 | rm -rf "${to_path}" 17 | if [ ! -f "$from_path" ]; then 18 | mkdir -vp "$from_path" 19 | fi 20 | mkdir -vp "$(dirname "${to_path}")" 21 | ln -sT "${from_path}" "${to_path}" 22 | echo Mounted $(basename "${from_path}") 23 | done 24 | 25 | if [ -f "/data/config/comfy/startup.sh" ]; then 26 | pushd ${ROOT} 27 | . /data/config/comfy/startup.sh 28 | popd 29 | fi 30 | 31 | exec "$@" 32 | -------------------------------------------------------------------------------- /services/comfy/extra_model_paths.yaml: -------------------------------------------------------------------------------- 1 | a111: 2 | base_path: /data 3 | 4 | checkpoints: models/Stable-diffusion 5 | configs: models/Stable-diffusion 6 | vae: models/VAE 7 | loras: models/Lora 8 | upscale_models: | 9 | models/RealESRGAN 10 | models/ESRGAN 11 | models/SwinIR 12 | models/GFPGAN 13 | hypernetworks: models/hypernetworks 14 | controlnet: models/ControlNet 15 | gligen: models/GLIGEN 16 | clip: models/CLIPEncoder 17 | embeddings: embeddings 18 | 19 | custom_nodes: config/comfy/custom_nodes 20 | 21 | # TODO: I am unsure about these, need more testing 22 | # style_models: config/comfy/style_models 23 | # t2i_adapter: config/comfy/t2i_adapter 24 | # clip_vision: config/comfy/clip_vision 25 | # diffusers: config/comfy/diffusers 26 | -------------------------------------------------------------------------------- /services/download/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bash:alpine3.19 2 | 3 | RUN apk update && apk add parallel aria2 4 | COPY . /docker 5 | RUN chmod +x /docker/download.sh 6 | ENTRYPOINT ["/docker/download.sh"] 7 | -------------------------------------------------------------------------------- /services/download/checksums.sha256: -------------------------------------------------------------------------------- 1 | cc6cb27103417325ff94f52b7a5d2dde45a7515b25c255d8e396c90014281516 /data/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt 2 | c6bbc15e3224e6973459ba78de4998b80b50112b0ae5b5c67113d56b4e366b19 /data/models/Stable-diffusion/sd-v1-5-inpainting.ckpt 3 | c6a580b13a5bc05a5e16e4dbb80608ff2ec251a162311590c1f34c013d7f3dab /data/models/VAE/vae-ft-mse-840000-ema-pruned.ckpt 4 | e2cd4703ab14f4d01fd1383a8a8b266f9a5833dacee8e6a79d3bf21a1b6be5ad /data/models/GFPGAN/GFPGANv1.4.pth 5 | 4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1 /data/models/RealESRGAN/RealESRGAN_x4plus.pth 6 | f872d837d3c90ed2e05227bed711af5671a6fd1c9f7d7e91c911a61f155e99da /data/models/RealESRGAN/RealESRGAN_x4plus_anime_6B.pth 7 | c209caecac2f97b4bb8f4d726b70ac2ac9b35904b7fc99801e1f5e61f9210c13 /data/models/LDSR/model.ckpt 8 | 9d6ad53c5dafeb07200fb712db14b813b527edd262bc80ea136777bdb41be2ba /data/models/LDSR/project.yaml 9 | -------------------------------------------------------------------------------- /services/download/download.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -Eeuo pipefail 4 | 5 | # TODO: maybe just use the .gitignore file to create all of these 6 | mkdir -vp /data/.cache \ 7 | /data/embeddings \ 8 | /data/config/ \ 9 | /data/models/ \ 10 | /data/models/Stable-diffusion \ 11 | /data/models/GFPGAN \ 12 | /data/models/RealESRGAN \ 13 | /data/models/LDSR \ 14 | /data/models/VAE 15 | 16 | echo "Downloading, this might take a while..." 17 | 18 | aria2c -x 10 --disable-ipv6 --input-file /docker/links.txt --dir /data/models --continue 19 | 20 | echo "Checking SHAs..." 21 | 22 | parallel --will-cite -a /docker/checksums.sha256 "echo -n {} | sha256sum -c" 23 | 24 | cat <