diff --git a/frameworks/stable-diffusion-webui/1.10.1/Dockerfile b/frameworks/stable-diffusion-webui/1.10.1/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..be1a53171148f0a8afabacab270d060942145873 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.10.1/Dockerfile @@ -0,0 +1,78 @@ +FROM opencloudos/opencloudos9-cuda-devel:12.8 + +LABEL maintainer="Anstarc " +LABEL org.opencontainers.image.source="https://gitee.com/OpenCloudOS/ai-agent-container" +LABEL org.opencontainers.image.description="Stable Diffusion WebUI 1.10.1 on OpenCloudOS 9" + +# 安装系统依赖 +RUN dnf install -y \ + python3.11 \ + python3.11-pip \ + git \ + wget \ + mesa-libGL \ + glib2 \ + libgomp \ + && dnf clean all \ + && rm -rf /var/cache/yum/* + +# 设置工作目录 +WORKDIR /app + +# 克隆 Stable Diffusion WebUI v1.10.1 +RUN git clone --depth 1 --branch v1.10.1 \ + https://github.com/AUTOMATIC1111/stable-diffusion-webui.git . + +# 安装 PyTorch +RUN pip3.11 install --no-cache-dir \ + torch torchvision --index-url https://download.pytorch.org/whl/cu128 + +# 安装 WebUI 依赖 +RUN pip3.11 install --no-cache-dir -r requirements.txt +RUN pip3.11 install --no-cache-dir clip +RUN pip3.11 install --no-cache-dir -U xformers --index-url https://download.pytorch.org/whl/cu128 + +# 创建必要目录 +RUN mkdir -p \ + models/Stable-diffusion \ + models/VAE \ + models/Lora \ + models/ESRGAN \ + models/GFPGAN \ + extensions \ + outputs \ + repositories + +RUN git clone https://github.com/w-e-w/stablediffusion.git repositories/stable-diffusion-stability-ai && \ + cd repositories/stable-diffusion-stability-ai && \ + git checkout cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf + +RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git repositories/stable-diffusion-webui-assets && \ + cd repositories/stable-diffusion-webui-assets && \ + git checkout 6f7db241d2f8ba7457bac5ca9753331f0c266917 + +RUN git clone https://github.com/Stability-AI/generative-models.git repositories/generative-models && \ + cd repositories/generative-models && \ + git checkout 45c443b316737a4ab6e40413d7794a7f5657c19f + +RUN git clone https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion && \ + cd repositories/k-diffusion && \ + git checkout ab527a9a6d347f364e3d185ba6d714e22d80cb3c + +RUN git clone https://github.com/salesforce/BLIP.git repositories/BLIP && \ + cd repositories/BLIP && \ + git checkout 48211a1594f1321b00f14c9f7a5b4813144b2fb9 + +RUN cd /app/models/Stable-diffusion && \ + wget -O v1-5-pruned-emaonly.safetensors \ + https://hf-mirror.com/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors + +# 设置 GPU 环境变量 +ENV NVIDIA_VISIBLE_DEVICES=all + +# 暴露端口 +EXPOSE 7860 + +# 启动命令 +CMD ["python3.11", "launch.py", "--listen", "--port", "7860", "--skip-torch-cuda-test", "--no-half-vae", "--xformers", "--api", "--skip-version-check"] + diff --git a/frameworks/stable-diffusion-webui/1.10.1/README.md b/frameworks/stable-diffusion-webui/1.10.1/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ae342a98e40625bb9e76a9f27e75721efe766231 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.10.1/README.md @@ -0,0 +1,142 @@ +# Stable Diffusion WebUI on OpenCloudOS 9 + +## 基本信息 + +- **框架版本**: 1.10.1 +- **基础镜像**: opencloudos/opencloudos9-cuda-devel:12.8 +- **Python 版本**: 3.11 +- **CUDA 版本**: 12.8 +- **核心组件**: + - Stable Diffusion WebUI 1.10.1 + - PyTorch 2.11.0+cu128 + - Gradio 3.41.2 + - xformers 0.0.35 + - transformers 4.30.2 + +## 构建 + +```bash +docker build -t oc9-stable-diffusion-webui:1.10.1 . +``` + +构建时间约 15-20 分钟,会自动下载 SD 1.5 模型(4GB)。 + +## 使用示例 + +### 1. 启动容器 + +```bash +docker run -d \ + --name sd-webui \ + --gpus all \ + -p 7860:7860 \ + -v ~/sd-outputs:/app/outputs \ + oc9-stable-diffusion-webui:1.10.1 +``` + +### 2. 访问 Web UI + +浏览器访问:http://localhost:7860 + +首次启动需要 10-15 秒加载模型。 + +### 3. API 调用示例 + +```bash +# 文本生成图像 +curl -X POST http://localhost:7860/sdapi/v1/txt2img \ + -H "Content-Type: application/json" \ + -d '{ + "prompt": "a beautiful sunset over mountains", + "steps": 20, + "width": 512, + "height": 512 + }' +``` + +### 4. 容器内测试 + +```bash +# 复制测试脚本到容器 +docker cp test.sh sd-webui:/app/test-inside.sh + +# 在容器内执行测试 +docker exec sd-webui chmod +x /app/test-inside.sh +docker exec sd-webui /app/test-inside.sh +``` + +## 功能特性 + +- ✓ txt2img 文本生成图像 +- ✓ img2img 图像转换 +- ✓ Inpainting 图像修复 +- ✓ LoRA 模型支持 +- ✓ xformers 内存优化 +- ✓ REST API 接口 +- ✓ 多种采样器(Euler、DPM++、DDIM 等) + +## 系统要求 + +### 最低配置 +- GPU: NVIDIA GPU with 6GB+ VRAM +- RAM: 16GB+ +- 存储: 30GB+ + +### 推荐配置 +- GPU: NVIDIA RTX 3060 (12GB VRAM) 或更高 +- RAM: 32GB+ +- 存储: 50GB+ SSD + +## 性能参考 + +在 RTX 4090 (24GB) 上测试: +- 512x512 图像,20 步采样:约 1-2 秒 +- 启用 xformers 优化 +- 模型加载时间:约 11 秒 + +## 已知问题 + +1. **首次启动较慢**:需要初始化 repositories 和加载模型,约需 15-20 秒 +2. **网络依赖**:构建时需要从 GitHub 和 HuggingFace 下载资源,建议使用网速快的服务器 +3. **显存要求**:生成 512x512 图像至少需要 6GB 显存,推荐 8GB+ + +## 低显存优化 + +如果 GPU 显存不足,可以使用以下参数: + +```bash +# 6-8GB 显存 +docker run -d --name sd-webui --gpus all -p 7860:7860 \ + oc9-stable-diffusion-webui:1.10.1 \ + python3.11 launch.py --listen --port 7860 --medvram --xformers + +# 4-6GB 显存 +docker run -d --name sd-webui --gpus all -p 7860:7860 \ + oc9-stable-diffusion-webui:1.10.1 \ + python3.11 launch.py --listen --port 7860 --lowvram --xformers +``` + +## 添加自定义模型 + +```bash +# 挂载模型目录 +docker run -d \ + --name sd-webui \ + --gpus all \ + -p 7860:7860 \ + -v ~/sd-models:/app/models/Stable-diffusion \ + -v ~/sd-outputs:/app/outputs \ + oc9-stable-diffusion-webui:1.10.1 +``` + +将 `.safetensors` 或 `.ckpt` 模型文件放入 `~/sd-models` 目录即可。 + +## 参考资源 + +- 官方仓库: https://github.com/AUTOMATIC1111/stable-diffusion-webui +- 模型下载: https://huggingface.co/runwayml/stable-diffusion-v1-5 +- Civitai 社区: https://civitai.com/ + +## 许可证 + +本镜像遵循 AGPL-3.0 许可证。 diff --git a/frameworks/stable-diffusion-webui/1.10.1/build.conf b/frameworks/stable-diffusion-webui/1.10.1/build.conf new file mode 100644 index 0000000000000000000000000000000000000000..bdf69126e91440bd06bb2a3cc29037e5664904b7 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.10.1/build.conf @@ -0,0 +1,4 @@ +# Stable Diffusion WebUI 1.10.1 on OpenCloudOS 9 (GPU) +IMAGE_NAME=oc9-stable-diffusion-webui +IMAGE_TAG=1.10.1 +GPU_TEST=true diff --git a/frameworks/stable-diffusion-webui/1.10.1/test.png b/frameworks/stable-diffusion-webui/1.10.1/test.png new file mode 100644 index 0000000000000000000000000000000000000000..eda154344aeb2971e82dfe1a0e1b9b30016ed362 Binary files /dev/null and b/frameworks/stable-diffusion-webui/1.10.1/test.png differ diff --git a/frameworks/stable-diffusion-webui/1.10.1/test.sh b/frameworks/stable-diffusion-webui/1.10.1/test.sh new file mode 100755 index 0000000000000000000000000000000000000000..b6976661a1dc0302418ff56d087d753c0902f668 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.10.1/test.sh @@ -0,0 +1,134 @@ +#!/bin/bash +set -e + +# 接收镜像名参数 +IMAGE="${1:-stable-diffusion-webui:1.10.1}" + +echo "==========================================" +echo "测试镜像: $IMAGE" +echo "==========================================" + +# 测试 1: 检查 Python 和 CUDA 环境 +echo -n "测试 1: Python 和 CUDA 环境 ... " +docker run --rm --gpus all "$IMAGE" bash -c ' +python3.11 -c " +import sys +try: + import torch + print(f\"Python {sys.version.split()[0]}\", end=\" \") + print(f\"PyTorch {torch.__version__}\", end=\" \") + if torch.cuda.is_available(): + print(f\"CUDA {torch.version.cuda}\") + else: + print(\"(无 GPU)\") +except Exception as e: + print(f\"错误: {e}\") + import traceback + traceback.print_exc() + sys.exit(1) +" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 2: 检查核心依赖 +echo -n "测试 2: 核心依赖版本 ... " +docker run --rm "$IMAGE" bash -c ' +python3.11 -c " +try: + import gradio + import transformers + import safetensors + print(f\"gradio {gradio.__version__}\", end=\" \") + print(f\"transformers {transformers.__version__}\", end=\" \") + print(f\"safetensors {safetensors.__version__}\") +except Exception as e: + print(f\"错误: {e}\") + sys.exit(1) +" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 3: 检查 xformers 优化 +echo -n "测试 3: xformers 优化 ... " +docker run --rm --gpus all "$IMAGE" bash -c ' +python3.11 -c " +try: + import xformers + print(f\"xformers {xformers.__version__}\") +except Exception as e: + print(f\"错误: {e}\") + sys.exit(1) +" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 4: 检查目录结构 +echo -n "测试 4: 目录结构 ... " +docker run --rm "$IMAGE" bash -c ' +for dir in /app/models/Stable-diffusion /app/models/Lora /app/outputs; do + if [ ! -d "$dir" ]; then + echo "目录不存在: $dir" + exit 1 + fi +done +echo "models/, outputs/ 存在" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 5: 检查 repositories +echo -n "测试 5: Repositories ... " +docker run --rm "$IMAGE" bash -c ' +REPOS=("stable-diffusion-stability-ai" "generative-models" "k-diffusion" "BLIP") +for repo in "${REPOS[@]}"; do + if [ ! -d "/app/repositories/$repo" ]; then + echo "仓库不存在: $repo" + exit 1 + fi +done +echo "4 个仓库已克隆" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 6: 检查 WebUI 核心文件 +echo -n "测试 6: WebUI 核心文件 ... " +docker run --rm "$IMAGE" bash -c ' +FILES=("/app/launch.py" "/app/webui.py" "/app/modules/api/api.py") +for file in "${FILES[@]}"; do + if [ ! -f "$file" ]; then + echo "文件不存在: $file" + exit 1 + fi +done +echo "launch.py, webui.py, api.py 存在" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 7: 检查 nvidia-smi (GPU 环境) +echo -n "测试 7: GPU 环境 (nvidia-smi) ... " +if docker run --rm --gpus all "$IMAGE" nvidia-smi > /dev/null 2>&1; then + GPU_COUNT=$(docker run --rm --gpus all "$IMAGE" nvidia-smi --query-gpu=name --format=csv,noheader | wc -l) + echo "✓ (检测到 $GPU_COUNT 个 GPU)" +else + echo "⊘ (无 GPU,跳过)" +fi + +# 测试 8: 启动 WebUI 服务并检查 API +echo -n "测试 8: WebUI 启动和 API 可用性 ... " +CONTAINER_NAME="sd-webui-test-$$" +docker run -d --name "$CONTAINER_NAME" --gpus all -p 7860:7860 "$IMAGE" > /dev/null 2>&1 || { echo "✗ (容器启动失败)"; exit 1; } + +# 等待服务启动 (最多 60 秒) +for i in {1..60}; do + if docker exec "$CONTAINER_NAME" curl -s http://localhost:7860/sdapi/v1/sd-models > /dev/null 2>&1; then + echo "✓ (服务已启动)" + docker stop "$CONTAINER_NAME" > /dev/null 2>&1 + docker rm "$CONTAINER_NAME" > /dev/null 2>&1 + break + fi + if [ $i -eq 60 ]; then + echo "✗ (服务启动超时)" + docker logs "$CONTAINER_NAME" | tail -20 + docker stop "$CONTAINER_NAME" > /dev/null 2>&1 + docker rm "$CONTAINER_NAME" > /dev/null 2>&1 + exit 1 + fi + sleep 1 +done + +echo "==========================================" +echo "所有测试通过 ✓" +echo "==========================================" diff --git a/frameworks/stable-diffusion-webui/1.9.4/Dockerfile b/frameworks/stable-diffusion-webui/1.9.4/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..be1a53171148f0a8afabacab270d060942145873 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.9.4/Dockerfile @@ -0,0 +1,78 @@ +FROM opencloudos/opencloudos9-cuda-devel:12.8 + +LABEL maintainer="Anstarc " +LABEL org.opencontainers.image.source="https://gitee.com/OpenCloudOS/ai-agent-container" +LABEL org.opencontainers.image.description="Stable Diffusion WebUI 1.10.1 on OpenCloudOS 9" + +# 安装系统依赖 +RUN dnf install -y \ + python3.11 \ + python3.11-pip \ + git \ + wget \ + mesa-libGL \ + glib2 \ + libgomp \ + && dnf clean all \ + && rm -rf /var/cache/yum/* + +# 设置工作目录 +WORKDIR /app + +# 克隆 Stable Diffusion WebUI v1.10.1 +RUN git clone --depth 1 --branch v1.10.1 \ + https://github.com/AUTOMATIC1111/stable-diffusion-webui.git . + +# 安装 PyTorch +RUN pip3.11 install --no-cache-dir \ + torch torchvision --index-url https://download.pytorch.org/whl/cu128 + +# 安装 WebUI 依赖 +RUN pip3.11 install --no-cache-dir -r requirements.txt +RUN pip3.11 install --no-cache-dir clip +RUN pip3.11 install --no-cache-dir -U xformers --index-url https://download.pytorch.org/whl/cu128 + +# 创建必要目录 +RUN mkdir -p \ + models/Stable-diffusion \ + models/VAE \ + models/Lora \ + models/ESRGAN \ + models/GFPGAN \ + extensions \ + outputs \ + repositories + +RUN git clone https://github.com/w-e-w/stablediffusion.git repositories/stable-diffusion-stability-ai && \ + cd repositories/stable-diffusion-stability-ai && \ + git checkout cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf + +RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git repositories/stable-diffusion-webui-assets && \ + cd repositories/stable-diffusion-webui-assets && \ + git checkout 6f7db241d2f8ba7457bac5ca9753331f0c266917 + +RUN git clone https://github.com/Stability-AI/generative-models.git repositories/generative-models && \ + cd repositories/generative-models && \ + git checkout 45c443b316737a4ab6e40413d7794a7f5657c19f + +RUN git clone https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion && \ + cd repositories/k-diffusion && \ + git checkout ab527a9a6d347f364e3d185ba6d714e22d80cb3c + +RUN git clone https://github.com/salesforce/BLIP.git repositories/BLIP && \ + cd repositories/BLIP && \ + git checkout 48211a1594f1321b00f14c9f7a5b4813144b2fb9 + +RUN cd /app/models/Stable-diffusion && \ + wget -O v1-5-pruned-emaonly.safetensors \ + https://hf-mirror.com/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors + +# 设置 GPU 环境变量 +ENV NVIDIA_VISIBLE_DEVICES=all + +# 暴露端口 +EXPOSE 7860 + +# 启动命令 +CMD ["python3.11", "launch.py", "--listen", "--port", "7860", "--skip-torch-cuda-test", "--no-half-vae", "--xformers", "--api", "--skip-version-check"] + diff --git a/frameworks/stable-diffusion-webui/1.9.4/README.md b/frameworks/stable-diffusion-webui/1.9.4/README.md new file mode 100644 index 0000000000000000000000000000000000000000..776c41514c39be6887a8b39908333d7c6a58c73a --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.9.4/README.md @@ -0,0 +1,142 @@ +# Stable Diffusion WebUI on OpenCloudOS 9 + +## 基本信息 + +- **框架版本**: 1.9.4 +- **基础镜像**: opencloudos/opencloudos9-cuda-devel:12.8 +- **Python 版本**: 3.11 +- **CUDA 版本**: 12.8 +- **核心组件**: + - Stable Diffusion WebUI 1.9.4 + - PyTorch 2.11.0+cu128 + - Gradio 3.41.2 + - xformers 0.0.35 + - transformers 4.30.2 + +## 构建 + +```bash +docker build -t oc9-stable-diffusion-webui:1.9.4 . +``` + +构建时间约 15-20 分钟,会自动下载 SD 1.5 模型(4GB)。 + +## 使用示例 + +### 1. 启动容器 + +```bash +docker run -d \ + --name sd-webui \ + --gpus all \ + -p 7860:7860 \ + -v ~/sd-outputs:/app/outputs \ + oc9-stable-diffusion-webui:1.9.4 +``` + +### 2. 访问 Web UI + +浏览器访问:http://localhost:7860 + +首次启动需要 10-15 秒加载模型。 + +### 3. API 调用示例 + +```bash +# 文本生成图像 +curl -X POST http://localhost:7860/sdapi/v1/txt2img \ + -H "Content-Type: application/json" \ + -d '{ + "prompt": "a beautiful sunset over mountains", + "steps": 20, + "width": 512, + "height": 512 + }' +``` + +### 4. 容器内测试 + +```bash +# 复制测试脚本到容器 +docker cp test.sh sd-webui:/app/test-inside.sh + +# 在容器内执行测试 +docker exec sd-webui chmod +x /app/test-inside.sh +docker exec sd-webui /app/test-inside.sh +``` + +## 功能特性 + +- ✓ txt2img 文本生成图像 +- ✓ img2img 图像转换 +- ✓ Inpainting 图像修复 +- ✓ LoRA 模型支持 +- ✓ xformers 内存优化 +- ✓ REST API 接口 +- ✓ 多种采样器(Euler、DPM++、DDIM 等) + +## 系统要求 + +### 最低配置 +- GPU: NVIDIA GPU with 6GB+ VRAM +- RAM: 16GB+ +- 存储: 30GB+ + +### 推荐配置 +- GPU: NVIDIA RTX 3060 (12GB VRAM) 或更高 +- RAM: 32GB+ +- 存储: 50GB+ SSD + +## 性能参考 + +在 RTX 4090 (24GB) 上测试: +- 512x512 图像,20 步采样:约 1-2 秒 +- 启用 xformers 优化 +- 模型加载时间:约 11 秒 + +## 已知问题 + +1. **首次启动较慢**:需要初始化 repositories 和加载模型,约需 15-20 秒 +2. **网络依赖**:构建时需要从 GitHub 和 HuggingFace 下载资源,建议使用网速快的服务器 +3. **显存要求**:生成 512x512 图像至少需要 6GB 显存,推荐 8GB+ + +## 低显存优化 + +如果 GPU 显存不足,可以使用以下参数: + +```bash +# 6-8GB 显存 +docker run -d --name sd-webui --gpus all -p 7860:7860 \ + oc9-stable-diffusion-webui:1.9.4 \ + python3.11 launch.py --listen --port 7860 --medvram --xformers + +# 4-6GB 显存 +docker run -d --name sd-webui --gpus all -p 7860:7860 \ + oc9-stable-diffusion-webui:1.9.4 \ + python3.11 launch.py --listen --port 7860 --lowvram --xformers +``` + +## 添加自定义模型 + +```bash +# 挂载模型目录 +docker run -d \ + --name sd-webui \ + --gpus all \ + -p 7860:7860 \ + -v ~/sd-models:/app/models/Stable-diffusion \ + -v ~/sd-outputs:/app/outputs \ + oc9-stable-diffusion-webui:1.9.4 +``` + +将 `.safetensors` 或 `.ckpt` 模型文件放入 `~/sd-models` 目录即可。 + +## 参考资源 + +- 官方仓库: https://github.com/AUTOMATIC1111/stable-diffusion-webui +- 模型下载: https://huggingface.co/runwayml/stable-diffusion-v1-5 +- Civitai 社区: https://civitai.com/ + +## 许可证 + +本镜像遵循 AGPL-3.0 许可证。 diff --git a/frameworks/stable-diffusion-webui/1.9.4/build.conf b/frameworks/stable-diffusion-webui/1.9.4/build.conf new file mode 100644 index 0000000000000000000000000000000000000000..3b067fe9cd9ad01186ed747e767db59c7ad23f84 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.9.4/build.conf @@ -0,0 +1,4 @@ +# Stable Diffusion WebUI 1.9.4 on OpenCloudOS 9 (GPU) +IMAGE_NAME=oc9-stable-diffusion-webui +IMAGE_TAG=1.9.4 +GPU_TEST=true diff --git a/frameworks/stable-diffusion-webui/1.9.4/test.png b/frameworks/stable-diffusion-webui/1.9.4/test.png new file mode 100644 index 0000000000000000000000000000000000000000..eda154344aeb2971e82dfe1a0e1b9b30016ed362 Binary files /dev/null and b/frameworks/stable-diffusion-webui/1.9.4/test.png differ diff --git a/frameworks/stable-diffusion-webui/1.9.4/test.sh b/frameworks/stable-diffusion-webui/1.9.4/test.sh new file mode 100755 index 0000000000000000000000000000000000000000..b6976661a1dc0302418ff56d087d753c0902f668 --- /dev/null +++ b/frameworks/stable-diffusion-webui/1.9.4/test.sh @@ -0,0 +1,134 @@ +#!/bin/bash +set -e + +# 接收镜像名参数 +IMAGE="${1:-stable-diffusion-webui:1.10.1}" + +echo "==========================================" +echo "测试镜像: $IMAGE" +echo "==========================================" + +# 测试 1: 检查 Python 和 CUDA 环境 +echo -n "测试 1: Python 和 CUDA 环境 ... " +docker run --rm --gpus all "$IMAGE" bash -c ' +python3.11 -c " +import sys +try: + import torch + print(f\"Python {sys.version.split()[0]}\", end=\" \") + print(f\"PyTorch {torch.__version__}\", end=\" \") + if torch.cuda.is_available(): + print(f\"CUDA {torch.version.cuda}\") + else: + print(\"(无 GPU)\") +except Exception as e: + print(f\"错误: {e}\") + import traceback + traceback.print_exc() + sys.exit(1) +" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 2: 检查核心依赖 +echo -n "测试 2: 核心依赖版本 ... " +docker run --rm "$IMAGE" bash -c ' +python3.11 -c " +try: + import gradio + import transformers + import safetensors + print(f\"gradio {gradio.__version__}\", end=\" \") + print(f\"transformers {transformers.__version__}\", end=\" \") + print(f\"safetensors {safetensors.__version__}\") +except Exception as e: + print(f\"错误: {e}\") + sys.exit(1) +" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 3: 检查 xformers 优化 +echo -n "测试 3: xformers 优化 ... " +docker run --rm --gpus all "$IMAGE" bash -c ' +python3.11 -c " +try: + import xformers + print(f\"xformers {xformers.__version__}\") +except Exception as e: + print(f\"错误: {e}\") + sys.exit(1) +" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 4: 检查目录结构 +echo -n "测试 4: 目录结构 ... " +docker run --rm "$IMAGE" bash -c ' +for dir in /app/models/Stable-diffusion /app/models/Lora /app/outputs; do + if [ ! -d "$dir" ]; then + echo "目录不存在: $dir" + exit 1 + fi +done +echo "models/, outputs/ 存在" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 5: 检查 repositories +echo -n "测试 5: Repositories ... " +docker run --rm "$IMAGE" bash -c ' +REPOS=("stable-diffusion-stability-ai" "generative-models" "k-diffusion" "BLIP") +for repo in "${REPOS[@]}"; do + if [ ! -d "/app/repositories/$repo" ]; then + echo "仓库不存在: $repo" + exit 1 + fi +done +echo "4 个仓库已克隆" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 6: 检查 WebUI 核心文件 +echo -n "测试 6: WebUI 核心文件 ... " +docker run --rm "$IMAGE" bash -c ' +FILES=("/app/launch.py" "/app/webui.py" "/app/modules/api/api.py") +for file in "${FILES[@]}"; do + if [ ! -f "$file" ]; then + echo "文件不存在: $file" + exit 1 + fi +done +echo "launch.py, webui.py, api.py 存在" +' && echo "✓" || { echo "✗"; exit 1; } + +# 测试 7: 检查 nvidia-smi (GPU 环境) +echo -n "测试 7: GPU 环境 (nvidia-smi) ... " +if docker run --rm --gpus all "$IMAGE" nvidia-smi > /dev/null 2>&1; then + GPU_COUNT=$(docker run --rm --gpus all "$IMAGE" nvidia-smi --query-gpu=name --format=csv,noheader | wc -l) + echo "✓ (检测到 $GPU_COUNT 个 GPU)" +else + echo "⊘ (无 GPU,跳过)" +fi + +# 测试 8: 启动 WebUI 服务并检查 API +echo -n "测试 8: WebUI 启动和 API 可用性 ... " +CONTAINER_NAME="sd-webui-test-$$" +docker run -d --name "$CONTAINER_NAME" --gpus all -p 7860:7860 "$IMAGE" > /dev/null 2>&1 || { echo "✗ (容器启动失败)"; exit 1; } + +# 等待服务启动 (最多 60 秒) +for i in {1..60}; do + if docker exec "$CONTAINER_NAME" curl -s http://localhost:7860/sdapi/v1/sd-models > /dev/null 2>&1; then + echo "✓ (服务已启动)" + docker stop "$CONTAINER_NAME" > /dev/null 2>&1 + docker rm "$CONTAINER_NAME" > /dev/null 2>&1 + break + fi + if [ $i -eq 60 ]; then + echo "✗ (服务启动超时)" + docker logs "$CONTAINER_NAME" | tail -20 + docker stop "$CONTAINER_NAME" > /dev/null 2>&1 + docker rm "$CONTAINER_NAME" > /dev/null 2>&1 + exit 1 + fi + sleep 1 +done + +echo "==========================================" +echo "所有测试通过 ✓" +echo "=========================================="