refactor: Restructure OCR module and centralize config

This commit is contained in:
begoniezhao
2026-01-16 15:05:18 +08:00
parent 74bf76eb3f
commit 88fd42cbc3
17 changed files with 586 additions and 352 deletions
+37
View File
@@ -0,0 +1,37 @@
import logging
import threading
from typing import Dict
from docreader.ocr.base import DummyOCRBackend, OCRBackend
from docreader.ocr.paddle import PaddleOCRBackend
from docreader.ocr.vlm import VLMOCRBackend
logger = logging.getLogger(__name__)
class OCREngine:
"""OCR Engine factory class for managing different OCR backend instances"""
_instances: Dict[str, OCRBackend] = {}
_lock = threading.Lock()
@classmethod
def get_instance(cls, backend_type: str) -> OCRBackend:
backend_type = (backend_type or "dummy").lower()
with cls._lock:
inst = cls._instances.get(backend_type)
if inst is not None:
return inst
logger.info(f"Creating OCR engine instance for backend: {backend_type}")
if backend_type == "paddle":
inst = PaddleOCRBackend()
elif backend_type == "vlm":
inst = VLMOCRBackend()
else:
inst = DummyOCRBackend()
cls._instances[backend_type] = inst
return inst