huggingface-hub 0.35.1__py3-none-any.whl → 1.0.0rc1__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 +28 -45
- huggingface_hub/_commit_api.py +28 -28
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +20 -20
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +14 -28
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +5 -5
- huggingface_hub/_upload_large_folder.py +15 -15
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/__init__.py +0 -14
- huggingface_hub/cli/_cli_utils.py +80 -3
- huggingface_hub/cli/auth.py +104 -150
- huggingface_hub/cli/cache.py +102 -126
- huggingface_hub/cli/download.py +93 -110
- huggingface_hub/cli/hf.py +37 -41
- huggingface_hub/cli/jobs.py +689 -1017
- huggingface_hub/cli/lfs.py +120 -143
- huggingface_hub/cli/repo.py +158 -216
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -212
- huggingface_hub/cli/upload_large_folder.py +90 -105
- huggingface_hub/commands/_cli_utils.py +2 -2
- huggingface_hub/commands/delete_cache.py +11 -11
- huggingface_hub/commands/download.py +4 -13
- huggingface_hub/commands/lfs.py +4 -4
- huggingface_hub/commands/repo_files.py +2 -2
- huggingface_hub/commands/tag.py +1 -3
- huggingface_hub/commands/upload.py +4 -4
- huggingface_hub/commands/upload_large_folder.py +3 -3
- huggingface_hub/commands/user.py +4 -5
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +3 -41
- huggingface_hub/dataclasses.py +16 -22
- huggingface_hub/errors.py +43 -30
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +154 -253
- huggingface_hub/hf_api.py +329 -558
- huggingface_hub/hf_file_system.py +104 -62
- huggingface_hub/hub_mixin.py +32 -54
- huggingface_hub/inference/_client.py +178 -163
- huggingface_hub/inference/_common.py +38 -54
- huggingface_hub/inference/_generated/_async_client.py +219 -259
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
- huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
- huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
- huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +10 -10
- huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
- huggingface_hub/inference/_generated/types/token_classification.py +2 -2
- huggingface_hub/inference/_generated/types/translation.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
- huggingface_hub/inference/_mcp/agent.py +3 -3
- huggingface_hub/inference/_mcp/constants.py +1 -2
- huggingface_hub/inference/_mcp/mcp_client.py +33 -22
- huggingface_hub/inference/_mcp/types.py +10 -10
- huggingface_hub/inference/_mcp/utils.py +4 -4
- huggingface_hub/inference/_providers/__init__.py +2 -13
- huggingface_hub/inference/_providers/_common.py +24 -25
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cohere.py +3 -3
- huggingface_hub/inference/_providers/fal_ai.py +25 -25
- huggingface_hub/inference/_providers/featherless_ai.py +4 -4
- huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
- huggingface_hub/inference/_providers/hf_inference.py +13 -13
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +10 -10
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +4 -4
- huggingface_hub/inference/_providers/replicate.py +15 -15
- huggingface_hub/inference/_providers/sambanova.py +6 -6
- huggingface_hub/inference/_providers/together.py +7 -7
- huggingface_hub/lfs.py +24 -33
- huggingface_hub/repocard.py +16 -17
- huggingface_hub/repocard_data.py +56 -56
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +9 -9
- huggingface_hub/serialization/_dduf.py +7 -7
- huggingface_hub/serialization/_torch.py +28 -28
- huggingface_hub/utils/__init__.py +10 -4
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +31 -31
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +3 -3
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +3 -3
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +369 -209
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +15 -13
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/utils/_typing.py +3 -3
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +1 -1
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/METADATA +17 -26
- huggingface_hub-1.0.0rc1.dist-info/RECORD +161 -0
- huggingface_hub/inference/_providers/publicai.py +0 -6
- huggingface_hub/inference/_providers/scaleway.py +0 -28
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -500
- huggingface_hub/repository.py +0 -1477
- huggingface_hub/serialization/_tensorflow.py +0 -95
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.35.1.dist-info/RECORD +0 -168
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/top_level.txt +0 -0
huggingface_hub/hf_api.py
CHANGED
|
@@ -34,22 +34,17 @@ from typing import (
|
|
|
34
34
|
Any,
|
|
35
35
|
BinaryIO,
|
|
36
36
|
Callable,
|
|
37
|
-
Dict,
|
|
38
37
|
Iterable,
|
|
39
38
|
Iterator,
|
|
40
|
-
List,
|
|
41
39
|
Literal,
|
|
42
40
|
Optional,
|
|
43
|
-
Tuple,
|
|
44
|
-
Type,
|
|
45
41
|
TypeVar,
|
|
46
42
|
Union,
|
|
47
43
|
overload,
|
|
48
44
|
)
|
|
49
45
|
from urllib.parse import quote, unquote
|
|
50
46
|
|
|
51
|
-
import
|
|
52
|
-
from requests.exceptions import HTTPError
|
|
47
|
+
import httpx
|
|
53
48
|
from tqdm.auto import tqdm as base_tqdm
|
|
54
49
|
from tqdm.contrib.concurrent import thread_map
|
|
55
50
|
|
|
@@ -78,32 +73,11 @@ from .community import (
|
|
|
78
73
|
DiscussionWithDetails,
|
|
79
74
|
deserialize_event,
|
|
80
75
|
)
|
|
81
|
-
from .constants import (
|
|
82
|
-
DEFAULT_ETAG_TIMEOUT, # noqa: F401 # kept for backward compatibility
|
|
83
|
-
DEFAULT_REQUEST_TIMEOUT, # noqa: F401 # kept for backward compatibility
|
|
84
|
-
DEFAULT_REVISION, # noqa: F401 # kept for backward compatibility
|
|
85
|
-
DISCUSSION_STATUS, # noqa: F401 # kept for backward compatibility
|
|
86
|
-
DISCUSSION_TYPES, # noqa: F401 # kept for backward compatibility
|
|
87
|
-
ENDPOINT, # noqa: F401 # kept for backward compatibility
|
|
88
|
-
INFERENCE_ENDPOINTS_ENDPOINT, # noqa: F401 # kept for backward compatibility
|
|
89
|
-
REGEX_COMMIT_OID, # noqa: F401 # kept for backward compatibility
|
|
90
|
-
REPO_TYPE_MODEL, # noqa: F401 # kept for backward compatibility
|
|
91
|
-
REPO_TYPES, # noqa: F401 # kept for backward compatibility
|
|
92
|
-
REPO_TYPES_MAPPING, # noqa: F401 # kept for backward compatibility
|
|
93
|
-
REPO_TYPES_URL_PREFIXES, # noqa: F401 # kept for backward compatibility
|
|
94
|
-
SAFETENSORS_INDEX_FILE, # noqa: F401 # kept for backward compatibility
|
|
95
|
-
SAFETENSORS_MAX_HEADER_LENGTH, # noqa: F401 # kept for backward compatibility
|
|
96
|
-
SAFETENSORS_SINGLE_FILE, # noqa: F401 # kept for backward compatibility
|
|
97
|
-
SPACES_SDK_TYPES, # noqa: F401 # kept for backward compatibility
|
|
98
|
-
WEBHOOK_DOMAIN_T, # noqa: F401 # kept for backward compatibility
|
|
99
|
-
DiscussionStatusFilter, # noqa: F401 # kept for backward compatibility
|
|
100
|
-
DiscussionTypeFilter, # noqa: F401 # kept for backward compatibility
|
|
101
|
-
)
|
|
102
76
|
from .errors import (
|
|
103
77
|
BadRequestError,
|
|
104
|
-
EntryNotFoundError,
|
|
105
78
|
GatedRepoError,
|
|
106
79
|
HfHubHTTPError,
|
|
80
|
+
RemoteEntryNotFoundError,
|
|
107
81
|
RepositoryNotFoundError,
|
|
108
82
|
RevisionNotFoundError,
|
|
109
83
|
)
|
|
@@ -111,8 +85,6 @@ from .file_download import HfFileMetadata, get_hf_file_metadata, hf_hub_url
|
|
|
111
85
|
from .repocard_data import DatasetCardData, ModelCardData, SpaceCardData
|
|
112
86
|
from .utils import (
|
|
113
87
|
DEFAULT_IGNORE_PATTERNS,
|
|
114
|
-
HfFolder, # noqa: F401 # kept for backward compatibility
|
|
115
|
-
LocalTokenNotFoundError,
|
|
116
88
|
NotASafetensorsRepoError,
|
|
117
89
|
SafetensorsFileMetadata,
|
|
118
90
|
SafetensorsParsingError,
|
|
@@ -137,7 +109,7 @@ from .utils._auth import (
|
|
|
137
109
|
_get_token_from_file,
|
|
138
110
|
_get_token_from_google_colab,
|
|
139
111
|
)
|
|
140
|
-
from .utils._deprecation import _deprecate_arguments
|
|
112
|
+
from .utils._deprecation import _deprecate_arguments
|
|
141
113
|
from .utils._runtime import is_xet_available
|
|
142
114
|
from .utils._typing import CallableT
|
|
143
115
|
from .utils.endpoint_helpers import _is_emission_within_threshold
|
|
@@ -243,7 +215,7 @@ _AUTH_CHECK_NO_REPO_ERROR_MESSAGE = (
|
|
|
243
215
|
logger = logging.get_logger(__name__)
|
|
244
216
|
|
|
245
217
|
|
|
246
|
-
def repo_type_and_id_from_hf_id(hf_id: str, hub_url: Optional[str] = None) ->
|
|
218
|
+
def repo_type_and_id_from_hf_id(hf_id: str, hub_url: Optional[str] = None) -> tuple[Optional[str], Optional[str], str]:
|
|
247
219
|
"""
|
|
248
220
|
Returns the repo type and ID from a huggingface.co URL linking to a
|
|
249
221
|
repository
|
|
@@ -353,8 +325,8 @@ class BlobLfsInfo(dict):
|
|
|
353
325
|
class BlobSecurityInfo(dict):
|
|
354
326
|
safe: bool # duplicate information with "status" field, keeping it for backward compatibility
|
|
355
327
|
status: str
|
|
356
|
-
av_scan: Optional[
|
|
357
|
-
pickle_import_scan: Optional[
|
|
328
|
+
av_scan: Optional[dict]
|
|
329
|
+
pickle_import_scan: Optional[dict]
|
|
358
330
|
|
|
359
331
|
def __post_init__(self): # hack to make BlogSecurityInfo backward compatible
|
|
360
332
|
self.update(asdict(self))
|
|
@@ -374,7 +346,7 @@ class TransformersInfo(dict):
|
|
|
374
346
|
|
|
375
347
|
@dataclass
|
|
376
348
|
class SafeTensorsInfo(dict):
|
|
377
|
-
parameters:
|
|
349
|
+
parameters: dict[str, int]
|
|
378
350
|
total: int
|
|
379
351
|
|
|
380
352
|
def __post_init__(self): # hack to make SafeTensorsInfo backward compatible
|
|
@@ -417,12 +389,6 @@ class CommitInfo(str):
|
|
|
417
389
|
|
|
418
390
|
repo_url (`RepoUrl`):
|
|
419
391
|
Repo URL of the commit containing info like repo_id, repo_type, etc.
|
|
420
|
-
|
|
421
|
-
_url (`str`, *optional*):
|
|
422
|
-
Legacy url for `str` compatibility. Can be the url to the uploaded file on the Hub (if returned by
|
|
423
|
-
[`upload_file`]), to the uploaded folder on the Hub (if returned by [`upload_folder`]) or to the commit on
|
|
424
|
-
the Hub (if returned by [`create_commit`]). Defaults to `commit_url`. It is deprecated to use this
|
|
425
|
-
attribute. Please use `commit_url` instead.
|
|
426
392
|
"""
|
|
427
393
|
|
|
428
394
|
commit_url: str
|
|
@@ -438,11 +404,8 @@ class CommitInfo(str):
|
|
|
438
404
|
pr_revision: Optional[str] = field(init=False)
|
|
439
405
|
pr_num: Optional[str] = field(init=False)
|
|
440
406
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
def __new__(cls, *args, commit_url: str, _url: Optional[str] = None, **kwargs):
|
|
445
|
-
return str.__new__(cls, _url or commit_url)
|
|
407
|
+
def __new__(cls, *args, commit_url: str, **kwargs):
|
|
408
|
+
return str.__new__(cls, commit_url)
|
|
446
409
|
|
|
447
410
|
def __post_init__(self):
|
|
448
411
|
"""Populate pr-related fields after initialization.
|
|
@@ -477,7 +440,7 @@ class AccessRequest:
|
|
|
477
440
|
Timestamp of the request.
|
|
478
441
|
status (`Literal["pending", "accepted", "rejected"]`):
|
|
479
442
|
Status of the request. Can be one of `["pending", "accepted", "rejected"]`.
|
|
480
|
-
fields (`
|
|
443
|
+
fields (`dict[str, Any]`, *optional*):
|
|
481
444
|
Additional fields filled by the user in the gate form.
|
|
482
445
|
"""
|
|
483
446
|
|
|
@@ -488,7 +451,7 @@ class AccessRequest:
|
|
|
488
451
|
status: Literal["pending", "accepted", "rejected"]
|
|
489
452
|
|
|
490
453
|
# Additional fields filled by the user in the gate form
|
|
491
|
-
fields: Optional[
|
|
454
|
+
fields: Optional[dict[str, Any]] = None
|
|
492
455
|
|
|
493
456
|
|
|
494
457
|
@dataclass
|
|
@@ -515,9 +478,9 @@ class WebhookInfo:
|
|
|
515
478
|
ID of the webhook.
|
|
516
479
|
url (`str`):
|
|
517
480
|
URL of the webhook.
|
|
518
|
-
watched (`
|
|
481
|
+
watched (`list[WebhookWatchedItem]`):
|
|
519
482
|
List of items watched by the webhook, see [`WebhookWatchedItem`].
|
|
520
|
-
domains (`
|
|
483
|
+
domains (`list[WEBHOOK_DOMAIN_T]`):
|
|
521
484
|
List of domains the webhook is watching. Can be one of `["repo", "discussions"]`.
|
|
522
485
|
secret (`str`, *optional*):
|
|
523
486
|
Secret of the webhook.
|
|
@@ -527,8 +490,8 @@ class WebhookInfo:
|
|
|
527
490
|
|
|
528
491
|
id: str
|
|
529
492
|
url: str
|
|
530
|
-
watched:
|
|
531
|
-
domains:
|
|
493
|
+
watched: list[WebhookWatchedItem]
|
|
494
|
+
domains: list[constants.WEBHOOK_DOMAIN_T]
|
|
532
495
|
secret: Optional[str]
|
|
533
496
|
disabled: bool
|
|
534
497
|
|
|
@@ -779,17 +742,17 @@ class ModelInfo:
|
|
|
779
742
|
gated (`Literal["auto", "manual", False]`, *optional*):
|
|
780
743
|
Is the repo gated.
|
|
781
744
|
If so, whether there is manual or automatic approval.
|
|
782
|
-
gguf (`
|
|
745
|
+
gguf (`dict`, *optional*):
|
|
783
746
|
GGUF information of the model.
|
|
784
747
|
inference (`Literal["warm"]`, *optional*):
|
|
785
748
|
Status of the model on Inference Providers. Warm if the model is served by at least one provider.
|
|
786
|
-
inference_provider_mapping (`
|
|
749
|
+
inference_provider_mapping (`list[InferenceProviderMapping]`, *optional*):
|
|
787
750
|
A list of [`InferenceProviderMapping`] ordered after the user's provider order.
|
|
788
751
|
likes (`int`):
|
|
789
752
|
Number of likes of the model.
|
|
790
753
|
library_name (`str`, *optional*):
|
|
791
754
|
Library associated with the model.
|
|
792
|
-
tags (`
|
|
755
|
+
tags (`list[str]`):
|
|
793
756
|
List of tags of the model. Compared to `card_data.tags`, contains extra tags computed by the Hub
|
|
794
757
|
(e.g. supported libraries, model's arXiv).
|
|
795
758
|
pipeline_tag (`str`, *optional*):
|
|
@@ -798,9 +761,9 @@ class ModelInfo:
|
|
|
798
761
|
Mask token used by the model.
|
|
799
762
|
widget_data (`Any`, *optional*):
|
|
800
763
|
Widget data associated with the model.
|
|
801
|
-
model_index (`
|
|
764
|
+
model_index (`dict`, *optional*):
|
|
802
765
|
Model index for evaluation.
|
|
803
|
-
config (`
|
|
766
|
+
config (`dict`, *optional*):
|
|
804
767
|
Model configuration.
|
|
805
768
|
transformers_info (`TransformersInfo`, *optional*):
|
|
806
769
|
Transformers-specific info (auto class, processor, etc.) associated with the model.
|
|
@@ -808,13 +771,13 @@ class ModelInfo:
|
|
|
808
771
|
Trending score of the model.
|
|
809
772
|
card_data (`ModelCardData`, *optional*):
|
|
810
773
|
Model Card Metadata as a [`huggingface_hub.repocard_data.ModelCardData`] object.
|
|
811
|
-
siblings (`
|
|
774
|
+
siblings (`list[RepoSibling]`):
|
|
812
775
|
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the model.
|
|
813
|
-
spaces (`
|
|
776
|
+
spaces (`list[str]`, *optional*):
|
|
814
777
|
List of spaces using the model.
|
|
815
778
|
safetensors (`SafeTensorsInfo`, *optional*):
|
|
816
779
|
Model's safetensors information.
|
|
817
|
-
security_repo_status (`
|
|
780
|
+
security_repo_status (`dict`, *optional*):
|
|
818
781
|
Model's security scan status.
|
|
819
782
|
"""
|
|
820
783
|
|
|
@@ -828,24 +791,24 @@ class ModelInfo:
|
|
|
828
791
|
downloads: Optional[int]
|
|
829
792
|
downloads_all_time: Optional[int]
|
|
830
793
|
gated: Optional[Literal["auto", "manual", False]]
|
|
831
|
-
gguf: Optional[
|
|
794
|
+
gguf: Optional[dict]
|
|
832
795
|
inference: Optional[Literal["warm"]]
|
|
833
|
-
inference_provider_mapping: Optional[
|
|
796
|
+
inference_provider_mapping: Optional[list[InferenceProviderMapping]]
|
|
834
797
|
likes: Optional[int]
|
|
835
798
|
library_name: Optional[str]
|
|
836
|
-
tags: Optional[
|
|
799
|
+
tags: Optional[list[str]]
|
|
837
800
|
pipeline_tag: Optional[str]
|
|
838
801
|
mask_token: Optional[str]
|
|
839
802
|
card_data: Optional[ModelCardData]
|
|
840
803
|
widget_data: Optional[Any]
|
|
841
|
-
model_index: Optional[
|
|
842
|
-
config: Optional[
|
|
804
|
+
model_index: Optional[dict]
|
|
805
|
+
config: Optional[dict]
|
|
843
806
|
transformers_info: Optional[TransformersInfo]
|
|
844
807
|
trending_score: Optional[int]
|
|
845
|
-
siblings: Optional[
|
|
846
|
-
spaces: Optional[
|
|
808
|
+
siblings: Optional[list[RepoSibling]]
|
|
809
|
+
spaces: Optional[list[str]]
|
|
847
810
|
safetensors: Optional[SafeTensorsInfo]
|
|
848
|
-
security_repo_status: Optional[
|
|
811
|
+
security_repo_status: Optional[dict]
|
|
849
812
|
xet_enabled: Optional[bool]
|
|
850
813
|
|
|
851
814
|
def __init__(self, **kwargs):
|
|
@@ -980,11 +943,11 @@ class DatasetInfo:
|
|
|
980
943
|
Cumulated number of downloads of the model since its creation.
|
|
981
944
|
likes (`int`):
|
|
982
945
|
Number of likes of the dataset.
|
|
983
|
-
tags (`
|
|
946
|
+
tags (`list[str]`):
|
|
984
947
|
List of tags of the dataset.
|
|
985
948
|
card_data (`DatasetCardData`, *optional*):
|
|
986
949
|
Model Card Metadata as a [`huggingface_hub.repocard_data.DatasetCardData`] object.
|
|
987
|
-
siblings (`
|
|
950
|
+
siblings (`list[RepoSibling]`):
|
|
988
951
|
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the dataset.
|
|
989
952
|
paperswithcode_id (`str`, *optional*):
|
|
990
953
|
Papers with code ID of the dataset.
|
|
@@ -1004,10 +967,10 @@ class DatasetInfo:
|
|
|
1004
967
|
downloads_all_time: Optional[int]
|
|
1005
968
|
likes: Optional[int]
|
|
1006
969
|
paperswithcode_id: Optional[str]
|
|
1007
|
-
tags: Optional[
|
|
970
|
+
tags: Optional[list[str]]
|
|
1008
971
|
trending_score: Optional[int]
|
|
1009
972
|
card_data: Optional[DatasetCardData]
|
|
1010
|
-
siblings: Optional[
|
|
973
|
+
siblings: Optional[list[RepoSibling]]
|
|
1011
974
|
xet_enabled: Optional[bool]
|
|
1012
975
|
|
|
1013
976
|
def __init__(self, **kwargs):
|
|
@@ -1099,9 +1062,9 @@ class SpaceInfo:
|
|
|
1099
1062
|
Subdomain of the Space.
|
|
1100
1063
|
likes (`int`):
|
|
1101
1064
|
Number of likes of the Space.
|
|
1102
|
-
tags (`
|
|
1065
|
+
tags (`list[str]`):
|
|
1103
1066
|
List of tags of the Space.
|
|
1104
|
-
siblings (`
|
|
1067
|
+
siblings (`list[RepoSibling]`):
|
|
1105
1068
|
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the Space.
|
|
1106
1069
|
card_data (`SpaceCardData`, *optional*):
|
|
1107
1070
|
Space Card Metadata as a [`huggingface_hub.repocard_data.SpaceCardData`] object.
|
|
@@ -1109,9 +1072,9 @@ class SpaceInfo:
|
|
|
1109
1072
|
Space runtime information as a [`huggingface_hub.hf_api.SpaceRuntime`] object.
|
|
1110
1073
|
sdk (`str`, *optional*):
|
|
1111
1074
|
SDK used by the Space.
|
|
1112
|
-
models (`
|
|
1075
|
+
models (`list[str]`, *optional*):
|
|
1113
1076
|
List of models used by the Space.
|
|
1114
|
-
datasets (`
|
|
1077
|
+
datasets (`list[str]`, *optional*):
|
|
1115
1078
|
List of datasets used by the Space.
|
|
1116
1079
|
trending_score (`int`, *optional*):
|
|
1117
1080
|
Trending score of the Space.
|
|
@@ -1129,13 +1092,13 @@ class SpaceInfo:
|
|
|
1129
1092
|
subdomain: Optional[str]
|
|
1130
1093
|
likes: Optional[int]
|
|
1131
1094
|
sdk: Optional[str]
|
|
1132
|
-
tags: Optional[
|
|
1133
|
-
siblings: Optional[
|
|
1095
|
+
tags: Optional[list[str]]
|
|
1096
|
+
siblings: Optional[list[RepoSibling]]
|
|
1134
1097
|
trending_score: Optional[int]
|
|
1135
1098
|
card_data: Optional[SpaceCardData]
|
|
1136
1099
|
runtime: Optional[SpaceRuntime]
|
|
1137
|
-
models: Optional[
|
|
1138
|
-
datasets: Optional[
|
|
1100
|
+
models: Optional[list[str]]
|
|
1101
|
+
datasets: Optional[list[str]]
|
|
1139
1102
|
xet_enabled: Optional[bool]
|
|
1140
1103
|
|
|
1141
1104
|
def __init__(self, **kwargs):
|
|
@@ -1223,7 +1186,7 @@ class CollectionItem:
|
|
|
1223
1186
|
id: str,
|
|
1224
1187
|
type: CollectionItemType_T,
|
|
1225
1188
|
position: int,
|
|
1226
|
-
note: Optional[
|
|
1189
|
+
note: Optional[dict] = None,
|
|
1227
1190
|
**kwargs,
|
|
1228
1191
|
) -> None:
|
|
1229
1192
|
self.item_object_id: str = _id # id in database
|
|
@@ -1249,7 +1212,7 @@ class Collection:
|
|
|
1249
1212
|
Title of the collection. E.g. `"Recent models"`.
|
|
1250
1213
|
owner (`str`):
|
|
1251
1214
|
Owner of the collection. E.g. `"TheBloke"`.
|
|
1252
|
-
items (`
|
|
1215
|
+
items (`list[CollectionItem]`):
|
|
1253
1216
|
List of items in the collection.
|
|
1254
1217
|
last_updated (`datetime`):
|
|
1255
1218
|
Date of the last update of the collection.
|
|
@@ -1270,7 +1233,7 @@ class Collection:
|
|
|
1270
1233
|
slug: str
|
|
1271
1234
|
title: str
|
|
1272
1235
|
owner: str
|
|
1273
|
-
items:
|
|
1236
|
+
items: list[CollectionItem]
|
|
1274
1237
|
last_updated: datetime
|
|
1275
1238
|
position: int
|
|
1276
1239
|
private: bool
|
|
@@ -1327,22 +1290,22 @@ class GitRefs:
|
|
|
1327
1290
|
Object is returned by [`list_repo_refs`].
|
|
1328
1291
|
|
|
1329
1292
|
Attributes:
|
|
1330
|
-
branches (`
|
|
1293
|
+
branches (`list[GitRefInfo]`):
|
|
1331
1294
|
A list of [`GitRefInfo`] containing information about branches on the repo.
|
|
1332
|
-
converts (`
|
|
1295
|
+
converts (`list[GitRefInfo]`):
|
|
1333
1296
|
A list of [`GitRefInfo`] containing information about "convert" refs on the repo.
|
|
1334
1297
|
Converts are refs used (internally) to push preprocessed data in Dataset repos.
|
|
1335
|
-
tags (`
|
|
1298
|
+
tags (`list[GitRefInfo]`):
|
|
1336
1299
|
A list of [`GitRefInfo`] containing information about tags on the repo.
|
|
1337
|
-
pull_requests (`
|
|
1300
|
+
pull_requests (`list[GitRefInfo]`, *optional*):
|
|
1338
1301
|
A list of [`GitRefInfo`] containing information about pull requests on the repo.
|
|
1339
1302
|
Only returned if `include_prs=True` is set.
|
|
1340
1303
|
"""
|
|
1341
1304
|
|
|
1342
|
-
branches:
|
|
1343
|
-
converts:
|
|
1344
|
-
tags:
|
|
1345
|
-
pull_requests: Optional[
|
|
1305
|
+
branches: list[GitRefInfo]
|
|
1306
|
+
converts: list[GitRefInfo]
|
|
1307
|
+
tags: list[GitRefInfo]
|
|
1308
|
+
pull_requests: Optional[list[GitRefInfo]] = None
|
|
1346
1309
|
|
|
1347
1310
|
|
|
1348
1311
|
@dataclass
|
|
@@ -1353,7 +1316,7 @@ class GitCommitInfo:
|
|
|
1353
1316
|
Attributes:
|
|
1354
1317
|
commit_id (`str`):
|
|
1355
1318
|
OID of the commit (e.g. `"e7da7f221d5bf496a48136c0cd264e630fe9fcc8"`)
|
|
1356
|
-
authors (`
|
|
1319
|
+
authors (`list[str]`):
|
|
1357
1320
|
List of authors of the commit.
|
|
1358
1321
|
created_at (`datetime`):
|
|
1359
1322
|
Datetime when the commit was created.
|
|
@@ -1369,7 +1332,7 @@ class GitCommitInfo:
|
|
|
1369
1332
|
|
|
1370
1333
|
commit_id: str
|
|
1371
1334
|
|
|
1372
|
-
authors:
|
|
1335
|
+
authors: list[str]
|
|
1373
1336
|
created_at: datetime
|
|
1374
1337
|
title: str
|
|
1375
1338
|
message: str
|
|
@@ -1388,11 +1351,11 @@ class UserLikes:
|
|
|
1388
1351
|
Name of the user for which we fetched the likes.
|
|
1389
1352
|
total (`int`):
|
|
1390
1353
|
Total number of likes.
|
|
1391
|
-
datasets (`
|
|
1354
|
+
datasets (`list[str]`):
|
|
1392
1355
|
List of datasets liked by the user (as repo_ids).
|
|
1393
|
-
models (`
|
|
1356
|
+
models (`list[str]`):
|
|
1394
1357
|
List of models liked by the user (as repo_ids).
|
|
1395
|
-
spaces (`
|
|
1358
|
+
spaces (`list[str]`):
|
|
1396
1359
|
List of spaces liked by the user (as repo_ids).
|
|
1397
1360
|
"""
|
|
1398
1361
|
|
|
@@ -1401,9 +1364,9 @@ class UserLikes:
|
|
|
1401
1364
|
total: int
|
|
1402
1365
|
|
|
1403
1366
|
# User likes
|
|
1404
|
-
datasets:
|
|
1405
|
-
models:
|
|
1406
|
-
spaces:
|
|
1367
|
+
datasets: list[str]
|
|
1368
|
+
models: list[str]
|
|
1369
|
+
spaces: list[str]
|
|
1407
1370
|
|
|
1408
1371
|
|
|
1409
1372
|
@dataclass
|
|
@@ -1489,7 +1452,7 @@ class User:
|
|
|
1489
1452
|
num_likes: Optional[int] = None
|
|
1490
1453
|
num_following: Optional[int] = None
|
|
1491
1454
|
num_followers: Optional[int] = None
|
|
1492
|
-
orgs:
|
|
1455
|
+
orgs: list[Organization] = field(default_factory=list)
|
|
1493
1456
|
|
|
1494
1457
|
def __init__(self, **kwargs) -> None:
|
|
1495
1458
|
self.username = kwargs.pop("user", "")
|
|
@@ -1522,7 +1485,7 @@ class PaperInfo:
|
|
|
1522
1485
|
Attributes:
|
|
1523
1486
|
id (`str`):
|
|
1524
1487
|
arXiv paper ID.
|
|
1525
|
-
authors (`
|
|
1488
|
+
authors (`list[str]`, **optional**):
|
|
1526
1489
|
Names of paper authors
|
|
1527
1490
|
published_at (`datetime`, **optional**):
|
|
1528
1491
|
Date paper published.
|
|
@@ -1545,7 +1508,7 @@ class PaperInfo:
|
|
|
1545
1508
|
"""
|
|
1546
1509
|
|
|
1547
1510
|
id: str
|
|
1548
|
-
authors: Optional[
|
|
1511
|
+
authors: Optional[list[str]]
|
|
1549
1512
|
published_at: Optional[datetime]
|
|
1550
1513
|
title: Optional[str]
|
|
1551
1514
|
summary: Optional[str]
|
|
@@ -1709,8 +1672,8 @@ class HfApi:
|
|
|
1709
1672
|
token: Union[str, bool, None] = None,
|
|
1710
1673
|
library_name: Optional[str] = None,
|
|
1711
1674
|
library_version: Optional[str] = None,
|
|
1712
|
-
user_agent: Union[
|
|
1713
|
-
headers: Optional[
|
|
1675
|
+
user_agent: Union[dict, str, None] = None,
|
|
1676
|
+
headers: Optional[dict[str, str]] = None,
|
|
1714
1677
|
) -> None:
|
|
1715
1678
|
self.endpoint = endpoint if endpoint is not None else constants.ENDPOINT
|
|
1716
1679
|
self.token = token
|
|
@@ -1761,7 +1724,7 @@ class HfApi:
|
|
|
1761
1724
|
return self._thread_pool.submit(fn, *args, **kwargs)
|
|
1762
1725
|
|
|
1763
1726
|
@validate_hf_hub_args
|
|
1764
|
-
def whoami(self, token: Union[bool, str, None] = None) ->
|
|
1727
|
+
def whoami(self, token: Union[bool, str, None] = None) -> dict:
|
|
1765
1728
|
"""
|
|
1766
1729
|
Call HF API to know "whoami".
|
|
1767
1730
|
|
|
@@ -1780,7 +1743,7 @@ class HfApi:
|
|
|
1780
1743
|
)
|
|
1781
1744
|
try:
|
|
1782
1745
|
hf_raise_for_status(r)
|
|
1783
|
-
except
|
|
1746
|
+
except HfHubHTTPError as e:
|
|
1784
1747
|
if e.response.status_code == 401:
|
|
1785
1748
|
error_message = "Invalid user token."
|
|
1786
1749
|
# Check which token is the effective one and generate the error message accordingly
|
|
@@ -1793,51 +1756,11 @@ class HfApi:
|
|
|
1793
1756
|
)
|
|
1794
1757
|
elif effective_token == _get_token_from_file():
|
|
1795
1758
|
error_message += " The token stored is invalid. Please run `hf auth login` to update it."
|
|
1796
|
-
raise
|
|
1759
|
+
raise HfHubHTTPError(error_message, response=e.response) from e
|
|
1797
1760
|
raise
|
|
1798
1761
|
return r.json()
|
|
1799
1762
|
|
|
1800
|
-
|
|
1801
|
-
version="1.0",
|
|
1802
|
-
message=(
|
|
1803
|
-
"Permissions are more complex than when `get_token_permission` was first introduced. "
|
|
1804
|
-
"OAuth and fine-grain tokens allows for more detailed permissions. "
|
|
1805
|
-
"If you need to know the permissions associated with a token, please use `whoami` and check the `'auth'` key."
|
|
1806
|
-
),
|
|
1807
|
-
)
|
|
1808
|
-
def get_token_permission(
|
|
1809
|
-
self, token: Union[bool, str, None] = None
|
|
1810
|
-
) -> Literal["read", "write", "fineGrained", None]:
|
|
1811
|
-
"""
|
|
1812
|
-
Check if a given `token` is valid and return its permissions.
|
|
1813
|
-
|
|
1814
|
-
<Tip warning={true}>
|
|
1815
|
-
|
|
1816
|
-
This method is deprecated and will be removed in version 1.0. Permissions are more complex than when
|
|
1817
|
-
`get_token_permission` was first introduced. OAuth and fine-grain tokens allows for more detailed permissions.
|
|
1818
|
-
If you need to know the permissions associated with a token, please use `whoami` and check the `'auth'` key.
|
|
1819
|
-
|
|
1820
|
-
</Tip>
|
|
1821
|
-
|
|
1822
|
-
For more details about tokens, please refer to https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens.
|
|
1823
|
-
|
|
1824
|
-
Args:
|
|
1825
|
-
token (Union[bool, str, None], optional):
|
|
1826
|
-
A valid user access token (string). Defaults to the locally saved
|
|
1827
|
-
token, which is the recommended method for authentication (see
|
|
1828
|
-
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1829
|
-
To disable authentication, pass `False`.
|
|
1830
|
-
|
|
1831
|
-
Returns:
|
|
1832
|
-
`Literal["read", "write", "fineGrained", None]`: Permission granted by the token ("read" or "write"). Returns `None` if no
|
|
1833
|
-
token passed, if token is invalid or if role is not returned by the server. This typically happens when the token is an OAuth token.
|
|
1834
|
-
"""
|
|
1835
|
-
try:
|
|
1836
|
-
return self.whoami(token=token)["auth"]["accessToken"]["role"]
|
|
1837
|
-
except (LocalTokenNotFoundError, HTTPError, KeyError):
|
|
1838
|
-
return None
|
|
1839
|
-
|
|
1840
|
-
def get_model_tags(self) -> Dict:
|
|
1763
|
+
def get_model_tags(self) -> dict:
|
|
1841
1764
|
"""
|
|
1842
1765
|
List all valid model tags as a nested namespace object
|
|
1843
1766
|
"""
|
|
@@ -1846,7 +1769,7 @@ class HfApi:
|
|
|
1846
1769
|
hf_raise_for_status(r)
|
|
1847
1770
|
return r.json()
|
|
1848
1771
|
|
|
1849
|
-
def get_dataset_tags(self) ->
|
|
1772
|
+
def get_dataset_tags(self) -> dict:
|
|
1850
1773
|
"""
|
|
1851
1774
|
List all valid dataset tags as a nested namespace object.
|
|
1852
1775
|
"""
|
|
@@ -1855,9 +1778,6 @@ class HfApi:
|
|
|
1855
1778
|
hf_raise_for_status(r)
|
|
1856
1779
|
return r.json()
|
|
1857
1780
|
|
|
1858
|
-
@_deprecate_arguments(
|
|
1859
|
-
version="1.0", deprecated_args=["language", "library", "task", "tags"], custom_message="Use `filter` instead."
|
|
1860
|
-
)
|
|
1861
1781
|
@validate_hf_hub_args
|
|
1862
1782
|
def list_models(
|
|
1863
1783
|
self,
|
|
@@ -1865,30 +1785,25 @@ class HfApi:
|
|
|
1865
1785
|
# Search-query parameter
|
|
1866
1786
|
filter: Union[str, Iterable[str], None] = None,
|
|
1867
1787
|
author: Optional[str] = None,
|
|
1868
|
-
apps: Optional[Union[str,
|
|
1788
|
+
apps: Optional[Union[str, list[str]]] = None,
|
|
1869
1789
|
gated: Optional[bool] = None,
|
|
1870
1790
|
inference: Optional[Literal["warm"]] = None,
|
|
1871
|
-
inference_provider: Optional[Union[Literal["all"], "PROVIDER_T",
|
|
1791
|
+
inference_provider: Optional[Union[Literal["all"], "PROVIDER_T", list["PROVIDER_T"]]] = None,
|
|
1872
1792
|
model_name: Optional[str] = None,
|
|
1873
|
-
trained_dataset: Optional[Union[str,
|
|
1793
|
+
trained_dataset: Optional[Union[str, list[str]]] = None,
|
|
1874
1794
|
search: Optional[str] = None,
|
|
1875
1795
|
pipeline_tag: Optional[str] = None,
|
|
1876
|
-
emissions_thresholds: Optional[
|
|
1796
|
+
emissions_thresholds: Optional[tuple[float, float]] = None,
|
|
1877
1797
|
# Sorting and pagination parameters
|
|
1878
1798
|
sort: Union[Literal["last_modified"], str, None] = None,
|
|
1879
1799
|
direction: Optional[Literal[-1]] = None,
|
|
1880
1800
|
limit: Optional[int] = None,
|
|
1881
1801
|
# Additional data to fetch
|
|
1882
|
-
expand: Optional[
|
|
1802
|
+
expand: Optional[list[ExpandModelProperty_T]] = None,
|
|
1883
1803
|
full: Optional[bool] = None,
|
|
1884
1804
|
cardData: bool = False,
|
|
1885
1805
|
fetch_config: bool = False,
|
|
1886
1806
|
token: Union[bool, str, None] = None,
|
|
1887
|
-
# Deprecated arguments - use `filter` instead
|
|
1888
|
-
language: Optional[Union[str, List[str]]] = None,
|
|
1889
|
-
library: Optional[Union[str, List[str]]] = None,
|
|
1890
|
-
tags: Optional[Union[str, List[str]]] = None,
|
|
1891
|
-
task: Optional[Union[str, List[str]]] = None,
|
|
1892
1807
|
) -> Iterable[ModelInfo]:
|
|
1893
1808
|
"""
|
|
1894
1809
|
List models hosted on the Huggingface Hub, given some filters.
|
|
@@ -1912,20 +1827,12 @@ class HfApi:
|
|
|
1912
1827
|
inference_provider (`Literal["all"]` or `str`, *optional*):
|
|
1913
1828
|
A string to filter models on the Hub that are served by a specific provider.
|
|
1914
1829
|
Pass `"all"` to get all models served by at least one provider.
|
|
1915
|
-
library (`str` or `List`, *optional*):
|
|
1916
|
-
Deprecated. Pass a library name in `filter` to filter models by library.
|
|
1917
|
-
language (`str` or `List`, *optional*):
|
|
1918
|
-
Deprecated. Pass a language in `filter` to filter models by language.
|
|
1919
1830
|
model_name (`str`, *optional*):
|
|
1920
1831
|
A string that contain complete or partial names for models on the
|
|
1921
1832
|
Hub, such as "bert" or "bert-base-cased"
|
|
1922
|
-
task (`str` or `List`, *optional*):
|
|
1923
|
-
Deprecated. Pass a task in `filter` to filter models by task.
|
|
1924
1833
|
trained_dataset (`str` or `List`, *optional*):
|
|
1925
1834
|
A string tag or a list of string tags of the trained dataset for a
|
|
1926
1835
|
model on the Hub.
|
|
1927
|
-
tags (`str` or `List`, *optional*):
|
|
1928
|
-
Deprecated. Pass tags in `filter` to filter models by tags.
|
|
1929
1836
|
search (`str`, *optional*):
|
|
1930
1837
|
A string that will be contained in the returned model ids.
|
|
1931
1838
|
pipeline_tag (`str`, *optional*):
|
|
@@ -1942,7 +1849,7 @@ class HfApi:
|
|
|
1942
1849
|
limit (`int`, *optional*):
|
|
1943
1850
|
The limit on the number of models fetched. Leaving this option
|
|
1944
1851
|
to `None` fetches all models.
|
|
1945
|
-
expand (`
|
|
1852
|
+
expand (`list[ExpandModelProperty_T]`, *optional*):
|
|
1946
1853
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
1947
1854
|
This parameter cannot be used if `full`, `cardData` or `fetch_config` are passed.
|
|
1948
1855
|
Possible values are `"author"`, `"cardData"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gguf"`, `"inference"`, `"inferenceProviderMapping"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"`, `"trendingScore"`, `"widgetData"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2001,27 +1908,15 @@ class HfApi:
|
|
|
2001
1908
|
|
|
2002
1909
|
path = f"{self.endpoint}/api/models"
|
|
2003
1910
|
headers = self._build_hf_headers(token=token)
|
|
2004
|
-
params:
|
|
1911
|
+
params: dict[str, Any] = {}
|
|
2005
1912
|
|
|
2006
1913
|
# Build the filter list
|
|
2007
|
-
filter_list:
|
|
1914
|
+
filter_list: list[str] = []
|
|
2008
1915
|
if filter:
|
|
2009
1916
|
filter_list.extend([filter] if isinstance(filter, str) else filter)
|
|
2010
|
-
if library:
|
|
2011
|
-
filter_list.extend([library] if isinstance(library, str) else library)
|
|
2012
|
-
if task:
|
|
2013
|
-
filter_list.extend([task] if isinstance(task, str) else task)
|
|
2014
1917
|
if trained_dataset:
|
|
2015
|
-
if isinstance(trained_dataset, str)
|
|
2016
|
-
|
|
2017
|
-
for dataset in trained_dataset:
|
|
2018
|
-
if not dataset.startswith("dataset:"):
|
|
2019
|
-
dataset = f"dataset:{dataset}"
|
|
2020
|
-
filter_list.append(dataset)
|
|
2021
|
-
if language:
|
|
2022
|
-
filter_list.extend([language] if isinstance(language, str) else language)
|
|
2023
|
-
if tags:
|
|
2024
|
-
filter_list.extend([tags] if isinstance(tags, str) else tags)
|
|
1918
|
+
datasets = [trained_dataset] if isinstance(trained_dataset, str) else trained_dataset
|
|
1919
|
+
filter_list.extend(f"dataset:{d}" if not d.startswith("dataset:") else d for d in datasets)
|
|
2025
1920
|
if len(filter_list) > 0:
|
|
2026
1921
|
params["filter"] = filter_list
|
|
2027
1922
|
|
|
@@ -2091,26 +1986,26 @@ class HfApi:
|
|
|
2091
1986
|
# Search-query parameter
|
|
2092
1987
|
filter: Union[str, Iterable[str], None] = None,
|
|
2093
1988
|
author: Optional[str] = None,
|
|
2094
|
-
benchmark: Optional[Union[str,
|
|
1989
|
+
benchmark: Optional[Union[str, list[str]]] = None,
|
|
2095
1990
|
dataset_name: Optional[str] = None,
|
|
2096
1991
|
gated: Optional[bool] = None,
|
|
2097
|
-
language_creators: Optional[Union[str,
|
|
2098
|
-
language: Optional[Union[str,
|
|
2099
|
-
multilinguality: Optional[Union[str,
|
|
2100
|
-
size_categories: Optional[Union[str,
|
|
2101
|
-
task_categories: Optional[Union[str,
|
|
2102
|
-
task_ids: Optional[Union[str,
|
|
1992
|
+
language_creators: Optional[Union[str, list[str]]] = None,
|
|
1993
|
+
language: Optional[Union[str, list[str]]] = None,
|
|
1994
|
+
multilinguality: Optional[Union[str, list[str]]] = None,
|
|
1995
|
+
size_categories: Optional[Union[str, list[str]]] = None,
|
|
1996
|
+
task_categories: Optional[Union[str, list[str]]] = None,
|
|
1997
|
+
task_ids: Optional[Union[str, list[str]]] = None,
|
|
2103
1998
|
search: Optional[str] = None,
|
|
2104
1999
|
# Sorting and pagination parameters
|
|
2105
2000
|
sort: Optional[Union[Literal["last_modified"], str]] = None,
|
|
2106
2001
|
direction: Optional[Literal[-1]] = None,
|
|
2107
2002
|
limit: Optional[int] = None,
|
|
2108
2003
|
# Additional data to fetch
|
|
2109
|
-
expand: Optional[
|
|
2004
|
+
expand: Optional[list[ExpandDatasetProperty_T]] = None,
|
|
2110
2005
|
full: Optional[bool] = None,
|
|
2111
2006
|
token: Union[bool, str, None] = None,
|
|
2112
2007
|
# Deprecated arguments - use `filter` instead
|
|
2113
|
-
tags: Optional[Union[str,
|
|
2008
|
+
tags: Optional[Union[str, list[str]]] = None,
|
|
2114
2009
|
) -> Iterable[DatasetInfo]:
|
|
2115
2010
|
"""
|
|
2116
2011
|
List datasets hosted on the Huggingface Hub, given some filters.
|
|
@@ -2165,7 +2060,7 @@ class HfApi:
|
|
|
2165
2060
|
limit (`int`, *optional*):
|
|
2166
2061
|
The limit on the number of datasets fetched. Leaving this option
|
|
2167
2062
|
to `None` fetches all datasets.
|
|
2168
|
-
expand (`
|
|
2063
|
+
expand (`list[ExpandDatasetProperty_T]`, *optional*):
|
|
2169
2064
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2170
2065
|
This parameter cannot be used if `full` is passed.
|
|
2171
2066
|
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"`, `"tags"`, `"trendingScore"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2225,7 +2120,7 @@ class HfApi:
|
|
|
2225
2120
|
|
|
2226
2121
|
path = f"{self.endpoint}/api/datasets"
|
|
2227
2122
|
headers = self._build_hf_headers(token=token)
|
|
2228
|
-
params:
|
|
2123
|
+
params: dict[str, Any] = {}
|
|
2229
2124
|
|
|
2230
2125
|
# Build `filter` list
|
|
2231
2126
|
filter_list = []
|
|
@@ -2312,7 +2207,7 @@ class HfApi:
|
|
|
2312
2207
|
direction: Optional[Literal[-1]] = None,
|
|
2313
2208
|
limit: Optional[int] = None,
|
|
2314
2209
|
# Additional data to fetch
|
|
2315
|
-
expand: Optional[
|
|
2210
|
+
expand: Optional[list[ExpandSpaceProperty_T]] = None,
|
|
2316
2211
|
full: Optional[bool] = None,
|
|
2317
2212
|
token: Union[bool, str, None] = None,
|
|
2318
2213
|
) -> Iterable[SpaceInfo]:
|
|
@@ -2343,7 +2238,7 @@ class HfApi:
|
|
|
2343
2238
|
limit (`int`, *optional*):
|
|
2344
2239
|
The limit on the number of Spaces fetched. Leaving this option
|
|
2345
2240
|
to `None` fetches all Spaces.
|
|
2346
|
-
expand (`
|
|
2241
|
+
expand (`list[ExpandSpaceProperty_T]`, *optional*):
|
|
2347
2242
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2348
2243
|
This parameter cannot be used if `full` is passed.
|
|
2349
2244
|
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"`, `"trendingScore"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2364,7 +2259,7 @@ class HfApi:
|
|
|
2364
2259
|
|
|
2365
2260
|
path = f"{self.endpoint}/api/spaces"
|
|
2366
2261
|
headers = self._build_hf_headers(token=token)
|
|
2367
|
-
params:
|
|
2262
|
+
params: dict[str, Any] = {}
|
|
2368
2263
|
if filter is not None:
|
|
2369
2264
|
params["filter"] = filter
|
|
2370
2265
|
if author is not None:
|
|
@@ -2581,7 +2476,7 @@ class HfApi:
|
|
|
2581
2476
|
timeout: Optional[float] = None,
|
|
2582
2477
|
securityStatus: Optional[bool] = None,
|
|
2583
2478
|
files_metadata: bool = False,
|
|
2584
|
-
expand: Optional[
|
|
2479
|
+
expand: Optional[list[ExpandModelProperty_T]] = None,
|
|
2585
2480
|
token: Union[bool, str, None] = None,
|
|
2586
2481
|
) -> ModelInfo:
|
|
2587
2482
|
"""
|
|
@@ -2604,7 +2499,7 @@ class HfApi:
|
|
|
2604
2499
|
files_metadata (`bool`, *optional*):
|
|
2605
2500
|
Whether or not to retrieve metadata for files in the repository
|
|
2606
2501
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2607
|
-
expand (`
|
|
2502
|
+
expand (`list[ExpandModelProperty_T]`, *optional*):
|
|
2608
2503
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2609
2504
|
This parameter cannot be used if `securityStatus` or `files_metadata` are passed.
|
|
2610
2505
|
Possible values are `"author"`, `"baseModels"`, `"cardData"`, `"childrenModelCount"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"gguf"`, `"inference"`, `"inferenceProviderMapping"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"`, `"trendingScore"`, `"widgetData"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2638,7 +2533,7 @@ class HfApi:
|
|
|
2638
2533
|
if revision is None
|
|
2639
2534
|
else (f"{self.endpoint}/api/models/{repo_id}/revision/{quote(revision, safe='')}")
|
|
2640
2535
|
)
|
|
2641
|
-
params:
|
|
2536
|
+
params: dict = {}
|
|
2642
2537
|
if securityStatus:
|
|
2643
2538
|
params["securityStatus"] = True
|
|
2644
2539
|
if files_metadata:
|
|
@@ -2658,7 +2553,7 @@ class HfApi:
|
|
|
2658
2553
|
revision: Optional[str] = None,
|
|
2659
2554
|
timeout: Optional[float] = None,
|
|
2660
2555
|
files_metadata: bool = False,
|
|
2661
|
-
expand: Optional[
|
|
2556
|
+
expand: Optional[list[ExpandDatasetProperty_T]] = None,
|
|
2662
2557
|
token: Union[bool, str, None] = None,
|
|
2663
2558
|
) -> DatasetInfo:
|
|
2664
2559
|
"""
|
|
@@ -2678,7 +2573,7 @@ class HfApi:
|
|
|
2678
2573
|
files_metadata (`bool`, *optional*):
|
|
2679
2574
|
Whether or not to retrieve metadata for files in the repository
|
|
2680
2575
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2681
|
-
expand (`
|
|
2576
|
+
expand (`list[ExpandDatasetProperty_T]`, *optional*):
|
|
2682
2577
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2683
2578
|
This parameter cannot be used if `files_metadata` is passed.
|
|
2684
2579
|
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"`, `"tags"`, `"trendingScore"`,`"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2712,7 +2607,7 @@ class HfApi:
|
|
|
2712
2607
|
if revision is None
|
|
2713
2608
|
else (f"{self.endpoint}/api/datasets/{repo_id}/revision/{quote(revision, safe='')}")
|
|
2714
2609
|
)
|
|
2715
|
-
params:
|
|
2610
|
+
params: dict = {}
|
|
2716
2611
|
if files_metadata:
|
|
2717
2612
|
params["blobs"] = True
|
|
2718
2613
|
if expand:
|
|
@@ -2731,7 +2626,7 @@ class HfApi:
|
|
|
2731
2626
|
revision: Optional[str] = None,
|
|
2732
2627
|
timeout: Optional[float] = None,
|
|
2733
2628
|
files_metadata: bool = False,
|
|
2734
|
-
expand: Optional[
|
|
2629
|
+
expand: Optional[list[ExpandSpaceProperty_T]] = None,
|
|
2735
2630
|
token: Union[bool, str, None] = None,
|
|
2736
2631
|
) -> SpaceInfo:
|
|
2737
2632
|
"""
|
|
@@ -2751,7 +2646,7 @@ class HfApi:
|
|
|
2751
2646
|
files_metadata (`bool`, *optional*):
|
|
2752
2647
|
Whether or not to retrieve metadata for files in the repository
|
|
2753
2648
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2754
|
-
expand (`
|
|
2649
|
+
expand (`list[ExpandSpaceProperty_T]`, *optional*):
|
|
2755
2650
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2756
2651
|
This parameter cannot be used if `full` is passed.
|
|
2757
2652
|
Possible values are `"author"`, `"cardData"`, `"createdAt"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"`, `"trendingScore"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2785,7 +2680,7 @@ class HfApi:
|
|
|
2785
2680
|
if revision is None
|
|
2786
2681
|
else (f"{self.endpoint}/api/spaces/{repo_id}/revision/{quote(revision, safe='')}")
|
|
2787
2682
|
)
|
|
2788
|
-
params:
|
|
2683
|
+
params: dict = {}
|
|
2789
2684
|
if files_metadata:
|
|
2790
2685
|
params["blobs"] = True
|
|
2791
2686
|
if expand:
|
|
@@ -3016,7 +2911,7 @@ class HfApi:
|
|
|
3016
2911
|
return True
|
|
3017
2912
|
except GatedRepoError: # raise specifically on gated repo
|
|
3018
2913
|
raise
|
|
3019
|
-
except (RepositoryNotFoundError,
|
|
2914
|
+
except (RepositoryNotFoundError, RemoteEntryNotFoundError, RevisionNotFoundError):
|
|
3020
2915
|
return False
|
|
3021
2916
|
|
|
3022
2917
|
@validate_hf_hub_args
|
|
@@ -3027,7 +2922,7 @@ class HfApi:
|
|
|
3027
2922
|
revision: Optional[str] = None,
|
|
3028
2923
|
repo_type: Optional[str] = None,
|
|
3029
2924
|
token: Union[str, bool, None] = None,
|
|
3030
|
-
) ->
|
|
2925
|
+
) -> list[str]:
|
|
3031
2926
|
"""
|
|
3032
2927
|
Get the list of files in a given repo.
|
|
3033
2928
|
|
|
@@ -3046,7 +2941,7 @@ class HfApi:
|
|
|
3046
2941
|
To disable authentication, pass `False`.
|
|
3047
2942
|
|
|
3048
2943
|
Returns:
|
|
3049
|
-
`
|
|
2944
|
+
`list[str]`: the list of files in a given repository.
|
|
3050
2945
|
"""
|
|
3051
2946
|
return [
|
|
3052
2947
|
f.rfilename
|
|
@@ -3106,7 +3001,7 @@ class HfApi:
|
|
|
3106
3001
|
does not exist.
|
|
3107
3002
|
[`~utils.RevisionNotFoundError`]:
|
|
3108
3003
|
If revision is not found (error 404) on the repo.
|
|
3109
|
-
[`~utils.
|
|
3004
|
+
[`~utils.RemoteEntryNotFoundError`]:
|
|
3110
3005
|
If the tree (folder) does not exist (error 404) on the repo.
|
|
3111
3006
|
|
|
3112
3007
|
Examples:
|
|
@@ -3248,7 +3143,7 @@ class HfApi:
|
|
|
3248
3143
|
hf_raise_for_status(response)
|
|
3249
3144
|
data = response.json()
|
|
3250
3145
|
|
|
3251
|
-
def _format_as_git_ref_info(item:
|
|
3146
|
+
def _format_as_git_ref_info(item: dict) -> GitRefInfo:
|
|
3252
3147
|
return GitRefInfo(name=item["name"], ref=item["ref"], target_commit=item["targetCommit"])
|
|
3253
3148
|
|
|
3254
3149
|
return GitRefs(
|
|
@@ -3269,7 +3164,7 @@ class HfApi:
|
|
|
3269
3164
|
token: Union[bool, str, None] = None,
|
|
3270
3165
|
revision: Optional[str] = None,
|
|
3271
3166
|
formatted: bool = False,
|
|
3272
|
-
) ->
|
|
3167
|
+
) -> list[GitCommitInfo]:
|
|
3273
3168
|
"""
|
|
3274
3169
|
Get the list of commits of a given revision for a repo on the Hub.
|
|
3275
3170
|
|
|
@@ -3316,7 +3211,7 @@ class HfApi:
|
|
|
3316
3211
|
```
|
|
3317
3212
|
|
|
3318
3213
|
Returns:
|
|
3319
|
-
|
|
3214
|
+
list[[`GitCommitInfo`]]: list of objects containing information about the commits for a repo on the Hub.
|
|
3320
3215
|
|
|
3321
3216
|
Raises:
|
|
3322
3217
|
[`~utils.RepositoryNotFoundError`]:
|
|
@@ -3350,20 +3245,20 @@ class HfApi:
|
|
|
3350
3245
|
def get_paths_info(
|
|
3351
3246
|
self,
|
|
3352
3247
|
repo_id: str,
|
|
3353
|
-
paths: Union[
|
|
3248
|
+
paths: Union[list[str], str],
|
|
3354
3249
|
*,
|
|
3355
3250
|
expand: bool = False,
|
|
3356
3251
|
revision: Optional[str] = None,
|
|
3357
3252
|
repo_type: Optional[str] = None,
|
|
3358
3253
|
token: Union[str, bool, None] = None,
|
|
3359
|
-
) ->
|
|
3254
|
+
) -> list[Union[RepoFile, RepoFolder]]:
|
|
3360
3255
|
"""
|
|
3361
3256
|
Get information about a repo's paths.
|
|
3362
3257
|
|
|
3363
3258
|
Args:
|
|
3364
3259
|
repo_id (`str`):
|
|
3365
3260
|
A namespace (user or an organization) and a repo name separated by a `/`.
|
|
3366
|
-
paths (`Union[
|
|
3261
|
+
paths (`Union[list[str], str]`, *optional*):
|
|
3367
3262
|
The paths to get information about. If a path do not exist, it is ignored without raising
|
|
3368
3263
|
an exception.
|
|
3369
3264
|
expand (`bool`, *optional*, defaults to `False`):
|
|
@@ -3383,7 +3278,7 @@ class HfApi:
|
|
|
3383
3278
|
To disable authentication, pass `False`.
|
|
3384
3279
|
|
|
3385
3280
|
Returns:
|
|
3386
|
-
`
|
|
3281
|
+
`list[Union[RepoFile, RepoFolder]]`:
|
|
3387
3282
|
The information about the paths, as a list of [`RepoFile`] and [`RepoFolder`] objects.
|
|
3388
3283
|
|
|
3389
3284
|
Raises:
|
|
@@ -3648,8 +3543,8 @@ class HfApi:
|
|
|
3648
3543
|
space_hardware: Optional[SpaceHardware] = None,
|
|
3649
3544
|
space_storage: Optional[SpaceStorage] = None,
|
|
3650
3545
|
space_sleep_time: Optional[int] = None,
|
|
3651
|
-
space_secrets: Optional[
|
|
3652
|
-
space_variables: Optional[
|
|
3546
|
+
space_secrets: Optional[list[dict[str, str]]] = None,
|
|
3547
|
+
space_variables: Optional[list[dict[str, str]]] = None,
|
|
3653
3548
|
) -> RepoUrl:
|
|
3654
3549
|
"""Create an empty repo on the HuggingFace Hub.
|
|
3655
3550
|
|
|
@@ -3686,10 +3581,10 @@ class HfApi:
|
|
|
3686
3581
|
your Space to sleep (default behavior for upgraded hardware). For free hardware, you can't configure
|
|
3687
3582
|
the sleep time (value is fixed to 48 hours of inactivity).
|
|
3688
3583
|
See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
|
|
3689
|
-
space_secrets (`
|
|
3584
|
+
space_secrets (`list[dict[str, str]]`, *optional*):
|
|
3690
3585
|
A list of secret keys to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional.
|
|
3691
3586
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets.
|
|
3692
|
-
space_variables (`
|
|
3587
|
+
space_variables (`list[dict[str, str]]`, *optional*):
|
|
3693
3588
|
A list of public environment variables to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional.
|
|
3694
3589
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables.
|
|
3695
3590
|
|
|
@@ -3704,7 +3599,7 @@ class HfApi:
|
|
|
3704
3599
|
if repo_type not in constants.REPO_TYPES:
|
|
3705
3600
|
raise ValueError("Invalid repo type")
|
|
3706
3601
|
|
|
3707
|
-
json:
|
|
3602
|
+
json: dict[str, Any] = {"name": name, "organization": organization}
|
|
3708
3603
|
if private is not None:
|
|
3709
3604
|
json["private"] = private
|
|
3710
3605
|
if repo_type is not None:
|
|
@@ -3764,7 +3659,7 @@ class HfApi:
|
|
|
3764
3659
|
|
|
3765
3660
|
try:
|
|
3766
3661
|
hf_raise_for_status(r)
|
|
3767
|
-
except
|
|
3662
|
+
except HfHubHTTPError as err:
|
|
3768
3663
|
if exist_ok and err.response.status_code == 409:
|
|
3769
3664
|
# Repo already exists and `exist_ok=True`
|
|
3770
3665
|
pass
|
|
@@ -3826,68 +3721,13 @@ class HfApi:
|
|
|
3826
3721
|
json["type"] = repo_type
|
|
3827
3722
|
|
|
3828
3723
|
headers = self._build_hf_headers(token=token)
|
|
3829
|
-
r = get_session().
|
|
3724
|
+
r = get_session().request("DELETE", path, headers=headers, json=json)
|
|
3830
3725
|
try:
|
|
3831
3726
|
hf_raise_for_status(r)
|
|
3832
3727
|
except RepositoryNotFoundError:
|
|
3833
3728
|
if not missing_ok:
|
|
3834
3729
|
raise
|
|
3835
3730
|
|
|
3836
|
-
@_deprecate_method(version="0.32", message="Please use `update_repo_settings` instead.")
|
|
3837
|
-
@validate_hf_hub_args
|
|
3838
|
-
def update_repo_visibility(
|
|
3839
|
-
self,
|
|
3840
|
-
repo_id: str,
|
|
3841
|
-
private: bool = False,
|
|
3842
|
-
*,
|
|
3843
|
-
token: Union[str, bool, None] = None,
|
|
3844
|
-
repo_type: Optional[str] = None,
|
|
3845
|
-
) -> Dict[str, bool]:
|
|
3846
|
-
"""Update the visibility setting of a repository.
|
|
3847
|
-
|
|
3848
|
-
Deprecated. Use `update_repo_settings` instead.
|
|
3849
|
-
|
|
3850
|
-
Args:
|
|
3851
|
-
repo_id (`str`, *optional*):
|
|
3852
|
-
A namespace (user or an organization) and a repo name separated by a `/`.
|
|
3853
|
-
private (`bool`, *optional*, defaults to `False`):
|
|
3854
|
-
Whether the repository should be private.
|
|
3855
|
-
token (Union[bool, str, None], optional):
|
|
3856
|
-
A valid user access token (string). Defaults to the locally saved
|
|
3857
|
-
token, which is the recommended method for authentication (see
|
|
3858
|
-
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3859
|
-
To disable authentication, pass `False`.
|
|
3860
|
-
repo_type (`str`, *optional*):
|
|
3861
|
-
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
3862
|
-
space, `None` or `"model"` if uploading to a model. Default is
|
|
3863
|
-
`None`.
|
|
3864
|
-
|
|
3865
|
-
Returns:
|
|
3866
|
-
The HTTP response in json.
|
|
3867
|
-
|
|
3868
|
-
<Tip>
|
|
3869
|
-
|
|
3870
|
-
Raises the following errors:
|
|
3871
|
-
|
|
3872
|
-
- [`~utils.RepositoryNotFoundError`]
|
|
3873
|
-
If the repository to download from cannot be found. This may be because it doesn't exist,
|
|
3874
|
-
or because it is set to `private` and you do not have access.
|
|
3875
|
-
|
|
3876
|
-
</Tip>
|
|
3877
|
-
"""
|
|
3878
|
-
if repo_type not in constants.REPO_TYPES:
|
|
3879
|
-
raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
|
|
3880
|
-
if repo_type is None:
|
|
3881
|
-
repo_type = constants.REPO_TYPE_MODEL # default repo type
|
|
3882
|
-
|
|
3883
|
-
r = get_session().put(
|
|
3884
|
-
url=f"{self.endpoint}/api/{repo_type}s/{repo_id}/settings",
|
|
3885
|
-
headers=self._build_hf_headers(token=token),
|
|
3886
|
-
json={"private": private},
|
|
3887
|
-
)
|
|
3888
|
-
hf_raise_for_status(r)
|
|
3889
|
-
return r.json()
|
|
3890
|
-
|
|
3891
3731
|
@validate_hf_hub_args
|
|
3892
3732
|
def update_repo_settings(
|
|
3893
3733
|
self,
|
|
@@ -3943,7 +3783,7 @@ class HfApi:
|
|
|
3943
3783
|
repo_type = constants.REPO_TYPE_MODEL # default repo type
|
|
3944
3784
|
|
|
3945
3785
|
# Prepare the JSON payload for the PUT request
|
|
3946
|
-
payload:
|
|
3786
|
+
payload: dict = {}
|
|
3947
3787
|
|
|
3948
3788
|
if gated is not None:
|
|
3949
3789
|
if gated not in ["auto", "manual", False]:
|
|
@@ -4338,12 +4178,12 @@ class HfApi:
|
|
|
4338
4178
|
params = {"create_pr": "1"} if create_pr else None
|
|
4339
4179
|
|
|
4340
4180
|
try:
|
|
4341
|
-
commit_resp = get_session().post(url=commit_url, headers=headers,
|
|
4181
|
+
commit_resp = get_session().post(url=commit_url, headers=headers, content=data, params=params)
|
|
4342
4182
|
hf_raise_for_status(commit_resp, endpoint_name="commit")
|
|
4343
4183
|
except RepositoryNotFoundError as e:
|
|
4344
4184
|
e.append_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)
|
|
4345
4185
|
raise
|
|
4346
|
-
except
|
|
4186
|
+
except RemoteEntryNotFoundError as e:
|
|
4347
4187
|
if nb_deletions > 0 and "A file with this name doesn't exist" in str(e):
|
|
4348
4188
|
e.append_to_message(
|
|
4349
4189
|
"\nMake sure to differentiate file and folder paths in delete"
|
|
@@ -4653,7 +4493,7 @@ class HfApi:
|
|
|
4653
4493
|
|
|
4654
4494
|
Raises the following errors:
|
|
4655
4495
|
|
|
4656
|
-
- [`
|
|
4496
|
+
- [`HfHubHTTPError`]
|
|
4657
4497
|
if the HuggingFace API returned an error
|
|
4658
4498
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
4659
4499
|
if some parameter value is invalid
|
|
@@ -4687,7 +4527,6 @@ class HfApi:
|
|
|
4687
4527
|
... repo_type="dataset",
|
|
4688
4528
|
... token="my_token",
|
|
4689
4529
|
... )
|
|
4690
|
-
"https://huggingface.co/datasets/username/my-dataset/blob/main/remote/file/path.h5"
|
|
4691
4530
|
|
|
4692
4531
|
>>> upload_file(
|
|
4693
4532
|
... path_or_fileobj=".\\\\local\\\\file\\\\path",
|
|
@@ -4695,7 +4534,6 @@ class HfApi:
|
|
|
4695
4534
|
... repo_id="username/my-model",
|
|
4696
4535
|
... token="my_token",
|
|
4697
4536
|
... )
|
|
4698
|
-
"https://huggingface.co/username/my-model/blob/main/remote/file/path.h5"
|
|
4699
4537
|
|
|
4700
4538
|
>>> upload_file(
|
|
4701
4539
|
... path_or_fileobj=".\\\\local\\\\file\\\\path",
|
|
@@ -4704,7 +4542,6 @@ class HfApi:
|
|
|
4704
4542
|
... token="my_token",
|
|
4705
4543
|
... create_pr=True,
|
|
4706
4544
|
... )
|
|
4707
|
-
"https://huggingface.co/username/my-model/blob/refs%2Fpr%2F1/remote/file/path.h5"
|
|
4708
4545
|
```
|
|
4709
4546
|
"""
|
|
4710
4547
|
if repo_type not in constants.REPO_TYPES:
|
|
@@ -4718,7 +4555,7 @@ class HfApi:
|
|
|
4718
4555
|
path_in_repo=path_in_repo,
|
|
4719
4556
|
)
|
|
4720
4557
|
|
|
4721
|
-
|
|
4558
|
+
return self.create_commit(
|
|
4722
4559
|
repo_id=repo_id,
|
|
4723
4560
|
repo_type=repo_type,
|
|
4724
4561
|
operations=[operation],
|
|
@@ -4730,23 +4567,6 @@ class HfApi:
|
|
|
4730
4567
|
parent_commit=parent_commit,
|
|
4731
4568
|
)
|
|
4732
4569
|
|
|
4733
|
-
if commit_info.pr_url is not None:
|
|
4734
|
-
revision = quote(_parse_revision_from_pr_url(commit_info.pr_url), safe="")
|
|
4735
|
-
if repo_type in constants.REPO_TYPES_URL_PREFIXES:
|
|
4736
|
-
repo_id = constants.REPO_TYPES_URL_PREFIXES[repo_type] + repo_id
|
|
4737
|
-
revision = revision if revision is not None else constants.DEFAULT_REVISION
|
|
4738
|
-
|
|
4739
|
-
return CommitInfo(
|
|
4740
|
-
commit_url=commit_info.commit_url,
|
|
4741
|
-
commit_message=commit_info.commit_message,
|
|
4742
|
-
commit_description=commit_info.commit_description,
|
|
4743
|
-
oid=commit_info.oid,
|
|
4744
|
-
pr_url=commit_info.pr_url,
|
|
4745
|
-
# Similar to `hf_hub_url` but it's "blob" instead of "resolve"
|
|
4746
|
-
# TODO: remove this in v1.0
|
|
4747
|
-
_url=f"{self.endpoint}/{repo_id}/blob/{revision}/{path_in_repo}",
|
|
4748
|
-
)
|
|
4749
|
-
|
|
4750
4570
|
@overload
|
|
4751
4571
|
def upload_folder( # type: ignore
|
|
4752
4572
|
self,
|
|
@@ -4761,9 +4581,9 @@ class HfApi:
|
|
|
4761
4581
|
revision: Optional[str] = None,
|
|
4762
4582
|
create_pr: Optional[bool] = None,
|
|
4763
4583
|
parent_commit: Optional[str] = None,
|
|
4764
|
-
allow_patterns: Optional[Union[
|
|
4765
|
-
ignore_patterns: Optional[Union[
|
|
4766
|
-
delete_patterns: Optional[Union[
|
|
4584
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
4585
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
4586
|
+
delete_patterns: Optional[Union[list[str], str]] = None,
|
|
4767
4587
|
run_as_future: Literal[False] = ...,
|
|
4768
4588
|
) -> CommitInfo: ...
|
|
4769
4589
|
|
|
@@ -4781,9 +4601,9 @@ class HfApi:
|
|
|
4781
4601
|
revision: Optional[str] = None,
|
|
4782
4602
|
create_pr: Optional[bool] = None,
|
|
4783
4603
|
parent_commit: Optional[str] = None,
|
|
4784
|
-
allow_patterns: Optional[Union[
|
|
4785
|
-
ignore_patterns: Optional[Union[
|
|
4786
|
-
delete_patterns: Optional[Union[
|
|
4604
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
4605
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
4606
|
+
delete_patterns: Optional[Union[list[str], str]] = None,
|
|
4787
4607
|
run_as_future: Literal[True] = ...,
|
|
4788
4608
|
) -> Future[CommitInfo]: ...
|
|
4789
4609
|
|
|
@@ -4802,9 +4622,9 @@ class HfApi:
|
|
|
4802
4622
|
revision: Optional[str] = None,
|
|
4803
4623
|
create_pr: Optional[bool] = None,
|
|
4804
4624
|
parent_commit: Optional[str] = None,
|
|
4805
|
-
allow_patterns: Optional[Union[
|
|
4806
|
-
ignore_patterns: Optional[Union[
|
|
4807
|
-
delete_patterns: Optional[Union[
|
|
4625
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
4626
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
4627
|
+
delete_patterns: Optional[Union[list[str], str]] = None,
|
|
4808
4628
|
run_as_future: bool = False,
|
|
4809
4629
|
) -> Union[CommitInfo, Future[CommitInfo]]:
|
|
4810
4630
|
"""
|
|
@@ -4866,11 +4686,11 @@ class HfApi:
|
|
|
4866
4686
|
If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.
|
|
4867
4687
|
Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be
|
|
4868
4688
|
especially useful if the repo is updated / committed to concurrently.
|
|
4869
|
-
allow_patterns (`
|
|
4689
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
4870
4690
|
If provided, only files matching at least one pattern are uploaded.
|
|
4871
|
-
ignore_patterns (`
|
|
4691
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
4872
4692
|
If provided, files matching any of the patterns are not uploaded.
|
|
4873
|
-
delete_patterns (`
|
|
4693
|
+
delete_patterns (`list[str]` or `str`, *optional*):
|
|
4874
4694
|
If provided, remote files matching any of the patterns will be deleted from the repo while committing
|
|
4875
4695
|
new files. This is useful if you don't know which files have already been uploaded.
|
|
4876
4696
|
Note: to avoid discrepancies the `.gitattributes` file is not deleted even if it matches the pattern.
|
|
@@ -4889,7 +4709,7 @@ class HfApi:
|
|
|
4889
4709
|
|
|
4890
4710
|
Raises the following errors:
|
|
4891
4711
|
|
|
4892
|
-
- [`
|
|
4712
|
+
- [`HfHubHTTPError`]
|
|
4893
4713
|
if the HuggingFace API returned an error
|
|
4894
4714
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
4895
4715
|
if some parameter value is invalid
|
|
@@ -4922,7 +4742,6 @@ class HfApi:
|
|
|
4922
4742
|
... token="my_token",
|
|
4923
4743
|
... ignore_patterns="**/logs/*.txt",
|
|
4924
4744
|
... )
|
|
4925
|
-
# "https://huggingface.co/datasets/username/my-dataset/tree/main/remote/experiment/checkpoints"
|
|
4926
4745
|
|
|
4927
4746
|
# Upload checkpoints folder including logs while deleting existing logs from the repo
|
|
4928
4747
|
# Useful if you don't know exactly which log files have already being pushed
|
|
@@ -4934,7 +4753,6 @@ class HfApi:
|
|
|
4934
4753
|
... token="my_token",
|
|
4935
4754
|
... delete_patterns="**/logs/*.txt",
|
|
4936
4755
|
... )
|
|
4937
|
-
"https://huggingface.co/datasets/username/my-dataset/tree/main/remote/experiment/checkpoints"
|
|
4938
4756
|
|
|
4939
4757
|
# Upload checkpoints folder while creating a PR
|
|
4940
4758
|
>>> upload_folder(
|
|
@@ -4945,8 +4763,6 @@ class HfApi:
|
|
|
4945
4763
|
... token="my_token",
|
|
4946
4764
|
... create_pr=True,
|
|
4947
4765
|
... )
|
|
4948
|
-
"https://huggingface.co/datasets/username/my-dataset/tree/refs%2Fpr%2F1/remote/experiment/checkpoints"
|
|
4949
|
-
|
|
4950
4766
|
```
|
|
4951
4767
|
"""
|
|
4952
4768
|
if repo_type not in constants.REPO_TYPES:
|
|
@@ -4990,7 +4806,7 @@ class HfApi:
|
|
|
4990
4806
|
|
|
4991
4807
|
commit_message = commit_message or "Upload folder using huggingface_hub"
|
|
4992
4808
|
|
|
4993
|
-
|
|
4809
|
+
return self.create_commit(
|
|
4994
4810
|
repo_type=repo_type,
|
|
4995
4811
|
repo_id=repo_id,
|
|
4996
4812
|
operations=commit_operations,
|
|
@@ -5002,24 +4818,6 @@ class HfApi:
|
|
|
5002
4818
|
parent_commit=parent_commit,
|
|
5003
4819
|
)
|
|
5004
4820
|
|
|
5005
|
-
# Create url to uploaded folder (for legacy return value)
|
|
5006
|
-
if create_pr and commit_info.pr_url is not None:
|
|
5007
|
-
revision = quote(_parse_revision_from_pr_url(commit_info.pr_url), safe="")
|
|
5008
|
-
if repo_type in constants.REPO_TYPES_URL_PREFIXES:
|
|
5009
|
-
repo_id = constants.REPO_TYPES_URL_PREFIXES[repo_type] + repo_id
|
|
5010
|
-
revision = revision if revision is not None else constants.DEFAULT_REVISION
|
|
5011
|
-
|
|
5012
|
-
return CommitInfo(
|
|
5013
|
-
commit_url=commit_info.commit_url,
|
|
5014
|
-
commit_message=commit_info.commit_message,
|
|
5015
|
-
commit_description=commit_info.commit_description,
|
|
5016
|
-
oid=commit_info.oid,
|
|
5017
|
-
pr_url=commit_info.pr_url,
|
|
5018
|
-
# Similar to `hf_hub_url` but it's "tree" instead of "resolve"
|
|
5019
|
-
# TODO: remove this in v1.0
|
|
5020
|
-
_url=f"{self.endpoint}/{repo_id}/tree/{revision}/{path_in_repo}",
|
|
5021
|
-
)
|
|
5022
|
-
|
|
5023
4821
|
@validate_hf_hub_args
|
|
5024
4822
|
def delete_file(
|
|
5025
4823
|
self,
|
|
@@ -5077,7 +4875,7 @@ class HfApi:
|
|
|
5077
4875
|
|
|
5078
4876
|
Raises the following errors:
|
|
5079
4877
|
|
|
5080
|
-
- [`
|
|
4878
|
+
- [`HfHubHTTPError`]
|
|
5081
4879
|
if the HuggingFace API returned an error
|
|
5082
4880
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
5083
4881
|
if some parameter value is invalid
|
|
@@ -5086,7 +4884,7 @@ class HfApi:
|
|
|
5086
4884
|
or because it is set to `private` and you do not have access.
|
|
5087
4885
|
- [`~utils.RevisionNotFoundError`]
|
|
5088
4886
|
If the revision to download from cannot be found.
|
|
5089
|
-
- [`~utils.
|
|
4887
|
+
- [`~utils.RemoteEntryNotFoundError`]
|
|
5090
4888
|
If the file to download cannot be found.
|
|
5091
4889
|
|
|
5092
4890
|
</Tip>
|
|
@@ -5114,7 +4912,7 @@ class HfApi:
|
|
|
5114
4912
|
def delete_files(
|
|
5115
4913
|
self,
|
|
5116
4914
|
repo_id: str,
|
|
5117
|
-
delete_patterns:
|
|
4915
|
+
delete_patterns: list[str],
|
|
5118
4916
|
*,
|
|
5119
4917
|
token: Union[bool, str, None] = None,
|
|
5120
4918
|
repo_type: Optional[str] = None,
|
|
@@ -5134,7 +4932,7 @@ class HfApi:
|
|
|
5134
4932
|
repo_id (`str`):
|
|
5135
4933
|
The repository from which the folder will be deleted, for example:
|
|
5136
4934
|
`"username/custom_transformers"`
|
|
5137
|
-
delete_patterns (`
|
|
4935
|
+
delete_patterns (`list[str]`):
|
|
5138
4936
|
List of files or folders to delete. Each string can either be
|
|
5139
4937
|
a file path, a folder path or a Unix shell-style wildcard.
|
|
5140
4938
|
E.g. `["file.txt", "folder/", "data/*.parquet"]`
|
|
@@ -5262,8 +5060,8 @@ class HfApi:
|
|
|
5262
5060
|
repo_type: str, # Repo type is required!
|
|
5263
5061
|
revision: Optional[str] = None,
|
|
5264
5062
|
private: Optional[bool] = None,
|
|
5265
|
-
allow_patterns: Optional[Union[
|
|
5266
|
-
ignore_patterns: Optional[Union[
|
|
5063
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
5064
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
5267
5065
|
num_workers: Optional[int] = None,
|
|
5268
5066
|
print_report: bool = True,
|
|
5269
5067
|
print_report_every: int = 60,
|
|
@@ -5291,9 +5089,9 @@ class HfApi:
|
|
|
5291
5089
|
private (`bool`, `optional`):
|
|
5292
5090
|
Whether the repository should be private.
|
|
5293
5091
|
If `None` (default), the repo will be public unless the organization's default is private.
|
|
5294
|
-
allow_patterns (`
|
|
5092
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
5295
5093
|
If provided, only files matching at least one pattern are uploaded.
|
|
5296
|
-
ignore_patterns (`
|
|
5094
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
5297
5095
|
If provided, files matching any of the patterns are not uploaded.
|
|
5298
5096
|
num_workers (`int`, *optional*):
|
|
5299
5097
|
Number of workers to start. Defaults to `os.cpu_count() - 2` (minimum 2).
|
|
@@ -5383,7 +5181,6 @@ class HfApi:
|
|
|
5383
5181
|
*,
|
|
5384
5182
|
url: str,
|
|
5385
5183
|
token: Union[bool, str, None] = None,
|
|
5386
|
-
proxies: Optional[Dict] = None,
|
|
5387
5184
|
timeout: Optional[float] = constants.DEFAULT_REQUEST_TIMEOUT,
|
|
5388
5185
|
) -> HfFileMetadata:
|
|
5389
5186
|
"""Fetch metadata of a file versioned on the Hub for a given url.
|
|
@@ -5396,8 +5193,6 @@ class HfApi:
|
|
|
5396
5193
|
token, which is the recommended method for authentication (see
|
|
5397
5194
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5398
5195
|
To disable authentication, pass `False`.
|
|
5399
|
-
proxies (`dict`, *optional*):
|
|
5400
|
-
Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
|
|
5401
5196
|
timeout (`float`, *optional*, defaults to 10):
|
|
5402
5197
|
How many seconds to wait for the server to send metadata before giving up.
|
|
5403
5198
|
|
|
@@ -5411,7 +5206,6 @@ class HfApi:
|
|
|
5411
5206
|
return get_hf_file_metadata(
|
|
5412
5207
|
url=url,
|
|
5413
5208
|
token=token,
|
|
5414
|
-
proxies=proxies,
|
|
5415
5209
|
timeout=timeout,
|
|
5416
5210
|
library_name=self.library_name,
|
|
5417
5211
|
library_version=self.library_version,
|
|
@@ -5431,14 +5225,9 @@ class HfApi:
|
|
|
5431
5225
|
cache_dir: Union[str, Path, None] = None,
|
|
5432
5226
|
local_dir: Union[str, Path, None] = None,
|
|
5433
5227
|
force_download: bool = False,
|
|
5434
|
-
proxies: Optional[Dict] = None,
|
|
5435
5228
|
etag_timeout: float = constants.DEFAULT_ETAG_TIMEOUT,
|
|
5436
5229
|
token: Union[bool, str, None] = None,
|
|
5437
5230
|
local_files_only: bool = False,
|
|
5438
|
-
# Deprecated args
|
|
5439
|
-
resume_download: Optional[bool] = None,
|
|
5440
|
-
force_filename: Optional[str] = None,
|
|
5441
|
-
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5442
5231
|
) -> str:
|
|
5443
5232
|
"""Download a given file if it's not already present in the local cache.
|
|
5444
5233
|
|
|
@@ -5495,12 +5284,9 @@ class HfApi:
|
|
|
5495
5284
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
5496
5285
|
Whether the file should be downloaded even if it already exists in
|
|
5497
5286
|
the local cache.
|
|
5498
|
-
proxies (`dict`, *optional*):
|
|
5499
|
-
Dictionary mapping protocol to the URL of the proxy passed to
|
|
5500
|
-
`requests.request`.
|
|
5501
5287
|
etag_timeout (`float`, *optional*, defaults to `10`):
|
|
5502
5288
|
When fetching ETag, how many seconds to wait for the server to send
|
|
5503
|
-
data before giving up which is passed to `
|
|
5289
|
+
data before giving up which is passed to `httpx.request`.
|
|
5504
5290
|
token (Union[bool, str, None], optional):
|
|
5505
5291
|
A valid user access token (string). Defaults to the locally saved
|
|
5506
5292
|
token, which is the recommended method for authentication (see
|
|
@@ -5519,7 +5305,7 @@ class HfApi:
|
|
|
5519
5305
|
or because it is set to `private` and you do not have access.
|
|
5520
5306
|
[`~utils.RevisionNotFoundError`]
|
|
5521
5307
|
If the revision to download from cannot be found.
|
|
5522
|
-
[`~utils.
|
|
5308
|
+
[`~utils.RemoteEntryNotFoundError`]
|
|
5523
5309
|
If the file to download cannot be found.
|
|
5524
5310
|
[`~utils.LocalEntryNotFoundError`]
|
|
5525
5311
|
If network is disabled or unavailable and file is not found in cache.
|
|
@@ -5547,13 +5333,9 @@ class HfApi:
|
|
|
5547
5333
|
library_version=self.library_version,
|
|
5548
5334
|
cache_dir=cache_dir,
|
|
5549
5335
|
local_dir=local_dir,
|
|
5550
|
-
local_dir_use_symlinks=local_dir_use_symlinks,
|
|
5551
5336
|
user_agent=self.user_agent,
|
|
5552
5337
|
force_download=force_download,
|
|
5553
|
-
force_filename=force_filename,
|
|
5554
|
-
proxies=proxies,
|
|
5555
5338
|
etag_timeout=etag_timeout,
|
|
5556
|
-
resume_download=resume_download,
|
|
5557
5339
|
token=token,
|
|
5558
5340
|
headers=self.headers,
|
|
5559
5341
|
local_files_only=local_files_only,
|
|
@@ -5568,18 +5350,14 @@ class HfApi:
|
|
|
5568
5350
|
revision: Optional[str] = None,
|
|
5569
5351
|
cache_dir: Union[str, Path, None] = None,
|
|
5570
5352
|
local_dir: Union[str, Path, None] = None,
|
|
5571
|
-
proxies: Optional[Dict] = None,
|
|
5572
5353
|
etag_timeout: float = constants.DEFAULT_ETAG_TIMEOUT,
|
|
5573
5354
|
force_download: bool = False,
|
|
5574
5355
|
token: Union[bool, str, None] = None,
|
|
5575
5356
|
local_files_only: bool = False,
|
|
5576
|
-
allow_patterns: Optional[Union[
|
|
5577
|
-
ignore_patterns: Optional[Union[
|
|
5357
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
5358
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
5578
5359
|
max_workers: int = 8,
|
|
5579
|
-
tqdm_class: Optional[
|
|
5580
|
-
# Deprecated args
|
|
5581
|
-
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5582
|
-
resume_download: Optional[bool] = None,
|
|
5360
|
+
tqdm_class: Optional[type[base_tqdm]] = None,
|
|
5583
5361
|
) -> str:
|
|
5584
5362
|
"""Download repo files.
|
|
5585
5363
|
|
|
@@ -5609,12 +5387,9 @@ class HfApi:
|
|
|
5609
5387
|
Path to the folder where cached files are stored.
|
|
5610
5388
|
local_dir (`str` or `Path`, *optional*):
|
|
5611
5389
|
If provided, the downloaded files will be placed under this directory.
|
|
5612
|
-
proxies (`dict`, *optional*):
|
|
5613
|
-
Dictionary mapping protocol to the URL of the proxy passed to
|
|
5614
|
-
`requests.request`.
|
|
5615
5390
|
etag_timeout (`float`, *optional*, defaults to `10`):
|
|
5616
5391
|
When fetching ETag, how many seconds to wait for the server to send
|
|
5617
|
-
data before giving up which is passed to `
|
|
5392
|
+
data before giving up which is passed to `httpx.request`.
|
|
5618
5393
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
5619
5394
|
Whether the file should be downloaded even if it already exists in the local cache.
|
|
5620
5395
|
token (Union[bool, str, None], optional):
|
|
@@ -5625,9 +5400,9 @@ class HfApi:
|
|
|
5625
5400
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
5626
5401
|
If `True`, avoid downloading the file and return the path to the
|
|
5627
5402
|
local cached file if it exists.
|
|
5628
|
-
allow_patterns (`
|
|
5403
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
5629
5404
|
If provided, only files matching at least one pattern are downloaded.
|
|
5630
|
-
ignore_patterns (`
|
|
5405
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
5631
5406
|
If provided, files matching any of the patterns are not downloaded.
|
|
5632
5407
|
max_workers (`int`, *optional*):
|
|
5633
5408
|
Number of concurrent threads to download files (1 thread = 1 file download).
|
|
@@ -5668,13 +5443,10 @@ class HfApi:
|
|
|
5668
5443
|
endpoint=self.endpoint,
|
|
5669
5444
|
cache_dir=cache_dir,
|
|
5670
5445
|
local_dir=local_dir,
|
|
5671
|
-
local_dir_use_symlinks=local_dir_use_symlinks,
|
|
5672
5446
|
library_name=self.library_name,
|
|
5673
5447
|
library_version=self.library_version,
|
|
5674
5448
|
user_agent=self.user_agent,
|
|
5675
|
-
proxies=proxies,
|
|
5676
5449
|
etag_timeout=etag_timeout,
|
|
5677
|
-
resume_download=resume_download,
|
|
5678
5450
|
force_download=force_download,
|
|
5679
5451
|
token=token,
|
|
5680
5452
|
local_files_only=local_files_only,
|
|
@@ -6291,7 +6063,7 @@ class HfApi:
|
|
|
6291
6063
|
headers = self._build_hf_headers(token=token)
|
|
6292
6064
|
path = f"{self.endpoint}/api/{repo_type}s/{repo_id}/discussions"
|
|
6293
6065
|
|
|
6294
|
-
params:
|
|
6066
|
+
params: dict[str, Union[str, int]] = {}
|
|
6295
6067
|
if discussion_type is not None:
|
|
6296
6068
|
params["type"] = discussion_type
|
|
6297
6069
|
if discussion_status is not None:
|
|
@@ -6361,7 +6133,7 @@ class HfApi:
|
|
|
6361
6133
|
|
|
6362
6134
|
Raises the following errors:
|
|
6363
6135
|
|
|
6364
|
-
- [`
|
|
6136
|
+
- [`HfHubHTTPError`]
|
|
6365
6137
|
if the HuggingFace API returned an error
|
|
6366
6138
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6367
6139
|
if some parameter value is invalid
|
|
@@ -6454,7 +6226,7 @@ class HfApi:
|
|
|
6454
6226
|
|
|
6455
6227
|
Raises the following errors:
|
|
6456
6228
|
|
|
6457
|
-
- [`
|
|
6229
|
+
- [`HfHubHTTPError`]
|
|
6458
6230
|
if the HuggingFace API returned an error
|
|
6459
6231
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6460
6232
|
if some parameter value is invalid
|
|
@@ -6542,7 +6314,7 @@ class HfApi:
|
|
|
6542
6314
|
|
|
6543
6315
|
Raises the following errors:
|
|
6544
6316
|
|
|
6545
|
-
- [`
|
|
6317
|
+
- [`HfHubHTTPError`]
|
|
6546
6318
|
if the HuggingFace API returned an error
|
|
6547
6319
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6548
6320
|
if some parameter value is invalid
|
|
@@ -6569,7 +6341,7 @@ class HfApi:
|
|
|
6569
6341
|
body: Optional[dict] = None,
|
|
6570
6342
|
token: Union[bool, str, None] = None,
|
|
6571
6343
|
repo_type: Optional[str] = None,
|
|
6572
|
-
) ->
|
|
6344
|
+
) -> httpx.Response:
|
|
6573
6345
|
"""Internal utility to POST changes to a Discussion or Pull Request"""
|
|
6574
6346
|
if not isinstance(discussion_num, int) or discussion_num <= 0:
|
|
6575
6347
|
raise ValueError("Invalid discussion_num, must be a positive integer")
|
|
@@ -6582,7 +6354,7 @@ class HfApi:
|
|
|
6582
6354
|
path = f"{self.endpoint}/api/{repo_id}/discussions/{discussion_num}/{resource}"
|
|
6583
6355
|
|
|
6584
6356
|
headers = self._build_hf_headers(token=token)
|
|
6585
|
-
resp =
|
|
6357
|
+
resp = get_session().post(path, headers=headers, json=body)
|
|
6586
6358
|
hf_raise_for_status(resp)
|
|
6587
6359
|
return resp
|
|
6588
6360
|
|
|
@@ -6645,7 +6417,7 @@ class HfApi:
|
|
|
6645
6417
|
|
|
6646
6418
|
Raises the following errors:
|
|
6647
6419
|
|
|
6648
|
-
- [`
|
|
6420
|
+
- [`HfHubHTTPError`]
|
|
6649
6421
|
if the HuggingFace API returned an error
|
|
6650
6422
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6651
6423
|
if some parameter value is invalid
|
|
@@ -6715,7 +6487,7 @@ class HfApi:
|
|
|
6715
6487
|
|
|
6716
6488
|
Raises the following errors:
|
|
6717
6489
|
|
|
6718
|
-
- [`
|
|
6490
|
+
- [`HfHubHTTPError`]
|
|
6719
6491
|
if the HuggingFace API returned an error
|
|
6720
6492
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6721
6493
|
if some parameter value is invalid
|
|
@@ -6788,7 +6560,7 @@ class HfApi:
|
|
|
6788
6560
|
|
|
6789
6561
|
Raises the following errors:
|
|
6790
6562
|
|
|
6791
|
-
- [`
|
|
6563
|
+
- [`HfHubHTTPError`]
|
|
6792
6564
|
if the HuggingFace API returned an error
|
|
6793
6565
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6794
6566
|
if some parameter value is invalid
|
|
@@ -6800,7 +6572,7 @@ class HfApi:
|
|
|
6800
6572
|
"""
|
|
6801
6573
|
if new_status not in ["open", "closed"]:
|
|
6802
6574
|
raise ValueError("Invalid status, valid statuses are: 'open' and 'closed'")
|
|
6803
|
-
body:
|
|
6575
|
+
body: dict[str, str] = {"status": new_status}
|
|
6804
6576
|
if comment and comment.strip():
|
|
6805
6577
|
body["comment"] = comment.strip()
|
|
6806
6578
|
resp = self._post_discussion_changes(
|
|
@@ -6850,7 +6622,7 @@ class HfApi:
|
|
|
6850
6622
|
|
|
6851
6623
|
Raises the following errors:
|
|
6852
6624
|
|
|
6853
|
-
- [`
|
|
6625
|
+
- [`HfHubHTTPError`]
|
|
6854
6626
|
if the HuggingFace API returned an error
|
|
6855
6627
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6856
6628
|
if some parameter value is invalid
|
|
@@ -6909,7 +6681,7 @@ class HfApi:
|
|
|
6909
6681
|
|
|
6910
6682
|
Raises the following errors:
|
|
6911
6683
|
|
|
6912
|
-
- [`
|
|
6684
|
+
- [`HfHubHTTPError`]
|
|
6913
6685
|
if the HuggingFace API returned an error
|
|
6914
6686
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6915
6687
|
if some parameter value is invalid
|
|
@@ -6970,7 +6742,7 @@ class HfApi:
|
|
|
6970
6742
|
|
|
6971
6743
|
Raises the following errors:
|
|
6972
6744
|
|
|
6973
|
-
- [`
|
|
6745
|
+
- [`HfHubHTTPError`]
|
|
6974
6746
|
if the HuggingFace API returned an error
|
|
6975
6747
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6976
6748
|
if some parameter value is invalid
|
|
@@ -7051,7 +6823,8 @@ class HfApi:
|
|
|
7051
6823
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7052
6824
|
To disable authentication, pass `False`.
|
|
7053
6825
|
"""
|
|
7054
|
-
r = get_session().
|
|
6826
|
+
r = get_session().request(
|
|
6827
|
+
"DELETE",
|
|
7055
6828
|
f"{self.endpoint}/api/spaces/{repo_id}/secrets",
|
|
7056
6829
|
headers=self._build_hf_headers(token=token),
|
|
7057
6830
|
json={"key": key},
|
|
@@ -7059,7 +6832,7 @@ class HfApi:
|
|
|
7059
6832
|
hf_raise_for_status(r)
|
|
7060
6833
|
|
|
7061
6834
|
@validate_hf_hub_args
|
|
7062
|
-
def get_space_variables(self, repo_id: str, *, token: Union[bool, str, None] = None) ->
|
|
6835
|
+
def get_space_variables(self, repo_id: str, *, token: Union[bool, str, None] = None) -> dict[str, SpaceVariable]:
|
|
7063
6836
|
"""Gets all variables from a Space.
|
|
7064
6837
|
|
|
7065
6838
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -7090,7 +6863,7 @@ class HfApi:
|
|
|
7090
6863
|
*,
|
|
7091
6864
|
description: Optional[str] = None,
|
|
7092
6865
|
token: Union[bool, str, None] = None,
|
|
7093
|
-
) ->
|
|
6866
|
+
) -> dict[str, SpaceVariable]:
|
|
7094
6867
|
"""Adds or updates a variable in a Space.
|
|
7095
6868
|
|
|
7096
6869
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -7125,7 +6898,7 @@ class HfApi:
|
|
|
7125
6898
|
@validate_hf_hub_args
|
|
7126
6899
|
def delete_space_variable(
|
|
7127
6900
|
self, repo_id: str, key: str, *, token: Union[bool, str, None] = None
|
|
7128
|
-
) ->
|
|
6901
|
+
) -> dict[str, SpaceVariable]:
|
|
7129
6902
|
"""Deletes a variable from a Space.
|
|
7130
6903
|
|
|
7131
6904
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -7142,7 +6915,8 @@ class HfApi:
|
|
|
7142
6915
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7143
6916
|
To disable authentication, pass `False`.
|
|
7144
6917
|
"""
|
|
7145
|
-
r = get_session().
|
|
6918
|
+
r = get_session().request(
|
|
6919
|
+
"DELETE",
|
|
7146
6920
|
f"{self.endpoint}/api/spaces/{repo_id}/variables",
|
|
7147
6921
|
headers=self._build_hf_headers(token=token),
|
|
7148
6922
|
json={"key": key},
|
|
@@ -7213,7 +6987,7 @@ class HfApi:
|
|
|
7213
6987
|
" you want to set a custom sleep time, you need to upgrade to a paid Hardware.",
|
|
7214
6988
|
UserWarning,
|
|
7215
6989
|
)
|
|
7216
|
-
payload:
|
|
6990
|
+
payload: dict[str, Any] = {"flavor": hardware}
|
|
7217
6991
|
if sleep_time is not None:
|
|
7218
6992
|
payload["sleepTimeSeconds"] = sleep_time
|
|
7219
6993
|
r = get_session().post(
|
|
@@ -7372,8 +7146,8 @@ class HfApi:
|
|
|
7372
7146
|
hardware: Optional[SpaceHardware] = None,
|
|
7373
7147
|
storage: Optional[SpaceStorage] = None,
|
|
7374
7148
|
sleep_time: Optional[int] = None,
|
|
7375
|
-
secrets: Optional[
|
|
7376
|
-
variables: Optional[
|
|
7149
|
+
secrets: Optional[list[dict[str, str]]] = None,
|
|
7150
|
+
variables: Optional[list[dict[str, str]]] = None,
|
|
7377
7151
|
) -> RepoUrl:
|
|
7378
7152
|
"""Duplicate a Space.
|
|
7379
7153
|
|
|
@@ -7404,10 +7178,10 @@ class HfApi:
|
|
|
7404
7178
|
your Space to sleep (default behavior for upgraded hardware). For free hardware, you can't configure
|
|
7405
7179
|
the sleep time (value is fixed to 48 hours of inactivity).
|
|
7406
7180
|
See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
|
|
7407
|
-
secrets (`
|
|
7181
|
+
secrets (`list[dict[str, str]]`, *optional*):
|
|
7408
7182
|
A list of secret keys to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional.
|
|
7409
7183
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets.
|
|
7410
|
-
variables (`
|
|
7184
|
+
variables (`list[dict[str, str]]`, *optional*):
|
|
7411
7185
|
A list of public environment variables to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional.
|
|
7412
7186
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables.
|
|
7413
7187
|
|
|
@@ -7419,7 +7193,7 @@ class HfApi:
|
|
|
7419
7193
|
[`~utils.RepositoryNotFoundError`]:
|
|
7420
7194
|
If one of `from_id` or `to_id` cannot be found. This may be because it doesn't exist,
|
|
7421
7195
|
or because it is set to `private` and you do not have access.
|
|
7422
|
-
[`
|
|
7196
|
+
[`HfHubHTTPError`]:
|
|
7423
7197
|
If the HuggingFace API returned an error
|
|
7424
7198
|
|
|
7425
7199
|
Example:
|
|
@@ -7447,7 +7221,7 @@ class HfApi:
|
|
|
7447
7221
|
to_repo_name = parsed_to_id.repo_name if to_id is not None else RepoUrl(from_id).repo_name # type: ignore
|
|
7448
7222
|
|
|
7449
7223
|
# repository must be a valid repo_id (namespace/repo_name).
|
|
7450
|
-
payload:
|
|
7224
|
+
payload: dict[str, Any] = {"repository": f"{to_namespace}/{to_repo_name}"}
|
|
7451
7225
|
|
|
7452
7226
|
keys = ["private", "hardware", "storageTier", "sleepTimeSeconds", "secrets", "variables"]
|
|
7453
7227
|
values = [private, hardware, storage, sleep_time, secrets, variables]
|
|
@@ -7469,7 +7243,7 @@ class HfApi:
|
|
|
7469
7243
|
|
|
7470
7244
|
try:
|
|
7471
7245
|
hf_raise_for_status(r)
|
|
7472
|
-
except
|
|
7246
|
+
except HfHubHTTPError as err:
|
|
7473
7247
|
if exist_ok and err.response.status_code == 409:
|
|
7474
7248
|
# Repo already exists and `exist_ok=True`
|
|
7475
7249
|
pass
|
|
@@ -7508,7 +7282,7 @@ class HfApi:
|
|
|
7508
7282
|
|
|
7509
7283
|
</Tip>
|
|
7510
7284
|
"""
|
|
7511
|
-
payload:
|
|
7285
|
+
payload: dict[str, SpaceStorage] = {"tier": storage}
|
|
7512
7286
|
r = get_session().post(
|
|
7513
7287
|
f"{self.endpoint}/api/spaces/{repo_id}/storage",
|
|
7514
7288
|
headers=self._build_hf_headers(token=token),
|
|
@@ -7554,7 +7328,7 @@ class HfApi:
|
|
|
7554
7328
|
|
|
7555
7329
|
def list_inference_endpoints(
|
|
7556
7330
|
self, namespace: Optional[str] = None, *, token: Union[bool, str, None] = None
|
|
7557
|
-
) ->
|
|
7331
|
+
) -> list[InferenceEndpoint]:
|
|
7558
7332
|
"""Lists all inference endpoints for the given namespace.
|
|
7559
7333
|
|
|
7560
7334
|
Args:
|
|
@@ -7568,7 +7342,7 @@ class HfApi:
|
|
|
7568
7342
|
To disable authentication, pass `False`.
|
|
7569
7343
|
|
|
7570
7344
|
Returns:
|
|
7571
|
-
|
|
7345
|
+
list[`InferenceEndpoint`]: A list of all inference endpoints for the given namespace.
|
|
7572
7346
|
|
|
7573
7347
|
Example:
|
|
7574
7348
|
```python
|
|
@@ -7583,7 +7357,7 @@ class HfApi:
|
|
|
7583
7357
|
user = self.whoami(token=token)
|
|
7584
7358
|
|
|
7585
7359
|
# List personal endpoints first
|
|
7586
|
-
endpoints:
|
|
7360
|
+
endpoints: list[InferenceEndpoint] = list_inference_endpoints(namespace=self._get_namespace(token=token))
|
|
7587
7361
|
|
|
7588
7362
|
# Then list endpoints for all orgs the user belongs to and ignore 401 errors (no billing or no access)
|
|
7589
7363
|
for org in user.get("orgs", []):
|
|
@@ -7627,14 +7401,14 @@ class HfApi:
|
|
|
7627
7401
|
scale_to_zero_timeout: Optional[int] = None,
|
|
7628
7402
|
revision: Optional[str] = None,
|
|
7629
7403
|
task: Optional[str] = None,
|
|
7630
|
-
custom_image: Optional[
|
|
7631
|
-
env: Optional[
|
|
7632
|
-
secrets: Optional[
|
|
7404
|
+
custom_image: Optional[dict] = None,
|
|
7405
|
+
env: Optional[dict[str, str]] = None,
|
|
7406
|
+
secrets: Optional[dict[str, str]] = None,
|
|
7633
7407
|
type: InferenceEndpointType = InferenceEndpointType.PROTECTED,
|
|
7634
7408
|
domain: Optional[str] = None,
|
|
7635
7409
|
path: Optional[str] = None,
|
|
7636
7410
|
cache_http_responses: Optional[bool] = None,
|
|
7637
|
-
tags: Optional[
|
|
7411
|
+
tags: Optional[list[str]] = None,
|
|
7638
7412
|
namespace: Optional[str] = None,
|
|
7639
7413
|
token: Union[bool, str, None] = None,
|
|
7640
7414
|
) -> InferenceEndpoint:
|
|
@@ -7671,12 +7445,12 @@ class HfApi:
|
|
|
7671
7445
|
The specific model revision to deploy on the Inference Endpoint (e.g. `"6c0e6080953db56375760c0471a8c5f2929baf11"`).
|
|
7672
7446
|
task (`str`, *optional*):
|
|
7673
7447
|
The task on which to deploy the model (e.g. `"text-classification"`).
|
|
7674
|
-
custom_image (`
|
|
7448
|
+
custom_image (`dict`, *optional*):
|
|
7675
7449
|
A custom Docker image to use for the Inference Endpoint. This is useful if you want to deploy an
|
|
7676
7450
|
Inference Endpoint running on the `text-generation-inference` (TGI) framework (see examples).
|
|
7677
|
-
env (`
|
|
7451
|
+
env (`dict[str, str]`, *optional*):
|
|
7678
7452
|
Non-secret environment variables to inject in the container environment.
|
|
7679
|
-
secrets (`
|
|
7453
|
+
secrets (`dict[str, str]`, *optional*):
|
|
7680
7454
|
Secret values to inject in the container environment.
|
|
7681
7455
|
type ([`InferenceEndpointType]`, *optional*):
|
|
7682
7456
|
The type of the Inference Endpoint, which can be `"protected"` (default), `"public"` or `"private"`.
|
|
@@ -7686,7 +7460,7 @@ class HfApi:
|
|
|
7686
7460
|
The custom path to the deployed model, should start with a `/` (e.g. `"/models/google-bert/bert-base-uncased"`).
|
|
7687
7461
|
cache_http_responses (`bool`, *optional*):
|
|
7688
7462
|
Whether to cache HTTP responses from the Inference Endpoint. Defaults to `False`.
|
|
7689
|
-
tags (`
|
|
7463
|
+
tags (`list[str]`, *optional*):
|
|
7690
7464
|
A list of tags to associate with the Inference Endpoint.
|
|
7691
7465
|
namespace (`str`, *optional*):
|
|
7692
7466
|
The namespace where the Inference Endpoint will be created. Defaults to the current user's namespace.
|
|
@@ -7789,7 +7563,7 @@ class HfApi:
|
|
|
7789
7563
|
else:
|
|
7790
7564
|
image = {"huggingface": {}}
|
|
7791
7565
|
|
|
7792
|
-
payload:
|
|
7566
|
+
payload: dict = {
|
|
7793
7567
|
"accountId": account_id,
|
|
7794
7568
|
"compute": {
|
|
7795
7569
|
"accelerator": accelerator,
|
|
@@ -7878,7 +7652,7 @@ class HfApi:
|
|
|
7878
7652
|
</Tip>
|
|
7879
7653
|
"""
|
|
7880
7654
|
token = token or self.token or get_token()
|
|
7881
|
-
payload:
|
|
7655
|
+
payload: dict = {
|
|
7882
7656
|
"namespace": namespace or self._get_namespace(token=token),
|
|
7883
7657
|
"repoId": repo_id,
|
|
7884
7658
|
}
|
|
@@ -7896,7 +7670,7 @@ class HfApi:
|
|
|
7896
7670
|
|
|
7897
7671
|
@experimental
|
|
7898
7672
|
@validate_hf_hub_args
|
|
7899
|
-
def list_inference_catalog(self, *, token: Union[bool, str, None] = None) ->
|
|
7673
|
+
def list_inference_catalog(self, *, token: Union[bool, str, None] = None) -> list[str]:
|
|
7900
7674
|
"""List models available in the Hugging Face Inference Catalog.
|
|
7901
7675
|
|
|
7902
7676
|
The goal of the Inference Catalog is to provide a curated list of models that are optimized for inference
|
|
@@ -7912,7 +7686,7 @@ class HfApi:
|
|
|
7912
7686
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7913
7687
|
|
|
7914
7688
|
Returns:
|
|
7915
|
-
|
|
7689
|
+
list[`str`]: A list of model IDs available in the catalog.
|
|
7916
7690
|
<Tip warning={true}>
|
|
7917
7691
|
|
|
7918
7692
|
`list_inference_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
|
|
@@ -7990,15 +7764,15 @@ class HfApi:
|
|
|
7990
7764
|
framework: Optional[str] = None,
|
|
7991
7765
|
revision: Optional[str] = None,
|
|
7992
7766
|
task: Optional[str] = None,
|
|
7993
|
-
custom_image: Optional[
|
|
7994
|
-
env: Optional[
|
|
7995
|
-
secrets: Optional[
|
|
7767
|
+
custom_image: Optional[dict] = None,
|
|
7768
|
+
env: Optional[dict[str, str]] = None,
|
|
7769
|
+
secrets: Optional[dict[str, str]] = None,
|
|
7996
7770
|
# Route update
|
|
7997
7771
|
domain: Optional[str] = None,
|
|
7998
7772
|
path: Optional[str] = None,
|
|
7999
7773
|
# Other
|
|
8000
7774
|
cache_http_responses: Optional[bool] = None,
|
|
8001
|
-
tags: Optional[
|
|
7775
|
+
tags: Optional[list[str]] = None,
|
|
8002
7776
|
namespace: Optional[str] = None,
|
|
8003
7777
|
token: Union[bool, str, None] = None,
|
|
8004
7778
|
) -> InferenceEndpoint:
|
|
@@ -8034,12 +7808,12 @@ class HfApi:
|
|
|
8034
7808
|
The specific model revision to deploy on the Inference Endpoint (e.g. `"6c0e6080953db56375760c0471a8c5f2929baf11"`).
|
|
8035
7809
|
task (`str`, *optional*):
|
|
8036
7810
|
The task on which to deploy the model (e.g. `"text-classification"`).
|
|
8037
|
-
custom_image (`
|
|
7811
|
+
custom_image (`dict`, *optional*):
|
|
8038
7812
|
A custom Docker image to use for the Inference Endpoint. This is useful if you want to deploy an
|
|
8039
7813
|
Inference Endpoint running on the `text-generation-inference` (TGI) framework (see examples).
|
|
8040
|
-
env (`
|
|
7814
|
+
env (`dict[str, str]`, *optional*):
|
|
8041
7815
|
Non-secret environment variables to inject in the container environment
|
|
8042
|
-
secrets (`
|
|
7816
|
+
secrets (`dict[str, str]`, *optional*):
|
|
8043
7817
|
Secret values to inject in the container environment.
|
|
8044
7818
|
|
|
8045
7819
|
domain (`str`, *optional*):
|
|
@@ -8049,7 +7823,7 @@ class HfApi:
|
|
|
8049
7823
|
|
|
8050
7824
|
cache_http_responses (`bool`, *optional*):
|
|
8051
7825
|
Whether to cache HTTP responses from the Inference Endpoint.
|
|
8052
|
-
tags (`
|
|
7826
|
+
tags (`list[str]`, *optional*):
|
|
8053
7827
|
A list of tags to associate with the Inference Endpoint.
|
|
8054
7828
|
|
|
8055
7829
|
namespace (`str`, *optional*):
|
|
@@ -8066,7 +7840,7 @@ class HfApi:
|
|
|
8066
7840
|
namespace = namespace or self._get_namespace(token=token)
|
|
8067
7841
|
|
|
8068
7842
|
# Populate only the fields that are not None
|
|
8069
|
-
payload:
|
|
7843
|
+
payload: dict = defaultdict(lambda: defaultdict(dict))
|
|
8070
7844
|
if accelerator is not None:
|
|
8071
7845
|
payload["compute"]["accelerator"] = accelerator
|
|
8072
7846
|
if instance_size is not None:
|
|
@@ -8273,8 +8047,8 @@ class HfApi:
|
|
|
8273
8047
|
def list_collections(
|
|
8274
8048
|
self,
|
|
8275
8049
|
*,
|
|
8276
|
-
owner: Union[
|
|
8277
|
-
item: Union[
|
|
8050
|
+
owner: Union[list[str], str, None] = None,
|
|
8051
|
+
item: Union[list[str], str, None] = None,
|
|
8278
8052
|
sort: Optional[Literal["lastModified", "trending", "upvotes"]] = None,
|
|
8279
8053
|
limit: Optional[int] = None,
|
|
8280
8054
|
token: Union[bool, str, None] = None,
|
|
@@ -8289,9 +8063,9 @@ class HfApi:
|
|
|
8289
8063
|
</Tip>
|
|
8290
8064
|
|
|
8291
8065
|
Args:
|
|
8292
|
-
owner (`
|
|
8066
|
+
owner (`list[str]` or `str`, *optional*):
|
|
8293
8067
|
Filter by owner's username.
|
|
8294
|
-
item (`
|
|
8068
|
+
item (`list[str]` or `str`, *optional*):
|
|
8295
8069
|
Filter collections containing a particular items. Example: `"models/teknium/OpenHermes-2.5-Mistral-7B"`, `"datasets/squad"` or `"papers/2311.12983"`.
|
|
8296
8070
|
sort (`Literal["lastModified", "trending", "upvotes"]`, *optional*):
|
|
8297
8071
|
Sort collections by last modified, trending or upvotes.
|
|
@@ -8309,7 +8083,7 @@ class HfApi:
|
|
|
8309
8083
|
# Construct the API endpoint
|
|
8310
8084
|
path = f"{self.endpoint}/api/collections"
|
|
8311
8085
|
headers = self._build_hf_headers(token=token)
|
|
8312
|
-
params:
|
|
8086
|
+
params: dict = {}
|
|
8313
8087
|
if owner is not None:
|
|
8314
8088
|
params.update({"owner": owner})
|
|
8315
8089
|
if item is not None:
|
|
@@ -8426,7 +8200,7 @@ class HfApi:
|
|
|
8426
8200
|
)
|
|
8427
8201
|
try:
|
|
8428
8202
|
hf_raise_for_status(r)
|
|
8429
|
-
except
|
|
8203
|
+
except HfHubHTTPError as err:
|
|
8430
8204
|
if exists_ok and err.response.status_code == 409:
|
|
8431
8205
|
# Collection already exists and `exists_ok=True`
|
|
8432
8206
|
slug = r.json()["slug"]
|
|
@@ -8537,7 +8311,7 @@ class HfApi:
|
|
|
8537
8311
|
)
|
|
8538
8312
|
try:
|
|
8539
8313
|
hf_raise_for_status(r)
|
|
8540
|
-
except
|
|
8314
|
+
except HfHubHTTPError as err:
|
|
8541
8315
|
if missing_ok and err.response.status_code == 404:
|
|
8542
8316
|
# Collection doesn't exists and `missing_ok=True`
|
|
8543
8317
|
return
|
|
@@ -8577,12 +8351,12 @@ class HfApi:
|
|
|
8577
8351
|
Returns: [`Collection`]
|
|
8578
8352
|
|
|
8579
8353
|
Raises:
|
|
8580
|
-
[`
|
|
8354
|
+
[`HfHubHTTPError`]:
|
|
8581
8355
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8582
8356
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8583
|
-
[`
|
|
8357
|
+
[`HfHubHTTPError`]:
|
|
8584
8358
|
HTTP 404 if the item you try to add to the collection does not exist on the Hub.
|
|
8585
|
-
[`
|
|
8359
|
+
[`HfHubHTTPError`]:
|
|
8586
8360
|
HTTP 409 if the item you try to add to the collection is already in the collection (and exists_ok=False)
|
|
8587
8361
|
|
|
8588
8362
|
Example:
|
|
@@ -8608,7 +8382,7 @@ class HfApi:
|
|
|
8608
8382
|
(...)
|
|
8609
8383
|
```
|
|
8610
8384
|
"""
|
|
8611
|
-
payload:
|
|
8385
|
+
payload: dict[str, Any] = {"item": {"id": item_id, "type": item_type}}
|
|
8612
8386
|
if note is not None:
|
|
8613
8387
|
payload["note"] = note
|
|
8614
8388
|
r = get_session().post(
|
|
@@ -8618,7 +8392,7 @@ class HfApi:
|
|
|
8618
8392
|
)
|
|
8619
8393
|
try:
|
|
8620
8394
|
hf_raise_for_status(r)
|
|
8621
|
-
except
|
|
8395
|
+
except HfHubHTTPError as err:
|
|
8622
8396
|
if exists_ok and err.response.status_code == 409:
|
|
8623
8397
|
# Item already exists and `exists_ok=True`
|
|
8624
8398
|
return self.get_collection(collection_slug, token=token)
|
|
@@ -8724,7 +8498,7 @@ class HfApi:
|
|
|
8724
8498
|
)
|
|
8725
8499
|
try:
|
|
8726
8500
|
hf_raise_for_status(r)
|
|
8727
|
-
except
|
|
8501
|
+
except HfHubHTTPError as err:
|
|
8728
8502
|
if missing_ok and err.response.status_code == 404:
|
|
8729
8503
|
# Item already deleted and `missing_ok=True`
|
|
8730
8504
|
return
|
|
@@ -8738,7 +8512,7 @@ class HfApi:
|
|
|
8738
8512
|
@validate_hf_hub_args
|
|
8739
8513
|
def list_pending_access_requests(
|
|
8740
8514
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8741
|
-
) ->
|
|
8515
|
+
) -> list[AccessRequest]:
|
|
8742
8516
|
"""
|
|
8743
8517
|
Get pending access requests for a given gated repo.
|
|
8744
8518
|
|
|
@@ -8761,14 +8535,14 @@ class HfApi:
|
|
|
8761
8535
|
To disable authentication, pass `False`.
|
|
8762
8536
|
|
|
8763
8537
|
Returns:
|
|
8764
|
-
`
|
|
8538
|
+
`list[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
8765
8539
|
`status` and `timestamp` attribute. If the gated repo has a custom form, the `fields` attribute will
|
|
8766
8540
|
be populated with user's answers.
|
|
8767
8541
|
|
|
8768
8542
|
Raises:
|
|
8769
|
-
[`
|
|
8543
|
+
[`HfHubHTTPError`]:
|
|
8770
8544
|
HTTP 400 if the repo is not gated.
|
|
8771
|
-
[`
|
|
8545
|
+
[`HfHubHTTPError`]:
|
|
8772
8546
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8773
8547
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8774
8548
|
|
|
@@ -8802,7 +8576,7 @@ class HfApi:
|
|
|
8802
8576
|
@validate_hf_hub_args
|
|
8803
8577
|
def list_accepted_access_requests(
|
|
8804
8578
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8805
|
-
) ->
|
|
8579
|
+
) -> list[AccessRequest]:
|
|
8806
8580
|
"""
|
|
8807
8581
|
Get accepted access requests for a given gated repo.
|
|
8808
8582
|
|
|
@@ -8827,14 +8601,14 @@ class HfApi:
|
|
|
8827
8601
|
To disable authentication, pass `False`.
|
|
8828
8602
|
|
|
8829
8603
|
Returns:
|
|
8830
|
-
`
|
|
8604
|
+
`list[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
8831
8605
|
`status` and `timestamp` attribute. If the gated repo has a custom form, the `fields` attribute will
|
|
8832
8606
|
be populated with user's answers.
|
|
8833
8607
|
|
|
8834
8608
|
Raises:
|
|
8835
|
-
[`
|
|
8609
|
+
[`HfHubHTTPError`]:
|
|
8836
8610
|
HTTP 400 if the repo is not gated.
|
|
8837
|
-
[`
|
|
8611
|
+
[`HfHubHTTPError`]:
|
|
8838
8612
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8839
8613
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8840
8614
|
|
|
@@ -8864,7 +8638,7 @@ class HfApi:
|
|
|
8864
8638
|
@validate_hf_hub_args
|
|
8865
8639
|
def list_rejected_access_requests(
|
|
8866
8640
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8867
|
-
) ->
|
|
8641
|
+
) -> list[AccessRequest]:
|
|
8868
8642
|
"""
|
|
8869
8643
|
Get rejected access requests for a given gated repo.
|
|
8870
8644
|
|
|
@@ -8889,14 +8663,14 @@ class HfApi:
|
|
|
8889
8663
|
To disable authentication, pass `False`.
|
|
8890
8664
|
|
|
8891
8665
|
Returns:
|
|
8892
|
-
`
|
|
8666
|
+
`list[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
8893
8667
|
`status` and `timestamp` attribute. If the gated repo has a custom form, the `fields` attribute will
|
|
8894
8668
|
be populated with user's answers.
|
|
8895
8669
|
|
|
8896
8670
|
Raises:
|
|
8897
|
-
[`
|
|
8671
|
+
[`HfHubHTTPError`]:
|
|
8898
8672
|
HTTP 400 if the repo is not gated.
|
|
8899
|
-
[`
|
|
8673
|
+
[`HfHubHTTPError`]:
|
|
8900
8674
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8901
8675
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8902
8676
|
|
|
@@ -8929,7 +8703,7 @@ class HfApi:
|
|
|
8929
8703
|
status: Literal["accepted", "rejected", "pending"],
|
|
8930
8704
|
repo_type: Optional[str] = None,
|
|
8931
8705
|
token: Union[bool, str, None] = None,
|
|
8932
|
-
) ->
|
|
8706
|
+
) -> list[AccessRequest]:
|
|
8933
8707
|
if repo_type not in constants.REPO_TYPES:
|
|
8934
8708
|
raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
|
|
8935
8709
|
if repo_type is None:
|
|
@@ -8978,16 +8752,16 @@ class HfApi:
|
|
|
8978
8752
|
To disable authentication, pass `False`.
|
|
8979
8753
|
|
|
8980
8754
|
Raises:
|
|
8981
|
-
[`
|
|
8755
|
+
[`HfHubHTTPError`]:
|
|
8982
8756
|
HTTP 400 if the repo is not gated.
|
|
8983
|
-
[`
|
|
8757
|
+
[`HfHubHTTPError`]:
|
|
8984
8758
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8985
8759
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8986
|
-
[`
|
|
8760
|
+
[`HfHubHTTPError`]:
|
|
8987
8761
|
HTTP 404 if the user does not exist on the Hub.
|
|
8988
|
-
[`
|
|
8762
|
+
[`HfHubHTTPError`]:
|
|
8989
8763
|
HTTP 404 if the user access request cannot be found.
|
|
8990
|
-
[`
|
|
8764
|
+
[`HfHubHTTPError`]:
|
|
8991
8765
|
HTTP 404 if the user access request is already in the pending list.
|
|
8992
8766
|
"""
|
|
8993
8767
|
self._handle_access_request(repo_id, user, "pending", repo_type=repo_type, token=token)
|
|
@@ -9020,16 +8794,16 @@ class HfApi:
|
|
|
9020
8794
|
To disable authentication, pass `False`.
|
|
9021
8795
|
|
|
9022
8796
|
Raises:
|
|
9023
|
-
[`
|
|
8797
|
+
[`HfHubHTTPError`]:
|
|
9024
8798
|
HTTP 400 if the repo is not gated.
|
|
9025
|
-
[`
|
|
8799
|
+
[`HfHubHTTPError`]:
|
|
9026
8800
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
9027
8801
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
9028
|
-
[`
|
|
8802
|
+
[`HfHubHTTPError`]:
|
|
9029
8803
|
HTTP 404 if the user does not exist on the Hub.
|
|
9030
|
-
[`
|
|
8804
|
+
[`HfHubHTTPError`]:
|
|
9031
8805
|
HTTP 404 if the user access request cannot be found.
|
|
9032
|
-
[`
|
|
8806
|
+
[`HfHubHTTPError`]:
|
|
9033
8807
|
HTTP 404 if the user access request is already in the accepted list.
|
|
9034
8808
|
"""
|
|
9035
8809
|
self._handle_access_request(repo_id, user, "accepted", repo_type=repo_type, token=token)
|
|
@@ -9070,16 +8844,16 @@ class HfApi:
|
|
|
9070
8844
|
To disable authentication, pass `False`.
|
|
9071
8845
|
|
|
9072
8846
|
Raises:
|
|
9073
|
-
[`
|
|
8847
|
+
[`HfHubHTTPError`]:
|
|
9074
8848
|
HTTP 400 if the repo is not gated.
|
|
9075
|
-
[`
|
|
8849
|
+
[`HfHubHTTPError`]:
|
|
9076
8850
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
9077
8851
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
9078
|
-
[`
|
|
8852
|
+
[`HfHubHTTPError`]:
|
|
9079
8853
|
HTTP 404 if the user does not exist on the Hub.
|
|
9080
|
-
[`
|
|
8854
|
+
[`HfHubHTTPError`]:
|
|
9081
8855
|
HTTP 404 if the user access request cannot be found.
|
|
9082
|
-
[`
|
|
8856
|
+
[`HfHubHTTPError`]:
|
|
9083
8857
|
HTTP 404 if the user access request is already in the rejected list.
|
|
9084
8858
|
"""
|
|
9085
8859
|
self._handle_access_request(
|
|
@@ -9143,14 +8917,14 @@ class HfApi:
|
|
|
9143
8917
|
To disable authentication, pass `False`.
|
|
9144
8918
|
|
|
9145
8919
|
Raises:
|
|
9146
|
-
[`
|
|
8920
|
+
[`HfHubHTTPError`]:
|
|
9147
8921
|
HTTP 400 if the repo is not gated.
|
|
9148
|
-
[`
|
|
8922
|
+
[`HfHubHTTPError`]:
|
|
9149
8923
|
HTTP 400 if the user already has access to the repo.
|
|
9150
|
-
[`
|
|
8924
|
+
[`HfHubHTTPError`]:
|
|
9151
8925
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
9152
8926
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
9153
|
-
[`
|
|
8927
|
+
[`HfHubHTTPError`]:
|
|
9154
8928
|
HTTP 404 if the user does not exist on the Hub.
|
|
9155
8929
|
"""
|
|
9156
8930
|
if repo_type not in constants.REPO_TYPES:
|
|
@@ -9222,7 +8996,7 @@ class HfApi:
|
|
|
9222
8996
|
return webhook
|
|
9223
8997
|
|
|
9224
8998
|
@validate_hf_hub_args
|
|
9225
|
-
def list_webhooks(self, *, token: Union[bool, str, None] = None) ->
|
|
8999
|
+
def list_webhooks(self, *, token: Union[bool, str, None] = None) -> list[WebhookInfo]:
|
|
9226
9000
|
"""List all configured webhooks.
|
|
9227
9001
|
|
|
9228
9002
|
Args:
|
|
@@ -9232,7 +9006,7 @@ class HfApi:
|
|
|
9232
9006
|
To disable authentication, pass `False`.
|
|
9233
9007
|
|
|
9234
9008
|
Returns:
|
|
9235
|
-
`
|
|
9009
|
+
`list[WebhookInfo]`:
|
|
9236
9010
|
List of webhook info objects.
|
|
9237
9011
|
|
|
9238
9012
|
Example:
|
|
@@ -9276,8 +9050,8 @@ class HfApi:
|
|
|
9276
9050
|
self,
|
|
9277
9051
|
*,
|
|
9278
9052
|
url: str,
|
|
9279
|
-
watched:
|
|
9280
|
-
domains: Optional[
|
|
9053
|
+
watched: list[Union[dict, WebhookWatchedItem]],
|
|
9054
|
+
domains: Optional[list[constants.WEBHOOK_DOMAIN_T]] = None,
|
|
9281
9055
|
secret: Optional[str] = None,
|
|
9282
9056
|
token: Union[bool, str, None] = None,
|
|
9283
9057
|
) -> WebhookInfo:
|
|
@@ -9286,10 +9060,10 @@ class HfApi:
|
|
|
9286
9060
|
Args:
|
|
9287
9061
|
url (`str`):
|
|
9288
9062
|
URL to send the payload to.
|
|
9289
|
-
watched (`
|
|
9063
|
+
watched (`list[WebhookWatchedItem]`):
|
|
9290
9064
|
List of [`WebhookWatchedItem`] to be watched by the webhook. It can be users, orgs, models, datasets or spaces.
|
|
9291
9065
|
Watched items can also be provided as plain dictionaries.
|
|
9292
|
-
domains (`
|
|
9066
|
+
domains (`list[Literal["repo", "discussion"]]`, optional):
|
|
9293
9067
|
List of domains to watch. It can be "repo", "discussion" or both.
|
|
9294
9068
|
secret (`str`, optional):
|
|
9295
9069
|
A secret to sign the payload with.
|
|
@@ -9350,8 +9124,8 @@ class HfApi:
|
|
|
9350
9124
|
webhook_id: str,
|
|
9351
9125
|
*,
|
|
9352
9126
|
url: Optional[str] = None,
|
|
9353
|
-
watched: Optional[
|
|
9354
|
-
domains: Optional[
|
|
9127
|
+
watched: Optional[list[Union[dict, WebhookWatchedItem]]] = None,
|
|
9128
|
+
domains: Optional[list[constants.WEBHOOK_DOMAIN_T]] = None,
|
|
9355
9129
|
secret: Optional[str] = None,
|
|
9356
9130
|
token: Union[bool, str, None] = None,
|
|
9357
9131
|
) -> WebhookInfo:
|
|
@@ -9362,10 +9136,10 @@ class HfApi:
|
|
|
9362
9136
|
The unique identifier of the webhook to be updated.
|
|
9363
9137
|
url (`str`, optional):
|
|
9364
9138
|
The URL to which the payload will be sent.
|
|
9365
|
-
watched (`
|
|
9139
|
+
watched (`list[WebhookWatchedItem]`, optional):
|
|
9366
9140
|
List of items to watch. It can be users, orgs, models, datasets, or spaces.
|
|
9367
9141
|
Refer to [`WebhookWatchedItem`] for more details. Watched items can also be provided as plain dictionaries.
|
|
9368
|
-
domains (`
|
|
9142
|
+
domains (`list[Literal["repo", "discussion"]]`, optional):
|
|
9369
9143
|
The domains to watch. This can include "repo", "discussion", or both.
|
|
9370
9144
|
secret (`str`, optional):
|
|
9371
9145
|
A secret to sign the payload with, providing an additional layer of security.
|
|
@@ -9561,8 +9335,8 @@ class HfApi:
|
|
|
9561
9335
|
token: Union[bool, str, None] = None,
|
|
9562
9336
|
library_name: Optional[str] = None,
|
|
9563
9337
|
library_version: Optional[str] = None,
|
|
9564
|
-
user_agent: Union[
|
|
9565
|
-
) ->
|
|
9338
|
+
user_agent: Union[dict, str, None] = None,
|
|
9339
|
+
) -> dict[str, str]:
|
|
9566
9340
|
"""
|
|
9567
9341
|
Alias for [`build_hf_headers`] that uses the token from [`HfApi`] client
|
|
9568
9342
|
when `token` is not provided.
|
|
@@ -9584,9 +9358,9 @@ class HfApi:
|
|
|
9584
9358
|
repo_type: Optional[str],
|
|
9585
9359
|
revision: Optional[str],
|
|
9586
9360
|
path_in_repo: str,
|
|
9587
|
-
delete_patterns: Optional[Union[
|
|
9361
|
+
delete_patterns: Optional[Union[list[str], str]],
|
|
9588
9362
|
token: Union[bool, str, None] = None,
|
|
9589
|
-
) ->
|
|
9363
|
+
) -> list[CommitOperationDelete]:
|
|
9590
9364
|
"""Generate the list of Delete operations for a commit to delete files from a repo.
|
|
9591
9365
|
|
|
9592
9366
|
List remote files and match them against the `delete_patterns` constraints. Returns a list of [`CommitOperationDelete`]
|
|
@@ -9622,11 +9396,11 @@ class HfApi:
|
|
|
9622
9396
|
self,
|
|
9623
9397
|
folder_path: Union[str, Path],
|
|
9624
9398
|
path_in_repo: str,
|
|
9625
|
-
allow_patterns: Optional[Union[
|
|
9626
|
-
ignore_patterns: Optional[Union[
|
|
9399
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
9400
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
9627
9401
|
repo_type: Optional[str] = None,
|
|
9628
9402
|
token: Union[bool, str, None] = None,
|
|
9629
|
-
) ->
|
|
9403
|
+
) -> list[CommitOperationAdd]:
|
|
9630
9404
|
"""Generate the list of Add operations for a commit to upload a folder.
|
|
9631
9405
|
|
|
9632
9406
|
Files not matching the `allow_patterns` (allowlist) and `ignore_patterns` (denylist)
|
|
@@ -9741,7 +9515,7 @@ class HfApi:
|
|
|
9741
9515
|
`User`: A [`User`] object with the user's overview.
|
|
9742
9516
|
|
|
9743
9517
|
Raises:
|
|
9744
|
-
[`
|
|
9518
|
+
[`HfHubHTTPError`]:
|
|
9745
9519
|
HTTP 404 If the user does not exist on the Hub.
|
|
9746
9520
|
"""
|
|
9747
9521
|
r = get_session().get(
|
|
@@ -9767,7 +9541,7 @@ class HfApi:
|
|
|
9767
9541
|
`Iterable[User]`: A list of [`User`] objects with the members of the organization.
|
|
9768
9542
|
|
|
9769
9543
|
Raises:
|
|
9770
|
-
[`
|
|
9544
|
+
[`HfHubHTTPError`]:
|
|
9771
9545
|
HTTP 404 If the organization does not exist on the Hub.
|
|
9772
9546
|
|
|
9773
9547
|
"""
|
|
@@ -9795,7 +9569,7 @@ class HfApi:
|
|
|
9795
9569
|
`Iterable[User]`: A list of [`User`] objects with the followers of the user.
|
|
9796
9570
|
|
|
9797
9571
|
Raises:
|
|
9798
|
-
[`
|
|
9572
|
+
[`HfHubHTTPError`]:
|
|
9799
9573
|
HTTP 404 If the user does not exist on the Hub.
|
|
9800
9574
|
|
|
9801
9575
|
"""
|
|
@@ -9823,7 +9597,7 @@ class HfApi:
|
|
|
9823
9597
|
`Iterable[User]`: A list of [`User`] objects with the users followed by the user.
|
|
9824
9598
|
|
|
9825
9599
|
Raises:
|
|
9826
|
-
[`
|
|
9600
|
+
[`HfHubHTTPError`]:
|
|
9827
9601
|
HTTP 404 If the user does not exist on the Hub.
|
|
9828
9602
|
|
|
9829
9603
|
"""
|
|
@@ -9892,7 +9666,7 @@ class HfApi:
|
|
|
9892
9666
|
`PaperInfo`: A `PaperInfo` object.
|
|
9893
9667
|
|
|
9894
9668
|
Raises:
|
|
9895
|
-
[`
|
|
9669
|
+
[`HfHubHTTPError`]:
|
|
9896
9670
|
HTTP 404 If the paper does not exist on the Hub.
|
|
9897
9671
|
"""
|
|
9898
9672
|
path = f"{self.endpoint}/api/papers/{id}"
|
|
@@ -9968,9 +9742,9 @@ class HfApi:
|
|
|
9968
9742
|
self,
|
|
9969
9743
|
*,
|
|
9970
9744
|
image: str,
|
|
9971
|
-
command:
|
|
9972
|
-
env: Optional[
|
|
9973
|
-
secrets: Optional[
|
|
9745
|
+
command: list[str],
|
|
9746
|
+
env: Optional[dict[str, Any]] = None,
|
|
9747
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
9974
9748
|
flavor: Optional[SpaceHardware] = None,
|
|
9975
9749
|
timeout: Optional[Union[int, float, str]] = None,
|
|
9976
9750
|
namespace: Optional[str] = None,
|
|
@@ -9985,13 +9759,13 @@ class HfApi:
|
|
|
9985
9759
|
Examples: `"ubuntu"`, `"python:3.12"`, `"pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel"`.
|
|
9986
9760
|
Example with an image from a Space: `"hf.co/spaces/lhoestq/duckdb"`.
|
|
9987
9761
|
|
|
9988
|
-
command (`
|
|
9762
|
+
command (`list[str]`):
|
|
9989
9763
|
The command to run. Example: `["echo", "hello"]`.
|
|
9990
9764
|
|
|
9991
|
-
env (`
|
|
9765
|
+
env (`dict[str, Any]`, *optional*):
|
|
9992
9766
|
Defines the environment variables for the Job.
|
|
9993
9767
|
|
|
9994
|
-
secrets (`
|
|
9768
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
9995
9769
|
Defines the secret environment variables for the Job.
|
|
9996
9770
|
|
|
9997
9771
|
flavor (`str`, *optional*):
|
|
@@ -10100,29 +9874,28 @@ class HfApi:
|
|
|
10100
9874
|
time.sleep(sleep_time)
|
|
10101
9875
|
sleep_time = min(max_wait_time, max(min_wait_time, sleep_time * 2))
|
|
10102
9876
|
try:
|
|
10103
|
-
|
|
9877
|
+
with get_session().stream(
|
|
9878
|
+
"GET",
|
|
10104
9879
|
f"https://huggingface.co/api/jobs/{namespace}/{job_id}/logs",
|
|
10105
9880
|
headers=self._build_hf_headers(token=token),
|
|
10106
|
-
stream=True,
|
|
10107
9881
|
timeout=120,
|
|
10108
|
-
)
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
except requests.exceptions.ChunkedEncodingError:
|
|
9882
|
+
) as response:
|
|
9883
|
+
log = None
|
|
9884
|
+
for line in response.iter_lines():
|
|
9885
|
+
if line and line.startswith("data: {"):
|
|
9886
|
+
data = json.loads(line[len("data: ") :])
|
|
9887
|
+
# timestamp = data["timestamp"]
|
|
9888
|
+
if not data["data"].startswith("===== Job started"):
|
|
9889
|
+
logging_started = True
|
|
9890
|
+
log = data["data"]
|
|
9891
|
+
yield log
|
|
9892
|
+
logging_finished = logging_started
|
|
9893
|
+
except httpx.DecodingError:
|
|
10121
9894
|
# Response ended prematurely
|
|
10122
9895
|
break
|
|
10123
9896
|
except KeyboardInterrupt:
|
|
10124
9897
|
break
|
|
10125
|
-
except
|
|
9898
|
+
except httpx.NetworkError as err:
|
|
10126
9899
|
is_timeout = err.__context__ and isinstance(getattr(err.__context__, "__cause__", None), TimeoutError)
|
|
10127
9900
|
if logging_started or not is_timeout:
|
|
10128
9901
|
raise
|
|
@@ -10145,7 +9918,7 @@ class HfApi:
|
|
|
10145
9918
|
timeout: Optional[int] = None,
|
|
10146
9919
|
namespace: Optional[str] = None,
|
|
10147
9920
|
token: Union[bool, str, None] = None,
|
|
10148
|
-
) ->
|
|
9921
|
+
) -> list[JobInfo]:
|
|
10149
9922
|
"""
|
|
10150
9923
|
List compute Jobs on Hugging Face infrastructure.
|
|
10151
9924
|
|
|
@@ -10256,12 +10029,12 @@ class HfApi:
|
|
|
10256
10029
|
self,
|
|
10257
10030
|
script: str,
|
|
10258
10031
|
*,
|
|
10259
|
-
script_args: Optional[
|
|
10260
|
-
dependencies: Optional[
|
|
10032
|
+
script_args: Optional[list[str]] = None,
|
|
10033
|
+
dependencies: Optional[list[str]] = None,
|
|
10261
10034
|
python: Optional[str] = None,
|
|
10262
10035
|
image: Optional[str] = None,
|
|
10263
|
-
env: Optional[
|
|
10264
|
-
secrets: Optional[
|
|
10036
|
+
env: Optional[dict[str, Any]] = None,
|
|
10037
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
10265
10038
|
flavor: Optional[SpaceHardware] = None,
|
|
10266
10039
|
timeout: Optional[Union[int, float, str]] = None,
|
|
10267
10040
|
namespace: Optional[str] = None,
|
|
@@ -10275,10 +10048,10 @@ class HfApi:
|
|
|
10275
10048
|
script (`str`):
|
|
10276
10049
|
Path or URL of the UV script, or a command.
|
|
10277
10050
|
|
|
10278
|
-
script_args (`
|
|
10051
|
+
script_args (`list[str]`, *optional*)
|
|
10279
10052
|
Arguments to pass to the script or command.
|
|
10280
10053
|
|
|
10281
|
-
dependencies (`
|
|
10054
|
+
dependencies (`list[str]`, *optional*)
|
|
10282
10055
|
Dependencies to use to run the UV script.
|
|
10283
10056
|
|
|
10284
10057
|
python (`str`, *optional*)
|
|
@@ -10287,10 +10060,10 @@ class HfApi:
|
|
|
10287
10060
|
image (`str`, *optional*, defaults to "ghcr.io/astral-sh/uv:python3.12-bookworm"):
|
|
10288
10061
|
Use a custom Docker image with `uv` installed.
|
|
10289
10062
|
|
|
10290
|
-
env (`
|
|
10063
|
+
env (`dict[str, Any]`, *optional*):
|
|
10291
10064
|
Defines the environment variables for the Job.
|
|
10292
10065
|
|
|
10293
|
-
secrets (`
|
|
10066
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
10294
10067
|
Defines the secret environment variables for the Job.
|
|
10295
10068
|
|
|
10296
10069
|
flavor (`str`, *optional*):
|
|
@@ -10370,12 +10143,12 @@ class HfApi:
|
|
|
10370
10143
|
self,
|
|
10371
10144
|
*,
|
|
10372
10145
|
image: str,
|
|
10373
|
-
command:
|
|
10146
|
+
command: list[str],
|
|
10374
10147
|
schedule: str,
|
|
10375
10148
|
suspend: Optional[bool] = None,
|
|
10376
10149
|
concurrency: Optional[bool] = None,
|
|
10377
|
-
env: Optional[
|
|
10378
|
-
secrets: Optional[
|
|
10150
|
+
env: Optional[dict[str, Any]] = None,
|
|
10151
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
10379
10152
|
flavor: Optional[SpaceHardware] = None,
|
|
10380
10153
|
timeout: Optional[Union[int, float, str]] = None,
|
|
10381
10154
|
namespace: Optional[str] = None,
|
|
@@ -10390,7 +10163,7 @@ class HfApi:
|
|
|
10390
10163
|
Examples: `"ubuntu"`, `"python:3.12"`, `"pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel"`.
|
|
10391
10164
|
Example with an image from a Space: `"hf.co/spaces/lhoestq/duckdb"`.
|
|
10392
10165
|
|
|
10393
|
-
command (`
|
|
10166
|
+
command (`list[str]`):
|
|
10394
10167
|
The command to run. Example: `["echo", "hello"]`.
|
|
10395
10168
|
|
|
10396
10169
|
schedule (`str`):
|
|
@@ -10403,10 +10176,10 @@ class HfApi:
|
|
|
10403
10176
|
concurrency (`bool`, *optional*):
|
|
10404
10177
|
If True, multiple instances of this Job can run concurrently. Defaults to False.
|
|
10405
10178
|
|
|
10406
|
-
env (`
|
|
10179
|
+
env (`dict[str, Any]`, *optional*):
|
|
10407
10180
|
Defines the environment variables for the Job.
|
|
10408
10181
|
|
|
10409
|
-
secrets (`
|
|
10182
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
10410
10183
|
Defines the secret environment variables for the Job.
|
|
10411
10184
|
|
|
10412
10185
|
flavor (`str`, *optional*):
|
|
@@ -10462,7 +10235,7 @@ class HfApi:
|
|
|
10462
10235
|
flavor=flavor,
|
|
10463
10236
|
timeout=timeout,
|
|
10464
10237
|
)
|
|
10465
|
-
input_json:
|
|
10238
|
+
input_json: dict[str, Any] = {
|
|
10466
10239
|
"jobSpec": job_spec,
|
|
10467
10240
|
"schedule": schedule,
|
|
10468
10241
|
}
|
|
@@ -10485,7 +10258,7 @@ class HfApi:
|
|
|
10485
10258
|
timeout: Optional[int] = None,
|
|
10486
10259
|
namespace: Optional[str] = None,
|
|
10487
10260
|
token: Union[bool, str, None] = None,
|
|
10488
|
-
) ->
|
|
10261
|
+
) -> list[ScheduledJobInfo]:
|
|
10489
10262
|
"""
|
|
10490
10263
|
List scheduled compute Jobs on Hugging Face infrastructure.
|
|
10491
10264
|
|
|
@@ -10643,15 +10416,15 @@ class HfApi:
|
|
|
10643
10416
|
self,
|
|
10644
10417
|
script: str,
|
|
10645
10418
|
*,
|
|
10646
|
-
script_args: Optional[
|
|
10419
|
+
script_args: Optional[list[str]] = None,
|
|
10647
10420
|
schedule: str,
|
|
10648
10421
|
suspend: Optional[bool] = None,
|
|
10649
10422
|
concurrency: Optional[bool] = None,
|
|
10650
|
-
dependencies: Optional[
|
|
10423
|
+
dependencies: Optional[list[str]] = None,
|
|
10651
10424
|
python: Optional[str] = None,
|
|
10652
10425
|
image: Optional[str] = None,
|
|
10653
|
-
env: Optional[
|
|
10654
|
-
secrets: Optional[
|
|
10426
|
+
env: Optional[dict[str, Any]] = None,
|
|
10427
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
10655
10428
|
flavor: Optional[SpaceHardware] = None,
|
|
10656
10429
|
timeout: Optional[Union[int, float, str]] = None,
|
|
10657
10430
|
namespace: Optional[str] = None,
|
|
@@ -10665,7 +10438,7 @@ class HfApi:
|
|
|
10665
10438
|
script (`str`):
|
|
10666
10439
|
Path or URL of the UV script, or a command.
|
|
10667
10440
|
|
|
10668
|
-
script_args (`
|
|
10441
|
+
script_args (`list[str]`, *optional*)
|
|
10669
10442
|
Arguments to pass to the script, or a command.
|
|
10670
10443
|
|
|
10671
10444
|
schedule (`str`):
|
|
@@ -10678,7 +10451,7 @@ class HfApi:
|
|
|
10678
10451
|
concurrency (`bool`, *optional*):
|
|
10679
10452
|
If True, multiple instances of this Job can run concurrently. Defaults to False.
|
|
10680
10453
|
|
|
10681
|
-
dependencies (`
|
|
10454
|
+
dependencies (`list[str]`, *optional*)
|
|
10682
10455
|
Dependencies to use to run the UV script.
|
|
10683
10456
|
|
|
10684
10457
|
python (`str`, *optional*)
|
|
@@ -10687,10 +10460,10 @@ class HfApi:
|
|
|
10687
10460
|
image (`str`, *optional*, defaults to "ghcr.io/astral-sh/uv:python3.12-bookworm"):
|
|
10688
10461
|
Use a custom Docker image with `uv` installed.
|
|
10689
10462
|
|
|
10690
|
-
env (`
|
|
10463
|
+
env (`dict[str, Any]`, *optional*):
|
|
10691
10464
|
Defines the environment variables for the Job.
|
|
10692
10465
|
|
|
10693
|
-
secrets (`
|
|
10466
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
10694
10467
|
Defines the secret environment variables for the Job.
|
|
10695
10468
|
|
|
10696
10469
|
flavor (`str`, *optional*):
|
|
@@ -10770,15 +10543,15 @@ class HfApi:
|
|
|
10770
10543
|
self,
|
|
10771
10544
|
*,
|
|
10772
10545
|
script: str,
|
|
10773
|
-
script_args: Optional[
|
|
10774
|
-
dependencies: Optional[
|
|
10546
|
+
script_args: Optional[list[str]],
|
|
10547
|
+
dependencies: Optional[list[str]],
|
|
10775
10548
|
python: Optional[str],
|
|
10776
|
-
env: Optional[
|
|
10777
|
-
secrets: Optional[
|
|
10549
|
+
env: Optional[dict[str, Any]],
|
|
10550
|
+
secrets: Optional[dict[str, Any]],
|
|
10778
10551
|
namespace: Optional[str],
|
|
10779
10552
|
token: Union[bool, str, None],
|
|
10780
10553
|
_repo: Optional[str],
|
|
10781
|
-
) ->
|
|
10554
|
+
) -> tuple[list[str], dict[str, Any], dict[str, Any]]:
|
|
10782
10555
|
env = env or {}
|
|
10783
10556
|
secrets = secrets or {}
|
|
10784
10557
|
|
|
@@ -10910,7 +10683,6 @@ api = HfApi()
|
|
|
10910
10683
|
|
|
10911
10684
|
whoami = api.whoami
|
|
10912
10685
|
auth_check = api.auth_check
|
|
10913
|
-
get_token_permission = api.get_token_permission
|
|
10914
10686
|
|
|
10915
10687
|
list_models = api.list_models
|
|
10916
10688
|
model_info = api.model_info
|
|
@@ -10940,7 +10712,6 @@ get_dataset_tags = api.get_dataset_tags
|
|
|
10940
10712
|
create_commit = api.create_commit
|
|
10941
10713
|
create_repo = api.create_repo
|
|
10942
10714
|
delete_repo = api.delete_repo
|
|
10943
|
-
update_repo_visibility = api.update_repo_visibility
|
|
10944
10715
|
update_repo_settings = api.update_repo_settings
|
|
10945
10716
|
move_repo = api.move_repo
|
|
10946
10717
|
upload_file = api.upload_file
|