初始化提交:contentm_agent 工作区全量快照
内容分四块: 1、产品规划产出 —— MCN 短视频整合营销工作台的①段五份(1a 需求/1b 竞品/1c 画像/1d 策略/1e 场景)、②段两份(2a 功能/2b 布局)、③段界面(DESIGN.md 契约与令牌表 + mcn-workbench.html 原型 + 实测/会诊/审查三份 + 23 张闸门截图)。 2、开源竞品调研 —— 5 个内容工作台项目的取证原始件与 1b 系列分析文档。 3、参考资料 —— 竞品视频抽帧 1145 张 + 2 个源视频 + 功能点截图。 4、机制侧 —— 协作脚本与状态台账、工作区记忆日志、抽帧/OCR 脚本。 .gitignore 只排运行时日志、脚本备份副本与一次性探针输出,其余按原样入库。
This commit is contained in:
commit
df56c2c137
1773 files changed
+205840
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
# LabNana API 配置(使用 GPT-image-2 模型)
|
||||
# 复制此文件为 .labnana.env 并填入你自己的 key
|
||||
# 申请: https://labnana.com
|
||||
|
||||
LABNANA_API_KEY=your_labnana_api_key_here
|
||||
LABNANA_API_URL=https://api.labnana.com
|
||||
LABNANA_MODEL=gpt-image-2
|
||||
LABNANA_PROVIDER=openai
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
---
|
||||
name: space-chart-image
|
||||
description: |
|
||||
使用 AI 图片生成技术绘制美观的图表。支持 10 种图表类型:流程图、架构图、ER 图、商业模式画布、用户旅程图、思维导图、竞品分析图、SWOT 分析、产品路线图、组织架构图。6 种内置视觉风格。
|
||||
触发词:"画个 XX 图"、"生成商业模式画布"、"做个架构图"、"画 ER 图"、"帮我画个流程图"、"生成用户旅程图"、"做个思维导图"、"竞品分析图"、"SWOT 分析图"、"产品路线图"、"组织架构图"、"帮我可视化图表"。
|
||||
【公众号配图版】用户给内容 → 产出公众号配图。优先用当前环境内置出图模型(Codex 内置 image_gen/image2、workbuddy 出图模型)直接生成 PNG;无内置模型时回退 scripts/ 下的 API 脚本。
|
||||
---
|
||||
|
||||
# Chart Image:AI 图表绘制器
|
||||
|
||||
## 你的角色
|
||||
|
||||
你是一位擅长信息可视化的设计师,能把文字描述转化为设计精美的图表图片,用于**公众号配图**。
|
||||
|
||||
## 公众号配图适配
|
||||
|
||||
**定位**:公众号配图工具。用户给一段内容(文章 / 段落 / 主题),你产出可直接放进公众号的图表配图。
|
||||
|
||||
**出图方式(优先内置模型)**:
|
||||
- **模型出图(本 Skill 主路径)**:调用当前环境内置的出图模型直接生成 PNG——
|
||||
- 在 **Codex** 里用内置 `image_gen` / `image2`;
|
||||
- 在 **workbuddy** 里用其内置出图模型;
|
||||
- 都没有时回退 `scripts/generate_chart.py`(需自备 key)。
|
||||
- **HTML 出图**:需要可编辑/可复制到公众号时,改走 `space-text-logic-diagram` 或 `space-wechat-layout` 出 HTML。
|
||||
|
||||
**公众号常用尺寸**:头图 2.35:1(1175×500)|正文配图 16:9 或 3:2|方图 1:1。
|
||||
|
||||
**输出**:默认存用户图片目录,命名 `MMDD-主题-风格.png`。
|
||||
|
||||
## 图表类型注册表
|
||||
|
||||
| # | 类型 | 英文名 | 适用场景 | 触发词 |
|
||||
|---|------|--------|----------|--------|
|
||||
| 1 | 流程图 | Flowchart | 工作流、决策树、系统流程 | 流程图、工作流、流程 |
|
||||
| 2 | 架构图 | Architecture | 系统架构、模块关系、技术栈 | 架构图、系统图、模块图 |
|
||||
| 3 | ER 图 | ER Diagram | 数据模型、实体关系、数据库设计 | ER图、实体关系、数据模型 |
|
||||
| 4 | 商业模式画布 | Business Model Canvas | 商业模式、产品规划、商业模式分析 | 商业模式画布、BMC、商业模式 |
|
||||
| 5 | 用户旅程图 | User Journey Map | 用户体验、触点分析、服务设计 | 用户旅程、旅程图、体验地图 |
|
||||
| 6 | 思维导图 | Mind Map | 头脑风暴、知识梳理、结构化思考 | 思维导图、脑图、发散图 |
|
||||
| 7 | 竞品分析图 | Competitive Analysis | 竞品对比、市场定位、功能对比 | 竞品分析、竞品对比、竞争格局 |
|
||||
| 8 | SWOT 分析 | SWOT Analysis | 战略分析、优劣势评估 | SWOT、优势劣势、战略分析 |
|
||||
| 9 | 产品路线图 | Product Roadmap | 版本规划、里程碑、时间线 | 产品路线图、路线图、Roadmap、版本规划 |
|
||||
| 10 | 组织架构图 | Org Chart | 团队结构、汇报关系、人员分工 | 组织架构、团队结构、组织图 |
|
||||
|
||||
当用户没有指定图表类型时,根据描述内容自动判断最适合的类型。
|
||||
|
||||
## 视觉风格系统
|
||||
|
||||
内置 6 种视觉风格,参考 space-slide-deck 风格体系:
|
||||
|
||||
| 风格 | 关键词 | 感觉 | 推荐图表类型 |
|
||||
|------|--------|------|-------------|
|
||||
| blueprint (默认) | 蓝底白线、网格、工程图纸 | 科技感、专业感、精准 | 架构图、流程图、ER图、产品路线图 |
|
||||
| notion | 白底黑线、几何、简约 | 干净利落、Notion 风格 | 所有类型(百搭) |
|
||||
| sketch-notes | 手绘、暖色、有机线条 | 教育感、亲和力、轻松 | 思维导图、用户旅程图、组织架构图 |
|
||||
| corporate | 深蓝、金灰、商务正装 | 正式、投资级、严肃 | SWOT 分析、商业模式画布、竞品分析 |
|
||||
| dark-atmospheric | 深色背景、霓虹发光线条 | 科技感、高级感、酷炫 | 产品路线图、竞品分析、架构图 |
|
||||
| watercolor | 水彩质感、暖色柔和 | 艺术、生活感、温暖 | 思维导图、组织架构图、用户旅程图 |
|
||||
|
||||
### 风格自动推荐
|
||||
|
||||
根据图表类型自动推荐最佳风格:
|
||||
|
||||
| 图表类型 | 推荐风格 |
|
||||
|----------|----------|
|
||||
| 流程图 | blueprint |
|
||||
| 架构图 | blueprint |
|
||||
| ER 图 | blueprint |
|
||||
| 商业模式画布 | corporate |
|
||||
| 用户旅程图 | sketch-notes |
|
||||
| 思维导图 | watercolor |
|
||||
| 竞品分析图 | dark-atmospheric |
|
||||
| SWOT 分析 | corporate |
|
||||
| 产品路线图 | dark-atmospheric |
|
||||
| 组织架构图 | sketch-notes |
|
||||
|
||||
用户说"XX 风格"时直接匹配。未指定时使用推荐风格。
|
||||
|
||||
---
|
||||
|
||||
## 工作流程
|
||||
|
||||
```
|
||||
用户输入(描述 + 图表意图)
|
||||
│
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Step 1:识别图表类型 │ ← 关键词匹配 + 内容分析
|
||||
└────────┬─────────────┘
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Step 2:收集内容 │ ← 从描述中提取 + 追问缺失信息
|
||||
└────────┬─────────────┘
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Step 2.5:用户确认 │ ← 选择风格 + 受众 + 数量 ⚠️ 必须执行
|
||||
└────────┬─────────────┘
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Step 3:生成提示词 │ ← 根据图表类型 + 风格生成提示词
|
||||
└────────┬─────────────┘
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Step 4:出图 │ ← 内置模型 codex/workbuddy
|
||||
└────────┬─────────────┘
|
||||
▼
|
||||
┌──────────────────────┐
|
||||
│ Step 5:保存并展示 │ ← 存图片目录 + 预览
|
||||
└──────────────────────┘
|
||||
```
|
||||
|
||||
### Step 1:识别图表类型
|
||||
|
||||
从用户的描述中判断要画什么图。判断依据:
|
||||
|
||||
1. **用户明确说了图表名** → 直接匹配注册表
|
||||
2. **用户描述了内容但没有说图表名** → 根据内容特征自动判断:
|
||||
- 描述了"步骤→步骤→步骤" → 流程图
|
||||
- 描述了"模块A连接模块B" → 架构图
|
||||
- 描述了"实体A有字段X,关联实体B" → ER 图
|
||||
- 描述了"客户细分、价值主张、收入来源" → 商业模式画布
|
||||
- 描述了"用户从XX到XX经历了什么" → 用户旅程图
|
||||
- 描述了发散式的层级结构 → 思维导图
|
||||
- 描述了多个产品/功能的对比 → 竞品分析图
|
||||
- 描述了优势、劣势、机会、威胁 → SWOT 分析
|
||||
- 描述了版本、时间线、里程碑 → 产品路线图
|
||||
- 描述了团队、角色、汇报关系 → 组织架构图
|
||||
|
||||
3. **无法判断** → 问用户一句话:"你想画哪种图?"并简要列出适合的 2-3 个选项。
|
||||
|
||||
### Step 2:收集内容
|
||||
|
||||
根据图表类型,从用户描述中提取关键信息。
|
||||
|
||||
**如果信息不够**:追问 2-3 个关键问题。不同图表的必填信息见 `references/chart-prompts.md`。
|
||||
|
||||
**追问原则**:
|
||||
- 一次不超过 3 个问题
|
||||
- 问题要具体,不要问"你还需要什么"
|
||||
- 给出默认选项供选择
|
||||
|
||||
### Step 2.5:用户确认 ⚠️ 必须执行
|
||||
|
||||
**在生成提示词之前**,使用 AskUserQuestion 让用户确认以下 3 项:
|
||||
|
||||
**问题 1:风格**
|
||||
```
|
||||
header: "风格"
|
||||
question: "选择哪种视觉风格?"
|
||||
options:
|
||||
- label: "{推荐风格} (推荐)"
|
||||
description: "根据图表类型自动推荐的最佳风格"
|
||||
- label: "blueprint"
|
||||
description: "蓝图工程风 - 蓝底白线网格,科技专业感"
|
||||
- label: "notion"
|
||||
description: "Notion简约风 - 白底黑线几何,干净利落"
|
||||
- label: "sketch-notes"
|
||||
description: "手绘笔记风 - 暖色有机线条,教育亲和力"
|
||||
- label: "corporate"
|
||||
description: "商务正装风 - 深蓝金灰,正式投资级"
|
||||
- label: "dark-atmospheric"
|
||||
description: "深色霓虹风 - 深色发光线条,科技酷炫"
|
||||
- label: "watercolor"
|
||||
description: "水彩柔和风 - 暖色水彩质感,艺术温暖"
|
||||
```
|
||||
|
||||
**问题 2:受众**
|
||||
```
|
||||
header: "受众"
|
||||
question: "图表面向什么读者?"
|
||||
options:
|
||||
- label: "普通读者 (推荐)"
|
||||
description: "广泛受众,内容通俗易懂"
|
||||
- label: "初学者"
|
||||
description: "教育导向,清晰解释概念"
|
||||
- label: "专家/从业者"
|
||||
description: "技术深度,领域术语"
|
||||
- label: "管理者/决策者"
|
||||
description: "高层洞察,少量细节"
|
||||
```
|
||||
|
||||
**问题 3:生成数量**
|
||||
```
|
||||
header: "数量"
|
||||
question: "生成几张图表?"
|
||||
options:
|
||||
- label: "1 张 (推荐)"
|
||||
description: "使用选定风格生成 1 张"
|
||||
- label: "2 张"
|
||||
description: "生成 2 张,可对比不同风格效果"
|
||||
- label: "3 张"
|
||||
description: "生成 3 张,多种风格对比"
|
||||
```
|
||||
|
||||
**如果用户选择多张**:每张使用不同风格(推荐风格 + 其他风格轮换),保存到同一目录。
|
||||
|
||||
### Step 3:生成提示词
|
||||
|
||||
根据图表类型、用户内容和选定风格,生成适合 GPT-image-2 的提示词。
|
||||
|
||||
提示词结构:
|
||||
1. **风格前缀** - 从 `references/chart-prompts.md` 的风格前缀库中选择对应的
|
||||
2. **图表类型** - 明确图表类型
|
||||
3. **内容描述** - 详细描述图表内容
|
||||
4. **受众调整** - 根据受众调整文字密度和专业度
|
||||
5. **中文指令** - 确保图片中文字为中文
|
||||
6. **排除项** - 不使用摄影、写实元素
|
||||
|
||||
提示词模板和风格前缀见 `references/chart-prompts.md`。
|
||||
|
||||
### Step 4:出图(优先内置模型)
|
||||
|
||||
确认提示词后,**用当前环境内置的出图模型生成图片**:
|
||||
|
||||
- **Codex**:调用内置 `image_gen` / `image2`,把提示词交给它出 PNG。
|
||||
- **workbuddy**:调用其内置出图模型。
|
||||
- **回退**(都没有内置模型时):用自备 key 的 API 脚本:
|
||||
|
||||
```bash
|
||||
python3 {baseDir}/scripts/generate_chart.py \
|
||||
--prompt "提示词内容" \
|
||||
--output "<图片目录>/MMDD-图表名.png" \
|
||||
--style {blueprint|notion|sketch-notes|corporate|dark-atmospheric|watercolor}
|
||||
```
|
||||
|
||||
**如果生成多张**:按顺序调用,每张使用不同风格。
|
||||
|
||||
### Step 5:保存并展示
|
||||
|
||||
保存路径规范:
|
||||
```
|
||||
<图片目录>/MMDD-图表简称/
|
||||
├── 01-图表名称-blueprint.png
|
||||
├── 02-图表名称-notion.png
|
||||
└── ...
|
||||
```
|
||||
|
||||
- MMDD 取当天日期
|
||||
- 图表简称从标题提取,2-4 个字
|
||||
- 多张时文件名附加风格名
|
||||
- 生成后用 `open` 命令展示图片预览
|
||||
|
||||
---
|
||||
|
||||
## 输出规范
|
||||
|
||||
### 图片规格
|
||||
|
||||
- 比例:16:9 横版(商业模式画布等宽图用 21:9)
|
||||
- 分辨率:2K
|
||||
- 格式:PNG
|
||||
|
||||
### 内容规范
|
||||
|
||||
- 标题简洁有力,不超过 15 个字
|
||||
- 文字内容精炼,每个要点一句话,不超过 20 字
|
||||
- 使用具体的词汇,不用"相关""各种"等模糊词
|
||||
- 数字和专有名词保持准确
|
||||
|
||||
## 图表结构速查
|
||||
|
||||
### 1 流程图
|
||||
- 布局:从上到下或从左到右的节点链
|
||||
- 核心元素:开始节点、处理节点、判断节点、结束节点
|
||||
- 连线带箭头,分支带标签
|
||||
|
||||
### 2 架构图
|
||||
- 布局:分层(前端/后端/数据/第三方)或环形
|
||||
- 核心元素:模块方块、连接线、数据流箭头
|
||||
|
||||
### 3 ER 图
|
||||
- 布局:实体矩形散布,关系线连接
|
||||
- 核心元素:实体名、字段列表、关系线(1:1 / 1:N / N:M)
|
||||
|
||||
### 4 商业模式画布
|
||||
- 布局:经典九宫格(5 列布局)
|
||||
- 九个区块:重要伙伴、关键活动、核心资源、价值主张、客户关系、渠道通路、客户细分、成本结构、收入来源
|
||||
|
||||
### 5 用户旅程图
|
||||
- 布局:横向时间线 + 纵向分层
|
||||
- 核心元素:阶段名、用户行为、情绪曲线、痛点标注
|
||||
|
||||
### 6 思维导图
|
||||
- 布局:中心主题向四周发散
|
||||
- 核心元素:中心节点、一级分支、二级分支
|
||||
|
||||
### 7 竞品分析图
|
||||
- 布局:矩阵或表格对比
|
||||
- 核心元素:产品名、关键维度评分、定位气泡
|
||||
|
||||
### 8 SWOT 分析
|
||||
- 布局:2x2 矩阵
|
||||
- 四个区块:优势(S)、劣势(W)、机会(O)、威胁(T)
|
||||
|
||||
### 9 产品路线图
|
||||
- 布局:横向时间线 + 纵向模块/功能分组
|
||||
- 核心元素:版本名、时间区间、功能条目、里程碑标记
|
||||
|
||||
### 10 组织架构图
|
||||
- 布局:树形结构,从上到下展开
|
||||
- 核心元素:角色名、人名、汇报关系连线
|
||||
|
||||
## 回退 API 配置(仅当无内置出图模型时)
|
||||
|
||||
> 优先用 Codex/workbuddy 内置出图;以下 API 是没有内置模型时的兜底,需自备 key。
|
||||
|
||||
| 配置项 | 值 |
|
||||
|-------|---|
|
||||
| API URL | `https://api.labnana.com` |
|
||||
| API Key | 存储在 `.labnana.env` 文件 |
|
||||
| Model | `gpt-image-2` |
|
||||
| Provider | `openai` |
|
||||
|
||||
## 常见用法
|
||||
|
||||
| 用户说 | 操作 |
|
||||
|-------|-----|
|
||||
| "画个流程图" | 识别类型 → 收集内容 → 选风格 → 生成图片 |
|
||||
| "深色风格的架构图" | 指定 dark-atmospheric 风格 → 生成 |
|
||||
| "做个 SWOT,商务风" | 指定 corporate 风格 → 生成 |
|
||||
| "画个思维导图,3 张不同风格" | 生成 3 张不同风格的思维导图 |
|
||||
| "重新生成" | 用修改后的提示词重新生成 |
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
interface:
|
||||
display_name: "AI 图表绘制"
|
||||
short_description: "使用 GPT-image-2 生成美观的图表图片"
|
||||
default_prompt: "使用 $space-chart-image 为我绘制一个图表"
|
||||
+482
@@ -0,0 +1,482 @@
|
||||
# 图表提示词模板
|
||||
|
||||
本文档定义每种图表类型的提示词生成模板。
|
||||
|
||||
---
|
||||
|
||||
## 风格前缀库
|
||||
|
||||
所有提示词开头根据选定风格添加对应前缀。共有 6 种视觉风格。
|
||||
|
||||
### blueprint 蓝图工程风(默认)
|
||||
|
||||
适合:流程图、架构图、ER 图、产品路线图
|
||||
|
||||
```
|
||||
A precise technical blueprint-style {图表类型} diagram.
|
||||
Background: Off-white (#FAF8F5) with subtle grid lines.
|
||||
Colors: Engineering Blue (#2563EB), Deep Slate (#334155), Navy (#1E3A5F), Light Blue (#BFDBFE).
|
||||
Line art with clean geometric shapes, dimension lines, precise connections.
|
||||
Thin borders, subtle shadows for depth. Professional engineering drawing feel.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use clean sans-serif Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.
|
||||
No photography, no realistic elements, no complex gradients, no 3D effects.
|
||||
```
|
||||
|
||||
### notion 简约风
|
||||
|
||||
适合:所有图表类型(百搭)
|
||||
|
||||
```
|
||||
A clean minimal {图表类型} diagram in Notion style.
|
||||
Background: Pure white (#FFFFFF) with subtle dot grid.
|
||||
Colors: Dark text (#37352f), subtle borders (#E3E2E0), accent blue (#2383E2), light fills (#F7F7F5).
|
||||
Clean rectangular shapes with rounded corners, thin 1px borders.
|
||||
Generous whitespace, geometric alignment, information-dense but organized.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use clean sans-serif Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.
|
||||
No photography, no realistic elements, no complex gradients, no 3D effects.
|
||||
```
|
||||
|
||||
### sketch-notes 手绘笔记风
|
||||
|
||||
适合:思维导图、用户旅程图、组织架构图
|
||||
|
||||
```
|
||||
A hand-drawn sketch-notes style {图表类型} diagram.
|
||||
Background: Warm off-white (#FFF8F0) with subtle paper texture.
|
||||
Colors: Warm tones - terracotta (#C0562F), forest green (#2F7A5C), navy pen (#2D3748), amber highlight (#F6AD55).
|
||||
Marker-style thick outlines, slightly wobbly organic lines.
|
||||
Handwritten feel, doodle-style icons, sticky-note shapes, arrow doodles.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use friendly rounded Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.
|
||||
No photography, no realistic elements, no complex gradients, no 3D effects.
|
||||
```
|
||||
|
||||
### corporate 商务正装风
|
||||
|
||||
适合:SWOT 分析、商业模式画布、竞品分析
|
||||
|
||||
```
|
||||
A professional corporate-style {图表类型} diagram.
|
||||
Background: White (#FFFFFF) with navy (#1E3A5F) header band and subtle pinstripe accents.
|
||||
Colors: Navy (#1E3A5F), Gold (#C5A55A), Charcoal (#4A4A4A), Silver (#B0B0B0), Light Gray (#F5F5F5).
|
||||
Sharp geometric shapes, gold accent lines, clean serif typography.
|
||||
Executive dashboard feel, data-driven, investment-grade presentation.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use professional Chinese font (serif for titles). Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.
|
||||
No photography, no realistic elements, no complex gradients, no 3D effects.
|
||||
```
|
||||
|
||||
### dark-atmospheric 深色霓虹风
|
||||
|
||||
适合:产品路线图、竞品分析、架构图
|
||||
|
||||
```
|
||||
A dark atmospheric {图表类型} diagram with glowing neon elements.
|
||||
Background: Deep dark (#0A0A0B) with subtle grid overlay.
|
||||
Colors: Neon cyan (#00F5FF), electric purple (#A855F7), hot pink (#F472B6), amber glow (#FBBF24).
|
||||
Glowing connection lines, luminous node borders, gradient light effects on edges.
|
||||
Futuristic dashboard feel, cyberpunk-inspired, high-tech aesthetic.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use clean light-colored Chinese font on dark background. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.
|
||||
No photography, no realistic elements, no complex gradients on flat surfaces, no 3D effects.
|
||||
```
|
||||
|
||||
### watercolor 水彩柔和风
|
||||
|
||||
适合:思维导图、组织架构图、用户旅程图
|
||||
|
||||
```
|
||||
A soft watercolor-style {图表类型} diagram.
|
||||
Background: Warm cream (#FEFCF8) with subtle watercolor wash texture.
|
||||
Colors: Soft pastels - rose pink (#FBBFCA), sky blue (#A3D5FF), lavender (#C4B5FD), sage green (#A7F3D0), peach (#FED7AA).
|
||||
Watercolor paint fill for shapes, soft bleeding edges, gentle color transitions.
|
||||
Organic flowing connections, hand-painted feel, warm and approachable.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use rounded friendly Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.
|
||||
No photography, no realistic elements, no sharp geometric shapes, no 3D effects.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 1 流程图 Flowchart
|
||||
|
||||
### 必填信息
|
||||
- 流程步骤列表(至少 3 个步骤)
|
||||
- 是否有分支/判断
|
||||
- 开始和结束节点
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: horizontal flow from left to right.
|
||||
|
||||
Nodes (rounded rectangles connected with arrows):
|
||||
- {开始节点} (start node, oval shape)
|
||||
- {步骤1} → {步骤2} → {步骤3}
|
||||
{如果有分支}
|
||||
- Decision node: {判断条件} (diamond shape)
|
||||
- If {条件A}: → {结果A}
|
||||
- If {条件B}: → {结果B}
|
||||
- {结束节点} (end node, oval shape)
|
||||
|
||||
Labels above arrows: {关系标签(如有)}
|
||||
|
||||
中文标签:直接在节点中写中文,如 "开始"、"数据处理"、"判断"、"结束" 等。
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
用户输入:用户注册流程,包括输入信息、验证码、验证成功后注册成功
|
||||
|
||||
提示词:
|
||||
```
|
||||
A minimal hand-drawn flowchart diagram with clean lines on white background.
|
||||
Black outlines, minimal blue accents for emphasis.
|
||||
No photography, no realistic elements, no complex gradients, no 3D effects.
|
||||
Flat, simple, professional style suitable for business presentation.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use clean Chinese font for main text. Technical terms and abbreviations may remain in English.
|
||||
|
||||
Layout: horizontal flow from left to right.
|
||||
|
||||
Nodes (rounded rectangles connected with arrows):
|
||||
- 开始 (start node, oval shape)
|
||||
- 输入注册信息 → 发送验证码
|
||||
- Decision: 验证码正确? (diamond shape)
|
||||
- If 否: → 重新输入
|
||||
- If 是: → 创建账户
|
||||
- 注册完成 (end node, oval shape, green accent)
|
||||
|
||||
中文标签:开始、输入注册信息、发送验证码、验证码正确、否、重新输入、是、创建账户、注册完成
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2 架构图 Architecture Diagram
|
||||
|
||||
### 必填信息
|
||||
- 系统分层/模块列表
|
||||
- 模块间的关系(数据流、调用关系)
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: layered architecture, horizontal arrangement from left to right.
|
||||
|
||||
Layers (separated with vertical dashed lines):
|
||||
- {层1名称}: {模块列表}
|
||||
- {层2名称}: {模块列表}
|
||||
- {层3名称}: {模块列表}
|
||||
|
||||
Connections (arrows with labels):
|
||||
- {模块A} → {模块B}: {数据/调用描述}
|
||||
|
||||
中文标签:层名、模块名使用中文,如 "前端层"、"用户服务"、"数据库" 等。
|
||||
```
|
||||
|
||||
### 示例
|
||||
|
||||
用户输入:Web 应用架构,包括前端、后端 API、数据库
|
||||
|
||||
提示词:
|
||||
```
|
||||
A minimal hand-drawn architecture diagram with clean lines on white background.
|
||||
Black outlines, minimal blue accents for emphasis.
|
||||
No photography, no realistic elements, no complex gradients, no 3D effects.
|
||||
Flat, simple, professional style suitable for business presentation.
|
||||
|
||||
ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).
|
||||
Use clean Chinese font for main text. Technical terms and abbreviations (e.g. API, HTTP, SQL) may remain in English.
|
||||
|
||||
Layout: layered architecture, horizontal arrangement from left to right.
|
||||
|
||||
Layers (separated with vertical dashed lines):
|
||||
- 前端层: Web 页面, 移动 App
|
||||
- API 层: 用户 API, 订单 API, 支付 API
|
||||
- 数据层: 用户数据库, 订单数据库
|
||||
|
||||
Connections (arrows with labels):
|
||||
- Web 页面 → 用户 API: HTTP/JSON
|
||||
- 移动 App → 用户 API: HTTP/JSON
|
||||
- 用户 API → 用户数据库: SQL 查询
|
||||
- 订单 API → 订单数据库: SQL 查询
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3 ER 图 ER Diagram
|
||||
|
||||
### 必填信息
|
||||
- 实体列表(至少 2 个)
|
||||
- 每个实体的主要字段
|
||||
- 实体间的关系
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: entities scattered, connected with relationship lines.
|
||||
|
||||
Entities (rectangles with field lists):
|
||||
- {实体名1}
|
||||
- {字段1} (PK, primary key, underline)
|
||||
- {字段2}
|
||||
- {字段3}
|
||||
- {实体名2}
|
||||
- {字段1} (PK)
|
||||
- {字段2} (FK, foreign key)
|
||||
|
||||
Relationships (lines with cardinality labels):
|
||||
- {实体A} 1:N {实体B}: {关系描述}
|
||||
|
||||
中文标签:实体名、字段名使用中文。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4 商业模式画布 Business Model Canvas
|
||||
|
||||
### 必填信息
|
||||
- 价值主张(核心)
|
||||
- 其他 8 个区块的内容
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前序,但使用 21:9 比例}
|
||||
|
||||
Layout: classic Business Model Canvas 9-grid layout (5 columns, 2 rows).
|
||||
|
||||
Nine blocks with Chinese labels:
|
||||
Top row (left to right):
|
||||
- 重要伙伴: {内容}
|
||||
- 关键活动: {内容}
|
||||
- 核心资源: {内容}
|
||||
- 价值主张: {内容 - central, highlighted}
|
||||
- 客户关系: {内容}
|
||||
|
||||
Bottom row (left to right):
|
||||
- 渠道通路: {内容}
|
||||
- 客户细分: {内容}
|
||||
- 成本结构: {内容}
|
||||
- 收入来源: {内容}
|
||||
|
||||
每个区块用浅色背景区分,区块内列出 3-5 条要点。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5 用户旅程图 User Journey Map
|
||||
|
||||
### 必填信息
|
||||
- 用户阶段列表
|
||||
- 每个阶段的行为和触点
|
||||
- 情绪变化
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: horizontal timeline with stages, vertical layers for different aspects.
|
||||
|
||||
Stages (top row, horizontal):
|
||||
- {阶段1} → {阶段2} → {阶段3} → {阶段4}
|
||||
|
||||
Layers (for each stage):
|
||||
- 用户行为: {具体行为}
|
||||
- 触点: {用户接触的界面/渠道}
|
||||
- 情绪: {情绪评分 1-5,用曲线连接各阶段}
|
||||
|
||||
情绪曲线:用平滑曲线连接各阶段的情绪评分,高点用绿色,低点用红色。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6 思维导图 Mind Map
|
||||
|
||||
### 必填信息
|
||||
- 中心主题
|
||||
- 主要分支(至少 3 个)
|
||||
- 每个分支的子节点
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: central topic in the middle, branches radiating outward.
|
||||
|
||||
Central node (center, large): {中心主题}
|
||||
|
||||
Primary branches (different colors for each):
|
||||
- {分支1}: {子节点1-1}, {子节点1-2}
|
||||
- {分支2}: {子节点2-1}, {子节点2-2}
|
||||
- {分支3}: {子节点3-1}, {子节点3-2}
|
||||
- {分支4}: {子节点4-1}, {子节点4-2}
|
||||
|
||||
Each branch uses a different accent color for visual distinction.
|
||||
中文标签:中心主题和所有分支节点使用中文。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7 竞品分析图 Competitive Analysis
|
||||
|
||||
### 必填信息
|
||||
- 竞品列表(至少 2 个)
|
||||
- 对比维度
|
||||
- 各产品在各维度的评分
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: comparison table or radar chart format.
|
||||
|
||||
Option 1 - Table format:
|
||||
Columns: 产品, {维度1}, {维度2}, {维度3}, {维度4}
|
||||
Rows: {产品1}, {产品2}, {产品3}
|
||||
Each cell contains: 评分 1-10 (用条形图表示)
|
||||
|
||||
Option 2 - Positioning matrix:
|
||||
X-axis: {维度1 (如价格)}
|
||||
Y-axis: {维度2 (如品质)}
|
||||
Each product plotted as a bubble with label: {产品名}
|
||||
|
||||
中文标签:产品名、维度名使用中文。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8 SWOT 分析 SWOT Analysis
|
||||
|
||||
### 必填信息
|
||||
- 优势 Strengths (3-5 条)
|
||||
- 劣势 Weaknesses (3-5 条)
|
||||
- 机会 Opportunities (3-5 条)
|
||||
- 威胁 Threats (3-5 条)
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: 2x2 matrix quadrants.
|
||||
|
||||
Top left - 优势 S:
|
||||
- {优势1}
|
||||
- {优势2}
|
||||
- {优势3}
|
||||
Background: light green tint
|
||||
|
||||
Top right - 劣势 W:
|
||||
- {劣势1}
|
||||
- {劣势2}
|
||||
- {劣势3}
|
||||
Background: light red tint
|
||||
|
||||
Bottom left - 机会 O:
|
||||
- {机会1}
|
||||
- {机会2}
|
||||
- {机会3}
|
||||
Background: light blue tint
|
||||
|
||||
Bottom right - 威胁 T:
|
||||
- {威胁1}
|
||||
- {威胁2}
|
||||
- {威胁3}
|
||||
Background: light yellow tint
|
||||
|
||||
中心标题:{分析对象} SWOT 分析
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9 产品路线图 Product Roadmap
|
||||
|
||||
### 必填信息
|
||||
- 时间线(季度或月份)
|
||||
- 各版本/功能计划
|
||||
- 里程碑
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: horizontal timeline at top, feature tracks below.
|
||||
|
||||
Timeline: Q1 → Q2 → Q3 → Q4 (或具体月份)
|
||||
|
||||
Tracks (horizontal swimlanes):
|
||||
- 核心功能: {功能1} (Q1, 完成), {功能2} (Q2, 进行中), {功能3} (Q3, 规划)
|
||||
- 优化项: {优化1} (Q2), {优化2} (Q3)
|
||||
- 基础设施: {基建1} (Q1), {基建2} (Q4)
|
||||
|
||||
Status colors:
|
||||
- 完成: 绿色
|
||||
- 进行中: 蓝色
|
||||
- 规划中: 灰色
|
||||
|
||||
里程碑:用菱形标记重要节点,标注里程碑名称。
|
||||
|
||||
中文标签:功能名、里程碑使用中文。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 10 组织架构图 Org Chart
|
||||
|
||||
### 必填信息
|
||||
- 组织层级结构
|
||||
- 各角色/人名
|
||||
|
||||
### 提示词模板
|
||||
|
||||
```
|
||||
{通用风格前缀}
|
||||
|
||||
Layout: tree structure, top to bottom.
|
||||
|
||||
Top level:
|
||||
- {最高角色}: {人名(可选)}
|
||||
|
||||
Second level:
|
||||
- {部门1负责人}: {人名}
|
||||
- {部门2负责人}: {人名}
|
||||
- {部门3负责人}: {人名}
|
||||
|
||||
Third level (under each department):
|
||||
- {下级角色1}, {下级角色2}
|
||||
|
||||
连接线:实线表示直接汇报关系,虚线表示虚线汇报。
|
||||
同级用浅色背景框分组。
|
||||
|
||||
中文标签:角色名、部门名使用中文。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 提示词生成规则
|
||||
|
||||
1. **中文优先**:所有图表内容、标签必须使用中文
|
||||
2. **专业术语保留英文**:如 API, SQL, HTTP, AI, JWT 等技术术语
|
||||
3. **简洁精炼**:每个要点不超过 15 个字
|
||||
4. **结构清晰**:明确层次关系,用缩进和符号表示层级
|
||||
5. **视觉提示**:用颜色、形状、线条区分不同元素类型
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Chart Image Generator - 使用 LabNana GPT-image-2 生成图表图片
|
||||
|
||||
Usage:
|
||||
python3 generate_chart.py --type flowchart --content "..." --output /path/to/output.png
|
||||
|
||||
Env:
|
||||
LABNANA_API_KEY - LabNana API key (自动从 .labnana.env 读取)
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
# LabNana 配置
|
||||
LABNANA_API_URL = "https://api.labnana.com"
|
||||
LABNANA_MODEL = "gpt-image-2"
|
||||
LABNANA_PROVIDER = "openai"
|
||||
|
||||
DEFAULT_ASPECT_RATIO = "16:9"
|
||||
DEFAULT_RESOLUTION = "2K"
|
||||
MAX_RETRIES = 3
|
||||
RETRY_DELAY = 5
|
||||
|
||||
# 图表类型映射
|
||||
CHART_TYPES = {
|
||||
"flowchart": "流程图",
|
||||
"architecture": "架构图",
|
||||
"er": "ER图",
|
||||
"bmc": "商业模式画布",
|
||||
"journey": "用户旅程图",
|
||||
"mindmap": "思维导图",
|
||||
"competitive": "竞品分析图",
|
||||
"swot": "SWOT分析",
|
||||
"roadmap": "产品路线图",
|
||||
"orgchart": "组织架构图",
|
||||
}
|
||||
|
||||
# 视觉风格
|
||||
STYLE_CHOICES = [
|
||||
"blueprint",
|
||||
"notion",
|
||||
"sketch-notes",
|
||||
"corporate",
|
||||
"dark-atmospheric",
|
||||
"watercolor",
|
||||
]
|
||||
|
||||
# 风格前缀库
|
||||
STYLE_PREFIXES = {
|
||||
"blueprint": (
|
||||
"A precise technical blueprint-style {chart_type} diagram.\n"
|
||||
"Background: Off-white (#FAF8F5) with subtle grid lines.\n"
|
||||
"Colors: Engineering Blue (#2563EB), Deep Slate (#334155), Navy (#1E3A5F), Light Blue (#BFDBFE).\n"
|
||||
"Line art with clean geometric shapes, dimension lines, precise connections.\n"
|
||||
"Thin borders, subtle shadows for depth. Professional engineering drawing feel.\n\n"
|
||||
"ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).\n"
|
||||
"Use clean sans-serif Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.\n"
|
||||
"No photography, no realistic elements, no complex gradients, no 3D effects."
|
||||
),
|
||||
"notion": (
|
||||
"A clean minimal {chart_type} diagram in Notion style.\n"
|
||||
"Background: Pure white (#FFFFFF) with subtle dot grid.\n"
|
||||
"Colors: Dark text (#37352f), subtle borders (#E3E2E0), accent blue (#2383E2), light fills (#F7F7F5).\n"
|
||||
"Clean rectangular shapes with rounded corners, thin 1px borders.\n"
|
||||
"Generous whitespace, geometric alignment, information-dense but organized.\n\n"
|
||||
"ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).\n"
|
||||
"Use clean sans-serif Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.\n"
|
||||
"No photography, no realistic elements, no complex gradients, no 3D effects."
|
||||
),
|
||||
"sketch-notes": (
|
||||
"A hand-drawn sketch-notes style {chart_type} diagram.\n"
|
||||
"Background: Warm off-white (#FFF8F0) with subtle paper texture.\n"
|
||||
"Colors: Warm tones - terracotta (#C0562F), forest green (#2F7A5C), navy pen (#2D3748), amber highlight (#F6AD55).\n"
|
||||
"Marker-style thick outlines, slightly wobbly organic lines.\n"
|
||||
"Handwritten feel, doodle-style icons, sticky-note shapes, arrow doodles.\n\n"
|
||||
"ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).\n"
|
||||
"Use friendly rounded Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.\n"
|
||||
"No photography, no realistic elements, no complex gradients, no 3D effects."
|
||||
),
|
||||
"corporate": (
|
||||
"A professional corporate-style {chart_type} diagram.\n"
|
||||
"Background: White (#FFFFFF) with navy (#1E3A5F) header band and subtle pinstripe accents.\n"
|
||||
"Colors: Navy (#1E3A5F), Gold (#C5A55A), Charcoal (#4A4A4A), Silver (#B0B0B0), Light Gray (#F5F5F5).\n"
|
||||
"Sharp geometric shapes, gold accent lines, clean serif typography.\n"
|
||||
"Executive dashboard feel, data-driven, investment-grade presentation.\n\n"
|
||||
"ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).\n"
|
||||
"Use professional Chinese font (serif for titles). Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.\n"
|
||||
"No photography, no realistic elements, no complex gradients, no 3D effects."
|
||||
),
|
||||
"dark-atmospheric": (
|
||||
"A dark atmospheric {chart_type} diagram with glowing neon elements.\n"
|
||||
"Background: Deep dark (#0A0A0B) with subtle grid overlay.\n"
|
||||
"Colors: Neon cyan (#00F5FF), electric purple (#A855F7), hot pink (#F472B6), amber glow (#FBBF24).\n"
|
||||
"Glowing connection lines, luminous node borders, gradient light effects on edges.\n"
|
||||
"Futuristic dashboard feel, cyberpunk-inspired, high-tech aesthetic.\n\n"
|
||||
"ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).\n"
|
||||
"Use clean light-colored Chinese font on dark background. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.\n"
|
||||
"No photography, no realistic elements, no complex gradients on flat surfaces, no 3D effects."
|
||||
),
|
||||
"watercolor": (
|
||||
"A soft watercolor-style {chart_type} diagram.\n"
|
||||
"Background: Warm cream (#FEFCF8) with subtle watercolor wash texture.\n"
|
||||
"Colors: Soft pastels - rose pink (#FBBFCA), sky blue (#A3D5FF), lavender (#C4B5FD), sage green (#A7F3D0), peach (#FED7AA).\n"
|
||||
"Watercolor paint fill for shapes, soft bleeding edges, gentle color transitions.\n"
|
||||
"Organic flowing connections, hand-painted feel, warm and approachable.\n\n"
|
||||
"ALL text, labels, and annotations in the image MUST be in Chinese (Simplified Chinese, 中文).\n"
|
||||
"Use rounded friendly Chinese font. Technical terms (e.g. AI, API, SQL, HTTP) may remain in English.\n"
|
||||
"No photography, no realistic elements, no sharp geometric shapes, no 3D effects."
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _save_image_from_base64(base64_data, output_path):
|
||||
"""Save base64 image data to file."""
|
||||
img_data = base64.b64decode(base64_data)
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
with open(output_path, "wb") as f:
|
||||
f.write(img_data)
|
||||
return len(img_data)
|
||||
|
||||
|
||||
def _do_http_request(endpoint, payload, headers, timeout=120):
|
||||
"""Execute HTTP request with retry logic."""
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
req = urllib.request.Request(endpoint, data=data, headers=headers, method="POST")
|
||||
|
||||
for attempt in range(MAX_RETRIES):
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||
return json.loads(resp.read().decode("utf-8")), None
|
||||
except urllib.error.HTTPError as e:
|
||||
body = e.read().decode("utf-8", errors="replace")
|
||||
error = {"code": e.code, "message": body[:500]}
|
||||
if e.code == 429 or e.code >= 500:
|
||||
if attempt < MAX_RETRIES - 1:
|
||||
wait = RETRY_DELAY * (attempt + 1)
|
||||
print(f"[INFO] 限流或服务器错误,{wait}秒后重试...", file=sys.stderr)
|
||||
time.sleep(wait)
|
||||
continue
|
||||
return None, error
|
||||
except Exception as e:
|
||||
error = {"code": -1, "message": str(e)}
|
||||
if attempt < MAX_RETRIES - 1:
|
||||
time.sleep(RETRY_DELAY)
|
||||
continue
|
||||
return None, error
|
||||
return None, {"code": -1, "message": "Max retries exceeded"}
|
||||
|
||||
|
||||
def generate_chart(prompt, output_path, api_key, api_url=LABNANA_API_URL,
|
||||
model=LABNANA_MODEL, provider=LABNANA_PROVIDER,
|
||||
aspect_ratio=DEFAULT_ASPECT_RATIO, resolution=DEFAULT_RESOLUTION):
|
||||
"""Call LabNana API to generate a chart image."""
|
||||
endpoint = f"{api_url}/openapi/v1/images/generation"
|
||||
|
||||
payload = {
|
||||
"provider": provider,
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"imageConfig": {
|
||||
"aspectRatio": aspect_ratio,
|
||||
"imageSize": resolution
|
||||
}
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
print(f"[INFO] 正在调用 LabNana API 生成图表...", file=sys.stderr)
|
||||
result, error = _do_http_request(endpoint, payload, headers)
|
||||
|
||||
if error:
|
||||
print(f"[ERROR] LabNana API 错误: {error}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
# Extract image from response
|
||||
candidates = result.get("candidates", [])
|
||||
if not candidates:
|
||||
print(f"[WARN] API 响应中没有图片数据", file=sys.stderr)
|
||||
return None
|
||||
|
||||
content = candidates[0].get("content", {})
|
||||
parts = content.get("parts", [])
|
||||
|
||||
for part in parts:
|
||||
if "inlineData" in part:
|
||||
inline = part["inlineData"]
|
||||
base64_data = inline.get("data", "")
|
||||
if base64_data:
|
||||
size = _save_image_from_base64(base64_data, output_path)
|
||||
print(f"[OK] 图表已保存: {output_path} ({size} bytes)", file=sys.stderr)
|
||||
return output_path
|
||||
|
||||
print(f"[WARN] 响应中没有找到图片数据", file=sys.stderr)
|
||||
return None
|
||||
|
||||
|
||||
def load_api_key():
|
||||
"""Load API key from .labnana.env file."""
|
||||
# 首先检查环境变量
|
||||
env_key = os.environ.get("LABNANA_API_KEY")
|
||||
if env_key:
|
||||
return env_key
|
||||
|
||||
# 然后尝试从 .labnana.env 文件读取
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
env_file = os.path.join(script_dir, "..", ".labnana.env")
|
||||
|
||||
if os.path.exists(env_file):
|
||||
with open(env_file) as f:
|
||||
for line in f:
|
||||
if line.startswith("LABNANA_API_KEY="):
|
||||
return line.strip().split("=", 1)[1]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def build_prompt(chart_type, content, style="blueprint"):
|
||||
"""
|
||||
根据图表类型和内容构建提示词。
|
||||
|
||||
Args:
|
||||
chart_type: 图表类型 (flowchart, architecture, er, bmc, journey, mindmap, competitive, swot, roadmap, orgchart)
|
||||
content: 图表内容描述
|
||||
style: 风格 (blueprint, notion, sketch-notes, corporate, dark-atmospheric, watercolor)
|
||||
"""
|
||||
chart_name = CHART_TYPES.get(chart_type, chart_type)
|
||||
prefix = STYLE_PREFIXES.get(style, STYLE_PREFIXES["blueprint"])
|
||||
style_prefix = prefix.replace("{chart_type}", chart_name)
|
||||
|
||||
return f"{style_prefix}\n\n{content}"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="使用 GPT-image-2 生成图表图片")
|
||||
parser.add_argument("--type", "-t", required=True, choices=list(CHART_TYPES.keys()),
|
||||
help=f"图表类型: {', '.join(CHART_TYPES.keys())}")
|
||||
parser.add_argument("--content", "-c", required=True, help="图表内容描述")
|
||||
parser.add_argument("--output", "-o", required=True, help="输出文件路径")
|
||||
parser.add_argument("--api-key", help="LabNana API key (可选,默认从 .labanana.env 读取)")
|
||||
parser.add_argument("--aspect-ratio", default=DEFAULT_ASPECT_RATIO,
|
||||
help="宽高比: 1:1, 16:9, 21:9 (默认: 16:9)")
|
||||
parser.add_argument("--resolution", default=DEFAULT_RESOLUTION,
|
||||
help="分辨率: 1K, 2K, 4K (默认: 2K)")
|
||||
parser.add_argument("--style", default="blueprint", choices=STYLE_CHOICES,
|
||||
help="视觉风格: blueprint (蓝图工程), notion (简约), sketch-notes (手绘笔记), corporate (商务正装), dark-atmospheric (深色霓虹), watercolor (水彩柔和)")
|
||||
args = parser.parse_args()
|
||||
|
||||
# 获取 API key
|
||||
api_key = args.api_key
|
||||
if not api_key:
|
||||
api_key = load_api_key()
|
||||
if not api_key:
|
||||
print("[ERROR] 无法获取 LabNana API Key。请设置 LABNANA_API_KEY 环境变量或在 .labnana.env 中配置。", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# 构建提示词
|
||||
prompt = build_prompt(args.type, args.content, args.style)
|
||||
|
||||
# 生成图片
|
||||
result = generate_chart(
|
||||
prompt=prompt,
|
||||
output_path=args.output,
|
||||
api_key=api_key,
|
||||
aspect_ratio=args.aspect_ratio,
|
||||
resolution=args.resolution
|
||||
)
|
||||
|
||||
if result:
|
||||
print(f"[OK] 完成: {result}", file=sys.stderr)
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("[ERROR] 图表生成失败。", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user