152 lines
2.9 KiB
Markdown
152 lines
2.9 KiB
Markdown
# AI海报生成系统 API文档
|
|
|
|
## 系统架构
|
|
|
|
```
|
|
前端 → FastAPI(8000) → ComfyUI(101.201.50.90:8188)
|
|
↓
|
|
Vue代码 + PSD文件
|
|
```
|
|
|
|
## API端点
|
|
|
|
### 1. 健康检查
|
|
**GET** `/health`
|
|
|
|
```json
|
|
{
|
|
"status": "healthy",
|
|
"timestamp": "2025-01-02T20:30:00"
|
|
}
|
|
```
|
|
|
|
### 2. 生成海报
|
|
**POST** `/api/generate-poster`
|
|
|
|
**请求**:
|
|
```json
|
|
{
|
|
"user_input": "端午节海报,传统风格",
|
|
"session_id": "可选"
|
|
}
|
|
```
|
|
|
|
**响应**:
|
|
```json
|
|
{
|
|
"status": "success",
|
|
"message": "海报生成完成",
|
|
"data": {
|
|
"vue_code": "完整Vue组件代码",
|
|
"suggestions": {
|
|
"layer5_logo_content": {
|
|
"text": "主办方",
|
|
"color": "#000000"
|
|
},
|
|
"layer6_title_content": {
|
|
"content": "端午安康",
|
|
"font_name": "SimHei",
|
|
"color": "#7E0C6E"
|
|
},
|
|
"layer7_subtitle_content": {
|
|
"content": "粽叶飘香,龙舟竞渡",
|
|
"font_name": "Microsoft YaHei",
|
|
"color": "#000000"
|
|
}
|
|
},
|
|
"analysis_result": {
|
|
"main_theme": "端午节祝福",
|
|
"width": 1080,
|
|
"height": 1920,
|
|
"keywords": ["端午节", "传统", "荷花"]
|
|
},
|
|
"file_size_mb": 5.93,
|
|
"generated_images": 2
|
|
},
|
|
"session_id": "会话ID"
|
|
}
|
|
```
|
|
|
|
### 3. 文件下载
|
|
**GET** `/api/download/{file_type}?session_id={session_id}`
|
|
|
|
参数: `file_type` = `vue` | `psd` | `json`
|
|
|
|
### 4. 会话状态
|
|
**GET** `/api/status/{session_id}`
|
|
|
|
```json
|
|
{
|
|
"session_id": "会话ID",
|
|
"files": {
|
|
"vue_file": true,
|
|
"psd_file": true,
|
|
"content_file": true
|
|
},
|
|
"folder": "会话文件夹路径"
|
|
}
|
|
```
|
|
|
|
## 使用示例
|
|
|
|
### JavaScript
|
|
```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();
|
|
if (result.status === 'success') {
|
|
// 下载文件
|
|
const url = `http://localhost:8000/api/download/psd?session_id=${result.session_id}`;
|
|
window.open(url);
|
|
}
|
|
```
|
|
|
|
### Python
|
|
```python
|
|
import requests
|
|
|
|
response = requests.post('http://localhost:8000/api/generate-poster',
|
|
json={"user_input": "端午节海报,传统风格"})
|
|
result = response.json()
|
|
|
|
if result["status"] == "success":
|
|
session_id = result["session_id"]
|
|
# 下载PSD文件
|
|
psd_url = f"http://localhost:8000/api/download/psd?session_id={session_id}"
|
|
psd_response = requests.get(psd_url)
|
|
with open("poster.psd", "wb") as f:
|
|
f.write(psd_response.content)
|
|
```
|
|
|
|
## 错误处理
|
|
|
|
```json
|
|
{
|
|
"status": "error",
|
|
"message": "错误描述",
|
|
"data": null
|
|
}
|
|
```
|
|
|
|
常见错误码:
|
|
- `400`: 请求参数错误
|
|
- `404`: 资源不存在
|
|
- `500`: 服务器内部错误
|
|
|
|
## 部署
|
|
|
|
### 开发环境
|
|
```bash
|
|
cd scripts
|
|
python run_pipeline.py # 选择2
|
|
```
|
|
|
|
### 生产环境
|
|
```bash
|
|
uvicorn scripts.run_pipeline:app --host 0.0.0.0 --port 8000
|
|
```
|