fix the issue

This commit is contained in:
saqib mir
2026-08-22 13:16:15 +05:30
parent 83f47488ab
commit eb514195bf
3 changed files with 22 additions and 2 deletions
+5
View File
@@ -92,6 +92,11 @@ RUN apt-get update \
zlib1g \
libpng16-16 \
fonts-liberation \
libgl1 \
libglib2.0-0 \
libgomp1 \
libsm6 \
libxext6 \
&& rm -rf /var/lib/apt/lists/*
# Install the extension globally so it's not shadowed by the volume mount ./gateway:/home/app
+7 -1
View File
@@ -77,9 +77,15 @@ def perform_ocr_on_page(document_id: str, page_index: int) -> OCRPageResponse:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Page index out of bounds")
if not ocr_service.is_ocr_available():
init_err = ocr_service.get_ocr_init_error()
err_detail = (
f"RapidOCR engine is not installed or available ({init_err})."
if init_err
else "RapidOCR engine is not installed or available."
)
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="RapidOCR engine is not installed or available.",
detail=err_detail,
)
try:
+10 -1
View File
@@ -8,11 +8,12 @@ logger = logging.getLogger(__name__)
_ocr_engine = None
_ocr_available = False
_ocr_init_error: Optional[str] = None
def load_ocr() -> bool:
"""Explicitly initializes the RapidOCR engine once during application startup."""
global _ocr_engine, _ocr_available
global _ocr_engine, _ocr_available, _ocr_init_error
if _ocr_engine is not None:
return _ocr_available
@@ -20,10 +21,14 @@ def load_ocr() -> bool:
from rapidocr_onnxruntime import RapidOCR
_ocr_engine = RapidOCR()
_ocr_available = True
_ocr_init_error = None
logger.info("[Startup] RapidOCR engine loaded successfully into memory.")
print("[Startup] RapidOCR engine loaded successfully into memory.")
except Exception as e:
_ocr_engine = None
_ocr_available = False
_ocr_init_error = str(e)
logger.error(f"[Startup] Warning: RapidOCR engine initialization failed: {e}", exc_info=True)
print(f"[Startup] Warning: RapidOCR engine not available: {e}")
return _ocr_available
@@ -37,6 +42,10 @@ def is_ocr_available() -> bool:
return _ocr_available and _ocr_engine is not None
def get_ocr_init_error() -> Optional[str]:
return _ocr_init_error
def recognize_image_bytes(image_bytes: bytes) -> Dict[str, Any]:
if not is_ocr_available():