'commit'
This commit is contained in:
30
dsLightRag/Test/QWenImage/T1_QwenImageSync.py
Normal file
30
dsLightRag/Test/QWenImage/T1_QwenImageSync.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from http import HTTPStatus
|
||||
from urllib.parse import urlparse, unquote
|
||||
from pathlib import PurePosixPath
|
||||
import requests
|
||||
# pip install -U dashscope
|
||||
from dashscope import ImageSynthesis
|
||||
import os
|
||||
|
||||
prompt = "一副典雅庄重的对联悬挂于厅堂之中,房间是个安静古典的中式布置,桌子上放着一些青花瓷,对联上左书“义本生知人机同道善思新”,右书“通云赋智乾坤启数高志远”, 横批“智启通义”,字体飘逸,中间挂在一着一副中国风的画作,内容是岳阳楼。"
|
||||
|
||||
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
|
||||
api_key = os.getenv("DASHSCOPE_API_KEY")
|
||||
|
||||
print('----同步调用,请等待任务执行----')
|
||||
rsp = ImageSynthesis.call(api_key=api_key,
|
||||
model="qwen-image",
|
||||
prompt=prompt,
|
||||
n=1,
|
||||
size='1328*1328')
|
||||
print('response: %s' % rsp)
|
||||
if rsp.status_code == HTTPStatus.OK:
|
||||
# 在当前目录下保存图片
|
||||
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('同步调用失败, status_code: %s, code: %s, message: %s' %
|
||||
(rsp.status_code, rsp.code, rsp.message))
|
||||
|
Reference in New Issue
Block a user