Add configs directory and README
This commit is contained in:
parent
b2bcb6616c
commit
31b35be742
41
README.md
41
README.md
@ -1 +1,42 @@
|
|||||||
# ai_service
|
# ai_service
|
||||||
|
|
||||||
|
## LLM 调用部分
|
||||||
|
|
||||||
|
### 功能组件
|
||||||
|
使用 DeepSeek API 提供的 LLM(大型语言模型)功能,用于生成 React 组件代码,主要服务于端午节活动海报的排版设计。当前实现的功能包括:
|
||||||
|
- **代码生成**:根据提示(prompt)生成 React 组件代码,专注于排版位置(不包含样式描述)。
|
||||||
|
- **分层排版**:生成包含背景图层、主体图层、活动亮点和页脚的 React 组件
|
||||||
|
|
||||||
|
- **文件保存**:将生成的 React 代码保存到指定路径。
|
||||||
|
|
||||||
|
### 如何调用
|
||||||
|
1. **环境准备**:
|
||||||
|
- 确保已安装 Python 环境和必要依赖(`openai`、`python-dotenv`等)。
|
||||||
|
- 在项目根目录的 `.env` 文件中配置 `DEEPSEEK_API_KEY`。
|
||||||
|
|
||||||
|
2. **运行脚本**:
|
||||||
|
- 直接运行 `generate_layout.py` 脚本:
|
||||||
|
```bash
|
||||||
|
python generate_layout.py
|
||||||
|
```
|
||||||
|
- 该脚本会自动调用 DeepSeek API 生成 React 组件代码,并将其保存到指定路径。
|
||||||
|
默认为``output/generated_code.jsx``,可以根据需要修改。
|
||||||
|
|
||||||
|
## 图层叠加和PSD导出部分
|
||||||
|
### 功能组件
|
||||||
|
- **图层合成**:根据生成的布局配置,将各个图层叠加在一起,生成完整的海报图像。
|
||||||
|
- **PSD导出**:将合成的海报图像保存为标准的PSD格式,同时保留各个图层的独立性,方便后续编辑。
|
||||||
|
### 如何调用
|
||||||
|
1. **环境准备**:
|
||||||
|
```bash
|
||||||
|
conda create -n ai_service python=3.8
|
||||||
|
conda activate ai_service
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
2. **运行脚本**:
|
||||||
|
```bash
|
||||||
|
python export_psd.py #简单生成
|
||||||
|
python export_psd_from_json.py #从json文件加载布局并生成
|
||||||
|
python PSD_test.py #在run_pipline.py中的调用方法
|
||||||
|
```
|
||||||
|
该脚本会自动调用图层合成模块生成完整海报图像,并将其保存为标准PSD格式。
|
40
configs/example.json
Normal file
40
configs/example.json
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"canvas": {
|
||||||
|
"width": 1000,
|
||||||
|
"height": 800,
|
||||||
|
"mode": "RGB"
|
||||||
|
},
|
||||||
|
"layers": [
|
||||||
|
{
|
||||||
|
"image_path": "../images/background.jpg",
|
||||||
|
"name": "background",
|
||||||
|
"position": {
|
||||||
|
"left": 0,
|
||||||
|
"top": 0
|
||||||
|
},
|
||||||
|
"visible": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image_path": "../images/nankai.jpg",
|
||||||
|
"name": "middle",
|
||||||
|
"position": {
|
||||||
|
"left": 100,
|
||||||
|
"top": 100
|
||||||
|
},
|
||||||
|
"visible": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image_path": "../images/aaai.png",
|
||||||
|
"name": "top",
|
||||||
|
"position": {
|
||||||
|
"left": 200,
|
||||||
|
"top": 200
|
||||||
|
},
|
||||||
|
"visible": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"output": {
|
||||||
|
"path": "../outputs/configured_output.psd",
|
||||||
|
"generate_preview": true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user