AI大模型-百炼AI试衣API
AI试衣(OutfitAnyone)是通义实验室自主研发的虚拟试衣模型服务产品。用户无需亲临实体店或经历繁琐的试穿过程,仅需上传服装平铺图以及正面全身人像照,便能生成高质量试衣效果,精准展现衣物穿着后的实际观感。
·
AI试衣(OutfitAnyone)是通义实验室自主研发的虚拟试衣模型服务产品。用户无需亲临实体店或经历繁琐的试穿过程,仅需上传服装平铺图以及正面全身人像照,便能生成高质量试衣效果,精准展现衣物穿着后的实际观感。
官方文档
https://help.aliyun.com/zh/model-studio/developer-reference/outfitanyone-api
代码示例:
AI试衣提交作业、查询作业结果
AI试衣图片精修提交作业、查询作业结果
import requests
import os
from dotenv import load_dotenv
load_dotenv()
# https://help.aliyun.com/zh/model-studio/developer-reference/outfitanyone-api
# AI试衣API调用
def clothes_tryon():
url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis"
payload = {
"model": "aitryon", # aitryon: 虚拟试衣图片生成模型
"input": {
# 上衣图片
"top_garment_url": "https://xxx.jpg",
# 下衣图片
"bottom_garment_url": "",
# 人像图片
"person_image_url": "https://xxx.png",
},
"parameters": {
"resolution": -1, # 输出图片分辨率,-1表示原图分辨率
"restore_face": True # 是否保留人脸
}
}
headers = {
"X-DashScope-Async": "enable", # 启用异步模式
"Authorization": "Bearer " + os.getenv('BAILIAN_API_KEY'),
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
text = response.text
print(text)
# 查询异步执行的作业结果:包括AI试衣API、AI试衣精修API的结果
def query_task_result(task_id):
url = "https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}".format(task_id=task_id)
headers = {
"Authorization": "Bearer " + os.getenv('BAILIAN_API_KEY')
}
response =requests.request("GET", url, headers=headers)
text = response.text
print(text)
# clothes_tryon()
# {"output":{"task_status":"PENDING","task_id":"470ca45a-315f-4a17-993f-47f4885abe91"},"request_id":"1e2f6e3e-01d8-9c25-9263-b630d1243201"}
# query_task_result("470ca45a-315f-4a17-993f-47f4885abe91")
# AI试衣精修API调用
def tryon_refiner():
url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2image/image-synthesis"
payload = {
"model": "aitryon-refiner", # aitryon-refiner: 精修模型
"input": {
# 上衣图片
"top_garment_url": "https://xxx.jpg",
# 下衣图片
"bottom_garment_url": "",
# 人像图片
"person_image_url": "https://xxx.png",
# 粗略图片-即上一步AI试衣API生成的图片
"coarse_image_url": "http://xxx.jpg"
},
"parameters": {
"gender": "woman", # 人物性别,woman或man
}
}
headers = {
"X-DashScope-Async": "enable", # 启用异步模式
"Authorization": "Bearer " + os.getenv('BAILIAN_API_KEY'),
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
text = response.text
print(text)
# tryon_refiner()
# {"output":{"task_status":"PENDING","task_id":"afd4a6aa-40f6-4784-9ce9-3f85122c989d"},"request_id":"d743231e-58f2-98fd-a579-53ff4be65875"}
# query_task_result("afd4a6aa-40f6-4784-9ce9-3f85122c989d")
更多推荐
所有评论(0)