Files
change_hair/test_haircolor.py
xsl 9b7324cd26 chore: 适配本机 xsl 路径(RTX 5090 机器)
将所有绝对路径从 /home/ubuntu 改回 /home/xsl,覆盖启动脚本、
configure.ini 及训练/测试脚本。纯路径替换,无功能性改动。

本分支(xsl5090)用于本机(RTX 5090)运行;master 维持 /home/ubuntu
供远程 ubuntu 机器使用。
2026-07-18 16:26:16 +08:00

33 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""换发色接口测试"""
import base64, json, requests, sys
img_path = "/home/xsl/change_hair/project/data/userImage/8488902485_20250630055547.jpg"
with open(img_path, "rb") as f:
img_b64 = base64.b64encode(f.read()).decode()
payload = {
"img": "data:image/jpeg;base64," + img_b64,
"userId": "test_xsl",
"rgb": [255, 0, 0], # 红色
"output_format": "base64"
}
print("=== 调用换发色 /hairColor/v2 (红色 rgb=[255,0,0]) ===")
try:
r = requests.post("http://127.0.0.1:8801/hairColor/v2", json=payload, timeout=180)
d = r.json()
print(f"HTTP {r.status_code} | msg={d.get('msg')} | state={d.get('state')}")
result = d.get("result", "")
if d.get("state") == 0 and result:
# 保存结果图
out = "/home/xsl/change_hair/project/logs/test_haircolor_result.jpg"
with open(out, "wb") as f:
f.write(base64.b64decode(result))
print(f"✅ 换发色成功! 结果图已保存: {out} ({len(result)} bytes base64)")
else:
print(f"❌ 换发色失败: {d}")
except Exception as e:
print(f"❌ 请求异常: {e}")
sys.exit(1)