mirror of
https://github.com/docling-project/docling.git
synced 2025-06-27 05:20:05 +00:00

* feat: Introduce automatic language detection in tesseract_ocr_cli model. Extend unit tests. Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com> * docs: Add example how to use "auto" language with tesseract OCR engines Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com> * fix: Refactor the TesseractOcrModel and TesseractOcrCliModel to validate if the auto-detected language is installed in the system and if not fall back to a default option without language. Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com> --------- Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
38 lines
1003 B
Python
38 lines
1003 B
Python
from pathlib import Path
|
|
|
|
from docling.datamodel.base_models import InputFormat
|
|
from docling.datamodel.pipeline_options import (
|
|
PdfPipelineOptions,
|
|
TesseractCliOcrOptions,
|
|
TesseractOcrOptions,
|
|
)
|
|
from docling.document_converter import DocumentConverter, PdfFormatOption
|
|
|
|
|
|
def main():
|
|
input_doc = Path("./tests/data/2206.01062.pdf")
|
|
|
|
# Set lang=["auto"] with a tesseract OCR engine: TesseractOcrOptions, TesseractCliOcrOptions
|
|
# ocr_options = TesseractOcrOptions(lang=["auto"])
|
|
ocr_options = TesseractCliOcrOptions(lang=["auto"])
|
|
|
|
pipeline_options = PdfPipelineOptions(
|
|
do_ocr=True, force_full_page_ocr=True, ocr_options=ocr_options
|
|
)
|
|
|
|
converter = DocumentConverter(
|
|
format_options={
|
|
InputFormat.PDF: PdfFormatOption(
|
|
pipeline_options=pipeline_options,
|
|
)
|
|
}
|
|
)
|
|
|
|
doc = converter.convert(input_doc).document
|
|
md = doc.export_to_markdown()
|
|
print(md)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|