From 71221ce1e3cb19604126990b1f5bc2d61fa27847 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Mar 2026 16:38:16 +0800 Subject: [PATCH] save code --- change2/change2_1_ex.json | 4 ++-- change2/service2.py | 10 +++++++++ change3/change2_2_0308.json | 4 ++-- change3/service3.py | 10 +++++++++ change_app.py | 2 +- requirements.txt | 8 +++++++ start_services.sh | 45 +++++++++++++++++++++++++++++++++++++ 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 requirements.txt create mode 100755 start_services.sh diff --git a/change2/change2_1_ex.json b/change2/change2_1_ex.json index b3bfa2c..6ee2f39 100644 --- a/change2/change2_1_ex.json +++ b/change2/change2_1_ex.json @@ -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": { diff --git a/change2/service2.py b/change2/service2.py index 71b9386..e1f45c5 100644 --- a/change2/service2.py +++ b/change2/service2.py @@ -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}" diff --git a/change3/change2_2_0308.json b/change3/change2_2_0308.json index 59f6881..cfcecd4 100644 --- a/change3/change2_2_0308.json +++ b/change3/change2_2_0308.json @@ -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": { diff --git a/change3/service3.py b/change3/service3.py index 2490108..03884b8 100644 --- a/change3/service3.py +++ b/change3/service3.py @@ -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}" diff --git a/change_app.py b/change_app.py index f8bc938..ddf8f45 100644 --- a/change_app.py +++ b/change_app.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0edca31 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +fastapi +uvicorn[standard] +httpx +pydantic +flask +requests +Pillow>=9.0,<11 +oss2 diff --git a/start_services.sh b/start_services.sh new file mode 100755 index 0000000..da82372 --- /dev/null +++ b/start_services.sh @@ -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"