Files
change_hair/hair_grow_service/README.md
T
2026-07-17 22:13:56 +08:00

69 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 区域生发测试服务
提供带「画笔涂抹遮罩」的 Web 测试页面,在用户涂抹的区域内生发。
## 快速开始
### 1. 确认 webui 已启动(生发依赖 SD inpainting
```bash
ss -tlnp | grep 57860 # 确认 webui 在跑
bash /home/ubuntu/change_hair/start_all.sh status # 看 webui 是否就绪
```
### 2. 启动生发服务(端口 8899)
```bash
nohup /home/ubuntu/change_hair/start_hairgrow.sh > /home/ubuntu/change_hair/project/logs/hair_grow_service.log 2>&1 &
```
### 3. 打开测试页面
浏览器访问:
```
http://172.21.246.70:8899
```
(如从 Windows 宿主机访问 WSL,用上面地址;或用 localhost:8899
### 4. 使用流程
1. **上传图片**:点击或拖拽一张人头像照片(正面、发际线/稀疏区清晰)
2. **涂抹遮罩**:用画笔在需要生发的区域涂抹(白色 = 生发区)
- 左侧可调画笔粗细、切换橡皮、清空
3. **调强度**:生发强度滑块(0.1~1.0,默认 0.5
- 低强度:轻微生发,严格保持遮罩边界
- 高强度:浓密生发,边缘自然过渡
4. **点「生成」**:等待约 5 秒
5. **看结果**:原图与生发结果并排对比,可下载
## 文件说明
```
hair_grow_service/
├── app.py # Flask 服务(端口 8899
├── static/index.html # 测试页面(画笔遮罩 + 结果对比)
└── README.md
start_hairgrow.sh # 启动脚本
```
## API 接口(可单独调用)
```
POST http://<host>:8899/api/grow
Content-Type: application/json
{
"img": "data:image/jpeg;base64,...", # 原图 base64
"mask": "data:image/png;base64,...", # 遮罩 base64,白色(255)=生发区,与img同分辨率
"strength": 0.5 # 生发强度 0.1~1.0
}
→ {"state": 0, "result": "<base64结果图>"}
{"state": -1, "msg": "错误信息"}
```
## 停止服务
```bash
pkill -f "hair_grow_service/app.py"
```
## 注意事项
- 生发服务**依赖 webui(57860)**webui 未启动会报连接失败
- 图片过大(>1024px)会自动缩放并对齐到 8 的倍数
- 生发结果是确定性的(固定 seed=123456789),同输入同输出