save code
This commit is contained in:
+3
-9
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user