1- def ocr_engines ():
1+ from __future__ import annotations
2+
3+ from contextlib import suppress
4+ from typing import TYPE_CHECKING
5+
6+ if TYPE_CHECKING :
7+ # Experimental table crops layout models
8+ from docling .experimental .models .table_crops_layout_model import (
9+ TableCropsLayoutModel ,
10+ )
11+
12+ # Layout models
13+ from docling .models .stages .layout .layout_model import LayoutModel
14+ from docling .models .stages .layout .layout_object_detection_model import (
15+ LayoutObjectDetectionModel ,
16+ )
17+
18+ # OCR models
219 from docling .models .stages .ocr .auto_ocr_model import OcrAutoModel
320 from docling .models .stages .ocr .easyocr_model import EasyOcrModel
421 from docling .models .stages .ocr .kserve_v2_ocr_model import KserveV2OcrModel
@@ -7,60 +24,19 @@ def ocr_engines():
724 from docling .models .stages .ocr .rapid_ocr_model import RapidOcrModel
825 from docling .models .stages .ocr .tesseract_ocr_cli_model import TesseractOcrCliModel
926 from docling .models .stages .ocr .tesseract_ocr_model import TesseractOcrModel
10-
11- return {
12- "ocr_engines" : [
13- OcrAutoModel ,
14- EasyOcrModel ,
15- KserveV2OcrModel ,
16- NemotronOcrModel ,
17- OcrMacModel ,
18- RapidOcrModel ,
19- TesseractOcrModel ,
20- TesseractOcrCliModel ,
21- ]
22- }
23-
24-
25- def picture_description ():
2627 from docling .models .stages .picture_description .picture_description_api_model import (
2728 PictureDescriptionApiModel ,
2829 )
30+
31+ # Picture description models
2932 from docling .models .stages .picture_description .picture_description_vlm_engine_model import (
3033 PictureDescriptionVlmEngineModel ,
3134 )
3235 from docling .models .stages .picture_description .picture_description_vlm_model import (
3336 PictureDescriptionVlmModel ,
3437 )
3538
36- return {
37- "picture_description" : [
38- PictureDescriptionVlmEngineModel , # New engine-based (preferred)
39- PictureDescriptionVlmModel , # Legacy direct transformers
40- PictureDescriptionApiModel , # API-based
41- ]
42- }
43-
44-
45- def layout_engines ():
46- from docling .experimental .models .table_crops_layout_model import (
47- TableCropsLayoutModel ,
48- )
49- from docling .models .stages .layout .layout_model import LayoutModel
50- from docling .models .stages .layout .layout_object_detection_model import (
51- LayoutObjectDetectionModel ,
52- )
53-
54- return {
55- "layout_engines" : [
56- LayoutObjectDetectionModel ,
57- LayoutModel ,
58- TableCropsLayoutModel ,
59- ]
60- }
61-
62-
63- def table_structure_engines ():
39+ # Table structure models
6440 from docling .models .stages .table_structure .table_structure_model import (
6541 TableStructureModel ,
6642 )
@@ -71,10 +47,137 @@ def table_structure_engines():
7147 TableStructureModelV2 ,
7248 )
7349
74- return {
75- "table_structure_engines" : [
50+
51+ def ocr_engines ():
52+ engines : list [
53+ type [OcrAutoModel ]
54+ | type [EasyOcrModel ]
55+ | type [KserveV2OcrModel ]
56+ | type [NemotronOcrModel ]
57+ | type [OcrMacModel ]
58+ | type [RapidOcrModel ]
59+ | type [TesseractOcrModel ]
60+ | type [TesseractOcrCliModel ]
61+ ] = []
62+
63+ with suppress (ImportError ):
64+ from docling .models .stages .ocr .auto_ocr_model import OcrAutoModel
65+
66+ engines .append (OcrAutoModel )
67+ with suppress (ImportError ):
68+ from docling .models .stages .ocr .easyocr_model import EasyOcrModel
69+
70+ engines .append (EasyOcrModel )
71+ with suppress (ImportError ):
72+ from docling .models .stages .ocr .kserve_v2_ocr_model import KserveV2OcrModel
73+
74+ engines .append (KserveV2OcrModel )
75+ with suppress (ImportError ):
76+ from docling .models .stages .ocr .nemotron_ocr_model import NemotronOcrModel
77+
78+ engines .append (NemotronOcrModel )
79+ with suppress (ImportError ):
80+ from docling .models .stages .ocr .ocr_mac_model import OcrMacModel
81+
82+ engines .append (OcrMacModel )
83+ with suppress (ImportError ):
84+ from docling .models .stages .ocr .rapid_ocr_model import RapidOcrModel
85+
86+ engines .append (RapidOcrModel )
87+ with suppress (ImportError ):
88+ from docling .models .stages .ocr .tesseract_ocr_model import TesseractOcrModel
89+
90+ engines .append (TesseractOcrModel )
91+ with suppress (ImportError ):
92+ from docling .models .stages .ocr .tesseract_ocr_cli_model import (
93+ TesseractOcrCliModel ,
94+ )
95+
96+ engines .append (TesseractOcrCliModel )
97+
98+ return {"ocr_engines" : engines }
99+
100+
101+ def picture_description ():
102+ engines : list [
103+ type [PictureDescriptionVlmEngineModel ]
104+ | type [PictureDescriptionVlmModel ]
105+ | type [PictureDescriptionApiModel ]
106+ ] = []
107+
108+ with suppress (ImportError ):
109+ from docling .models .stages .picture_description .picture_description_vlm_engine_model import (
110+ PictureDescriptionVlmEngineModel ,
111+ )
112+
113+ engines .append (PictureDescriptionVlmEngineModel ) # New engine-based (preferred)
114+ with suppress (ImportError ):
115+ from docling .models .stages .picture_description .picture_description_vlm_model import (
116+ PictureDescriptionVlmModel ,
117+ )
118+
119+ engines .append (PictureDescriptionVlmModel ) # Legacy direct transformers
120+ with suppress (ImportError ):
121+ from docling .models .stages .picture_description .picture_description_api_model import (
122+ PictureDescriptionApiModel ,
123+ )
124+
125+ engines .append (PictureDescriptionApiModel ) # API-based
126+
127+ return {"picture_description" : engines }
128+
129+
130+ def layout_engines ():
131+ engines : list [
132+ type [LayoutObjectDetectionModel ]
133+ | type [LayoutModel ]
134+ | type [TableCropsLayoutModel ]
135+ ] = []
136+
137+ with suppress (ImportError ):
138+ from docling .models .stages .layout .layout_object_detection_model import (
139+ LayoutObjectDetectionModel ,
140+ )
141+
142+ engines .append (LayoutObjectDetectionModel )
143+ with suppress (ImportError ):
144+ from docling .models .stages .layout .layout_model import LayoutModel
145+
146+ engines .append (LayoutModel )
147+ with suppress (ImportError ):
148+ from docling .experimental .models .table_crops_layout_model import (
149+ TableCropsLayoutModel ,
150+ )
151+
152+ engines .append (TableCropsLayoutModel )
153+
154+ return {"layout_engines" : engines }
155+
156+
157+ def table_structure_engines ():
158+ engines : list [
159+ type [TableStructureModel ]
160+ | type [TableStructureModelV2 ]
161+ | type [GraniteVisionTableStructureModel ]
162+ ] = []
163+
164+ with suppress (ImportError ):
165+ from docling .models .stages .table_structure .table_structure_model import (
76166 TableStructureModel ,
167+ )
168+
169+ engines .append (TableStructureModel )
170+ with suppress (ImportError ):
171+ from docling .models .stages .table_structure .table_structure_model_v2 import (
77172 TableStructureModelV2 ,
173+ )
174+
175+ engines .append (TableStructureModelV2 )
176+ with suppress (ImportError ):
177+ from docling .models .stages .table_structure .table_structure_model_granite_vision import (
78178 GraniteVisionTableStructureModel ,
79- ]
80- }
179+ )
180+
181+ engines .append (GraniteVisionTableStructureModel )
182+
183+ return {"table_structure_engines" : engines }
0 commit comments