save code

This commit is contained in:
Your Name
2026-03-12 10:14:01 +00:00
parent 42f83d3619
commit 8221c8be65
3 changed files with 78 additions and 24 deletions
+3 -9
View File
@@ -44,7 +44,6 @@ app.add_middleware(
class TryOnRequest(BaseModel):
model_image: str # base64 模特图片
shirt_image: str # base64 上衣图片
pants_image: str # base64 裤子图片
class TryOnResponse(BaseModel):
@@ -113,7 +112,6 @@ async def try_on(req: TryOnRequest):
换装接口
- model_image: 模特图片 base64
- shirt_image: 上衣图片 base64
- pants_image: 裤子图片 base64
返回 result_image: 换装结果 base64
"""
@@ -124,11 +122,10 @@ async def try_on(req: TryOnRequest):
async with httpx.AsyncClient(timeout=60.0) as client:
# 解码张图片
# 解码张图片
try:
model_bytes = decode_base64_image(req.model_image)
shirt_bytes = decode_base64_image(req.shirt_image)
# pants_bytes = decode_base64_image(req.pants_image)
except Exception as e:
raise HTTPException(status_code=400, detail=f"图片解码失败: {e}")
@@ -136,14 +133,12 @@ async def try_on(req: TryOnRequest):
uid = uuid.uuid4().hex[:8]
model_fname = f"model_{uid}.jpg"
shirt_fname = f"shirt_{uid}.jpg"
# pants_fname = f"pants_{uid}.jpg"
# 并发上传张图片
# 并发上传张图片
try:
model_name, shirt_name, pants_name = await asyncio.gather(
model_name, shirt_name = await asyncio.gather(
upload_image(client, model_bytes, model_fname),
upload_image(client, shirt_bytes, shirt_fname),
# upload_image(client, pants_bytes, pants_fname),
)
except httpx.HTTPError as e:
raise HTTPException(status_code=502, detail=f"上传图片到 ComfyUI 失败: {e}")
@@ -151,7 +146,6 @@ async def try_on(req: TryOnRequest):
# 修改工作流节点的图片输入
workflow[NODE_MODEL]["inputs"]["image"] = model_name
workflow[NODE_SHIRT]["inputs"]["image"] = shirt_name
# workflow[NODE_PANTS]["inputs"]["image"] = pants_name
# 提交工作流
try: