Spaces:
Sleeping
Sleeping
| import os | |
| from dashscope import ImageSynthesis | |
| from PIL import Image | |
| from .image_utils import encode_image_base64, download_image | |
| def edit_image(pil_image: Image.Image, instruction: str) -> Image.Image: | |
| """Edit an image using wanx2.1-imageedit for structural/body adjustments.""" | |
| b64 = encode_image_base64(pil_image) | |
| rsp = ImageSynthesis.call( | |
| api_key=os.environ["DASHSCOPE_API_KEY"], | |
| model="wanx2.1-imageedit", | |
| input={ | |
| "function": "description_edit", | |
| "prompt": instruction, | |
| "base_image_url": b64, | |
| }, | |
| parameters={"n": 1}, | |
| ) | |
| result_url = rsp.output.results[0].url | |
| return download_image(result_url) | |