Skip to content

Commit f6fd704

Browse files
authored
Merge pull request #35 from kevinlin09/feat/cv_model_call
feat(cv): support model calling
2 parents 94e3b90 + 29f9b4d commit f6fd704

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

dashscope/utils/oss_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def check_and_upload_local(model: str, content: str, api_key: str):
157157
elif content.startswith('oss://'):
158158
return True, content
159159
elif not content.startswith('http'):
160+
content = os.path.expanduser(content)
160161
if os.path.isfile(content):
161162
file_url = OssUtils.upload(model=model,
162163
file_path=content,

samples/test_cv_models.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
3+
from dashscope.client.base_api import BaseAsyncApi
4+
from dashscope.utils.oss_utils import check_and_upload_local
5+
6+
# style repaint (ref: https://help.aliyun.com/zh/model-studio/portrait-style-redraw-api-reference)
7+
8+
api_key = os.getenv('DASHSCOPE_API_KEY')
9+
model = 'wanx-style-repaint-v1'
10+
file_path = '~/Downloads/cat.png'
11+
12+
uploaded, image_url = check_and_upload_local(model=model, content=file_path, api_key=api_key)
13+
14+
kwargs = {}
15+
if uploaded is True:
16+
headers = {'X-DashScope-OssResourceResolve': 'enable'}
17+
kwargs['headers'] = headers
18+
19+
response = BaseAsyncApi.call(
20+
model=model,
21+
input={
22+
# "image_url": "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/public/dashscope/test.png",
23+
"image_url": image_url,
24+
"style_index":3
25+
},
26+
task_group='aigc',
27+
task='image-generation',
28+
function='generation',
29+
**kwargs
30+
)
31+
32+
print('response: \n%s\n' % response)

samples/test_image_synthesis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
model="wanx2.1-t2i-turbo",
1414
prompt=prompt,
1515
n=1,
16-
size='1024*1024',
17-
enable_encryption=True)
16+
size='1024*1024')
1817

1918
print('response: %s' % rsp)
2019
if rsp.status_code == HTTPStatus.OK:

0 commit comments

Comments
 (0)