OCR Worker: add check and systemd install scripts.

This commit is contained in:
dekun
2026-06-28 14:39:38 +08:00
parent ff0c103dc5
commit 9713c640b4
5 changed files with 211 additions and 24 deletions
+12 -6
View File
@@ -112,12 +112,18 @@ def run_ocr_on_bytes(content: bytes) -> dict:
@app.on_event("startup")
def warmup():
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
"""延迟预热,不阻塞 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")