4.2 KiB
4.2 KiB
基于多种LLMs组合以及ComfyUI参与的定制化用户海报生成的智能融合ai系统
概述
AI海报生成系统集成DeepSeek、Kimi、ComfyUI三大AI模型,一键生成Vue组件代码和PSD文件。
核心功能:
- 🤖 AI驱动: DeepSeek分析 + Kimi文案 + ComfyUI图片
- 🎨 一键生成: 输入需求 → Vue代码 + PSD文件
- 📱 REST API: 统一接口,支持前端集成
- 🎭 预定义模板: lotus.jpg, nku.png, stamp.jpg, background.png
- 🖼️ 自动合成: 多图层PSD文件生成
系统架构
前端 → FastAPI(8000) → AI模型集群
↓
Vue代码 + PSD文件
快速开始
环境准备
# 创建虚拟环境
conda create -n ai_service python=3.11
conda activate ai_service
# 安装依赖
pip install -r requirements.txt
# 配置API密钥
cp .env.example .env
# 编辑 .env 文件,添加:
# DEEPSEEK_API_KEY=your_key
# MOONSHOT_API_KEY=your_key
启动服务
cd scripts
python run_pipeline.py # 选择: 2 (API服务器)
验证服务
curl http://localhost:8000/health
API使用
生成海报
curl -X POST http://localhost:8000/api/generate-poster \
-H "Content-Type: application/json" \
-d '{"user_input": "端午节海报,传统风格"}'
下载文件
curl "http://localhost:8000/api/download/psd?session_id=SESSION_ID" -o poster.psd
curl "http://localhost:8000/api/download/vue?session_id=SESSION_ID" -o poster.vue
项目结构
ai_service/
├── scripts/ # 核心脚本
│ ├── run_pipeline.py # API服务器
│ ├── utils.py # 工具函数
│ ├── generate_layout.py # Vue代码生成
│ ├── generate_text.py # 文案生成
│ ├── flux_con.py # 图片生成
│ └── export_psd_from_json.py # PSD合成
├── configs/ # 配置文件
│ ├── vue_templates.yaml # Vue模板
│ └── font.yaml # 字体配置
├── outputs/ # 输出目录
└── workflows/ # ComfyUI工作流
核心模块
模块 | 功能 | AI模型 |
---|---|---|
utils.py |
用户输入分析 | DeepSeek |
flux_con.py |
图片生成 | ComfyUI |
generate_text.py |
文案生成 | Kimi |
generate_layout.py |
Vue代码生成 | DeepSeek |
export_psd_from_json.py |
PSD合成 | - |
使用示例
JavaScript调用
const response = await fetch('http://localhost:8000/api/generate-poster', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_input: "春节海报,红色背景" })
});
const result = await response.json();
console.log('Vue代码:', result.data.vue_code);
Python调用
import requests
response = requests.post('http://localhost:8000/api/generate-poster',
json={"user_input": "端午节海报,传统风格"})
result = response.json()
if result["status"] == "success":
print("生成成功!")
print("Vue代码:", result["data"]["vue_code"])
本地测试
cd scripts
python run_pipeline.py # 选择: 1 (本地测试)
# 输入: "春节海报,红色背景,现代风格"
部署
Docker部署
FROM python:3.11
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["uvicorn", "scripts.run_pipeline:app", "--host", "0.0.0.0", "--port", "8000"]
PM2部署
pm2 start "uvicorn scripts.run_pipeline:app --host 0.0.0.0 --port 8000" --name poster-api
Nginx反向代理
server {
listen 80;
location / {
proxy_pass http://localhost:8000;
}
}
故障排查
常见问题
# 检查API密钥
echo $DEEPSEEK_API_KEY
# 测试ComfyUI连接
curl http://101.201.50.90:8188/system_stats
# 检查端口占用
netstat -tulpn | grep 8000
更新日志
v2.0.0 (2025-07-03)
- ✅ 重构代码结构,移除冗余代码
- ✅ 新增预定义Vue模板系统
- ✅ 优化工具函数模块化
- ✅ 简化API接口设计
v1.0.0 (2025-01-02)
- ✅ 集成DeepSeek + Kimi + ComfyUI
- ✅ 统一API接口设计
- ✅ 支持Vue组件和PSD文件生成