diff --git a/README.md b/README.md new file mode 100644 index 0000000..6291f70 --- /dev/null +++ b/README.md @@ -0,0 +1,200 @@ +# 图片生成器 + +基于 MiniMax API 的文生图 Web 界面,支持 `image-01` 和 `image-01-live` 双模型。 + +**本地访问:** 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 的倍数;同时设置宽高时优先于比例 +- **输出格式**:URL(24小时有效)或 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')" # 验证 +``` + +### Systemd Service + +```ini +# ~/.config/systemd/user/image-generator.service +[Unit] +Description=MiniMax Image Generator +After=network.target + +[Service] +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 # 更新日志 +``` + +--- + +## 更新日志 + +参见 [CHANGELOG.md](./CHANGELOG.md)