Skip to content

Commit c4542fa

Browse files
mose-zmmose-x.zm
andauthored
Support wan2.5 (#65)
Co-authored-by: mose-x.zm <[email protected]>
1 parent 311d142 commit c4542fa

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

dashscope/aigc/video_synthesis.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def call(cls,
3838
negative_prompt: str = None,
3939
template: str = None,
4040
img_url: str = None,
41+
audio_url: str = None,
4142
api_key: str = None,
4243
extra_input: Dict = None,
4344
workspace: str = None,
@@ -56,6 +57,7 @@ def call(cls,
5657
negative_prompt (str): The negative prompt is the opposite of the prompt meaning.
5758
template (str): LoRa input, such as gufeng, katong, etc.
5859
img_url (str): The input image url, Generate the URL of the image referenced by the video.
60+
audio_url (str): The input audio url
5961
api_key (str, optional): The api api_key. Defaults to None.
6062
workspace (str): The dashscope workspace id.
6163
extra_input (Dict): The extra input parameters.
@@ -76,6 +78,7 @@ def call(cls,
7678
return super().call(model,
7779
prompt,
7880
img_url=img_url,
81+
audio_url=audio_url,
7982
api_key=api_key,
8083
extend_prompt=extend_prompt,
8184
negative_prompt=negative_prompt,
@@ -94,6 +97,7 @@ def _get_input(cls,
9497
model: str,
9598
prompt: Any = None,
9699
img_url: str = None,
100+
audio_url: str = None,
97101
# """@deprecated, use prompt_extend in parameters """
98102
extend_prompt: bool = True,
99103
negative_prompt: str = None,
@@ -125,6 +129,13 @@ def _get_input(cls,
125129
has_upload = True
126130
inputs['img_url'] = res_img_url
127131

132+
if audio_url is not None and audio_url:
133+
is_upload, res_audio_url = check_and_upload_local(
134+
model, audio_url, api_key)
135+
if is_upload:
136+
has_upload = True
137+
inputs['audio_url'] = res_audio_url
138+
128139
if head_frame is not None and head_frame:
129140
is_upload, res_head_frame = check_and_upload_local(
130141
model, head_frame, api_key)
@@ -172,6 +183,7 @@ def async_call(cls,
172183
model: str,
173184
prompt: Any = None,
174185
img_url: str = None,
186+
audio_url: str = None,
175187
# """@deprecated, use prompt_extend in parameters """
176188
extend_prompt: bool = True,
177189
negative_prompt: str = None,
@@ -194,6 +206,7 @@ def async_call(cls,
194206
negative_prompt (str): The negative prompt is the opposite of the prompt meaning.
195207
template (str): LoRa input, such as gufeng, katong, etc.
196208
img_url (str): The input image url, Generate the URL of the image referenced by the video.
209+
audio_url (str): The input audio url.
197210
api_key (str, optional): The api api_key. Defaults to None.
198211
workspace (str): The dashscope workspace id.
199212
extra_input (Dict): The extra input parameters.
@@ -215,7 +228,7 @@ def async_call(cls,
215228
task_group, function = _get_task_group_and_task(__name__)
216229

217230
inputs, kwargs, task = cls._get_input(
218-
model, prompt, img_url, extend_prompt, negative_prompt, template, api_key,
231+
model, prompt, img_url, audio_url, extend_prompt, negative_prompt, template, api_key,
219232
extra_input, task, function, head_frame, tail_frame,
220233
first_frame_url, last_frame_url, **kwargs)
221234

@@ -339,6 +352,7 @@ async def call(cls,
339352
model: str,
340353
prompt: Any = None,
341354
img_url: str = None,
355+
audio_url: str = None,
342356
# """@deprecated, use prompt_extend in parameters """
343357
extend_prompt: bool = True,
344358
negative_prompt: str = None,
@@ -361,6 +375,7 @@ async def call(cls,
361375
negative_prompt (str): The negative prompt is the opposite of the prompt meaning.
362376
template (str): LoRa input, such as gufeng, katong, etc.
363377
img_url (str): The input image url, Generate the URL of the image referenced by the video.
378+
audio_url (str): The input audio url.
364379
api_key (str, optional): The api api_key. Defaults to None.
365380
workspace (str): The dashscope workspace id.
366381
extra_input (Dict): The extra input parameters.
@@ -380,7 +395,7 @@ async def call(cls,
380395
"""
381396
task_group, f = _get_task_group_and_task(__name__)
382397
inputs, kwargs, task = VideoSynthesis._get_input(
383-
model, prompt, img_url, extend_prompt, negative_prompt, template, api_key,
398+
model, prompt, img_url, audio_url, extend_prompt, negative_prompt, template, api_key,
384399
extra_input, task, f, head_frame, tail_frame,
385400
first_frame_url, last_frame_url, **kwargs)
386401
response = await super().call(model, inputs, task_group, task, f, api_key, workspace, **kwargs)
@@ -391,6 +406,7 @@ async def async_call(cls,
391406
model: str,
392407
prompt: Any = None,
393408
img_url: str = None,
409+
audio_url: str = None,
394410
# """@deprecated, use prompt_extend in parameters """
395411
extend_prompt: bool = True,
396412
negative_prompt: str = None,
@@ -413,6 +429,7 @@ async def async_call(cls,
413429
negative_prompt (str): The negative prompt is the opposite of the prompt meaning.
414430
template (str): LoRa input, such as gufeng, katong, etc.
415431
img_url (str): The input image url, Generate the URL of the image referenced by the video.
432+
audio_url (str): The input audio url.
416433
api_key (str, optional): The api api_key. Defaults to None.
417434
workspace (str): The dashscope workspace id.
418435
extra_input (Dict): The extra input parameters.
@@ -434,7 +451,7 @@ async def async_call(cls,
434451
task_group, function = _get_task_group_and_task(__name__)
435452

436453
inputs, kwargs, task = VideoSynthesis._get_input(
437-
model, prompt, img_url, extend_prompt, negative_prompt, template, api_key,
454+
model, prompt, img_url, audio_url, extend_prompt, negative_prompt, template, api_key,
438455
extra_input, task, function, head_frame, tail_frame,
439456
first_frame_url, last_frame_url, **kwargs)
440457

samples/test_video_synthesis.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from http import HTTPStatus
2+
from dashscope import VideoSynthesis
3+
import os
4+
5+
prompt = "一幅史诗级可爱的场景。一只小巧可爱的卡通小猫将军,身穿细节精致的金色盔甲,头戴一个稍大的头盔,勇敢地站在悬崖上。他骑着一匹虽小但英勇的战马。悬崖下方,一支由老鼠组成的、数量庞大、无穷无尽的军队正带着临时制作的武器向前冲锋。这是一个戏剧性的、大规模的战斗场景,灵感来自中国古代的战争史诗。远处的雪山上空,天空乌云密布。整体氛围是“可爱”与“霸气”的搞笑和史诗般的融合"
6+
audio_url = 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3'
7+
api_key = os.getenv("DASHSCOPE_API_KEY")
8+
9+
10+
def simple_call():
11+
print('----sync call, please wait a moment----')
12+
rsp = VideoSynthesis.call(api_key=api_key,
13+
model="wan2.5-t2v-preview",
14+
prompt=prompt,
15+
audio_url=audio_url)
16+
if rsp.status_code == HTTPStatus.OK:
17+
18+
print('response: %s' % rsp)
19+
else:
20+
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
21+
(rsp.status_code, rsp.code, rsp.message))
22+
23+
24+
if __name__ == '__main__':
25+
simple_call()

0 commit comments

Comments
 (0)