docs/usage/providers/comfyui.zh-CN.mdx
<Image alt={'在 LobeHub 中使用 ComfyUI'} cover src={'https://hub-apac-1.lobeobjects.space/docs/e9b811f248a1db2bd1be1af888cf9b9d.png'} />
本文档将指导你如何在 LobeHub 中使用 ComfyUI 进行高质量的 AI 图像生成和编辑。
ComfyUI 是一个功能强大的稳定扩散和流扩散 GUI,提供基于节点的工作流界面。LobeHub 集成了 ComfyUI,支持完整的 FLUX 系列模型,包括文本生成图像和图像编辑功能。
设置 界面AI 服务商 下找到 ComfyUI 的设置项<Image alt={'ComfyUI 设置界面'} inStep src={'/blog/assets17870709/3f31bc33-509f-4ad2-ba81-280c2a6ec5fa.webp'} />
基本配置:
http://localhost:8000在对话界面中:
<Image alt={'选择 FLUX 模型'} inStep src={'/blog/assets17870709/ff7ebacf-27f0-42d7-810b-00314499a084.webp'} />
使用 FLUX Schnell(快速生成):
Generate an image: A cute orange cat sitting on a sunny windowsill, warm lighting, detailed fur texture
使用 FLUX Dev(高质量生成):
Generate high quality image: City skyline at sunset, cyberpunk style, neon lights, 4K high resolution, detailed architecture
使用 FLUX Kontext-dev 编辑图像:
Edit this image: Change the background to a starry night sky, keep the main subject, cosmic atmosphere
然后上传需要编辑的原始图像。
<Callout type={'info'}> 图像编辑功能需要先上传原始图像,然后描述你希望进行的修改。 </Callout>
ComfyUI 支持四种认证方式,请根据你的服务器配置和安全需求选择合适的认证方式:
适用场景:
配置方法:
认证类型:无认证
服务器地址:http://localhost:8000
适用场景:
配置方法:
# 安装 apache2-utils
sudo apt-get install apache2-utils
# 创建用户 'admin'
sudo htpasswd -c /etc/nginx/.htpasswd admin
认证类型:基本认证
服务器地址:https://your-domain.com
用户名:admin
密码:your_secure_password
适用场景:
生成 Token:
import jwt
import datetime
payload = {
'user': 'admin',
'exp': datetime.datetime.utcnow() + datetime.timedelta(days=30)
}
secret_key = "your-secret-key"
token = jwt.encode(payload, secret_key, algorithm='HS256')
print(f"Bearer Token: {token}")
LobeHub 配置:
认证类型:Bearer Token
服务器地址:https://your-domain.com
API 密钥:example-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
适用场景:
LobeHub 配置:
认证类型:自定义
服务器地址:https://your-domain.com
自定义请求头:
{
"X-API-Key": "your_api_key",
"X-Client-ID": "LobeHub"
}
Comfy-Manager 是 ComfyUI 的扩展管理器,让你能够轻松安装和管理各种节点、模型和扩展。
<details> <summary><b>📦 安装 Comfy-Manager 步骤</b></summary># 进入 ComfyUI 的 custom_nodes 目录
cd ComfyUI/custom_nodes
# 克隆 Comfy-Manager 仓库
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
# 重启 ComfyUI 服务器
# 重新启动后,你会在 UI 中看到 Manager 按钮
# 在 ComfyUI 根目录下执行
curl -fsSL https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/install.sh | bash
http://localhost:8000安装模型:
安装节点扩展:
管理已安装内容:
当你看到类似 Model not found: flux1-dev.safetensors, please install one first. 的错误时,说明服务器上缺少所需的模型文件。
Model not found: flux1-dev.safetensors, please install one first.
这个错误表示系统期望找到 flux1-dev.safetensors 模型文件,但在服务器上没有找到。
方法一:使用 Comfy-Manager 下载(推荐)
方法二:手动下载模型
下载模型文件:
flux1-dev.safetensors)放置到正确目录:
# FLUX 和 SD3.5 主模型放入
ComfyUI/models/diffusion_models/flux1-dev.safetensors
# SD1.5 和 SDXL 模型放入
ComfyUI/models/checkpoints/
验证文件:
# 检查文件是否存在
ls -la ComfyUI/models/diffusion_models/flux1-dev.safetensors
# 检查文件完整性(可选)
sha256sum flux1-dev.safetensors
重启 ComfyUI 服务器
方法三:使用 wget/curl 直接下载
# 进入模型目录
cd ComfyUI/models/diffusion_models/
# 使用 wget 下载(替换为实际下载链接)
wget https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/flux1-dev.safetensors
# 或使用 curl
curl -L -o flux1-dev.safetensors https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/flux1-dev.safetensors
基础模型包:至少下载一个基础模型
flux1-schnell.safetensors(快速)或 flux1-dev.safetensors(高质量)sd3.5_large.safetensors检查磁盘空间:
# 检查可用空间
df -h ComfyUI/models/
设置模型路径(可选): 如果你的模型存储在其他位置,可以创建符号链接:
ln -s /path/to/your/models ComfyUI/models/diffusion_models/
当你看到类似 Missing VAE encoder: ae.safetensors 或其他组件文件缺失的错误时,需要下载相应的系统组件。
Missing VAE encoder: ae.safetensors. Please download and place it in the models/vae folder.
Missing CLIP encoder: clip_l.safetensors. Please download and place it in the models/clip folder.
Missing T5 encoder: t5xxl_fp16.safetensors. Please download and place it in the models/clip folder.
| 组件类型 | 文件名示例 | 用途 | 存放目录 |
|---|---|---|---|
| VAE | ae.safetensors | 图像编码 / 解码 | models/vae/ |
| CLIP | clip_l.safetensors | 文本编码(CLIP) | models/clip/ |
| T5 | t5xxl_fp16.safetensors | 文本编码(T5) | models/clip/ |
| ControlNet | flux-controlnet-*.safetensors | 控制网络 | models/controlnet/ |
方法一:使用 Comfy-Manager(推荐)
方法二:手动下载必需组件
# 1. VAE 编码器
cd ComfyUI/models/vae/
wget https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/ae.safetensors
# 2. CLIP-L 编码器
cd ComfyUI/models/clip/
wget https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors
# 3. T5-XXL 编码器(可选择不同精度)
# FP16 版本(推荐,平衡性能)
wget https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp16.safetensors
# 或 FP8 版本(节省显存)
wget https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp8_e4m3fn.safetensors
# SD3.5 使用不同的编码器
cd ComfyUI/models/clip/
# CLIP-G 编码器
wget https://huggingface.co/stabilityai/stable-diffusion-3.5-large/resolve/main/text_encoders/clip_g.safetensors
# CLIP-L 编码器
wget https://huggingface.co/stabilityai/stable-diffusion-3.5-large/resolve/main/text_encoders/clip_l.safetensors
# T5-XXL 编码器
wget https://huggingface.co/stabilityai/stable-diffusion-3.5-large/resolve/main/text_encoders/t5xxl_fp16.safetensors
# SDXL VAE
cd ComfyUI/models/vae/
wget https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors
# SDXL 使用内置的 CLIP 编码器,通常不需要单独下载
| 模型系列 | 必需 VAE | 必需 CLIP | 必需 T5 | 可选组件 |
|---|---|---|---|---|
| FLUX | ae.safetensors | clip_l.safetensors | t5xxl_fp16.safetensors | ControlNet |
| SD3.5 | 内置 | clip_g + clip_l | t5xxl_fp16 | - |
| SDXL | sdxl_vae | 内置 | - | Refiner |
| SD1.5 | vae-ft-mse | 内置 | - | ControlNet |
T5 编码器精度选择:
| 显存容量 | 推荐版本 | 文件名 |
|---|---|---|
| < 12GB | FP8 量化 | t5xxl_fp8_e4m3fn.safetensors |
| 12-16GB | FP16 | t5xxl_fp16.safetensors |
| > 16GB | FP32 | t5xxl.safetensors |
# 检查所有必需组件
echo "=== VAE Components ==="
ls -la ComfyUI/models/vae/
echo "=== CLIP/T5 Components ==="
ls -la ComfyUI/models/clip/
echo "=== ControlNet Components ==="
ls -la ComfyUI/models/controlnet/
问题:下载后仍然报错
检查文件权限:
chmod 644 ComfyUI/models/vae/*.safetensors
chmod 644 ComfyUI/models/clip/*.safetensors
清除缓存:
# 清除 ComfyUI 缓存
rm -rf ComfyUI/temp/*
rm -rf ComfyUI/__pycache__/*
重启服务器:
# 完全重启 ComfyUI
pkill -f "python main.py"
python main.py --listen 0.0.0.0 --port 8000
问题:显存不足
使用量化版本的组件:
t5xxl_fp8_e4m3fn.safetensors 而不是 FP16/FP32问题:下载速度慢
aria2c -x 16 -s 16 -k 1M [下载链接]
# 克隆 ComfyUI 仓库
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
# 安装依赖
pip install -r requirements.txt
# 可选:安装JWT支持(用于Token认证)
pip install PyJWT
# 启动 ComfyUI 服务器
python main.py --listen 0.0.0.0 --port 8000
推荐基础配置 (最小化安装):
主模型 (放入 models/diffusion_models/ 目录):
flux1-schnell.safetensors - 快速生成(4 步)flux1-dev.safetensors - 高质量创作(20 步)必需组件 (放入相应目录):
models/vae/ae.safetensors - VAE 编码器models/clip/clip_l.safetensors - CLIP 文本编码器models/clip/t5xxl_fp16.safetensors - T5 文本编码器访问 http://localhost:8000 确认 ComfyUI 界面正常加载。
<Callout type={'info'}> 智能模型选择:LobeHub 会根据服务器上可用的模型文件自动选择最佳模型。您无需下载所有模型,系统会在可用模型中按优先级(官方 > 企业 > 社区)自动选择。 </Callout>
</details>LobeHub ComfyUI 集成采用配置驱动的架构,支持 223 个模型,提供从官方模型到社区优化版本的全覆盖。
| 模型类型 | 推荐步数 | CFG Scale | 分辨率范围 |
|---|---|---|---|
| Schnell | 4 步 | - | 512×512 至 1536×1536 |
| Dev | 20 步 | 3.5 | 512×512 至 2048×2048 |
| Kontext | 20 步 | 3.5 | 512×512 至 2048×2048 |
| Krea | 20 步 | 4.5 | 512×512 至 2048×2048 |
| 模型类型 | 推荐步数 | CFG Scale | 分辨率范围 |
|---|---|---|---|
| Large | 25 步 | 7.0 | 512×512 至 2048×2048 |
| Large Turbo | 8 步 | 3.5 | 512×512 至 1536×1536 |
| Medium | 20 步 | 6.0 | 512×512 至 1536×1536 |
FLUX.1 Official 系列:
flux1-dev.safetensors - 高质量创作模型flux1-schnell.safetensors - 快速生成模型flux1-kontext-dev.safetensors - 图像编辑模型flux1-krea-dev.safetensors - 安全增强模型SD3.5 Official 系列:
sd3.5_large.safetensors - SD3.5 大型基础模型sd3.5_large_turbo.safetensors - 快速生成版本sd3.5_medium.safetensors - 中等规模模型量化优化系列:
社区优化系列:
SD3.5 系列:5 个模型 SD1.5 系列:37 个模型(包括官方、量化和社区版本) SDXL 系列:50 个模型(包括基础、Refiner 和 Playground 模型)
系统支持 6 种工作流:
最低配置 (GGUF 量化模型):
推荐配置 (标准模型):
| 显存容量 | 推荐量化 | 模型示例 | 性能特点 |
|---|---|---|---|
| 6-8GB | Q4_0, Q4_K_S | flux1-dev-Q4_0.gguf | 最小显存占用 |
| 10-12GB | Q6_K, Q8_0 | flux1-dev-Q6_K.gguf | 平衡性能与质量 |
| 16GB+ | FP8, FP16 | flux1-dev-fp8-e4m3fn.safetensors | 接近原始质量 |
| 24GB+ | 完整模型 | flux1-dev.safetensors | 最佳质量 |
LobeHub 支持使用自定义的 Stable Diffusion 模型。系统使用固定的文件名来识别自定义模型。
必需文件:
custom_sd_lobe.safetensorscustom_sd_vae_lobe.safetensors方法一:重命名现有模型
# 将您的模型重命名为固定文件名
mv your_custom_model.safetensors custom_sd_lobe.safetensors
# 移动到正确目录
mv custom_sd_lobe.safetensors ComfyUI/models/diffusion_models/
方法二:创建符号链接(推荐)
# 创建软链接,方便切换不同模型
ln -s /path/to/your_model.safetensors ComfyUI/models/diffusion_models/custom_sd_lobe.safetensors
在 LobeHub 中,自定义模型会显示为:
| 参数 | SD 1.5 模型 | SDXL 模型 |
|---|---|---|
| steps | 20-30 | 25-40 |
| cfg | 7.0 | 6.0-8.0 |
| width | 512 | 1024 |
| height | 512 | 1024 |
LobeHub 集成了智能错误处理系统,能够自动诊断并提供针对性的解决方案。
| 错误类型 | 用户提示 | 自动诊断 |
|---|---|---|
| 连接问题 | "无法连接到 ComfyUI 服务器" | 自动检测服务器状态和网络连通性 |
| 认证问题 | "API 密钥无效或已过期" | 自动验证认证凭据有效性 |
| 权限问题 | "访问权限不足" | 自动检查用户权限和文件访问权限 |
| 模型问题 | "找不到指定的模型文件" | 自动扫描可用模型并建议替代方案 |
| 配置问题 | "配置文件存在错误" | 自动验证配置完整性和语法正确性 |
问题:无法连接到 ComfyUI 服务器
解决方案:
# 确认服务器运行
curl http://localhost:8000/system_stats
# 检查端口
netstat -tulpn | grep 8000
问题:生成过程中出现内存错误
解决方案:
问题:401 或 403 错误
解决方案:
示例:
A young woman with flowing long hair, wearing an elegant blue dress, standing in a cherry blossom park,
sunlight filtering through leaves, warm atmosphere, cinematic lighting, 4K high resolution, detailed, photorealistic
<Callout type={'warning'}> 在使用过程中请注意:
interface ComfyUIRequest {
model: string; // 模型 ID,如 'flux-schnell'
prompt: string; // 文本提示词
width: number; // 图像宽度
height: number; // 图像高度
steps: number; // 生成步数
seed: number; // 随机种子
cfg?: number; // CFG Scale (Dev/Krea/Kontext 专用)
strength?: number; // 编辑强度 (Kontext 专用)
imageUrl?: string; // 输入图像 (Kontext 专用)
}
interface ComfyUIResponse {
images: Array<{
url: string; // 生成的图像 URL
filename: string; // 文件名
subfolder: string; // 子目录
type: string; // 文件类型
}>;
prompt_id: string; // 提示 ID
}
| 错误代码 | 描述 | 解决建议 |
|---|---|---|
400 | 请求参数无效 | 检查参数格式和范围 |
401 | 认证失败 | 验证 API 密钥和认证配置 |
403 | 权限不足 | 检查用户权限 |
404 | 模型未找到 | 确认模型文件存在 |
500 | 服务器错误 | 检查 ComfyUI 日志 |
至此你已经可以在 LobeHub 中使用 ComfyUI 进行高质量的 AI 图像生成和编辑了。如果遇到问题,请参考故障排除部分或查阅 ComfyUI 官方文档。