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}"
+2 -2
View File
@@ -401,7 +401,7 @@
},
"29": {
"inputs": {
"Number": "1152"
"Number": "768"
},
"class_type": "Int",
"_meta": {
@@ -410,7 +410,7 @@
},
"30": {
"inputs": {
"Number": "1536"
"Number": "1024"
},
"class_type": "Int",
"_meta": {
+10
View File
@@ -18,6 +18,7 @@ from pathlib import Path
import httpx
import oss2
from PIL import Image
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
@@ -201,6 +202,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}"
+1 -1
View File
@@ -68,4 +68,4 @@ def change_cloth_base64():
if __name__ == '__main__':
app.run(host="0.0.0.0", port=28888, debug=False)
app.run(host="0.0.0.0", port=28888, debug=True)
+8
View File
@@ -0,0 +1,8 @@
fastapi
uvicorn[standard]
httpx
pydantic
flask
requests
Pillow>=9.0,<11
oss2
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
LOG_DIR="/home/ubuntu/log"
mkdir -p "$LOG_DIR"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 开始停止旧进程..."
# 杀掉已有进程
pkill -f "main.py" 2>/dev/null && echo " 已停止 ComfyUI" || echo " ComfyUI 未在运行"
pkill -f "change_cloth_server/change2/service2.py" 2>/dev/null && echo " 已停止 service2" || echo " service2 未在运行"
pkill -f "change_cloth_server/change3/service3.py" 2>/dev/null && echo " 已停止 service3" || echo " service3 未在运行"
pkill -f "change_cloth_server/change_app.py" 2>/dev/null && echo " 已停止 change_app" || echo " change_app 未在运行"
# 等待进程退出
sleep 2
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 开始启动服务..."
# 启动 ComfyUI(使用项目 venv
COMFYUI_PYTHON="/home/ubuntu/ComfyUI/.venv/bin/python"
if [ -x "$COMFYUI_PYTHON" ]; then
cd /home/ubuntu/ComfyUI
nohup "$COMFYUI_PYTHON" main.py >> "$LOG_DIR/comfyui.log" 2>&1 &
echo " ComfyUI 已启动 (PID: $!)"
else
cd /home/ubuntu/ComfyUI
nohup python3 main.py >> "$LOG_DIR/comfyui.log" 2>&1 &
echo " ComfyUI 已启动 (PID: $!)"
fi
# 启动 service2 / service3 / change_app(使用 python3,依赖已 pip install --user
export PATH="/home/ubuntu/.local/bin:$PATH"
cd /home/ubuntu/change_cloth_server/change2
nohup python3 service2.py >> "$LOG_DIR/service2.log" 2>&1 &
echo " service2 已启动 (PID: $!)"
cd /home/ubuntu/change_cloth_server/change3
nohup python3 service3.py >> "$LOG_DIR/service3.log" 2>&1 &
echo " service3 已启动 (PID: $!)"
cd /home/ubuntu/change_cloth_server
nohup python3 change_app.py >> "$LOG_DIR/change_app.log" 2>&1 &
echo " change_app 已启动 (PID: $!)"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 所有服务启动完毕,日志目录: $LOG_DIR"