from __future__ import annotations import httpx from app.config import Settings from .base import OcrProvider class LocalOcrProvider(OcrProvider): def __init__(self, settings: Settings): self.settings = settings async def extract(self, image_bytes: bytes, region: tuple[float, float, float, float] | None = None) -> dict: files = {"file": ("image.png", image_bytes, "image/png")} data = {} if region: data["region"] = ",".join(str(x) for x in region) async with httpx.AsyncClient(timeout=60) as client: response = await client.post(f"{self.settings.ocr_base_url.rstrip('/')}/ocr", files=files, data=data) response.raise_for_status() return response.json()