hfutils 0.4.2__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hfutils-0.4.2/hfutils.egg-info → hfutils-0.4.4}/PKG-INFO +22 -22
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/config/meta.py +1 -1
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/index/fetch.py +58 -42
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/repository/__init__.py +1 -0
- hfutils-0.4.4/hfutils/repository/url.py +86 -0
- {hfutils-0.4.2 → hfutils-0.4.4/hfutils.egg-info}/PKG-INFO +22 -22
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils.egg-info/SOURCES.txt +1 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/LICENSE +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/MANIFEST.in +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/README.md +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/__main__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/archive/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/archive/base.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/archive/rar.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/archive/sevenz.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/archive/tar.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/archive/zip.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/cache/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/cache/delete.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/config/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/base.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/cli.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/clone.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/dispatch.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/download.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/ils.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/index.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/ls.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/ls_repo.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/rollback.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/tree.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/upload.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/entry/whoami.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/index/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/index/hash.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/index/local_fetch.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/index/make.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/index/validate.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/operate/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/operate/base.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/operate/download.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/operate/upload.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/operate/validate.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/repository/base.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/repository/clone.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/repository/rollback.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/__init__.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/archive.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/binary.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/data.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/download.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/irregular_repo.json +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/logging.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/model.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/number.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/path.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/session.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/temp.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/tqdm_.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/type_.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils/utils/walk.py +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils.egg-info/dependency_links.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils.egg-info/entry_points.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils.egg-info/requires.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/hfutils.egg-info/top_level.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements-7z.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements-build.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements-doc.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements-rar.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements-test.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements-transfer.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/requirements.txt +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/setup.cfg +0 -0
- {hfutils-0.4.2 → hfutils-0.4.4}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hfutils
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Useful utilities for huggingface
|
|
5
5
|
Home-page: https://github.com/deepghs/hfutils
|
|
6
6
|
Author: narugo1992
|
|
@@ -30,28 +30,13 @@ Requires-Dist: natsort
|
|
|
30
30
|
Requires-Dist: urlobject
|
|
31
31
|
Requires-Dist: fsspec>=2024
|
|
32
32
|
Requires-Dist: random_user_agent
|
|
33
|
-
Provides-Extra: test
|
|
34
|
-
Requires-Dist: coverage>=5; extra == "test"
|
|
35
|
-
Requires-Dist: mock>=4.0.3; extra == "test"
|
|
36
|
-
Requires-Dist: flake8~=3.5; extra == "test"
|
|
37
|
-
Requires-Dist: testfixtures>=6.18.5; extra == "test"
|
|
38
|
-
Requires-Dist: pytest~=6.2.5; extra == "test"
|
|
39
|
-
Requires-Dist: pytest-cov~=3.0.0; extra == "test"
|
|
40
|
-
Requires-Dist: pytest-mock~=3.6.1; extra == "test"
|
|
41
|
-
Requires-Dist: pytest-xdist>=1.34.0; extra == "test"
|
|
42
|
-
Requires-Dist: pytest-rerunfailures~=10.2; extra == "test"
|
|
43
|
-
Requires-Dist: pytest-timeout~=2.0.2; extra == "test"
|
|
44
|
-
Requires-Dist: pytest-benchmark~=3.4.0; extra == "test"
|
|
45
|
-
Requires-Dist: easydict<2,>=1.7; extra == "test"
|
|
46
|
-
Requires-Dist: testtools>=2; extra == "test"
|
|
47
|
-
Requires-Dist: where>=1.0.2; extra == "test"
|
|
48
|
-
Requires-Dist: responses>=0.20.0; extra == "test"
|
|
49
|
-
Requires-Dist: natsort; extra == "test"
|
|
50
|
-
Provides-Extra: rar
|
|
51
|
-
Requires-Dist: rarfile; extra == "rar"
|
|
52
33
|
Provides-Extra: build
|
|
53
34
|
Requires-Dist: pyinstaller<5,>=4.7; extra == "build"
|
|
54
35
|
Requires-Dist: setuptools<70; extra == "build"
|
|
36
|
+
Provides-Extra: 7z
|
|
37
|
+
Requires-Dist: py7zr; extra == "7z"
|
|
38
|
+
Provides-Extra: rar
|
|
39
|
+
Requires-Dist: rarfile; extra == "rar"
|
|
55
40
|
Provides-Extra: doc
|
|
56
41
|
Requires-Dist: Jinja2>=3.0.0; extra == "doc"
|
|
57
42
|
Requires-Dist: sphinx>=3.2.0; extra == "doc"
|
|
@@ -72,10 +57,25 @@ Requires-Dist: ipykernel>=6.15; extra == "doc"
|
|
|
72
57
|
Requires-Dist: py-cpuinfo>=8.0.0; extra == "doc"
|
|
73
58
|
Requires-Dist: click>=7.0.0; extra == "doc"
|
|
74
59
|
Requires-Dist: pandas; extra == "doc"
|
|
60
|
+
Provides-Extra: test
|
|
61
|
+
Requires-Dist: coverage>=5; extra == "test"
|
|
62
|
+
Requires-Dist: mock>=4.0.3; extra == "test"
|
|
63
|
+
Requires-Dist: flake8~=3.5; extra == "test"
|
|
64
|
+
Requires-Dist: testfixtures>=6.18.5; extra == "test"
|
|
65
|
+
Requires-Dist: pytest~=6.2.5; extra == "test"
|
|
66
|
+
Requires-Dist: pytest-cov~=3.0.0; extra == "test"
|
|
67
|
+
Requires-Dist: pytest-mock~=3.6.1; extra == "test"
|
|
68
|
+
Requires-Dist: pytest-xdist>=1.34.0; extra == "test"
|
|
69
|
+
Requires-Dist: pytest-rerunfailures~=10.2; extra == "test"
|
|
70
|
+
Requires-Dist: pytest-timeout~=2.0.2; extra == "test"
|
|
71
|
+
Requires-Dist: pytest-benchmark~=3.4.0; extra == "test"
|
|
72
|
+
Requires-Dist: easydict<2,>=1.7; extra == "test"
|
|
73
|
+
Requires-Dist: testtools>=2; extra == "test"
|
|
74
|
+
Requires-Dist: where>=1.0.2; extra == "test"
|
|
75
|
+
Requires-Dist: responses>=0.20.0; extra == "test"
|
|
76
|
+
Requires-Dist: natsort; extra == "test"
|
|
75
77
|
Provides-Extra: transfer
|
|
76
78
|
Requires-Dist: hf-transfer; extra == "transfer"
|
|
77
|
-
Provides-Extra: 7z
|
|
78
|
-
Requires-Dist: py7zr; extra == "7z"
|
|
79
79
|
|
|
80
80
|
# hfutils
|
|
81
81
|
|
|
@@ -6,6 +6,7 @@ from typing import Optional, Dict, Union, List
|
|
|
6
6
|
|
|
7
7
|
from huggingface_hub.file_download import http_get, hf_hub_url
|
|
8
8
|
from huggingface_hub.utils import build_hf_headers
|
|
9
|
+
from tqdm import tqdm
|
|
9
10
|
|
|
10
11
|
from .hash import _f_sha256
|
|
11
12
|
from ..operate.base import RepoTypeTyping, get_hf_client
|
|
@@ -438,23 +439,27 @@ def hf_tar_file_download(repo_id: str, archive_in_repo: str, file_in_archive: st
|
|
|
438
439
|
idx_repo_type: Optional[RepoTypeTyping] = None, idx_revision: Optional[str] = None,
|
|
439
440
|
proxies: Optional[Dict] = None, user_agent: Union[Dict, str, None] = None,
|
|
440
441
|
headers: Optional[Dict[str, str]] = None, endpoint: Optional[str] = None,
|
|
441
|
-
force_download: bool = False, hf_token: Optional[str] = None):
|
|
442
|
+
force_download: bool = False, silent: bool = False, hf_token: Optional[str] = None):
|
|
442
443
|
"""
|
|
443
|
-
Download a file from a tar archive
|
|
444
|
+
Download a specific file from a tar archive stored in a Hugging Face repository.
|
|
444
445
|
|
|
445
|
-
|
|
446
|
+
This function allows you to extract and download a single file from a tar archive
|
|
447
|
+
that is hosted in a Hugging Face repository. It handles authentication, supports
|
|
448
|
+
different repository types, and can work with separate index repositories.
|
|
449
|
+
|
|
450
|
+
:param repo_id: The identifier of the repository containing the tar archive.
|
|
446
451
|
:type repo_id: str
|
|
447
|
-
:param archive_in_repo: The path to the archive file
|
|
452
|
+
:param archive_in_repo: The path to the tar archive file within the repository.
|
|
448
453
|
:type archive_in_repo: str
|
|
449
|
-
:param file_in_archive: The path to the file inside the archive.
|
|
454
|
+
:param file_in_archive: The path to the desired file inside the tar archive.
|
|
450
455
|
:type file_in_archive: str
|
|
451
|
-
:param local_file: The path
|
|
456
|
+
:param local_file: The local path where the downloaded file will be saved.
|
|
452
457
|
:type local_file: str
|
|
453
|
-
:param repo_type: The type of the Hugging Face repository.
|
|
458
|
+
:param repo_type: The type of the Hugging Face repository (e.g., 'dataset', 'model', 'space').
|
|
454
459
|
:type repo_type: RepoTypeTyping, optional
|
|
455
|
-
:param revision: The revision of the repository.
|
|
460
|
+
:param revision: The specific revision of the repository to use.
|
|
456
461
|
:type revision: str, optional
|
|
457
|
-
:param idx_repo_id: The identifier of
|
|
462
|
+
:param idx_repo_id: The identifier of a separate index repository, if applicable.
|
|
458
463
|
:type idx_repo_id: str, optional
|
|
459
464
|
:param idx_file_in_repo: The path to the index file in the index repository.
|
|
460
465
|
:type idx_file_in_repo: str, optional
|
|
@@ -462,48 +467,58 @@ def hf_tar_file_download(repo_id: str, archive_in_repo: str, file_in_archive: st
|
|
|
462
467
|
:type idx_repo_type: RepoTypeTyping, optional
|
|
463
468
|
:param idx_revision: The revision of the index repository.
|
|
464
469
|
:type idx_revision: str, optional
|
|
465
|
-
:param proxies:
|
|
470
|
+
:param proxies: Proxy settings for the HTTP request.
|
|
466
471
|
:type proxies: Dict, optional
|
|
467
|
-
:param user_agent:
|
|
472
|
+
:param user_agent: Custom user agent for the HTTP request.
|
|
468
473
|
:type user_agent: Union[Dict, str, None], optional
|
|
469
|
-
:param headers:
|
|
474
|
+
:param headers: Additional headers for the HTTP request.
|
|
470
475
|
:type headers: Dict[str, str], optional
|
|
471
|
-
:param endpoint:
|
|
476
|
+
:param endpoint: Custom Hugging Face API endpoint.
|
|
472
477
|
:type endpoint: str, optional
|
|
473
|
-
:param force_download:
|
|
474
|
-
Defualt to `False`, downloading will be skipped if the local file
|
|
475
|
-
is fully matched with expected file.
|
|
478
|
+
:param force_download: If True, force re-download even if the file exists locally.
|
|
476
479
|
:type force_download: bool
|
|
477
|
-
:param
|
|
480
|
+
:param silent: If True, suppress progress bar output.
|
|
481
|
+
:type silent: bool
|
|
482
|
+
:param hf_token: Hugging Face authentication token.
|
|
478
483
|
:type hf_token: str, optional
|
|
479
|
-
:raises FileNotFoundError: Raise this when file not exist in tar archive.
|
|
480
|
-
:raises ArchiveStandaloneFileIncompleteDownload: Raise when download incomplete.
|
|
481
|
-
:raises ArchiveStandaloneFileHashNotMatch: Raise when download hash not match.
|
|
482
484
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
485
|
+
:raises FileNotFoundError: If the specified file is not found in the tar archive.
|
|
486
|
+
:raises ArchiveStandaloneFileIncompleteDownload: If the download is incomplete.
|
|
487
|
+
:raises ArchiveStandaloneFileHashNotMatch: If the downloaded file's hash doesn't match the expected hash.
|
|
488
|
+
|
|
489
|
+
This function performs several steps:
|
|
490
|
+
|
|
491
|
+
1. Retrieves the index of the tar archive.
|
|
492
|
+
2. Checks if the desired file exists in the archive.
|
|
493
|
+
3. Constructs the download URL and headers.
|
|
494
|
+
4. Checks if the file already exists locally and matches the expected size and hash.
|
|
495
|
+
5. Downloads the file if necessary, using byte range requests for efficiency.
|
|
496
|
+
6. Verifies the downloaded file's size and hash.
|
|
497
|
+
|
|
498
|
+
Usage examples:
|
|
499
|
+
1. Basic usage:
|
|
500
|
+
>>> hf_tar_file_download(
|
|
501
|
+
... repo_id='deepghs/danbooru_newest',
|
|
502
|
+
... archive_in_repo='images/0000.tar',
|
|
503
|
+
... file_in_archive='7506000.jpg',
|
|
504
|
+
... local_file='test_example.jpg' # download destination
|
|
505
|
+
... )
|
|
506
|
+
|
|
507
|
+
2. Using a separate index repository:
|
|
508
|
+
>>> hf_tar_file_download(
|
|
509
|
+
... repo_id='nyanko7/danbooru2023',
|
|
510
|
+
... idx_repo_id='deepghs/danbooru2023_index',
|
|
511
|
+
... archive_in_repo='original/data-0000.tar',
|
|
512
|
+
... file_in_archive='1000.png',
|
|
513
|
+
... local_file='test_example.png' # download destination
|
|
514
|
+
... )
|
|
492
515
|
|
|
493
516
|
.. note::
|
|
494
517
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
>>>
|
|
500
|
-
>>> hf_tar_file_download(
|
|
501
|
-
... repo_id='nyanko7/danbooru2023',
|
|
502
|
-
... idx_repo_id='deepghs/danbooru2023_index',
|
|
503
|
-
... archive_in_repo='original/data-0000.tar',
|
|
504
|
-
... file_in_archive='1000.png',
|
|
505
|
-
... local_file='test_example.png' # download destination
|
|
506
|
-
... )
|
|
518
|
+
- This function is particularly useful for efficiently downloading single files from large tar archives
|
|
519
|
+
without having to download the entire archive.
|
|
520
|
+
- It supports authentication via the `hf_token` parameter, which is crucial for accessing private repositories.
|
|
521
|
+
- The function includes checks to avoid unnecessary downloads and to ensure the integrity of the downloaded file.
|
|
507
522
|
"""
|
|
508
523
|
index = hf_tar_get_index(
|
|
509
524
|
repo_id=repo_id,
|
|
@@ -547,7 +562,7 @@ def hf_tar_file_download(repo_id: str, archive_in_repo: str, file_in_archive: st
|
|
|
547
562
|
if os.path.dirname(local_file):
|
|
548
563
|
os.makedirs(os.path.dirname(local_file), exist_ok=True)
|
|
549
564
|
try:
|
|
550
|
-
with open(local_file, 'wb') as f:
|
|
565
|
+
with open(local_file, 'wb') as f, tqdm(disable=True) as empty_tqdm:
|
|
551
566
|
if info['size'] > 0:
|
|
552
567
|
http_get(
|
|
553
568
|
url_to_download,
|
|
@@ -557,6 +572,7 @@ def hf_tar_file_download(repo_id: str, archive_in_repo: str, file_in_archive: st
|
|
|
557
572
|
headers=headers,
|
|
558
573
|
expected_size=info['size'],
|
|
559
574
|
displayed_filename=file_in_archive,
|
|
575
|
+
_tqdm_bar=empty_tqdm if silent else None,
|
|
560
576
|
)
|
|
561
577
|
|
|
562
578
|
if os.path.getsize(local_file) != info['size']:
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides functions for generating URLs related to Hugging Face Hub repositories.
|
|
3
|
+
|
|
4
|
+
It includes functions to create URLs for repository paths and files, which can be useful
|
|
5
|
+
for accessing and referencing resources within Hugging Face Hub repositories.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Optional
|
|
9
|
+
from urllib.parse import quote_plus, urljoin
|
|
10
|
+
|
|
11
|
+
from .base import hf_hub_repo_url
|
|
12
|
+
from ..utils.path import RepoTypeTyping, hf_normpath
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def hf_hub_repo_path_url(repo_id: str, path: str, repo_type: RepoTypeTyping = 'dataset',
|
|
16
|
+
revision: str = 'main', endpoint: Optional[str] = None) -> str:
|
|
17
|
+
"""
|
|
18
|
+
Generate the URL for a path within a Hugging Face Hub repository.
|
|
19
|
+
|
|
20
|
+
This function constructs a URL that points to a specific path within a Hugging Face Hub repository.
|
|
21
|
+
It's useful for creating links to directories or files in the repository's web interface.
|
|
22
|
+
|
|
23
|
+
:param repo_id: The repository ID (e.g., 'username/repo-name').
|
|
24
|
+
:type repo_id: str
|
|
25
|
+
:param path: The path within the repository to generate the URL for.
|
|
26
|
+
:type path: str
|
|
27
|
+
:param repo_type: The type of the repository. Defaults to 'dataset'.
|
|
28
|
+
:type repo_type: RepoTypeTyping, optional
|
|
29
|
+
:param revision: The revision (branch, tag, or commit) to use. Defaults to 'main'.
|
|
30
|
+
:type revision: str, optional
|
|
31
|
+
:param endpoint: The API endpoint to use. If None, the default endpoint will be used.
|
|
32
|
+
:type endpoint: str, optional
|
|
33
|
+
|
|
34
|
+
:return: The URL for the specified path in the Hugging Face Hub repository.
|
|
35
|
+
:rtype: str
|
|
36
|
+
|
|
37
|
+
:example:
|
|
38
|
+
>>> url = hf_hub_repo_path_url('username/my-dataset', 'data/train.csv')
|
|
39
|
+
>>> print(url)
|
|
40
|
+
https://huggingface.co/datasets/username/my-dataset/tree/main/data/train.csv
|
|
41
|
+
"""
|
|
42
|
+
repo_url = hf_hub_repo_url(
|
|
43
|
+
repo_id=repo_id,
|
|
44
|
+
repo_type=repo_type,
|
|
45
|
+
endpoint=endpoint,
|
|
46
|
+
)
|
|
47
|
+
return urljoin(repo_url + '/', hf_normpath(f'tree/{quote_plus(revision)}/{hf_normpath(path)}'))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def hf_hub_repo_file_url(repo_id: str, path: str, repo_type: RepoTypeTyping = 'dataset',
|
|
51
|
+
revision: str = 'main', endpoint: Optional[str] = None) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Generate the URL for a file within a Hugging Face Hub repository.
|
|
54
|
+
|
|
55
|
+
This function constructs a URL that points to a specific file within a Hugging Face Hub repository.
|
|
56
|
+
It's useful for creating links to view files in the repository's web interface.
|
|
57
|
+
|
|
58
|
+
:param repo_id: The repository ID (e.g., 'username/repo-name').
|
|
59
|
+
:type repo_id: str
|
|
60
|
+
:param path: The path to the file within the repository.
|
|
61
|
+
:type path: str
|
|
62
|
+
:param repo_type: The type of the repository. Defaults to 'dataset'.
|
|
63
|
+
:type repo_type: RepoTypeTyping, optional
|
|
64
|
+
:param revision: The revision (branch, tag, or commit) to use. Defaults to 'main'.
|
|
65
|
+
:type revision: str, optional
|
|
66
|
+
:param endpoint: The API endpoint to use. If None, the default endpoint will be used.
|
|
67
|
+
:type endpoint: str, optional
|
|
68
|
+
|
|
69
|
+
:return: The URL for the specified file in the Hugging Face Hub repository.
|
|
70
|
+
:rtype: str
|
|
71
|
+
|
|
72
|
+
:example:
|
|
73
|
+
>>> url = hf_hub_repo_file_url('username/my-model', 'config.json')
|
|
74
|
+
>>> print(url)
|
|
75
|
+
https://huggingface.co/username/my-model/blob/main/config.json
|
|
76
|
+
|
|
77
|
+
.. note::
|
|
78
|
+
This is not the downloadable URL of the file in the repository.
|
|
79
|
+
For downloading URLs, use :func:`huggingface_hub.hf_hub_url`.
|
|
80
|
+
"""
|
|
81
|
+
repo_url = hf_hub_repo_url(
|
|
82
|
+
repo_id=repo_id,
|
|
83
|
+
repo_type=repo_type,
|
|
84
|
+
endpoint=endpoint,
|
|
85
|
+
)
|
|
86
|
+
return urljoin(repo_url + '/', hf_normpath(f'blob/{quote_plus(revision)}/{hf_normpath(path)}'))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hfutils
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Useful utilities for huggingface
|
|
5
5
|
Home-page: https://github.com/deepghs/hfutils
|
|
6
6
|
Author: narugo1992
|
|
@@ -30,28 +30,13 @@ Requires-Dist: natsort
|
|
|
30
30
|
Requires-Dist: urlobject
|
|
31
31
|
Requires-Dist: fsspec>=2024
|
|
32
32
|
Requires-Dist: random_user_agent
|
|
33
|
-
Provides-Extra: test
|
|
34
|
-
Requires-Dist: coverage>=5; extra == "test"
|
|
35
|
-
Requires-Dist: mock>=4.0.3; extra == "test"
|
|
36
|
-
Requires-Dist: flake8~=3.5; extra == "test"
|
|
37
|
-
Requires-Dist: testfixtures>=6.18.5; extra == "test"
|
|
38
|
-
Requires-Dist: pytest~=6.2.5; extra == "test"
|
|
39
|
-
Requires-Dist: pytest-cov~=3.0.0; extra == "test"
|
|
40
|
-
Requires-Dist: pytest-mock~=3.6.1; extra == "test"
|
|
41
|
-
Requires-Dist: pytest-xdist>=1.34.0; extra == "test"
|
|
42
|
-
Requires-Dist: pytest-rerunfailures~=10.2; extra == "test"
|
|
43
|
-
Requires-Dist: pytest-timeout~=2.0.2; extra == "test"
|
|
44
|
-
Requires-Dist: pytest-benchmark~=3.4.0; extra == "test"
|
|
45
|
-
Requires-Dist: easydict<2,>=1.7; extra == "test"
|
|
46
|
-
Requires-Dist: testtools>=2; extra == "test"
|
|
47
|
-
Requires-Dist: where>=1.0.2; extra == "test"
|
|
48
|
-
Requires-Dist: responses>=0.20.0; extra == "test"
|
|
49
|
-
Requires-Dist: natsort; extra == "test"
|
|
50
|
-
Provides-Extra: rar
|
|
51
|
-
Requires-Dist: rarfile; extra == "rar"
|
|
52
33
|
Provides-Extra: build
|
|
53
34
|
Requires-Dist: pyinstaller<5,>=4.7; extra == "build"
|
|
54
35
|
Requires-Dist: setuptools<70; extra == "build"
|
|
36
|
+
Provides-Extra: 7z
|
|
37
|
+
Requires-Dist: py7zr; extra == "7z"
|
|
38
|
+
Provides-Extra: rar
|
|
39
|
+
Requires-Dist: rarfile; extra == "rar"
|
|
55
40
|
Provides-Extra: doc
|
|
56
41
|
Requires-Dist: Jinja2>=3.0.0; extra == "doc"
|
|
57
42
|
Requires-Dist: sphinx>=3.2.0; extra == "doc"
|
|
@@ -72,10 +57,25 @@ Requires-Dist: ipykernel>=6.15; extra == "doc"
|
|
|
72
57
|
Requires-Dist: py-cpuinfo>=8.0.0; extra == "doc"
|
|
73
58
|
Requires-Dist: click>=7.0.0; extra == "doc"
|
|
74
59
|
Requires-Dist: pandas; extra == "doc"
|
|
60
|
+
Provides-Extra: test
|
|
61
|
+
Requires-Dist: coverage>=5; extra == "test"
|
|
62
|
+
Requires-Dist: mock>=4.0.3; extra == "test"
|
|
63
|
+
Requires-Dist: flake8~=3.5; extra == "test"
|
|
64
|
+
Requires-Dist: testfixtures>=6.18.5; extra == "test"
|
|
65
|
+
Requires-Dist: pytest~=6.2.5; extra == "test"
|
|
66
|
+
Requires-Dist: pytest-cov~=3.0.0; extra == "test"
|
|
67
|
+
Requires-Dist: pytest-mock~=3.6.1; extra == "test"
|
|
68
|
+
Requires-Dist: pytest-xdist>=1.34.0; extra == "test"
|
|
69
|
+
Requires-Dist: pytest-rerunfailures~=10.2; extra == "test"
|
|
70
|
+
Requires-Dist: pytest-timeout~=2.0.2; extra == "test"
|
|
71
|
+
Requires-Dist: pytest-benchmark~=3.4.0; extra == "test"
|
|
72
|
+
Requires-Dist: easydict<2,>=1.7; extra == "test"
|
|
73
|
+
Requires-Dist: testtools>=2; extra == "test"
|
|
74
|
+
Requires-Dist: where>=1.0.2; extra == "test"
|
|
75
|
+
Requires-Dist: responses>=0.20.0; extra == "test"
|
|
76
|
+
Requires-Dist: natsort; extra == "test"
|
|
75
77
|
Provides-Extra: transfer
|
|
76
78
|
Requires-Dist: hf-transfer; extra == "transfer"
|
|
77
|
-
Provides-Extra: 7z
|
|
78
|
-
Requires-Dist: py7zr; extra == "7z"
|
|
79
79
|
|
|
80
80
|
# hfutils
|
|
81
81
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|