问题:接口2 与接口3/5 乱序调用时耗时抖动(最差 15~22s)。两个根因: 1. GPU 24G 常驻 21.4G,Flux-2(3.9G) 无法完全驻留显存,每次采样动态换页, 速度随空闲显存波动(2s~8s); 2. ComfyUI 单队列 FIFO,接口2 排在接口3/5 批量任务后面。 改动: - hairline/comfyui.py: run() 新增 front 参数,/prompt 带 "front": true 插队到队列最前; redraw.py 透传;service.py 接口2 三处调用(女重绘 + 男有/无遮罩)传 front=True, 接口3/5 仍走普通队列。 - add_hair.json / 0716add-hair-api.json: 节点61 CLIPLoader device default→cpu。 qwen CLIP(4G) 不再占显存(文本条件缓存常年命中),ComfyUI 显存 8.8G→4.5G, Flux-2 完全驻留,采样稳定 ~3-5s。代价:换 prompt 后首次请求 CPU 编码 ~11s(一次性)。 - 提示词全局统一为「填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜」: app.py 4处默认值、service.py _REDRAW_PROMPT、redraw.py _DEFAULT_PROMPT、 4个工作流节点60内置文案、测试页(test_interface2/3/7/12/12_final)、local_test。 任何两个不同 prompt 交替提交都会打爆 CLIP 编码缓存(--cache-classic 只存最近一次), 之前测试页旧文案与服务端不一致导致交替测试每次 +11s。 - app.py: 接口7 /api/v1/hair/grow-v2 下线(业务弃用;add_hair2.json 的 Klein-9b 会把常驻 Klein-4b 挤出显存)。保留 stub 返回 1007 明确报错,避免裸 404。 实测(1024 档):接口2女 8.5~10s、接口2男 ~5s、接口3 ~7-10s,交替混跑无尖刺。 Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Test script: send image+mask to the local service and save result."""
|
|
import requests
|
|
import sys
|
|
import os
|
|
|
|
SERVICE_URL = "http://127.0.0.1:8899"
|
|
IMAGE_PATH = "/home/ubuntu/hair/local_test/用来重绘.jpg"
|
|
MASK_PATH = "/home/ubuntu/hair/local_test/用来重绘.png"
|
|
OUTPUT_DIR = "/home/ubuntu/hair/local_test/output"
|
|
|
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
print(f"Sending image: {IMAGE_PATH}")
|
|
print(f"Sending mask: {MASK_PATH}")
|
|
|
|
with open(IMAGE_PATH, "rb") as f:
|
|
img_data = f.read()
|
|
with open(MASK_PATH, "rb") as f:
|
|
mask_data = f.read()
|
|
|
|
resp = requests.post(
|
|
f"{SERVICE_URL}/api/generate",
|
|
files={
|
|
"image": ("original.jpg", img_data, "image/jpeg"),
|
|
"mask": ("mask.png", mask_data, "image/png"),
|
|
},
|
|
data={"prompt": "填充遮罩区域的头发,皮肤加一点磨皮,再加一点美颜"},
|
|
timeout=600,
|
|
)
|
|
|
|
print(f"Status: {resp.status_code}")
|
|
print(f"Content-Type: {resp.headers.get('Content-Type')}")
|
|
|
|
if resp.status_code == 200 and "image" in resp.headers.get("Content-Type", ""):
|
|
out_path = os.path.join(OUTPUT_DIR, "result.png")
|
|
with open(out_path, "wb") as f:
|
|
f.write(resp.content)
|
|
print(f"SUCCESS! Result saved to: {out_path}")
|
|
else:
|
|
print(f"FAILED! Response: {resp.text[:2000]}")
|
|
sys.exit(1)
|