Skip to content

Commit b29d2a0

Browse files
mose-zmmose-x.zm
andauthored
support wan2.5 i2i (#66)
Co-authored-by: mose-x.zm <[email protected]>
1 parent c4542fa commit b29d2a0

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

dashscope/aigc/image_synthesis.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ def _get_input(cls,
138138
has_upload = False
139139
if negative_prompt is not None:
140140
inputs[NEGATIVE_PROMPT] = negative_prompt
141-
if images is not None:
142-
inputs[IMAGES] = images
141+
if images is not None and images and len(images) > 0:
142+
new_images = []
143+
for image in images:
144+
is_upload, new_image = check_and_upload_local(
145+
model, image, api_key)
146+
if is_upload:
147+
has_upload = True
148+
new_images.append(new_image)
149+
inputs[IMAGES] = new_images
143150
if sketch_image_url is not None and sketch_image_url:
144151
is_upload, sketch_image_url = check_and_upload_local(
145152
model, sketch_image_url, api_key)
@@ -178,10 +185,20 @@ def _get_input(cls,
178185
headers['X-DashScope-OssResourceResolve'] = 'enable'
179186
kwargs['headers'] = headers
180187

181-
if task is None:
182-
task = ImageSynthesis.task
183-
if model is not None and model and 'imageedit' in model:
184-
task = 'image2image'
188+
def __get_i2i_task(task, model) -> str:
189+
# 处理task参数:优先使用有效的task值
190+
if task is not None and task != "":
191+
return task
192+
193+
# 根据model确定任务类型
194+
if model is not None and model != "":
195+
if 'imageedit' in model or "wan2.5-i2i" in model:
196+
return 'image2image'
197+
198+
# 默认返回文本到图像任务
199+
return ImageSynthesis.task
200+
201+
task = __get_i2i_task(task, model)
185202

186203
return inputs, kwargs, task
187204

0 commit comments

Comments
 (0)