赞
踩
根据用户输入的文字内容,生成符合语义描述的不同风格的图像,支持中英文双语输入。
当前模型支持的风格包括但不限于:
- 水彩
- 油画
- 中国画
- 素描
- 扁平插
- 二次元
- 3D卡通
模型名 | 模型简介 |
---|---|
wanx-v1 | 通义万相-文本生成图像大模型,支持中英文双语输入,重点风格包括但不限于水彩、油画、中国画、素描、扁平插画、二次元、3D卡通 |
export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
from http import HTTPStatus from urllib.parse import urlparse, unquote from pathlib import PurePosixPath import requests from dashscope import ImageSynthesis def simple_call(): prompt = 'Mouse rides elephant' rsp = ImageSynthesis.call(model=ImageSynthesis.Models.wanx_v1, prompt=prompt, n=4, size='1024*1024') if rsp.status_code == HTTPStatus.OK: print(rsp.output) print(rsp.usage) # save file to current directory for result in rsp.output.results: file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1] with open('./%s' % file_name, 'wb+') as f: f.write(requests.get(result.url).content) else: print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message)) if __name__ == '__main__': simple_call()
{"task_id": "5e91752a-69bb-42d5-9881-0e436936ecfa", "task_status": "SUCCEEDED", "results": [{"url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/86/20231214/8d820c8d/cb25cb45-352d-4a47-a171-37e5d648ddcd-1.png?Expires=1702624876&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=vzikxqBcu8CZbnzaU8RMgsUVcTo%3D"}, {"url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/c9/20231214/8d820c8d/da6237bd-31a0-4958-8d84-64015f3cf487-1.png?Expires=1702624876&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=XaKkftm6mTFD8QXthVL0UrzQfus%3D"}, {"url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/8a/20231214/8d820c8d/c925ba50-6f1c-4830-8997-9b295120a371-1.png?Expires=1702624876&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=GaCHjAklGZwB7lbP66M%2FgdC2cSQ%3D"}, {"url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/81/20231214/723609ee/af60f086-6067-4529-8caf-dd182811033a-1.png?Expires=1702624876&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=CICXRun%2FLsyaGCw6AAxMM4iRGF8%3D"}], "submit_time": "2023-12-14 15:20:49.516", "scheduled_time": "2023-12-14 15:20:49.536", "end_time": "2023-12-14 15:21:18.312", "task_metrics": {"TOTAL": 4, "SUCCEEDED": 4, "FAILED": 0}}
{"image_count": 4}
参数说明
参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
model | string | 指定模型名,目前仅支持 wanx-v1 | |
prompt | string | 用户当前输入的期望模型执行指令 | |
n | int | 期望生成的图片数量,目前限制最多生成4张 | |
size | string | 1024*1024 | 生成的图片的规格 |
返回结果
{ "status_code": 200, "request_id": "b54ffeb8-6212-9dac-808c-b3771cba3788", "code": null, "message": "", "output": { "task_id": "996523eb-034d-459b-ac88-b340b95007a4", "task_status": "SUCCEEDED", "results": [ { "url": "RESULT_URL1" }, { "url": "RESULT_URL2" }, { "url": "RESULT_URL3" }, { "url": "RESULT_URL4" } ], "task_metrics": { "TOTAL": 4, "SUCCEEDED": 4, "FAILED": 0 } }, "usage": { "image_count": 4 } }
返回参数说明
返回参数 | 类型 | 说明 |
---|---|---|
status_code | int | 200(HTTPStatus.OK)表示请求成功,否则表示请求失败,可以通过code获取错误码,通过message字段获取错误详细信息。 |
request_Id | string | 系统生成的标志本次调用的id。 |
code | string | 表示请求失败,表示错误码,成功忽略。 |
message | string | 失败,表示失败详细信息,成功忽略。 |
output | dict | 调用结果信息,对于千问模型,包含输出text。 |
task_id | string | 异步任务id。 |
task_status | string | 任务状态SUCCESSED: 任务执行成功、FAILED: 任务执行失败、CANCELED: 任务被取消、PENDING:任务排队中、SUSPENDED:任务挂起、RUNNING:任务处理中 |
results | list | 生成结果,每个元素为生成图片的url |
task_metrics | dict | 任务结果信息,TOTAL期望生成数量,SUCCEEDED成功生成数量,FAILED失败数量 |
usage | dict | image_count用于计量的图片个数 |
from http import HTTPStatus from dashscope import ImageSynthesis # 创建异步任务 def create_async_task(): rsp = ImageSynthesis.async_call(model=ImageSynthesis.Models.wanx_v1, prompt='Eagle flying in blue sky', n=4, size='1024*1024') print(rsp) if rsp.status_code == HTTPStatus.OK: print(rsp.output) print(rsp.usage) else: print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message)) return rsp # 获取异步任务信息 def fetch_task_status(task): status = ImageSynthesis.fetch(task) print(status) if status.status_code == HTTPStatus.OK: print(status.output.task_status) else: print('Failed, status_code: %s, code: %s, message: %s' % (status.status_code, status.code, status.message)) # 等待异步任务结束 def wait_task(task): rsp = ImageSynthesis.wait(task) print(rsp) if rsp.status_code == HTTPStatus.OK: print(rsp.output.task_status) else: print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message)) # 取消异步任务,只有处于PENDING状态的任务才可以取消 def cancel_task(task): rsp = ImageSynthesis.cancel(task) print(rsp) if rsp.status_code == HTTPStatus.OK: print(rsp.output.task_status) else: print('Failed, status_code: %s, code: %s, message: %s' % (rsp.status_code, rsp.code, rsp.message)) if __name__ == '__main__': task_info = create_async_task() fetch_task_status(task_info) wait_task(task_info)
异步任务输出
{
"status_code": 200,
"request_id": "814762c1-6565-917d-9f6b-bcfa1cc26117",
"code": "",
"message": "",
"output": {
"task_id": "ea06d3c3-15fa-4487-aee5-348392f4fdcd", # 任务ID
"task_status": "PENDING", # 任务状态
"results": []
},
"usage": null
}
任务信息输出
{ "status_code": 200, "request_id": "d8811fd1-fc33-9a64-90d8-69cd94051239", "code": null, "message": "", "output": { "task_id": "4257e084-30ce-46f1-8f59-5d4d8b3807ec", "task_status": "RUNNING", "results": [], "task_metrics": { "TOTAL": 4, "SUCCEEDED": 0, "FAILED": 0 } }, "usage": null }
通义万相-人像风格重绘 可以将输入的人物图像进行多种风格化的重绘生成,使新生成的图像在兼顾原始人物相貌的同时,带来不同风格的绘画效果。当前支持的风格有:复古漫画、3D童话、二次元、小清新、未来科技、3D写实等。
示意图
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。