save code

This commit is contained in:
Your Name
2026-03-19 16:38:16 +08:00
parent ef8bbad157
commit 71221ce1e3
7 changed files with 78 additions and 5 deletions
+2 -2
View File
@@ -347,7 +347,7 @@
},
"29": {
"inputs": {
"Number": "1152"
"Number": "768"
},
"class_type": "Int",
"_meta": {
@@ -356,7 +356,7 @@
},
"30": {
"inputs": {
"Number": "1536"
"Number": "1024"
},
"class_type": "Int",
"_meta": {
+10
View File
@@ -17,6 +17,7 @@ import uuid
from pathlib import Path
import httpx
from PIL import Image
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
@@ -208,6 +209,15 @@ async def try_on(req: TryOnRequest):
async with httpx.AsyncClient(timeout=30.0) as dl_client:
result_bytes = await fetch_image_bytes(dl_client, filename, subfolder, type_)
# 缩放到 768x1024
# img = Image.open(io.BytesIO(result_bytes))
# img = img.resize((768, 1024), Image.LANCZOS)
# buf = io.BytesIO()
# fmt = (Path(filename).suffix.lstrip(".") or "png").upper()
# fmt = "JPEG" if fmt in ("JPG", "JPEG") else fmt
# img.save(buf, format=fmt)
# result_bytes = buf.getvalue()
# 将图片保存到临时文件,上传到 OSS
suffix = Path(filename).suffix or ".png"
object_name = f"tryon/{uuid.uuid4().hex}{suffix}"