Initializes the CodeFormulaModel with the given configuration. Parameters ---------- enabled : bool True if the model is enabled, False otherwise. artifacts_path : Path Path to the directory containing the model artifacts. opt
(
self,
enabled: bool,
artifacts_path: Optional[Path],
options: CodeFormulaModelOptions,
accelerator_options: AcceleratorOptions,
)
| 68 | expansion_factor = 0.03 |
| 69 | |
| 70 | def __init__( |
| 71 | self, |
| 72 | enabled: bool, |
| 73 | artifacts_path: Optional[Path], |
| 74 | options: CodeFormulaModelOptions, |
| 75 | accelerator_options: AcceleratorOptions, |
| 76 | ): |
| 77 | """ |
| 78 | Initializes the CodeFormulaModel with the given configuration. |
| 79 | |
| 80 | Parameters |
| 81 | ---------- |
| 82 | enabled : bool |
| 83 | True if the model is enabled, False otherwise. |
| 84 | artifacts_path : Path |
| 85 | Path to the directory containing the model artifacts. |
| 86 | options : CodeFormulaModelOptions |
| 87 | Configuration options for the model. |
| 88 | accelerator_options : AcceleratorOptions |
| 89 | Options specifying the device and number of threads for acceleration. |
| 90 | """ |
| 91 | self.enabled = enabled |
| 92 | self.options = options |
| 93 | |
| 94 | if self.enabled: |
| 95 | device = decide_device(accelerator_options.device) |
| 96 | |
| 97 | from docling_ibm_models.code_formula_model.code_formula_predictor import ( |
| 98 | CodeFormulaPredictor, |
| 99 | ) |
| 100 | |
| 101 | if artifacts_path is None: |
| 102 | artifacts_path = self.download_models() |
| 103 | else: |
| 104 | artifacts_path = artifacts_path / self._model_repo_folder |
| 105 | |
| 106 | self.code_formula_model = CodeFormulaPredictor( |
| 107 | artifacts_path=str(artifacts_path), |
| 108 | device=device, |
| 109 | num_threads=accelerator_options.num_threads, |
| 110 | ) |
| 111 | |
| 112 | @staticmethod |
| 113 | def download_models( |
nothing calls this directly
no test coverage detected