初始化:换发型/换发色/训练发型服务
包含: - hair_service_sd: 主服务(换发型/换发色/生发,端口8801) - photo_service: LoRA调度+训练(端口32678) - hair_grow_service: 调试测试页(端口8888,含4个测试页) - 批量训练脚本(batch_train_hairstyles.py) - 发际线mask自动识别(hairline_mask.py,4种方案) - 手绘mask换发型(hair_swap_manual.py) - 文档:README.md + LARGE_FILES.md + docs/ 大文件(模型权重200G、训练数据123G)已排除,见 LARGE_FILES.md OSS/COS密钥已脱敏为环境变量,原文件备份在本地
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
"""测试 /api/hairGrow/v1 接口"""
|
||||
import base64, requests, sys
|
||||
|
||||
img_path = "/home/xsl/change_hair/project/data/userImage/8488902485_20250630055547.jpg"
|
||||
mask_path = "/home/xsl/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,
|
||||
"strength": 0.5,
|
||||
"output_format": "base64"
|
||||
}
|
||||
|
||||
print("=== 调用 /api/hairGrow/v1 (strength=0.5) ===")
|
||||
import time
|
||||
t0 = time.time()
|
||||
try:
|
||||
r = requests.post("http://127.0.0.1:8801/api/hairGrow/v1", json=payload, timeout=180)
|
||||
d = r.json()
|
||||
print(f"HTTP {r.status_code} | msg={d.get('msg')} | state={d.get('state')} | 耗时={time.time()-t0:.1f}s")
|
||||
result = d.get("result", "")
|
||||
if d.get("state") == 0 and result:
|
||||
out = "/home/xsl/change_hair/project/logs/test_hairgrow_api_result.jpg"
|
||||
with open(out, "wb") as f:
|
||||
f.write(base64.b64decode(result))
|
||||
print(f"✅ 生发成功! 结果图: {out}")
|
||||
else:
|
||||
print(f"❌ 失败: {d}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"❌ 异常: {e}")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user