Files
doc_processer/app/core/dependencies.py
liuyuanchuang 30d2c2f45b fix: remove padding from GLMOCREndToEndService and clean up ruff violations
- Drop image padding in GLMOCREndToEndService.recognize(); use raw image directly
- Fix F821 undefined `padded` references replaced with `image`
- Fix F601 duplicate dict key "≠" in converter
- Fix F841 unused `image_cls_ids` variable in layout_postprocess
- Fix E702 semicolon-separated statements in layout_postprocess
- Fix UP031 percent-format replaced with f-string in logging_config
- Auto-fix 44 additional ruff violations (import order, UP035/UP045/UP006, F401, F541)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 19:52:22 +08:00

48 lines
1.4 KiB
Python

"""Application dependencies."""
from app.core.config import get_settings
from app.services.converter import Converter
from app.services.image_processor import ImageProcessor
from app.services.layout_detector import LayoutDetector
from app.services.ocr_service import GLMOCREndToEndService
# Global instances (initialized on startup)
_layout_detector: LayoutDetector | None = None
def init_layout_detector() -> None:
"""Initialize the global layout detector.
Called during application startup.
"""
global _layout_detector
_layout_detector = LayoutDetector()
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_converter() -> Converter:
"""Get a DOCX converter instance."""
return Converter()
def get_glmocr_endtoend_service() -> GLMOCREndToEndService:
"""Get end-to-end GLM-OCR service (layout detection + per-region OCR)."""
settings = get_settings()
return GLMOCREndToEndService(
vl_server_url=settings.glm_ocr_url,
image_processor=get_image_processor(),
converter=get_converter(),
layout_detector=get_layout_detector(),
)