modelscope-zimage-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ModelScope Z-Image Generator

ModelScope Z-Image 生成器

Generate images using ModelScope's Z-Image series models.
使用ModelScope的Z-Image系列模型生成图片。

IMPORTANT: Response Format

重要提示:响应格式

After generating an image, you MUST:
  1. Use the Python script to generate the image
  2. Respond with ONLY a simple text message like: "Image saved to: /path/to/output.jpg"
  3. DO NOT include the image URL in your response
  4. DO NOT try to display or reference the image URL - this will cause errors with non-multimodal models
The user can view the generated image at the file path you provide.
生成图片后,你必须:
  1. 使用Python脚本生成图片
  2. 仅回复简单的文本消息,例如:"图片已保存至:/path/to/output.jpg"
  3. 请勿在回复中包含图片URL
  4. 请勿尝试展示或引用图片URL - 这会导致非多模态模型出错
用户可以通过你提供的文件路径查看生成的图片。

Prerequisites

前置条件

Get your ModelScope API key from: https://modelscope.cn/my/myaccesstoken
The script will automatically prompt for your API key the first time you use it and offer to save it for future use.
Optional: Manual Configuration
You can also manually configure the API key:
Config file:
bash
mkdir -p ~/.config/modelscope
cat > ~/.config/modelscope/config.json << EOF
{
  "api_key": "ms-your-api-key-here"
}
EOF
Environment variable:
bash
export MODELSCOPE_API_KEY="ms-your-api-key-here"
从以下地址获取你的ModelScope API密钥:https://modelscope.cn/my/myaccesstoken
首次使用脚本时,它会自动提示你输入API密钥,并提供保存密钥以便后续使用的选项。
可选:手动配置
你也可以手动配置API密钥:
配置文件:
bash
mkdir -p ~/.config/modelscope
cat > ~/.config/modelscope/config.json << EOF
{
  "api_key": "ms-your-api-key-here"
}
EOF
环境变量:
bash
export MODELSCOPE_API_KEY="ms-your-api-key-here"

Quick Start

快速开始

Use the Python script to generate images:
bash
cd /Users/ningoo/.claude/skills/modelscope-image-generator/scripts
python generate_image.py "A golden cat" output.jpg
使用Python脚本生成图片:
bash
cd /Users/ningoo/.claude/skills/modelscope-image-generator/scripts
python generate_image.py "一只金色的猫" output.jpg

Models

模型

Available Z-Image models:
  • Tongyi-MAI/Z-Image-Turbo
    (default, fast generation)
  • Tongyi-MAI/Z-Image
    (balanced quality and speed)
  • Tongyi-MAI/Z-Image-Edit
    (image editing)
可用的Z-Image模型:
  • Tongyi-MAI/Z-Image-Turbo
    (默认,生成速度快)
  • Tongyi-MAI/Z-Image
    (画质与速度平衡)
  • Tongyi-MAI/Z-Image-Edit
    (图片编辑)

Model Selection Rule

模型选择规则

  • If the user explicitly mentions "Z-Image-Turbo", use
    Tongyi-MAI/Z-Image-Turbo
  • If the user explicitly mentions "Z-Image" (without Turbo), use
    Tongyi-MAI/Z-Image
  • Otherwise, use the default
    Tongyi-MAI/Z-Image-Turbo
Specify a different model using
--model
:
bash
python generate_image.py "A golden cat" output.jpg --model "Tongyi-MAI/Z-Image-Turbo"
  • 如果用户明确提到"Z-Image-Turbo",使用
    Tongyi-MAI/Z-Image-Turbo
  • 如果用户明确提到"Z-Image"(不带Turbo),使用
    Tongyi-MAI/Z-Image
  • 否则,使用默认的
    Tongyi-MAI/Z-Image-Turbo
使用
--model
参数指定其他模型:
bash
python generate_image.py "一只金色的猫" output.jpg --model "Tongyi-MAI/Z-Image-Turbo"

LoRA Support

LoRA支持

Single LoRA:
python
"loras": "<lora-repo-id>"
Multiple LoRAs (weights must sum to 1.0):
python
"loras": {"<lora-id1>": 0.6, "<lora-id2>": 0.4}
单个LoRA:
python
"loras": "<lora-repo-id>"
多个LoRA(权重总和必须为1.0):
python
"loras": {"<lora-id1>": 0.6, "<lora-id2>": 0.4}

API Flow

API流程

  1. Submit generation request with
    X-ModelScope-Async-Mode: true
  2. Receive
    task_id
    in response
  3. Poll
    /v1/tasks/{task_id}
    with
    X-ModelScope-Task-Type: image_generation
  4. Wait for status
    SUCCEED
    or
    FAILED
  5. Download image from
    output_images[0]
    URL
  1. 提交生成请求时携带
    X-ModelScope-Async-Mode: true
  2. 在响应中接收
    task_id
  3. 携带
    X-ModelScope-Task-Type: image_generation
    轮询
    /v1/tasks/{task_id}
  4. 等待状态变为
    SUCCEED
    FAILED
  5. output_images[0]
    对应的URL下载图片