docs: 精简 README,适配 AI 一键部署

This commit is contained in:
zwbcc
2026-03-28 20:54:22 +08:00
parent 3f754b1a7f
commit 2c52515010

218
README.md
View File

@@ -1,75 +1,44 @@
# 图片生成器
基于 MiniMax API 的文生图 Web 界面,支持 `image-01``image-01-live` 双模型。
**本地访问:** http://10.0.10.110:8195
MiniMax 文生图工具,访问 http://10.0.10.110:8195
---
## 功能特性
### 模型
| 模型 | 说明 |
|------|------|
| `image-01` | 标准文生图,支持全部比例和自定义分辨率 |
| `image-01-live` | 支持画风类型,适合风格化创作 |
### 图片参数
- **比例**1:1 / 16:9 / 4:3 / 3:2 / 2:3 / 3:4 / 9:16 / 21:9仅 image-01
- **自定义分辨率**:宽度 × 高度512-2048必须为 8 的倍数;同时设置宽高时优先于比例
- **输出格式**URL24小时有效或 Base64直接保存
- **生成数量**1-9 张
- **随机种子**:输入整数用于复现,留空则随机
### 画风(仅 image-01-live
| 画风 | 说明 |
|------|------|
| 漫画 | 漫画风格 |
| 元气 | 活力元气风格 |
| 中世纪 | 中世纪风格 |
| 水彩 | 水彩画风格 |
权重 0.1-1.0 通过滑块调节。
### 高级选项
- **自动优化 Prompt**:启用后自动优化描述
- **添加 AI 水印**:在图片中嵌入 MiniMax 水印
---
## API Key 配置
首次使用需配置 MiniMax API Key
1. 点击右上角 ⚙️ 设置按钮
2. 填写 API Key格式`eyJhbGciOiJIUzI1NiIsInR5...`
3. API 地址默认 `https://api.minimaxi.com`(中国区),仅在需要代理时修改
4. 点击保存
> API Key 获取地址https://platform.minimaxi.com/user-center/basic-information/interface-key
Key 存储在 `config.json` 中(服务进程内存,不暴露给前端)。
---
## 部署
### 环境依赖
- Node.js已安装
- 全局模块:`express``node-fetch`
## 一键部署
```bash
# 检查依赖
npm root -g # 查看全局模块路径
node -e "require('express'); require('node-fetch')" # 验证
# SSH 登录目标机器后,一键运行:
bash <(curl -fsSL https://gitea.zwbcc.cn/zwbpc/image-generator/raw/branch/master/start.sh)
```
### Systemd Service
或手动部署:
```bash
# 1. 安装依赖
npm i -g express node-fetch
# 2. 下载项目(到 /home/zwbpc/image-generator 或其他目录)
git clone https://gitea.zwbcc.cn/zwbpc/image-generator.git
cd image-generator
# 3. 启动
chmod +x start.sh
./start.sh
# 4. 配置开机自启(可选)
# 创建 service~/.config/systemd/user/image-generator.service
# 内容见下方「Systemd」小节
systemctl --user daemon-reload
systemctl --user enable --now image-generator.service
```
**访问:** http://目标机器:8195
**配置 API Key** 页面右上角 ⚙️ → 填入 MiniMax Key → 保存
---
## Systemd Service可选
```ini
# ~/.config/systemd/user/image-generator.service
@@ -82,119 +51,52 @@ Type=simple
WorkingDirectory=/home/zwbpc/image-generator
ExecStart=/home/zwbpc/image-generator/start.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
```
```bash
# 启用并启动
systemctl --user daemon-reload
systemctl --user enable --now image-generator.service
# 重启
systemctl --user restart image-generator.service
# 查看日志
journalctl --user -u image-generator.service -n50 -f
```
### 手动启动
```bash
cd /home/zwbpc/image-generator
export NODE_PATH=$(npm root -g)
node app.js
```
---
## 接口
### `POST /api/generate`
生成图片。
**请求体:**
```json
{
"model": "image-01",
"prompt": "一只赛博朋克风格的小猫",
"aspect_ratio": "16:9",
"response_format": "url",
"n": 1
}
```
| 参数 | 类型 | 说明 |
|------|------|------|
| `model` | string | `image-01``image-01-live` |
| `prompt` | string | 图片描述,最多 1500 字符 |
| `aspect_ratio` | string | 比例,如 `16:9` |
| `width` | number | 自定义宽度512-2048需同时设置 height |
| `height` | number | 自定义高度512-2048需同时设置 width |
| `response_format` | string | `url``base64` |
| `n` | number | 生成数量 1-9 |
| `seed` | number | 随机种子,用于复现 |
| `prompt_optimizer` | boolean | 自动优化 Prompt |
| `aigc_watermark` | boolean | 添加 AI 水印 |
| `style.style_type` | string | 画风类型(仅 image-01-live |
| `style.style_weight` | number | 画风权重 0.1-1.0(仅 image-01-live |
**响应:**
```json
{
"images": ["https://..."],
"id": "task_xxx",
"success_count": 1,
"failed_count": 0
}
```
### `GET /api/config`
获取当前配置(不含 Key
### `POST /api/config`
保存配置。
### `GET /api/task/:id`
查询任务状态(预留)。
---
## 常见错误
| 错误码 | 说明 |
|--------|------|
| 1002 | 限流,请稍后再试 |
| 1004 | 账号鉴权失败,检查 API Key |
| 1008 | 账号余额不足 |
| 1026 | 内容涉及敏感词,修改 Prompt |
| 2013 | 参数异常,检查输入是否合规 |
| 2049 | 无效的 API Key |
---
## 项目结构
```
image-generator/
├── index.html # 前端页面
├── style.css # 样式(深色主题)
├── app.js # Express 服务端
├── config.json # API Key 存储(不提交)
├── start.sh # 启动脚本(设置 NODE_PATH
└── CHANGELOG.md # 更新日志
├── index.html # 前端
├── style.css # 样式
├── app.js # 服务端(Express
├── start.sh # 启动脚本
├── config.json # API Key 存储(自动生成
└── CHANGELOG.md
```
---
## 更新日志
## API 端点
参见 [CHANGELOG.md](./CHANGELOG.md)
| 方法 | 路径 | 说明 |
|------|------|------|
| `POST` | `/api/generate` | 生成图片 |
| `GET` | `/api/config` | 获取配置 |
| `POST` | `/api/config` | 保存配置 |
**生成参数:**
| 参数 | 默认值 | 说明 |
|------|--------|------|
| `model` | `image-01` | `image-01``image-01-live` |
| `prompt` | — | 图片描述(必填) |
| `aspect_ratio` | `16:9` | 比例:`1:1` `16:9` `4:3` `3:2` `2:3` `3:4` `9:16` `21:9` |
| `response_format` | `url` | `url`24h有效`base64` |
| `n` | `1` | 数量 1-9 |
| `seed` | 随机 | 整数,用于复现 |
| `width` / `height` | — | 自定义分辨率512-20488的倍数 |
| `style.style_type` | — | 画风:`漫画` `元气` `中世纪` `水彩`(仅 live |
| `style.style_weight` | 0.8 | 画风权重 0.1-1.0(仅 live |
**常见错误码:** `1002`限流 `1004`鉴权失败 `1008`余额不足 `1026`敏感词 `2049`无效Key