Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: None env parse for OCR_ENGINE #257

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions marker/ocr/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def replace_langs_with_codes(langs):
for i, lang in enumerate(langs):
if lang.title() in LANGUAGE_TO_CODE:
langs[i] = LANGUAGE_TO_CODE[lang.title()]
else:
elif settings.OCR_ENGINE == "ocrmypdf":
for i, lang in enumerate(langs):
if lang in LANGUAGE_TO_CODE:
langs[i] = LANGUAGE_TO_TESSERACT_CODE[lang]
Expand All @@ -30,7 +30,7 @@ def validate_langs(langs):
for lang in langs:
if lang not in CODE_TO_LANGUAGE:
raise ValueError(f"Invalid language code {lang} for Surya OCR")
else:
elif settings.OCR_ENGINE == "ocrmypdf":
for lang in langs:
if lang not in TESSERACT_CODE_TO_LANGUAGE:
raise ValueError(f"Invalid language code {lang} for Tesseract")
2 changes: 1 addition & 1 deletion marker/ocr/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run_ocr(doc, pages: List[Page], langs: List[str], rec_model, batch_multiplie
return pages, {"ocr_pages": 0, "ocr_failed": 0, "ocr_success": 0, "ocr_engine": "none"}

ocr_method = settings.OCR_ENGINE
if ocr_method is None:
if ocr_method == "None":
return pages, {"ocr_pages": 0, "ocr_failed": 0, "ocr_success": 0, "ocr_engine": "none"}
elif ocr_method == "surya":
new_pages = surya_recognition(doc, ocr_idxs, langs, rec_model, pages, batch_multiplier=batch_multiplier)
Expand Down
2 changes: 1 addition & 1 deletion marker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def TORCH_DEVICE_MODEL(self) -> str:

# OCR
INVALID_CHARS: List[str] = [chr(0xfffd), "�"]
OCR_ENGINE: Optional[Literal["surya", "ocrmypdf"]] = "surya" # Which OCR engine to use, either "surya" or "ocrmypdf". Defaults to "ocrmypdf" on CPU, "surya" on GPU.
OCR_ENGINE: Optional[Literal["surya", "ocrmypdf", "None"]] = "surya" # Which OCR engine to use, either "surya", "ocrmypdf" or "None". Defaults to "ocrmypdf" on CPU, "surya" on GPU.
OCR_ALL_PAGES: bool = False # Run OCR on every page even if text can be extracted

## Surya
Expand Down
Loading