Qwen-Image-Example/README.md

68 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Qwen-Image 文生图示例
使用阿里云 DashScope API 调用 **通义千问 Qwen-Image** 模型进行文生图。
## 快速开始
### 1. 配置 API Key
`.env` 文件中设置你的 DashScope API Key
```env
DASHSCOPE_API_KEY=sk-xxxxxxxx
```
> 获取 API Key: https://help.aliyun.com/zh/model-studio/get-api-key
### 2. 安装依赖
```bash
uv sync
```
### 3. 运行示例
```bash
uv run qwen_image_example.py
```
## 支持的模型
| 模型名称 | 说明 | 异步支持 |
|---------|------|---------|
| `qwen-image-plus` | 通用文生图模型 | ✅ |
| `qwen-image-max` | 高质量文生图模型 | ❌ |
## 支持的分辨率
| 比例 | 尺寸 |
|------|------|
| 1:1 | 1328×1328 |
| 16:9 | 1664×928 (默认) |
| 9:16 | 928×1664 |
| 4:3 | 1472×1104 |
| 3:4 | 1104×1472 |
## 核心参数
```python
from dashscope import ImageSynthesis
response = ImageSynthesis.call(
api_key="your-api-key",
model="qwen-image-plus",
prompt="你的图像描述",
negative_prompt=" ", # 反向提示词
n=1, # 生成数量
size="1328*1328", # 图像尺寸
prompt_extend=True, # 智能改写 prompt (额外 3-5 秒)
watermark=False, # 是否添加水印
)
```
## 生成效果
| 橘猫下午茶 | 赛博朋克城市 |
|-----------|-------------|
| ![cat](cat_coffee.png) | ![city](cyberpunk_city.png) |