Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of local vlm folder support #1051

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions docling/models/picture_description_vlm_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from typing import Iterable, Optional, Union

import os
from PIL import Image

from docling.datamodel.pipeline_options import (
Expand Down Expand Up @@ -59,18 +59,24 @@ def download_models(
force: bool = False,
progress: bool = False,
) -> Path:
from huggingface_hub import snapshot_download
from huggingface_hub.utils import disable_progress_bars

if not progress:
disable_progress_bars()
download_path = snapshot_download(
repo_id=repo_id,
force_download=force,
local_dir=local_dir,
)

return Path(download_path)
# Check if repo_id is a local path and exists
if os.path.exists(repo_id):
# If it exists, return the path directly
return Path(repo_id)
else:
# If it doesn't exist, download the repository
from huggingface_hub import snapshot_download
from huggingface_hub.utils import disable_progress_bars

if not progress:
disable_progress_bars()
download_path = snapshot_download(
repo_id=repo_id,
force_download=force,
local_dir=local_dir,
)

return Path(download_path)

def _annotate_images(self, images: Iterable[Image.Image]) -> Iterable[str]:
from transformers import GenerationConfig
Expand Down