A text-to-image tool based on the ModelScope API, supporting asynchronous generation and LoRA style stacking.
Configuration
Edit skills/image-gen/scripts/config.json:
{
"api_token": "YOUR_MODELSCOPE_TOKEN"
}
Token acquisition:ModelScope Console Create an Access Token.
Command-line invocation
# 基础文生图
python3 skills/image-gen/scripts/generate.py generate --prompt "一只金色的猫"
# 指定输出路径
python3 skills/image-gen/scripts/generate.py generate --prompt "赛博朋克城市" --output cyberpunk.jpg
# 指定模型
python3 skills/image-gen/scripts/generate.py generate --prompt "水墨山水画" --model Tongyi-MAI/Z-Image-Turbo
# 使用 LoRA 风格
python3 skills/image-gen/scripts/generate.py generate --prompt "一个女孩" --lora "repo-id/lora-model"
# 多 LoRA 叠加(JSON 格式,权重之和为 1.0)
python3 skills/image-gen/scripts/generate.py generate --prompt "风景画" --lora '{"lora1": 0.6, "lora2": 0.4}'
# 指定尺寸
python3 skills/image-gen/scripts/generate.py generate --prompt "壁纸" --size 1920x1080
# 查询任务状态
python3 skills/image-gen/scripts/generate.py status --task-id TASK_ID
# JSON 格式输出
python3 skills/image-gen/scripts/generate.py generate --prompt "猫" --json
AI invocation flow
Step 1: Generate the image
Construct an English prompt based on the user's description (English works better), call the script to generate the image and save it locally:
python3 skills/image-gen/scripts/generate.py generate --prompt "A cute golden cat, high quality, detailed fur, studio lighting" --output data/temp/images/golden_cat.jpg
Step 2: Send to the channel (automatically links with send_media)
After the image is generated successfully, if the current session is a channel session (Feishu/QQ/DingTalk/Telegram, etc.), you must use the built-in tool send_media to send the image to the user:
send_media(file_paths=["data/temp/images/golden_cat.jpg"], message="已为你生成图片 🎨")
If it is a web session, just tell the user the path where the image is saved.
Complete example
The user says "draw me a cat":
- Execute generation:
python3 skills/image-gen/scripts/generate.py generate --prompt "A cute golden cat, high quality, detailed fur" --output data/temp/images/cat.jpg
- Send to the channel:
send_media(file_paths=["data/temp/images/cat.jpg"], message="🎨 已生成图片:一只金色的猫")
The user says "draw a cyberpunk-style city wallpaper":
- Execute generation:
python3 skills/image-gen/scripts/generate.py generate --prompt "Cyberpunk city skyline, neon lights, rain, cinematic, 4K" --output data/temp/images/cyberpunk.jpg --size 1920x1080
- Send to the channel:
send_media(file_paths=["data/temp/images/cyberpunk.jpg"], message="🎨 赛博朋克城市壁纸")
Supported models
| Model | Description |
|---|---|
Tongyi-MAI/Z-Image-Turbo |
Default, Tongyi Wanxiang fast generation |
You can specify other text-to-image models on ModelScope via the --model parameter.
Prompt tips
- Using English prompts works better
- Add quality descriptors:
high quality,detailed,4K,studio lighting - Add style descriptions:
oil painting,watercolor,anime style,photorealistic - Add composition descriptions:
close-up,wide angle,bird's eye view - Negative descriptions can be expressed in the prompt with
no xxxexpress
Notes
- Asynchronous generation; the script will automatically poll until completion (default timeout 5 minutes)
- It is recommended to save generated images to the
data/temp/images/directory - LoRA stacking is limited to 6, and the sum of weights must be 1.0
- After generating an image in a channel session, be sure to call
send_mediato send it; do not just return the file path