install: show wait progress, shorten OCR health wait, log to file.
This commit is contained in:
@@ -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(...),
|
||||
|
||||
Reference in New Issue
Block a user