Download Convertpdf.py from vqh159/myproject: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/vqh159/myproject/resolve/main/Convertpdf.py
- Command line
-
hf download hf://spaces/vqh159/myproject/Convertpdf.py
-
curl -L -o Convertpdf.py https://huggingface.co/spaces/vqh159/myproject/resolve/main/Convertpdf.py
1.35 kB
| from docling.document_converter import DocumentConverter | |
| from docling.datamodel.pipeline_options import PdfPipelineOptions, TableFormerMode | |
| from docling.datamodel.base_models import InputFormat | |
| from docling.document_converter import PdfFormatOption | |
| import os | |
| def build_converter(mode: str) -> DocumentConverter: | |
| pipeline_options = PdfPipelineOptions() | |
| if mode == "turbo": | |
| pipeline_options.do_ocr = False | |
| pipeline_options.do_table_structure = False | |
| elif mode == "fast": | |
| pipeline_options.do_ocr = False | |
| pipeline_options.do_table_structure = True | |
| pipeline_options.table_structure_options.mode = TableFormerMode.FAST | |
| pipeline_options.table_structure_options.do_cell_matching = False | |
| elif mode == "balanced": | |
| pipeline_options.do_ocr = False | |
| pipeline_options.do_table_structure = True | |
| pipeline_options.table_structure_options.mode = TableFormerMode.ACCURATE | |
| pipeline_options.table_structure_options.do_cell_matching = True | |
| else: | |
| pipeline_options.do_ocr = True | |
| pipeline_options.do_table_structure = True | |
| pipeline_options.table_structure_options.mode = TableFormerMode.ACCURATE | |
| return DocumentConverter( | |
| format_options={ | |
| InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options) | |
| } | |
| ) |