优化为4b 模型
This commit is contained in:
@@ -138,7 +138,8 @@ app = FastAPI(
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
|
||||
# 不校验鉴权的路径前缀(供网关探测 / 文档 / 静态)
|
||||
_AUTH_EXEMPT = ("/health", "/docs", "/openapi.json", "/redoc", "/static", "/api/v1/debug")
|
||||
_AUTH_EXEMPT = ("/health", "/docs", "/openapi.json", "/redoc", "/static",
|
||||
"/api/v1/debug", "/api/v1/redraw")
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
@@ -1677,6 +1678,42 @@ async def hairline_grow_v2_final_v2(
|
||||
return await _run_v2_final(image_file, image_url, image_base64, hairline_id, "接口12finalv2")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 重绘端点(替代 local_test /api/generate)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@app.post(
|
||||
"/api/v1/redraw",
|
||||
summary="ComfyUI 重绘",
|
||||
tags=["重绘"],
|
||||
description="""
|
||||
传入人物图片 + 遮罩图片,直接调 ComfyUI(0716add-hair 工作流)执行局部重绘。
|
||||
替代原 local_test :8899 的 /api/generate 接口。
|
||||
|
||||
**遮罩图片格式**:支持红色遮罩(R=255)、白色遮罩(R=G=B=255)、Alpha遮罩(A=255),服务取所有通道最大值。
|
||||
**遮罩区域**表示需要重绘的部分,非遮罩区域保持原图不变。
|
||||
""",
|
||||
)
|
||||
async def api_redraw(
|
||||
image_file: UploadFile = File(..., description="人物图片(JPG/PNG)"),
|
||||
mask_file: UploadFile = File(..., description="遮罩图片(PNG,支持红/白/alpha 格式)"),
|
||||
prompt: str = Form(default="填充遮罩区域的头发,皮肤加一点磨皮",
|
||||
description="ComfyUI 提示词"),
|
||||
):
|
||||
image_bytes = await image_file.read()
|
||||
mask_bytes = await mask_file.read()
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
from hairline.redraw import run_redraw
|
||||
try:
|
||||
png_bytes = await run_in_threadpool(
|
||||
run_redraw, image_bytes, mask_bytes, prompt)
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.warning("重绘失败: %s", e)
|
||||
return err(500, f"重绘失败: {e}")
|
||||
b64 = base64.b64encode(png_bytes).decode()
|
||||
return ok({"image_base64": f"data:image/png;base64,{b64}"})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 调试:下载后端日志(接口11 遮罩计算全过程)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user