From 0ba08adb2647ef1960ad568de03901dc5120c3df Mon Sep 17 00:00:00 2001 From: Michele Dolfi Date: Wed, 5 Feb 2025 17:04:54 +0100 Subject: [PATCH] rename download methods and deprecation warnings Signed-off-by: Michele Dolfi --- docling/cli/models_download.py | 8 ++++---- docling/models/code_formula_model.py | 4 ++-- docling/models/document_picture_classifier.py | 4 ++-- docling/models/layout_model.py | 4 ++-- docling/models/table_structure_model.py | 4 ++-- docling/pipeline/standard_pdf_pipeline.py | 16 ++++++++++++---- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/docling/cli/models_download.py b/docling/cli/models_download.py index 3250d36d..c5c4d37b 100644 --- a/docling/cli/models_download.py +++ b/docling/cli/models_download.py @@ -93,7 +93,7 @@ def download( if layout: if not quite: typer.secho(f"Downloading layout model...", fg="blue") - LayoutModel.download_models_hf( + LayoutModel.download_models( local_dir=output_dir / LayoutModel._model_repo_folder, force=force, progress=show_progress, @@ -102,7 +102,7 @@ def download( if tableformer: if not quite: typer.secho(f"Downloading tableformer model...", fg="blue") - TableStructureModel.download_models_hf( + TableStructureModel.download_models( local_dir=output_dir / TableStructureModel._model_repo_folder, force=force, progress=show_progress, @@ -111,7 +111,7 @@ def download( if picture_classifier: if not quite: typer.secho(f"Downloading picture classifier model...", fg="blue") - DocumentPictureClassifier.download_models_hf( + DocumentPictureClassifier.download_models( local_dir=output_dir / DocumentPictureClassifier._model_repo_folder, force=force, progress=show_progress, @@ -120,7 +120,7 @@ def download( if code_formula: if not quite: typer.secho(f"Downloading code formula model...", fg="blue") - CodeFormulaModel.download_models_hf( + CodeFormulaModel.download_models( local_dir=output_dir / CodeFormulaModel._model_repo_folder, force=force, progress=show_progress, diff --git a/docling/models/code_formula_model.py b/docling/models/code_formula_model.py index 5906775f..b54f8ac4 100644 --- a/docling/models/code_formula_model.py +++ b/docling/models/code_formula_model.py @@ -97,7 +97,7 @@ class CodeFormulaModel(BaseItemAndImageEnrichmentModel): ) if artifacts_path is None: - artifacts_path = self.download_models_hf() + artifacts_path = self.download_models() else: artifacts_path = artifacts_path / self._model_repo_folder @@ -108,7 +108,7 @@ class CodeFormulaModel(BaseItemAndImageEnrichmentModel): ) @staticmethod - def download_models_hf( + def download_models( local_dir: Optional[Path] = None, force: bool = False, progress: bool = False, diff --git a/docling/models/document_picture_classifier.py b/docling/models/document_picture_classifier.py index 0e6fd95d..5e9b3995 100644 --- a/docling/models/document_picture_classifier.py +++ b/docling/models/document_picture_classifier.py @@ -89,7 +89,7 @@ class DocumentPictureClassifier(BaseEnrichmentModel): ) if artifacts_path is None: - artifacts_path = self.download_models_hf() + artifacts_path = self.download_models() else: artifacts_path = artifacts_path / self._model_repo_folder @@ -100,7 +100,7 @@ class DocumentPictureClassifier(BaseEnrichmentModel): ) @staticmethod - def download_models_hf( + def download_models( local_dir: Optional[Path] = None, force: bool = False, progress: bool = False ) -> Path: from huggingface_hub import snapshot_download diff --git a/docling/models/layout_model.py b/docling/models/layout_model.py index df74eb6d..56890c59 100644 --- a/docling/models/layout_model.py +++ b/docling/models/layout_model.py @@ -51,7 +51,7 @@ class LayoutModel(BasePageModel): device = decide_device(accelerator_options.device) if artifacts_path is None: - artifacts_path = self.download_models_hf() / self._model_path + artifacts_path = self.download_models() / self._model_path else: # will become the default in the future if (artifacts_path / self._model_repo_folder).exists(): @@ -76,7 +76,7 @@ class LayoutModel(BasePageModel): ) @staticmethod - def download_models_hf( + def download_models( local_dir: Optional[Path] = None, force: bool = False, progress: bool = False, diff --git a/docling/models/table_structure_model.py b/docling/models/table_structure_model.py index b02f5cfd..b5ab5a2a 100644 --- a/docling/models/table_structure_model.py +++ b/docling/models/table_structure_model.py @@ -41,7 +41,7 @@ class TableStructureModel(BasePageModel): if self.enabled: if artifacts_path is None: - artifacts_path = self.download_models_hf() / self._model_path + artifacts_path = self.download_models() / self._model_path else: # will become the default in the future if (artifacts_path / self._model_repo_folder).exists(): @@ -83,7 +83,7 @@ class TableStructureModel(BasePageModel): self.scale = 2.0 # Scale up table input images to 144 dpi @staticmethod - def download_models_hf( + def download_models( local_dir: Optional[Path] = None, force: bool = False, progress: bool = False ) -> Path: from huggingface_hub import snapshot_download diff --git a/docling/pipeline/standard_pdf_pipeline.py b/docling/pipeline/standard_pdf_pipeline.py index f06bf5c6..8eb2866f 100644 --- a/docling/pipeline/standard_pdf_pipeline.py +++ b/docling/pipeline/standard_pdf_pipeline.py @@ -1,5 +1,6 @@ import logging import sys +import warnings from pathlib import Path from typing import Optional @@ -125,6 +126,13 @@ class StandardPdfPipeline(PaginatedPipeline): def download_models_hf( local_dir: Optional[Path] = None, force: bool = False ) -> Path: + warnings.warn( + "The usage of StandardPdfPipeline.download_models_hf() is deprecated " + "use instead the utility `docling-tools models download`, or " + "the upstream method in docling.utils.", + DeprecationWarning, + stacklevel=3, + ) if local_dir is None: local_dir = settings.cache_dir / "models" @@ -133,17 +141,17 @@ class StandardPdfPipeline(PaginatedPipeline): local_dir.mkdir(exist_ok=True, parents=True) # Download model weights - LayoutModel.download_models_hf( + LayoutModel.download_models( local_dir=local_dir / LayoutModel._model_repo_folder, force=force ) - TableStructureModel.download_models_hf( + TableStructureModel.download_models( local_dir=local_dir / TableStructureModel._model_repo_folder, force=force ) - DocumentPictureClassifier.download_models_hf( + DocumentPictureClassifier.download_models( local_dir=local_dir / DocumentPictureClassifier._model_repo_folder, force=force, ) - CodeFormulaModel.download_models_hf( + CodeFormulaModel.download_models( local_dir=local_dir / CodeFormulaModel._model_repo_folder, force=force )