huggingface-hub 0.26.3__py3-none-any.whl → 0.27.0rc0__py3-none-any.whl
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.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +49 -23
- huggingface_hub/_commit_scheduler.py +30 -4
- huggingface_hub/_local_folder.py +0 -4
- huggingface_hub/_login.py +38 -54
- huggingface_hub/_snapshot_download.py +6 -3
- huggingface_hub/_tensorboard_logger.py +2 -3
- huggingface_hub/_upload_large_folder.py +1 -1
- huggingface_hub/errors.py +19 -0
- huggingface_hub/fastai_utils.py +3 -2
- huggingface_hub/file_download.py +10 -12
- huggingface_hub/hf_api.py +102 -498
- huggingface_hub/hf_file_system.py +274 -35
- huggingface_hub/hub_mixin.py +5 -25
- huggingface_hub/inference/_client.py +185 -136
- huggingface_hub/inference/_common.py +2 -2
- huggingface_hub/inference/_generated/_async_client.py +186 -137
- huggingface_hub/inference/_generated/types/__init__.py +31 -10
- huggingface_hub/inference/_generated/types/audio_classification.py +3 -5
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +4 -8
- huggingface_hub/inference/_generated/types/chat_completion.py +8 -5
- huggingface_hub/inference/_generated/types/depth_estimation.py +1 -1
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -6
- huggingface_hub/inference/_generated/types/feature_extraction.py +1 -1
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -4
- huggingface_hub/inference/_generated/types/image_classification.py +3 -5
- huggingface_hub/inference/_generated/types/image_segmentation.py +2 -4
- huggingface_hub/inference/_generated/types/image_to_image.py +2 -4
- huggingface_hub/inference/_generated/types/image_to_text.py +4 -8
- huggingface_hub/inference/_generated/types/object_detection.py +2 -4
- huggingface_hub/inference/_generated/types/question_answering.py +2 -4
- huggingface_hub/inference/_generated/types/sentence_similarity.py +1 -1
- huggingface_hub/inference/_generated/types/summarization.py +2 -4
- huggingface_hub/inference/_generated/types/table_question_answering.py +21 -3
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -4
- huggingface_hub/inference/_generated/types/text_classification.py +4 -10
- huggingface_hub/inference/_generated/types/text_to_audio.py +6 -10
- huggingface_hub/inference/_generated/types/text_to_image.py +2 -4
- huggingface_hub/inference/_generated/types/text_to_speech.py +6 -10
- huggingface_hub/inference/_generated/types/token_classification.py +11 -12
- huggingface_hub/inference/_generated/types/translation.py +2 -4
- huggingface_hub/inference/_generated/types/video_classification.py +3 -4
- huggingface_hub/inference/_generated/types/visual_question_answering.py +2 -5
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +8 -18
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +9 -19
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +7 -9
- huggingface_hub/keras_mixin.py +3 -2
- huggingface_hub/lfs.py +2 -5
- huggingface_hub/repocard_data.py +4 -4
- huggingface_hub/serialization/__init__.py +2 -0
- huggingface_hub/serialization/_dduf.py +387 -0
- huggingface_hub/serialization/_torch.py +407 -25
- huggingface_hub/utils/_cache_manager.py +1 -1
- huggingface_hub/utils/_headers.py +9 -25
- huggingface_hub/utils/tqdm.py +15 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.27.0rc0.dist-info}/METADATA +8 -3
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.27.0rc0.dist-info}/RECORD +60 -60
- huggingface_hub/_multi_commits.py +0 -306
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.27.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.27.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.27.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.27.0rc0.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import inspect
|
|
2
1
|
import os
|
|
3
2
|
import re
|
|
4
3
|
import tempfile
|
|
@@ -7,7 +6,7 @@ from dataclasses import dataclass, field
|
|
|
7
6
|
from datetime import datetime
|
|
8
7
|
from itertools import chain
|
|
9
8
|
from pathlib import Path
|
|
10
|
-
from typing import Any, Dict, List, NoReturn, Optional, Tuple, Union
|
|
9
|
+
from typing import Any, Dict, Iterator, List, NoReturn, Optional, Tuple, Union
|
|
11
10
|
from urllib.parse import quote, unquote
|
|
12
11
|
|
|
13
12
|
import fsspec
|
|
@@ -20,11 +19,7 @@ from ._commit_api import CommitOperationCopy, CommitOperationDelete
|
|
|
20
19
|
from .errors import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError
|
|
21
20
|
from .file_download import hf_hub_url, http_get
|
|
22
21
|
from .hf_api import HfApi, LastCommitInfo, RepoFile
|
|
23
|
-
from .utils import
|
|
24
|
-
HFValidationError,
|
|
25
|
-
hf_raise_for_status,
|
|
26
|
-
http_backoff,
|
|
27
|
-
)
|
|
22
|
+
from .utils import HFValidationError, hf_raise_for_status, http_backoff
|
|
28
23
|
|
|
29
24
|
|
|
30
25
|
# Regex used to match special revisions with "/" in them (see #1710)
|
|
@@ -64,13 +59,22 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
64
59
|
"""
|
|
65
60
|
Access a remote Hugging Face Hub repository as if were a local file system.
|
|
66
61
|
|
|
62
|
+
<Tip warning={true}>
|
|
63
|
+
|
|
64
|
+
[`HfFileSystem`] provides fsspec compatibility, which is useful for libraries that require it (e.g., reading
|
|
65
|
+
Hugging Face datasets directly with `pandas`). However, it introduces additional overhead due to this compatibility
|
|
66
|
+
layer. For better performance and reliability, it's recommended to use `HfApi` methods when possible.
|
|
67
|
+
|
|
68
|
+
</Tip>
|
|
69
|
+
|
|
67
70
|
Args:
|
|
68
71
|
token (`str` or `bool`, *optional*):
|
|
69
72
|
A valid user access token (string). Defaults to the locally saved
|
|
70
73
|
token, which is the recommended method for authentication (see
|
|
71
74
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
72
75
|
To disable authentication, pass `False`.
|
|
73
|
-
|
|
76
|
+
endpoint (`str`, *optional*):
|
|
77
|
+
Endpoint of the Hub. Defaults to <https://huggingface.co>.
|
|
74
78
|
Usage:
|
|
75
79
|
|
|
76
80
|
```python
|
|
@@ -133,6 +137,25 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
133
137
|
return self._repo_and_revision_exists_cache[(repo_type, repo_id, revision)]
|
|
134
138
|
|
|
135
139
|
def resolve_path(self, path: str, revision: Optional[str] = None) -> HfFileSystemResolvedPath:
|
|
140
|
+
"""
|
|
141
|
+
Resolve a Hugging Face file system path into its components.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
path (`str`):
|
|
145
|
+
Path to resolve.
|
|
146
|
+
revision (`str`, *optional*):
|
|
147
|
+
The revision of the repo to resolve. Defaults to the revision specified in the path.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
[`HfFileSystemResolvedPath`]: Resolved path information containing `repo_type`, `repo_id`, `revision` and `path_in_repo`.
|
|
151
|
+
|
|
152
|
+
Raises:
|
|
153
|
+
`ValueError`:
|
|
154
|
+
If path contains conflicting revision information.
|
|
155
|
+
`NotImplementedError`:
|
|
156
|
+
If trying to list repositories.
|
|
157
|
+
"""
|
|
158
|
+
|
|
136
159
|
def _align_revision_in_path_with_revision(
|
|
137
160
|
revision_in_path: Optional[str], revision: Optional[str]
|
|
138
161
|
) -> Optional[str]:
|
|
@@ -209,15 +232,33 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
209
232
|
return HfFileSystemResolvedPath(repo_type, repo_id, revision, path_in_repo, _raw_revision=revision_in_path)
|
|
210
233
|
|
|
211
234
|
def invalidate_cache(self, path: Optional[str] = None) -> None:
|
|
235
|
+
"""
|
|
236
|
+
Clear the cache for a given path.
|
|
237
|
+
|
|
238
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.invalidate_cache).
|
|
239
|
+
|
|
240
|
+
Args:
|
|
241
|
+
path (`str`, *optional*):
|
|
242
|
+
Path to clear from cache. If not provided, clear the entire cache.
|
|
243
|
+
|
|
244
|
+
"""
|
|
212
245
|
if not path:
|
|
213
246
|
self.dircache.clear()
|
|
214
247
|
self._repo_and_revision_exists_cache.clear()
|
|
215
248
|
else:
|
|
216
|
-
|
|
249
|
+
resolved_path = self.resolve_path(path)
|
|
250
|
+
path = resolved_path.unresolve()
|
|
217
251
|
while path:
|
|
218
252
|
self.dircache.pop(path, None)
|
|
219
253
|
path = self._parent(path)
|
|
220
254
|
|
|
255
|
+
# Only clear repo cache if path is to repo root
|
|
256
|
+
if not resolved_path.path_in_repo:
|
|
257
|
+
self._repo_and_revision_exists_cache.pop((resolved_path.repo_type, resolved_path.repo_id, None), None)
|
|
258
|
+
self._repo_and_revision_exists_cache.pop(
|
|
259
|
+
(resolved_path.repo_type, resolved_path.repo_id, resolved_path.revision), None
|
|
260
|
+
)
|
|
261
|
+
|
|
221
262
|
def _open(
|
|
222
263
|
self,
|
|
223
264
|
path: str,
|
|
@@ -254,6 +295,28 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
254
295
|
revision: Optional[str] = None,
|
|
255
296
|
**kwargs,
|
|
256
297
|
) -> None:
|
|
298
|
+
"""
|
|
299
|
+
Delete files from a repository.
|
|
300
|
+
|
|
301
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.rm).
|
|
302
|
+
|
|
303
|
+
<Tip warning={true}>
|
|
304
|
+
|
|
305
|
+
Note: When possible, use `HfApi.delete_file()` for better performance.
|
|
306
|
+
|
|
307
|
+
</Tip>
|
|
308
|
+
|
|
309
|
+
Args:
|
|
310
|
+
path (`str`):
|
|
311
|
+
Path to delete.
|
|
312
|
+
recursive (`bool`, *optional*):
|
|
313
|
+
If True, delete directory and all its contents. Defaults to False.
|
|
314
|
+
maxdepth (`int`, *optional*):
|
|
315
|
+
Maximum number of subdirectories to visit when deleting recursively.
|
|
316
|
+
revision (`str`, *optional*):
|
|
317
|
+
The git revision to delete from.
|
|
318
|
+
|
|
319
|
+
"""
|
|
257
320
|
resolved_path = self.resolve_path(path, revision=revision)
|
|
258
321
|
paths = self.expand_path(path, recursive=recursive, maxdepth=maxdepth, revision=revision)
|
|
259
322
|
paths_in_repo = [self.resolve_path(path).path_in_repo for path in paths if not self.isdir(path)]
|
|
@@ -276,7 +339,32 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
276
339
|
def ls(
|
|
277
340
|
self, path: str, detail: bool = True, refresh: bool = False, revision: Optional[str] = None, **kwargs
|
|
278
341
|
) -> List[Union[str, Dict[str, Any]]]:
|
|
279
|
-
"""
|
|
342
|
+
"""
|
|
343
|
+
List the contents of a directory.
|
|
344
|
+
|
|
345
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.ls).
|
|
346
|
+
|
|
347
|
+
<Tip warning={true}>
|
|
348
|
+
|
|
349
|
+
Note: When possible, use `HfApi.list_repo_tree()` for better performance.
|
|
350
|
+
|
|
351
|
+
</Tip>
|
|
352
|
+
|
|
353
|
+
Args:
|
|
354
|
+
path (`str`):
|
|
355
|
+
Path to the directory.
|
|
356
|
+
detail (`bool`, *optional*):
|
|
357
|
+
If True, returns a list of dictionaries containing file information. If False,
|
|
358
|
+
returns a list of file paths. Defaults to True.
|
|
359
|
+
refresh (`bool`, *optional*):
|
|
360
|
+
If True, bypass the cache and fetch the latest data. Defaults to False.
|
|
361
|
+
revision (`str`, *optional*):
|
|
362
|
+
The git revision to list from.
|
|
363
|
+
|
|
364
|
+
Returns:
|
|
365
|
+
`List[Union[str, Dict[str, Any]]]`: List of file paths (if detail=False) or list of file information
|
|
366
|
+
dictionaries (if detail=True).
|
|
367
|
+
"""
|
|
280
368
|
resolved_path = self.resolve_path(path, revision=revision)
|
|
281
369
|
path = resolved_path.unresolve()
|
|
282
370
|
kwargs = {"expand_info": detail, **kwargs}
|
|
@@ -396,13 +484,37 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
396
484
|
out.append(cache_path_info)
|
|
397
485
|
return out
|
|
398
486
|
|
|
399
|
-
def walk(self, path, *args, **kwargs):
|
|
487
|
+
def walk(self, path: str, *args, **kwargs) -> Iterator[Tuple[str, List[str], List[str]]]:
|
|
488
|
+
"""
|
|
489
|
+
Return all files below the given path.
|
|
490
|
+
|
|
491
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.walk).
|
|
492
|
+
|
|
493
|
+
Args:
|
|
494
|
+
path (`str`):
|
|
495
|
+
Root path to list files from.
|
|
496
|
+
|
|
497
|
+
Returns:
|
|
498
|
+
`Iterator[Tuple[str, List[str], List[str]]]`: An iterator of (path, list of directory names, list of file names) tuples.
|
|
499
|
+
"""
|
|
400
500
|
# Set expand_info=False by default to get a x10 speed boost
|
|
401
501
|
kwargs = {"expand_info": kwargs.get("detail", False), **kwargs}
|
|
402
502
|
path = self.resolve_path(path, revision=kwargs.get("revision")).unresolve()
|
|
403
503
|
yield from super().walk(path, *args, **kwargs)
|
|
404
504
|
|
|
405
|
-
def glob(self, path, **kwargs):
|
|
505
|
+
def glob(self, path: str, **kwargs) -> List[str]:
|
|
506
|
+
"""
|
|
507
|
+
Find files by glob-matching.
|
|
508
|
+
|
|
509
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.glob).
|
|
510
|
+
|
|
511
|
+
Args:
|
|
512
|
+
path (`str`):
|
|
513
|
+
Path pattern to match.
|
|
514
|
+
|
|
515
|
+
Returns:
|
|
516
|
+
`List[str]`: List of paths matching the pattern.
|
|
517
|
+
"""
|
|
406
518
|
# Set expand_info=False by default to get a x10 speed boost
|
|
407
519
|
kwargs = {"expand_info": kwargs.get("detail", False), **kwargs}
|
|
408
520
|
path = self.resolve_path(path, revision=kwargs.get("revision")).unresolve()
|
|
@@ -418,6 +530,28 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
418
530
|
revision: Optional[str] = None,
|
|
419
531
|
**kwargs,
|
|
420
532
|
) -> Union[List[str], Dict[str, Dict[str, Any]]]:
|
|
533
|
+
"""
|
|
534
|
+
List all files below path.
|
|
535
|
+
|
|
536
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.find).
|
|
537
|
+
|
|
538
|
+
Args:
|
|
539
|
+
path (`str`):
|
|
540
|
+
Root path to list files from.
|
|
541
|
+
maxdepth (`int`, *optional*):
|
|
542
|
+
Maximum depth to descend into subdirectories.
|
|
543
|
+
withdirs (`bool`, *optional*):
|
|
544
|
+
Include directory paths in the output. Defaults to False.
|
|
545
|
+
detail (`bool`, *optional*):
|
|
546
|
+
If True, returns a dict mapping paths to file information. Defaults to False.
|
|
547
|
+
refresh (`bool`, *optional*):
|
|
548
|
+
If True, bypass the cache and fetch the latest data. Defaults to False.
|
|
549
|
+
revision (`str`, *optional*):
|
|
550
|
+
The git revision to list from.
|
|
551
|
+
|
|
552
|
+
Returns:
|
|
553
|
+
`Union[List[str], Dict[str, Dict[str, Any]]]`: List of paths or dict of file information.
|
|
554
|
+
"""
|
|
421
555
|
if maxdepth:
|
|
422
556
|
return super().find(
|
|
423
557
|
path, maxdepth=maxdepth, withdirs=withdirs, detail=detail, refresh=refresh, revision=revision, **kwargs
|
|
@@ -448,6 +582,24 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
448
582
|
return {name: out[name] for name in names}
|
|
449
583
|
|
|
450
584
|
def cp_file(self, path1: str, path2: str, revision: Optional[str] = None, **kwargs) -> None:
|
|
585
|
+
"""
|
|
586
|
+
Copy a file within or between repositories.
|
|
587
|
+
|
|
588
|
+
<Tip warning={true}>
|
|
589
|
+
|
|
590
|
+
Note: When possible, use `HfApi.upload_file()` for better performance.
|
|
591
|
+
|
|
592
|
+
</Tip>
|
|
593
|
+
|
|
594
|
+
Args:
|
|
595
|
+
path1 (`str`):
|
|
596
|
+
Source path to copy from.
|
|
597
|
+
path2 (`str`):
|
|
598
|
+
Destination path to copy to.
|
|
599
|
+
revision (`str`, *optional*):
|
|
600
|
+
The git revision to copy from.
|
|
601
|
+
|
|
602
|
+
"""
|
|
451
603
|
resolved_path1 = self.resolve_path(path1, revision=revision)
|
|
452
604
|
resolved_path2 = self.resolve_path(path2, revision=revision)
|
|
453
605
|
|
|
@@ -489,10 +641,45 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
489
641
|
self.invalidate_cache(path=resolved_path2.unresolve())
|
|
490
642
|
|
|
491
643
|
def modified(self, path: str, **kwargs) -> datetime:
|
|
644
|
+
"""
|
|
645
|
+
Get the last modified time of a file.
|
|
646
|
+
|
|
647
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.modified).
|
|
648
|
+
|
|
649
|
+
Args:
|
|
650
|
+
path (`str`):
|
|
651
|
+
Path to the file.
|
|
652
|
+
|
|
653
|
+
Returns:
|
|
654
|
+
`datetime`: Last commit date of the file.
|
|
655
|
+
"""
|
|
492
656
|
info = self.info(path, **kwargs)
|
|
493
657
|
return info["last_commit"]["date"]
|
|
494
658
|
|
|
495
659
|
def info(self, path: str, refresh: bool = False, revision: Optional[str] = None, **kwargs) -> Dict[str, Any]:
|
|
660
|
+
"""
|
|
661
|
+
Get information about a file or directory.
|
|
662
|
+
|
|
663
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.info).
|
|
664
|
+
|
|
665
|
+
<Tip warning={true}>
|
|
666
|
+
|
|
667
|
+
Note: When possible, use `HfApi.get_paths_info()` or `HfApi.repo_info()` for better performance.
|
|
668
|
+
|
|
669
|
+
</Tip>
|
|
670
|
+
|
|
671
|
+
Args:
|
|
672
|
+
path (`str`):
|
|
673
|
+
Path to get info for.
|
|
674
|
+
refresh (`bool`, *optional*):
|
|
675
|
+
If True, bypass the cache and fetch the latest data. Defaults to False.
|
|
676
|
+
revision (`str`, *optional*):
|
|
677
|
+
The git revision to get info from.
|
|
678
|
+
|
|
679
|
+
Returns:
|
|
680
|
+
`Dict[str, Any]`: Dictionary containing file information (type, size, commit info, etc.).
|
|
681
|
+
|
|
682
|
+
"""
|
|
496
683
|
resolved_path = self.resolve_path(path, revision=revision)
|
|
497
684
|
path = resolved_path.unresolve()
|
|
498
685
|
expand_info = kwargs.get(
|
|
@@ -570,30 +757,80 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
570
757
|
return out
|
|
571
758
|
|
|
572
759
|
def exists(self, path, **kwargs):
|
|
573
|
-
"""
|
|
760
|
+
"""
|
|
761
|
+
Check if a file exists.
|
|
762
|
+
|
|
763
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.exists).
|
|
764
|
+
|
|
765
|
+
<Tip warning={true}>
|
|
766
|
+
|
|
767
|
+
Note: When possible, use `HfApi.file_exists()` for better performance.
|
|
768
|
+
|
|
769
|
+
</Tip>
|
|
770
|
+
|
|
771
|
+
Args:
|
|
772
|
+
path (`str`):
|
|
773
|
+
Path to check.
|
|
774
|
+
|
|
775
|
+
Returns:
|
|
776
|
+
`bool`: True if file exists, False otherwise.
|
|
777
|
+
"""
|
|
574
778
|
try:
|
|
779
|
+
if kwargs.get("refresh", False):
|
|
780
|
+
self.invalidate_cache(path)
|
|
781
|
+
|
|
575
782
|
self.info(path, **{**kwargs, "expand_info": False})
|
|
576
783
|
return True
|
|
577
784
|
except: # noqa: E722
|
|
578
|
-
# any exception allowed bar FileNotFoundError?
|
|
579
785
|
return False
|
|
580
786
|
|
|
581
787
|
def isdir(self, path):
|
|
582
|
-
"""
|
|
788
|
+
"""
|
|
789
|
+
Check if a path is a directory.
|
|
790
|
+
|
|
791
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.isdir).
|
|
792
|
+
|
|
793
|
+
Args:
|
|
794
|
+
path (`str`):
|
|
795
|
+
Path to check.
|
|
796
|
+
|
|
797
|
+
Returns:
|
|
798
|
+
`bool`: True if path is a directory, False otherwise.
|
|
799
|
+
"""
|
|
583
800
|
try:
|
|
584
801
|
return self.info(path, expand_info=False)["type"] == "directory"
|
|
585
802
|
except OSError:
|
|
586
803
|
return False
|
|
587
804
|
|
|
588
805
|
def isfile(self, path):
|
|
589
|
-
"""
|
|
806
|
+
"""
|
|
807
|
+
Check if a path is a file.
|
|
808
|
+
|
|
809
|
+
For more details, refer to [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.isfile).
|
|
810
|
+
|
|
811
|
+
Args:
|
|
812
|
+
path (`str`):
|
|
813
|
+
Path to check.
|
|
814
|
+
|
|
815
|
+
Returns:
|
|
816
|
+
`bool`: True if path is a file, False otherwise.
|
|
817
|
+
"""
|
|
590
818
|
try:
|
|
591
819
|
return self.info(path, expand_info=False)["type"] == "file"
|
|
592
820
|
except: # noqa: E722
|
|
593
821
|
return False
|
|
594
822
|
|
|
595
823
|
def url(self, path: str) -> str:
|
|
596
|
-
"""
|
|
824
|
+
"""
|
|
825
|
+
Get the HTTP URL of the given path.
|
|
826
|
+
|
|
827
|
+
Args:
|
|
828
|
+
path (`str`):
|
|
829
|
+
Path to get URL for.
|
|
830
|
+
|
|
831
|
+
Returns:
|
|
832
|
+
`str`: HTTP URL to access the file or directory on the Hub.
|
|
833
|
+
"""
|
|
597
834
|
resolved_path = self.resolve_path(path)
|
|
598
835
|
url = hf_hub_url(
|
|
599
836
|
resolved_path.repo_id,
|
|
@@ -607,7 +844,26 @@ class HfFileSystem(fsspec.AbstractFileSystem):
|
|
|
607
844
|
return url
|
|
608
845
|
|
|
609
846
|
def get_file(self, rpath, lpath, callback=_DEFAULT_CALLBACK, outfile=None, **kwargs) -> None:
|
|
610
|
-
"""
|
|
847
|
+
"""
|
|
848
|
+
Copy single remote file to local.
|
|
849
|
+
|
|
850
|
+
<Tip warning={true}>
|
|
851
|
+
|
|
852
|
+
Note: When possible, use `HfApi.hf_hub_download()` for better performance.
|
|
853
|
+
|
|
854
|
+
</Tip>
|
|
855
|
+
|
|
856
|
+
Args:
|
|
857
|
+
rpath (`str`):
|
|
858
|
+
Remote path to download from.
|
|
859
|
+
lpath (`str`):
|
|
860
|
+
Local path to download to.
|
|
861
|
+
callback (`Callback`, *optional*):
|
|
862
|
+
Optional callback to track download progress. Defaults to no callback.
|
|
863
|
+
outfile (`IO`, *optional*):
|
|
864
|
+
Optional file-like object to write to. If provided, `lpath` is ignored.
|
|
865
|
+
|
|
866
|
+
"""
|
|
611
867
|
revision = kwargs.get("revision")
|
|
612
868
|
unhandled_kwargs = set(kwargs.keys()) - {"revision"}
|
|
613
869
|
if not isinstance(callback, (NoOpCallback, TqdmCallback)) or len(unhandled_kwargs) > 0:
|
|
@@ -882,20 +1138,3 @@ def _raise_file_not_found(path: str, err: Optional[Exception]) -> NoReturn:
|
|
|
882
1138
|
|
|
883
1139
|
def reopen(fs: HfFileSystem, path: str, mode: str, block_size: int, cache_type: str):
|
|
884
1140
|
return fs.open(path, mode=mode, block_size=block_size, cache_type=cache_type)
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
# Add docstrings to the methods of HfFileSystem from fsspec.AbstractFileSystem
|
|
888
|
-
for name, function in inspect.getmembers(HfFileSystem, predicate=inspect.isfunction):
|
|
889
|
-
parent = getattr(fsspec.AbstractFileSystem, name, None)
|
|
890
|
-
if parent is not None and parent.__doc__ is not None:
|
|
891
|
-
parent_doc = parent.__doc__
|
|
892
|
-
parent_doc = parent_doc.replace("Parameters\n ----------\n", "Args:\n")
|
|
893
|
-
parent_doc = parent_doc.replace("Returns\n -------\n", "Return:\n")
|
|
894
|
-
function.__doc__ = (
|
|
895
|
-
(
|
|
896
|
-
"\n_Docstring taken from "
|
|
897
|
-
f"[fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.{name})._"
|
|
898
|
-
)
|
|
899
|
-
+ "\n\n"
|
|
900
|
-
+ parent_doc
|
|
901
|
-
)
|
huggingface_hub/hub_mixin.py
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import json
|
|
3
3
|
import os
|
|
4
|
-
import warnings
|
|
5
4
|
from dataclasses import asdict, dataclass, is_dataclass
|
|
6
5
|
from pathlib import Path
|
|
7
|
-
from typing import
|
|
8
|
-
TYPE_CHECKING,
|
|
9
|
-
Any,
|
|
10
|
-
Callable,
|
|
11
|
-
Dict,
|
|
12
|
-
List,
|
|
13
|
-
Optional,
|
|
14
|
-
Tuple,
|
|
15
|
-
Type,
|
|
16
|
-
TypeVar,
|
|
17
|
-
Union,
|
|
18
|
-
)
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union
|
|
19
7
|
|
|
20
8
|
import packaging.version
|
|
21
9
|
|
|
@@ -221,8 +209,6 @@ class ModelHubMixin:
|
|
|
221
209
|
# Value is a tuple (encoder, decoder).
|
|
222
210
|
# Example: {MyCustomType: (lambda x: x.value, lambda data: MyCustomType(data))}
|
|
223
211
|
] = None,
|
|
224
|
-
# Deprecated arguments
|
|
225
|
-
languages: Optional[List[str]] = None,
|
|
226
212
|
) -> None:
|
|
227
213
|
"""Inspect __init__ signature only once when subclassing + handle modelcard."""
|
|
228
214
|
super().__init_subclass__()
|
|
@@ -248,13 +234,6 @@ class ModelHubMixin:
|
|
|
248
234
|
info.repo_url = cls._hub_mixin_info.repo_url
|
|
249
235
|
cls._hub_mixin_info = info
|
|
250
236
|
|
|
251
|
-
if languages is not None:
|
|
252
|
-
warnings.warn(
|
|
253
|
-
"The `languages` argument is deprecated. Use `language` instead. This will be removed in `huggingface_hub>=0.27.0`.",
|
|
254
|
-
DeprecationWarning,
|
|
255
|
-
)
|
|
256
|
-
language = languages
|
|
257
|
-
|
|
258
237
|
# Update MixinInfo with metadata
|
|
259
238
|
if model_card_template is not None and model_card_template != DEFAULT_MODEL_CARD:
|
|
260
239
|
info.model_card_template = model_card_template
|
|
@@ -295,7 +274,7 @@ class ModelHubMixin:
|
|
|
295
274
|
}
|
|
296
275
|
cls._hub_mixin_inject_config = "config" in inspect.signature(cls._from_pretrained).parameters
|
|
297
276
|
|
|
298
|
-
def __new__(cls, *args, **kwargs) ->
|
|
277
|
+
def __new__(cls: Type[T], *args, **kwargs) -> T:
|
|
299
278
|
"""Create a new instance of the class and handle config.
|
|
300
279
|
|
|
301
280
|
3 cases:
|
|
@@ -641,7 +620,7 @@ class ModelHubMixin:
|
|
|
641
620
|
*,
|
|
642
621
|
config: Optional[Union[dict, "DataclassInstance"]] = None,
|
|
643
622
|
commit_message: str = "Push model using huggingface_hub.",
|
|
644
|
-
private: bool =
|
|
623
|
+
private: Optional[bool] = None,
|
|
645
624
|
token: Optional[str] = None,
|
|
646
625
|
branch: Optional[str] = None,
|
|
647
626
|
create_pr: Optional[bool] = None,
|
|
@@ -664,8 +643,9 @@ class ModelHubMixin:
|
|
|
664
643
|
Model configuration specified as a key/value dictionary or a dataclass instance.
|
|
665
644
|
commit_message (`str`, *optional*):
|
|
666
645
|
Message to commit while pushing.
|
|
667
|
-
private (`bool`, *optional
|
|
646
|
+
private (`bool`, *optional*):
|
|
668
647
|
Whether the repository created should be private.
|
|
648
|
+
If `None` (default), the repo will be public unless the organization's default is private.
|
|
669
649
|
token (`str`, *optional*):
|
|
670
650
|
The token to use as HTTP bearer authorization for remote files. By default, it will use the token
|
|
671
651
|
cached when running `huggingface-cli login`.
|