Files
hair/local_test/test_api.py
T
xsl 752630e4f5 feat: ComfyUI 默认提示词统一改为「填充遮罩区域的头发,人物增加一点磨皮」
- app.py 各接口 Form 默认值与说明、hairline/service.py _REDRAW_PROMPT、
  hairline/redraw.py _DEFAULT_PROMPT、face_analysis/hairline_grow.py 兜底值
- add_hair.json / 0716add-hair-api.json / 0716add-hair.json / hair_repaint.json
  工作流节点60内置文本
- static 测试页、local_test、benchmark 脚本、接口文档同步
注意:新提示词首次请求会因 CLIP 缓存失效变慢一次,之后恢复
2026-09-16 00:27:33 +08:00

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)