[Snow Team] ocr-python: auto-commit work
This commit is contained in:
@@ -5,6 +5,8 @@ readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
"ddddocr>=1.6.1",
|
||||
"fastapi>=0.115.0",
|
||||
"uvicorn>=0.34.0",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .engine import get_ocr_engine
|
||||
from .cli import recognize_payload, batch_recognize_payload
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Eagerly load model on startup
|
||||
get_ocr_engine()
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"code": 0, "msg": "ok"}
|
||||
|
||||
|
||||
@app.post("/ocr/recognize")
|
||||
async def recognize(payload: dict):
|
||||
return await asyncio.to_thread(recognize_payload, payload)
|
||||
|
||||
|
||||
@app.post("/ocr/batch")
|
||||
async def batch_recognize(payload: dict):
|
||||
return await asyncio.to_thread(batch_recognize_payload, payload)
|
||||
Reference in New Issue
Block a user