install: show wait progress, shorten OCR health wait, log to file.

This commit is contained in:
dekun
2026-06-28 14:58:06 +08:00
parent 04f1381a2d
commit edd3e80ef1
3 changed files with 25 additions and 23 deletions
+3 -16
View File
@@ -110,27 +110,14 @@ def run_ocr_on_bytes(content: bytes) -> dict:
}
@app.on_event("startup")
def warmup():
"""延迟预热,不阻塞 HTTP 服务启动。"""
import threading
def _run():
buf = __import__("io").BytesIO()
Image.new("RGB", (120, 40), color=(255, 255, 255)).save(buf, format="JPEG")
try:
run_ocr_on_bytes(buf.getvalue())
except Exception:
pass
threading.Thread(target=_run, daemon=True, name="ocr-warmup").start()
@app.get("/health")
def health():
return {"status": "ok", "gpu": OCR_USE_GPU}
# 首次 /api/ocr/regions 请求时再加载模型(/health 立即响应,避免安装脚本长时间等待)
@app.post("/api/ocr/regions")
async def ocr_regions(
file: UploadFile = File(...),