All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 31s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 31s
Deploy to Staging / Verify Staging (pull_request) Successful in 2m19s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 8s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
Implement VIN-specific OCR extraction with optimized preprocessing: - Add POST /extract/vin endpoint for VIN extraction - VIN preprocessor: CLAHE, deskew, denoise, adaptive threshold - VIN validator: check digit validation, OCR error correction (I->1, O->0) - VIN extractor: PSM modes 6/7/8, character whitelist, alternatives - Response includes confidence, bounding box, and alternatives - Unit tests for validator and preprocessor - Integration tests for VIN extraction endpoint Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
"""OCR Service FastAPI Application."""
|
|
import logging
|
|
from contextlib import asynccontextmanager
|
|
from typing import AsyncIterator
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from app.config import settings
|
|
from app.routers import extract_router, jobs_router
|
|
from app.services import job_queue
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=getattr(logging, settings.log_level.upper(), logging.INFO),
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
"""Application lifespan handler for startup/shutdown."""
|
|
# Startup
|
|
logger.info("OCR service starting up")
|
|
yield
|
|
# Shutdown
|
|
logger.info("OCR service shutting down")
|
|
await job_queue.close()
|
|
|
|
|
|
app = FastAPI(
|
|
title="MotoVaultPro OCR Service",
|
|
description="OCR processing service for vehicle documents",
|
|
version="1.0.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(extract_router)
|
|
app.include_router(jobs_router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check() -> dict:
|
|
"""Health check endpoint for container orchestration."""
|
|
return {"status": "healthy"}
|
|
|
|
|
|
@app.get("/")
|
|
async def root() -> dict:
|
|
"""Root endpoint with service information."""
|
|
return {
|
|
"service": "mvp-ocr",
|
|
"version": "1.0.0",
|
|
"log_level": settings.log_level,
|
|
"endpoints": [
|
|
"POST /extract - Synchronous OCR extraction",
|
|
"POST /extract/vin - VIN-specific extraction with validation",
|
|
"POST /jobs - Submit async OCR job",
|
|
"GET /jobs/{job_id} - Get async job status",
|
|
],
|
|
}
|