fix: args
This commit is contained in:
parent
429d27c3f3
commit
f9098e7950
@ -23,7 +23,7 @@ argument-hint: "需要 prompt 参数(画图提示词),可选 model(模
|
||||
|
||||
## 参数说明(JSON Schema)
|
||||
|
||||
调用脚本时,需要通过第一个命令行参数传入 JSON 字符串,结构如下:
|
||||
调用脚本时,需要通过 shell 风格参数传入,参数结构如下:
|
||||
|
||||
```json
|
||||
{
|
||||
@ -71,6 +71,14 @@ argument-hint: "需要 prompt 参数(画图提示词),可选 model(模
|
||||
}
|
||||
```
|
||||
|
||||
对应的命令行参数为:
|
||||
|
||||
- `--prompt <画图提示词>` 必填
|
||||
- `--model <模型名>` 可选
|
||||
- `--negative_prompt <反向提示词>` 可选
|
||||
- `--ratio <宽高比>` 可选
|
||||
- `--resolution <分辨率>` 可选
|
||||
|
||||
## 依赖安装
|
||||
|
||||
- 在执行 `text-to-image/scripts/text_to_image.py` 之前,必须先安装依赖。
|
||||
@ -81,7 +89,7 @@ argument-hint: "需要 prompt 参数(画图提示词),可选 model(模
|
||||
1. 当用户输入绘图相关内容时触发该技能。
|
||||
2. 从用户输入中提取 prompt(画图提示词),不对提示词做总结或修改。可选提取 model、negative_prompt、ratio、resolution 参数。
|
||||
3. 在执行脚本前,先安装依赖:`python3 text-to-image/scripts/bootstrap.py`。
|
||||
4. 将参数组装为 JSON 字符串,在仓库根目录下执行本地脚本:`python3 text-to-image/scripts/text_to_image.py '<JSON参数>'`。
|
||||
4. 将参数组装为 shell 风格命令行参数,在仓库根目录下执行本地脚本,例如:`python3 text-to-image/scripts/text_to_image.py --prompt '一只小白兔' --model jimeng-5.0`。
|
||||
5. 成功是脚本输出
|
||||
|
||||
```
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@ -301,15 +302,35 @@ DOUBAO_MODELS = {"doubao-seedream-4.5", "doubao-seedream-4.0", "doubao-seedream-
|
||||
ZIMAGE_MODELS = {"Z-Image", "Z-Image-Turbo", "Qwen-Image-Edit-2511"}
|
||||
|
||||
|
||||
def _parse_cli_params(argv: list[str]) -> dict[str, str]:
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
parser.add_argument("--prompt", default="")
|
||||
parser.add_argument("--model", default="")
|
||||
parser.add_argument("--negative_prompt", default="")
|
||||
parser.add_argument("--ratio", default="")
|
||||
parser.add_argument("--resolution", default="")
|
||||
|
||||
namespace, unknown = parser.parse_known_args(argv)
|
||||
if unknown:
|
||||
raise ValueError(f"存在不支持的参数: {' '.join(unknown)}")
|
||||
|
||||
return {
|
||||
"prompt": namespace.prompt,
|
||||
"model": namespace.model,
|
||||
"negative_prompt": namespace.negative_prompt,
|
||||
"ratio": namespace.ratio,
|
||||
"resolution": namespace.resolution,
|
||||
}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
# Parse input params from first CLI argument
|
||||
if len(sys.argv) < 2:
|
||||
sys.stdout.write("缺少输入参数\n")
|
||||
return 1
|
||||
|
||||
try:
|
||||
params = json.loads(sys.argv[1])
|
||||
except json.JSONDecodeError as exc:
|
||||
params = _parse_cli_params(sys.argv[1:])
|
||||
except ValueError as exc:
|
||||
sys.stdout.write(f"参数格式错误: {exc}\n")
|
||||
return 1
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user