Files
doc_processer/app/core/dependencies.py
liuyuanchuang 874fd383cc init repo
2025-12-29 17:34:58 +08:00

43 lines
1.2 KiB
Python

"""Application dependencies."""
from app.services.image_processor import ImageProcessor
from app.services.layout_detector import LayoutDetector
from app.services.ocr_service import OCRService
from app.services.docx_converter import DocxConverter
# Global instances (initialized on startup)
_layout_detector: LayoutDetector | None = None
def init_layout_detector(model_path: str) -> None:
"""Initialize the global layout detector.
Called during application startup.
"""
global _layout_detector
_layout_detector = LayoutDetector(model_path=model_path)
_layout_detector.load_model()
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()
def get_ocr_service() -> OCRService:
"""Get an OCR service instance."""
return OCRService()
def get_docx_converter() -> DocxConverter:
"""Get a DOCX converter instance."""
return DocxConverter()