百度文生图(ERNIE‑Image)文生图生成。通过百度 AI Studio 的 ERNIE‑Image 与 ERNIE‑Image‑Turbo 模型快速生成 AI 图片。
Generate images with Baidu AI Studio's ERNIE-Image models through the OpenAI-compatible API. Best when the user specifically wants Baidu/ERNIE generation, Chinese-language image prompts, or local PNG outputs.
AI_STUDIO_API_KEY into chat.
The script reads it from the environment only.uv installedAI_STUDIO_API_KEY environment variable set to your Baidu AI Studio access tokenPrefer ERNIE-Image-Turbo, 1024x1024, n=1, and b64_json unless the user
asks for different parameters.
ModelBest forERNIE-Image-TurboFast drafts, iteration, batch previewsERNIE-ImageSlower, higher-quality final outputs
Chinese prompts usually work especially well with these models.
Write a descriptive prompt (max 1024 characters, ~150 words). Chinese and English both work well. Be specific about subject, style, composition, and mood.
Good: "A golden retriever puppy sitting in a sunflower field at sunset, warm golden light, shallow depth of field, professional photography" Bad: "dog"
ParameterValuesDefaultmodelERNIE-Image-Turbo, ERNIE-Image``ERNIE-Image-Turbosize1024x1024, 768x1376, 1376x768, 896x1200, 1200x896, 848x1264, 1264x848``1024x1024n1-41seedany integerrandomsteps4-20provider defaultguidance1.0-7.5provider defaultuse-peflagoff
Select size based on content: portraits and posters use vertical ( 768x1376, 848x1264, 896x1200), landscapes and covers use horizontal ( 1376x768, 1264x848, 1200x896), general use 1024x1024.
Execute the bundled script with uv run:
bash
uv run {baseDir}/scripts/generate.py "<PROMPT>" --model ERNIE-Image-Turbo --size 1024x1024
For batch generation:
bash
uv run {baseDir}/scripts/generate.py "<PROMPT>" --n 4 --output ./output_dir
For higher quality with more inference steps and stronger guidance:
bash
uv run {baseDir}/scripts/generate.py "<PROMPT>" --model ERNIE-Image --steps 16 --guidance 3.5
For reproducible results:
bash
uv run {baseDir}/scripts/generate.py "<PROMPT>" --seed 42
The script saves images as PNG files to the output directory and prints:
text
Saved: ernie_20260430_110100.png (1.7 MB)
MEDIA:/absolute/path/to/ernie_20260430_110100.png
The MEDIA: line enables automatic image attachment in compatible environments.
The script avoids overwriting existing files by adding a numeric suffix when needed.
For JSON output, add --json to get structured results:
json
{
"success": true,
"model": "ERNIE-Image-Turbo",
"files": [{"path": "/abs/path/ernie_20260430_110100.png", "size_bytes": 1715660}],
"prompt": "...",
"parameters": {"size": "1024x1024", "seed": 42}
}
When the user says any of these, treat the text after the trigger as the prompt and generate immediately with defaults:
Defaults: model= ERNIE-Image-Turbo, size= 1024x1024, n=1, b64_json format.
MEDIA:/absolute/path/to/file.png for auto-attach.--use-pe) lets the model expand simple prompts into richer descriptions before generation. Enable for short prompts, disable for precise control.--quiet to suppress progress output; only MEDIA: lines (or JSON with --json) are printed. Recommended when calling from agent workflows to reduce context noise.{baseDir}/references/api-guide.md.