Skip to content

Commit

Permalink
feat: allow artifacts_path to be defined as ENV (#940)
Browse files Browse the repository at this point in the history
* allow the artifacts_path to be defined as ENV

Signed-off-by: Michele Dolfi <[email protected]>

* add check if artifacts_path exists and is dir

Signed-off-by: Michele Dolfi <[email protected]>

---------

Signed-off-by: Michele Dolfi <[email protected]>
  • Loading branch information
dolfim-ibm authored Feb 12, 2025
1 parent c47ae70 commit 5101e25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docling/datamodel/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from pathlib import Path
from typing import Annotated, Tuple
from typing import Annotated, Optional, Tuple

from pydantic import BaseModel, PlainValidator
from pydantic_settings import BaseSettings, SettingsConfigDict
Expand Down Expand Up @@ -62,6 +62,7 @@ class AppSettings(BaseSettings):
debug: DebugSettings

cache_dir: Path = Path.home() / ".cache" / "docling"
artifacts_path: Optional[Path] = None


settings = AppSettings(perf=BatchConcurrencySettings(), debug=DebugSettings())
8 changes: 8 additions & 0 deletions docling/pipeline/standard_pdf_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def __init__(self, pipeline_options: PdfPipelineOptions):
artifacts_path: Optional[Path] = None
if pipeline_options.artifacts_path is not None:
artifacts_path = Path(pipeline_options.artifacts_path).expanduser()
elif settings.artifacts_path is not None:
artifacts_path = Path(settings.artifacts_path).expanduser()

if artifacts_path is not None and not artifacts_path.is_dir():
raise RuntimeError(
f"The value of {artifacts_path=} is not valid. "
"When defined, it must point to a folder containing all models required by the pipeline."
)

self.keep_images = (
self.pipeline_options.generate_page_images
Expand Down

0 comments on commit 5101e25

Please sign in to comment.