feat(ocr): auto-install Tesseract/EasyOCR languages from settings
- Add app/utils/ocr_language_manager.py: detects tessdata dir, downloads missing .traineddata files via wget/curl from tessdata_fast GitHub repo, pre-downloads EasyOCR models, exposes async background-thread helper - TesseractOCRProvider.process() calls ensure_tesseract_languages() before running pytesseract; raises clear error if languages remain unavailable - EasyOCRProvider.process() logs informational message when models download - app/main.py: calls ensure_ocr_languages_async() at startup - app/utils/settings_sync.py: triggers language re-check after every settings reload so UI changes take effect without container restart - app/api/settings.py: adds POST /api/settings/install-ocr-languages endpoint for on-demand language installation from the admin UI - Dockerfile: adds wget for runtime tessdata downloads - docs/ConfigurationGuide.md: documents automatic language download - tests/test_ocr_language_manager.py: 29 unit tests Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -297,6 +297,19 @@ class TesseractOCRProvider(OCRProvider):
|
||||
|
||||
lang = getattr(settings, "tesseract_language", None) or "eng"
|
||||
|
||||
# Ensure language data files are present; attempt download if missing.
|
||||
from app.utils.ocr_language_manager import ensure_tesseract_languages # noqa: PLC0415
|
||||
|
||||
missing = ensure_tesseract_languages(lang)
|
||||
if missing:
|
||||
raise RuntimeError(
|
||||
f"[TesseractOCR] Required language data files are not available and could not be "
|
||||
f"downloaded: {', '.join(missing)}. "
|
||||
"Install the corresponding tesseract-ocr language packages "
|
||||
"(e.g. apt-get install tesseract-ocr-deu) or ensure internet access so DocuElevate "
|
||||
"can download them automatically."
|
||||
)
|
||||
|
||||
logger.info(f"[TesseractOCR] Processing {os.path.basename(file_path)} (lang={lang})")
|
||||
pages = convert_from_path(file_path, dpi=300)
|
||||
texts: List[str] = []
|
||||
@@ -342,6 +355,9 @@ class EasyOCRProvider(OCRProvider):
|
||||
gpu = getattr(settings, "easyocr_gpu", False)
|
||||
|
||||
logger.info(f"[EasyOCR] Processing {os.path.basename(file_path)} (langs={langs}, gpu={gpu})")
|
||||
# easyocr.Reader automatically downloads missing models on first use;
|
||||
# log a clear message so operators know a download may be in progress.
|
||||
logger.info(f"[EasyOCR] Initialising reader for langs={langs} (models will be downloaded if absent)")
|
||||
reader = easyocr.Reader(langs, gpu=gpu)
|
||||
pages = convert_from_path(file_path, dpi=300)
|
||||
texts: List[str] = []
|
||||
|
||||
Reference in New Issue
Block a user