diff --git a/apps/sd-webui-comfy/README.md b/apps/sd-webui-comfy/README.md new file mode 100644 index 00000000..aae205b5 --- /dev/null +++ b/apps/sd-webui-comfy/README.md @@ -0,0 +1,45 @@ +## 项目介绍 + +stable-deffusion是基于pytorch的目标检测模型, +当前版本镜像支持GPU,CPU模式需要修改yaml参数,未测试。 +GPU最小8G起,4G显存下未测试 + +安装过程比较漫长,取决于初始模型下载速度,需要耐心等待 +安装面板支持apt、pip指令。详细可参考yml文件,当前版本默认安装即可,由于比较消耗资源,限定镜像仅部署1个 + +本镜像仅做移植,所有功能基于原作者,参考:https://github.com/thirdscam/SD-WebUI-Docker + +webui有两个可以选择,都在应用商店里,a1111版和comfy + +安装前确保docker默认支持gpu,配置在/etc/docker/daemon.json上改,像这样: +``` +{ + "runtimes": { + "nvidia": { + "path": "nvidia-container-runtime", + "runtimeArgs": [] + } + }, + "default-runtime": "nvidia" +} +``` + +## 关于缺少依赖的报错 +安装镜像过程会自动安装当前版本所需依赖 +为适应未来版本变化,添加了apt和pip指令,当前版本不填即可。 +当然如果宿主机未安装nvidia-docker-runtime、nvidia-docker2、nvidia-container-toolkit等nvidia容器运行的依赖,可以使用该功能,只需在APT参数上写包名即可,多个包加空格。 + + +## 关于GPU +当前仅设置单GPU,nvdia-smi可以查看gpu的ID,默认0,单显卡默认即可 +多显卡可以根据id选择, +如果需要使用所有显卡,需要更改yaml文件,将id设置为all + +## 其他 +stable-deffusion相关教程:https://www.bilibili.com/video/BV1As4y127HW/?spm_id_from=333.337.search-card.all.click&vd_source=101386edb3f81944f8492e12ee8cb5b6 + +## api接口 +http://localhost:7860/docs/ + +## 模型下载站 +https://civitai.com/ \ No newline at end of file diff --git a/apps/sd-webui-comfy/data.yml b/apps/sd-webui-comfy/data.yml new file mode 100644 index 00000000..a2ec101e --- /dev/null +++ b/apps/sd-webui-comfy/data.yml @@ -0,0 +1,13 @@ +additionalProperties: #固定参数 + key: sd-webui-comfy #应用的 key ,仅限英文,用于在 Linux 创建文件夹 + name: sd-webui-comfy #应用名称 + tags: + - Local #应用标签,可以有多个,请参照下方的标签列表 + shortDescZh: comfy版sd-web #应用中文描述,不要超过30个字 + shortDescEn: stable-diffusion-webui-comfy #应用英文描述 + type: Local #应用类型,区别于应用分类,只能有一个,请参照下方的类型列表 + crossVersionUpdate: true #是否可以跨大版本升级 + limit: 0 #应用安装数量限制,0 代表无限制 + website: https://github.com/thirdscam/SD-WebUI-Docker #官网地址 + github: https://github.com/thirdscam/SD-WebUI-Docker #github 地址 + document: https://github.com/thirdscam/SD-WebUI-Docker #文档地址 diff --git a/apps/sd-webui-comfy/logo.png b/apps/sd-webui-comfy/logo.png new file mode 100644 index 00000000..65524863 Binary files /dev/null and b/apps/sd-webui-comfy/logo.png differ diff --git a/apps/sd-webui-comfy/sd-webui-comfy/comfy/Dockerfile b/apps/sd-webui-comfy/sd-webui-comfy/comfy/Dockerfile new file mode 100644 index 00000000..43a41675 --- /dev/null +++ b/apps/sd-webui-comfy/sd-webui-comfy/comfy/Dockerfile @@ -0,0 +1,32 @@ +FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 + +ENV DEBIAN_FRONTEND=noninteractive +ENV PIP_PREFER_BINARY=1 +ENV ROOT=/apt + +RUN mkdir ${ROOT} +WORKDIR ${ROOT} + +# Install Essential Packages (APT) +RUN apt-get update && apt-get install -y git python3 python3-pip && apt-get clean + +# Get Comfy +RUN git clone https://github.com/comfyanonymous/ComfyUI.git . + +# Install Essential Packages (PIP) +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118 && \ + pip install -r requirements.txt && \ + pip install --pre xformers && \ + pip install triton + +# Setting up +COPY entrypoint.sh /docker/entrypoint.sh +RUN chmod +x /docker/entrypoint.sh +ENTRYPOINT ["/docker/entrypoint.sh"] + +ENV PYTHONPATH="${PYTHONPATH}:${PWD}" + +CMD test -z "${APT_ARGS}" || apt-get -y install ${APT_ARGS} \ + && test -z "${PIP_ARGS}" || pip install ${PIP_ARGS} \ + && python3 -u main.py ${CLI_ARGS} \ No newline at end of file diff --git a/apps/sd-webui-comfy/sd-webui-comfy/comfy/entrypoint.sh b/apps/sd-webui-comfy/sd-webui-comfy/comfy/entrypoint.sh new file mode 100644 index 00000000..b3723318 --- /dev/null +++ b/apps/sd-webui-comfy/sd-webui-comfy/comfy/entrypoint.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -Eeuo pipefail + +declare -A MOUNTS + +mkdir -vp /data/config/comfy/ + +# cache +MOUNTS["/root/.cache"]=/data/.cache +# ui specific +MOUNTS["${ROOT}/models/checkpoints"]="/data/StableDiffusion" +MOUNTS["${ROOT}/models/controlnet"]="/data/ControlNet" +MOUNTS["${ROOT}/models/upscale_models/RealESRGAN"]="/data/RealESRGAN" +MOUNTS["${ROOT}/models/upscale_models/GFPGAN"]="/data/GFPGAN" +MOUNTS["${ROOT}/models/upscale_models/SwinIR"]="/data/SwinIR" +MOUNTS["${ROOT}/models/vae"]="/data/VAE" + +# data +MOUNTS["${ROOT}/models/loras"]="/data/Lora" +MOUNTS["${ROOT}/models/embeddings"]="/data/embeddings" + +# config +# TODO: I am not sure if this is final, maybe it should change in the future +MOUNTS["${ROOT}/models/clip"]="/data/.cache/comfy/clip" +MOUNTS["${ROOT}/models/clip_vision"]="/data/.cache/comfy/clip_vision" +MOUNTS["${ROOT}/models/custom_nodes"]="/data/config/comfy/custom_nodes" +MOUNTS["${ROOT}/models/style_models"]="/data/config/comfy/style_models" +MOUNTS["${ROOT}/models/t2i_adapter"]="/data/config/comfy/t2i_adapter" + +# output +MOUNTS["${ROOT}/output"]="/output/comfy" + +for to_path in "${!MOUNTS[@]}"; do + set -Eeuo pipefail + from_path="${MOUNTS[${to_path}]}" + rm -rf "${to_path}" + if [ ! -f "$from_path" ]; then + mkdir -vp "$from_path" + fi + mkdir -vp "$(dirname "${to_path}")" + ln -sT "${from_path}" "${to_path}" + echo Mounted $(basename "${from_path}") +done + +exec "$@" diff --git a/apps/sd-webui-comfy/sd-webui-comfy/data.yml b/apps/sd-webui-comfy/sd-webui-comfy/data.yml new file mode 100644 index 00000000..2a9fd10c --- /dev/null +++ b/apps/sd-webui-comfy/sd-webui-comfy/data.yml @@ -0,0 +1,46 @@ +additionalProperties: + formFields: + - default: http://localhost:7890 + edit: true + envKey: SD_CONSOLE_URL + labelEn: External URL + labelZh: 外部访问地址 + required: true + rule: paramExtUrl + type: text + - default: 7890 + edit: true + envKey: SD_CONSOLE_PORT + labelEn: Port + labelZh: 端口 + required: true + rule: paramPort + type: number + - default: --listen --port 7890 + edit: true + envKey: SD_CONSOLE_CLI_COMFY + labelEn: CLI_ARGS_for_Comfy + labelZh: COMFY的CLI_ARGS参数 + required: true + type: text + - default: "" + edit: true + envKey: SD_CONSOLE_APT_COMFY + labelEn: APT_For_COMFY + labelZh: COMFY的APT参数 + required: false + type: text + - default: "" + edit: true + envKey: SD_CONSOLE_PIP_COMFY + labelEn: PIP_For_COMFY + labelZh: COMFY的PIP参数 + required: false + type: text + - default: 0 + edit: true + envKey: SD_CONSOLE_DEVICE_IDS + labelEn: SD_CONSOLE_GPU_DEVICE_IDS + labelZh: SD运行指定的GPU设备ID + required: true + type: number diff --git a/apps/sd-webui-comfy/sd-webui-comfy/docker-compose.yml b/apps/sd-webui-comfy/sd-webui-comfy/docker-compose.yml new file mode 100644 index 00000000..3f0d8016 --- /dev/null +++ b/apps/sd-webui-comfy/sd-webui-comfy/docker-compose.yml @@ -0,0 +1,41 @@ +version: '3.9' +services: + a1111: + container_name: ${CONTAINER_NAME} + build: ./comfy + ports: + - "${SD_CONSOLE_PORT}:7890" + volumes: + - ./data:/data + - ./output:/output + stop_signal: SIGINT + environment: + # CLI_ARGS: Command Line Arguments. + # https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Command-Line-Arguments-and-Settings + # If you want, you can add other Command Line Arguments by referring to the link above. + + # By default, it runs through `--opt-sdp-no-mem-attention` without using xformers. + # If you want, you can run it through xformers by deleting `--opt-sdp-no-mem-attention` and inserting `--xformers`. + - CLI_ARGS=${SD_CONSOLE_CLI_COMFY} + #--listen --port 7890 --enable-insecure-extension-access --api --theme=dark --no-half-vae --opt-sdp-no-mem-attention + + # APT_ARGS, PIP_ARGS: This is where you write the apt and pip packages to install. + # Install some package if you want. + - APT_ARGS=${SD_CONSOLE_APT_COMFY} + # ex) APT_ARGS=package1 package2 ... + # equals apt-get install -y package1 package2 ... + - PIP_ARGS=${SD_CONSOLE_PIP_COMFY} + # ex) PIP_ARGS=package1 package2 ... + # equals pip install package1 package2 ... + + # Tip: If you want to do "pip install -U SomePackage", you can do "-U SomePackage" on the PIP_ARGS. + # Like This: PIP_ARGS=-U SomePackage + # Same at "--user SomePackage" + # PIP_ARGS=--user SomePackage + deploy: + resources: + reservations: + devices: + - driver: nvidia + device_ids: ['${SD_CONSOLE_DEVICE_IDS}'] + capabilities: [gpu,compute,utility] diff --git a/apps/sd-webui-comfy/sd-webui-comfy/scripts/init.sh b/apps/sd-webui-comfy/sd-webui-comfy/scripts/init.sh new file mode 100644 index 00000000..993344ef --- /dev/null +++ b/apps/sd-webui-comfy/sd-webui-comfy/scripts/init.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker compose up -d --build diff --git a/apps/sd-webui-comfy/sd-webui-comfy/scripts/update.sh b/apps/sd-webui-comfy/sd-webui-comfy/scripts/update.sh new file mode 100644 index 00000000..3e1d3e03 --- /dev/null +++ b/apps/sd-webui-comfy/sd-webui-comfy/scripts/update.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker compose build --no-cache +docker compose up -d \ No newline at end of file