2025-12-29 17:34:58 +08:00
|
|
|
"""Application dependencies."""
|
|
|
|
|
|
|
|
|
|
from app.services.image_processor import ImageProcessor
|
|
|
|
|
from app.services.layout_detector import LayoutDetector
|
2026-03-09 16:51:06 +08:00
|
|
|
from app.services.ocr_service import GLMOCREndToEndService
|
2025-12-31 17:38:32 +08:00
|
|
|
from app.services.converter import Converter
|
|
|
|
|
from app.core.config import get_settings
|
2025-12-29 17:34:58 +08:00
|
|
|
|
|
|
|
|
# Global instances (initialized on startup)
|
|
|
|
|
_layout_detector: LayoutDetector | None = None
|
|
|
|
|
|
|
|
|
|
|
2025-12-31 17:38:32 +08:00
|
|
|
def init_layout_detector() -> None:
|
2025-12-29 17:34:58 +08:00
|
|
|
"""Initialize the global layout detector.
|
|
|
|
|
|
|
|
|
|
Called during application startup.
|
|
|
|
|
"""
|
|
|
|
|
global _layout_detector
|
2025-12-31 17:38:32 +08:00
|
|
|
_layout_detector = LayoutDetector()
|
2025-12-29 17:34:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_layout_detector() -> LayoutDetector:
|
|
|
|
|
"""Get the global layout detector instance."""
|
|
|
|
|
if _layout_detector is None:
|
|
|
|
|
raise RuntimeError("Layout detector not initialized. Call init_layout_detector() first.")
|
|
|
|
|
return _layout_detector
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_image_processor() -> ImageProcessor:
|
|
|
|
|
"""Get an image processor instance."""
|
|
|
|
|
return ImageProcessor()
|
|
|
|
|
|
|
|
|
|
|
2025-12-31 17:38:32 +08:00
|
|
|
def get_converter() -> Converter:
|
2025-12-29 17:34:58 +08:00
|
|
|
"""Get a DOCX converter instance."""
|
2025-12-31 17:38:32 +08:00
|
|
|
return Converter()
|
2025-12-29 17:34:58 +08:00
|
|
|
|
2026-01-05 17:30:54 +08:00
|
|
|
|
2026-03-09 16:51:06 +08:00
|
|
|
def get_glmocr_endtoend_service() -> GLMOCREndToEndService:
|
|
|
|
|
"""Get end-to-end GLM-OCR service (layout detection + per-region OCR)."""
|
2026-01-05 17:30:54 +08:00
|
|
|
settings = get_settings()
|
2026-03-09 16:51:06 +08:00
|
|
|
return GLMOCREndToEndService(
|
|
|
|
|
vl_server_url=settings.glm_ocr_url,
|
2026-02-06 15:06:50 +08:00
|
|
|
image_processor=get_image_processor(),
|
|
|
|
|
converter=get_converter(),
|
2026-03-09 16:51:06 +08:00
|
|
|
layout_detector=get_layout_detector(),
|
2026-02-06 15:06:50 +08:00
|
|
|
)
|