Files
change_hair/test_grow_swap.py
T
2026-07-17 22:13:56 +08:00

37 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""端到端测试:生发走换发型工作流"""
import base64, requests, time, sys
img_path = "/home/ubuntu/change_hair/project/data/userImage/8488902485_20250630055547.jpg"
mask_path = "/home/ubuntu/change_hair/project/logs/hairgrow_test_mask.png"
with open(img_path, "rb") as f:
img_b64 = "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()
with open(mask_path, "rb") as f:
mask_b64 = "data:image/png;base64," + base64.b64encode(f.read()).decode()
payload = {
"img": img_b64,
"mask": mask_b64,
"hair_id": "1905785164224868354", # girl发型
"is_hr": "true"
}
print("=== 调用 /api/grow (走换发型工作流+LoRA) ===")
t0 = time.time()
try:
r = requests.post("http://127.0.0.1:8899/api/grow", json=payload, timeout=600)
d = r.json()
print(f"HTTP {r.status_code} | state={d.get('state')} | msg={d.get('msg','')} | 耗时={time.time()-t0:.1f}s")
if d.get("state") == 0:
out = "/home/ubuntu/change_hair/project/logs/test_grow_swap_result.jpg"
with open(out, "wb") as f:
f.write(base64.b64decode(d["result"]))
print(f"✅ 生发成功! 结果图: {out}")
else:
print(f"❌ 失败: {d}")
sys.exit(1)
except Exception as e:
print(f"❌ 异常(耗时{time.time()-t0:.1f}s): {e}")
sys.exit(1)