Skip to content

Commit d045ae1

Browse files
nik875claude
andauthored
Update to support huggingface-hub 1.3.5 (#2036)
- Update huggingface-hub dependency to support versions up to 2.0.0 - Migrate from deprecated Repository class to HfApi.upload_folder() - Remove deprecated get_token_permission and write_permission parameters - Use HTTP-based upload instead of git-based workflow Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 96d8ed7 commit d045ae1

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

doctr/models/factory/hub.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import logging
1010
import os
1111
import subprocess
12+
import tempfile
1213
import textwrap
1314
from pathlib import Path
1415
from typing import Any
1516

1617
import torch
1718
from huggingface_hub import (
1819
HfApi,
19-
Repository,
2020
get_token,
21-
get_token_permission,
2221
hf_hub_download,
2322
login,
2423
)
@@ -38,9 +37,9 @@
3837
def login_to_hub() -> None: # pragma: no cover
3938
"""Login to huggingface hub"""
4039
access_token = get_token()
41-
if access_token is not None and get_token_permission(access_token):
40+
if access_token is not None:
4241
logging.info("Huggingface Hub token found and valid")
43-
login(token=access_token, write_permission=True)
42+
login(token=access_token)
4443
else:
4544
login()
4645
# check if git lfs is installed
@@ -161,16 +160,23 @@ def push_to_hf_hub(model: Any, model_name: str, task: str, **kwargs) -> None: #
161160

162161
commit_message = f"Add {model_name} model"
163162

164-
local_cache_dir = os.path.join(os.path.expanduser("~"), ".cache", "huggingface", "hub", model_name)
165-
repo_url = HfApi().create_repo(model_name, token=get_token(), exist_ok=False)
166-
repo = Repository(local_dir=local_cache_dir, clone_from=repo_url)
163+
# Create repository
164+
api = HfApi()
165+
api.create_repo(model_name, token=get_token(), exist_ok=False)
167166

168-
with repo.commit(commit_message):
169-
_save_model_and_config_for_hf_hub(model, repo.local_dir, arch=arch, task=task)
170-
readme_path = Path(repo.local_dir) / "README.md"
167+
# Save model files to a temporary directory
168+
with tempfile.TemporaryDirectory() as tmp_dir:
169+
_save_model_and_config_for_hf_hub(model, tmp_dir, arch=arch, task=task)
170+
readme_path = Path(tmp_dir) / "README.md"
171171
readme_path.write_text(readme)
172172

173-
repo.git_push()
173+
# Upload all files to the hub
174+
api.upload_folder(
175+
folder_path=tmp_dir,
176+
repo_id=model_name,
177+
commit_message=commit_message,
178+
token=get_token(),
179+
)
174180

175181

176182
def from_hub(repo_id: str, **kwargs: Any):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies = [
4646
"shapely>=1.6.0,<3.0.0",
4747
"langdetect>=1.0.9,<2.0.0",
4848
"rapidfuzz>=3.0.0,<4.0.0",
49-
"huggingface-hub>=0.20.0,<1.0.0",
49+
"huggingface-hub>=0.20.0,<2.0.0",
5050
"Pillow>=9.2.0",
5151
"defusedxml>=0.7.0",
5252
"anyascii>=0.3.2",

0 commit comments

Comments
 (0)