Spaces:
Sleeping
Sleeping
Download bl_ocr/api/main.py from youssefboutaleb/BL: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/youssefboutaleb/BL/resolve/main/bl_ocr/api/main.py
- Command line
-
hf download hf://spaces/youssefboutaleb/BL/bl_ocr/api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/youssefboutaleb/BL/resolve/main/bl_ocr/api/main.py
1.36 kB
| from __future__ import annotations | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from bl_ocr import __version__ | |
| from bl_ocr.api.routes import router | |
| from bl_ocr.application.service import OcrInferenceService | |
| from bl_ocr.core.config import Settings, get_settings | |
| from bl_ocr.ocr.client import MistralOcrClient | |
| from bl_ocr.ocr.prompt import PromptAssets | |
| def create_app( | |
| settings: Settings | None = None, | |
| inference_service: OcrInferenceService | None = None, | |
| ) -> FastAPI: | |
| settings = settings or get_settings() | |
| prompt_assets = PromptAssets.load(settings) | |
| service = inference_service or OcrInferenceService( | |
| MistralOcrClient(settings=settings, assets=prompt_assets), | |
| settings=settings, | |
| ) | |
| app = FastAPI( | |
| title="Delivery Note OCR API", | |
| version=__version__, | |
| description="Standalone OCR and structured extraction API for delivery-note images.", | |
| ) | |
| app.state.settings = settings | |
| app.state.prompt_assets = prompt_assets | |
| app.state.inference_service = service | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=list(settings.cors_allow_origins), | |
| allow_credentials=False, | |
| allow_methods=["GET", "POST", "OPTIONS"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(router) | |
| return app | |
| app = create_app() | |