huggingface-hub 0.35.0rc0__py3-none-any.whl → 1.0.0rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +46 -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 +176 -20
- huggingface_hub/_local_folder.py +1 -1
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +10 -14
- huggingface_hub/_snapshot_download.py +14 -28
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +13 -14
- huggingface_hub/_upload_large_folder.py +120 -13
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/_cli_utils.py +2 -2
- huggingface_hub/cli/auth.py +8 -6
- huggingface_hub/cli/cache.py +18 -20
- huggingface_hub/cli/download.py +4 -4
- huggingface_hub/cli/hf.py +2 -5
- huggingface_hub/cli/jobs.py +599 -22
- huggingface_hub/cli/lfs.py +4 -4
- huggingface_hub/cli/repo.py +11 -7
- huggingface_hub/cli/repo_files.py +2 -2
- huggingface_hub/cli/upload.py +4 -4
- huggingface_hub/cli/upload_large_folder.py +3 -3
- huggingface_hub/commands/_cli_utils.py +2 -2
- huggingface_hub/commands/delete_cache.py +13 -13
- 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/scan_cache.py +1 -1
- 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 -19
- huggingface_hub/errors.py +42 -29
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +162 -259
- huggingface_hub/hf_api.py +841 -616
- huggingface_hub/hf_file_system.py +98 -62
- huggingface_hub/hub_mixin.py +37 -57
- huggingface_hub/inference/_client.py +257 -325
- huggingface_hub/inference/_common.py +110 -124
- huggingface_hub/inference/_generated/_async_client.py +307 -432
- 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 +18 -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/_cli_hacks.py +3 -3
- huggingface_hub/inference/_mcp/agent.py +3 -3
- huggingface_hub/inference/_mcp/cli.py +1 -1
- huggingface_hub/inference/_mcp/constants.py +2 -3
- huggingface_hub/inference/_mcp/mcp_client.py +58 -30
- huggingface_hub/inference/_mcp/types.py +10 -7
- huggingface_hub/inference/_mcp/utils.py +11 -7
- huggingface_hub/inference/_providers/__init__.py +4 -2
- huggingface_hub/inference/_providers/_common.py +49 -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 +52 -21
- 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 +28 -20
- 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 +20 -31
- huggingface_hub/repocard.py +18 -18
- 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 +25 -21
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +4 -4
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +366 -208
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +16 -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 +25 -5
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +32 -11
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/METADATA +18 -29
- huggingface_hub-1.0.0rc0.dist-info/RECORD +161 -0
- 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.0rc0.dist-info/RECORD +0 -166
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.35.0rc0.dist-info → huggingface_hub-1.0.0rc0.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
|
|
|
@@ -67,7 +62,7 @@ from ._commit_api import (
|
|
|
67
62
|
_warn_on_overwriting_operations,
|
|
68
63
|
)
|
|
69
64
|
from ._inference_endpoints import InferenceEndpoint, InferenceEndpointType
|
|
70
|
-
from ._jobs_api import JobInfo
|
|
65
|
+
from ._jobs_api import JobInfo, ScheduledJobInfo, _create_job_spec
|
|
71
66
|
from ._space_api import SpaceHardware, SpaceRuntime, SpaceStorage, SpaceVariable
|
|
72
67
|
from ._upload_large_folder import upload_large_folder_internal
|
|
73
68
|
from .community import (
|
|
@@ -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,
|
|
@@ -132,8 +104,12 @@ from .utils import (
|
|
|
132
104
|
validate_hf_hub_args,
|
|
133
105
|
)
|
|
134
106
|
from .utils import tqdm as hf_tqdm
|
|
135
|
-
from .utils._auth import
|
|
136
|
-
|
|
107
|
+
from .utils._auth import (
|
|
108
|
+
_get_token_from_environment,
|
|
109
|
+
_get_token_from_file,
|
|
110
|
+
_get_token_from_google_colab,
|
|
111
|
+
)
|
|
112
|
+
from .utils._deprecation import _deprecate_arguments
|
|
137
113
|
from .utils._runtime import is_xet_available
|
|
138
114
|
from .utils._typing import CallableT
|
|
139
115
|
from .utils.endpoint_helpers import _is_emission_within_threshold
|
|
@@ -239,7 +215,7 @@ _AUTH_CHECK_NO_REPO_ERROR_MESSAGE = (
|
|
|
239
215
|
logger = logging.get_logger(__name__)
|
|
240
216
|
|
|
241
217
|
|
|
242
|
-
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]:
|
|
243
219
|
"""
|
|
244
220
|
Returns the repo type and ID from a huggingface.co URL linking to a
|
|
245
221
|
repository
|
|
@@ -349,8 +325,8 @@ class BlobLfsInfo(dict):
|
|
|
349
325
|
class BlobSecurityInfo(dict):
|
|
350
326
|
safe: bool # duplicate information with "status" field, keeping it for backward compatibility
|
|
351
327
|
status: str
|
|
352
|
-
av_scan: Optional[
|
|
353
|
-
pickle_import_scan: Optional[
|
|
328
|
+
av_scan: Optional[dict]
|
|
329
|
+
pickle_import_scan: Optional[dict]
|
|
354
330
|
|
|
355
331
|
def __post_init__(self): # hack to make BlogSecurityInfo backward compatible
|
|
356
332
|
self.update(asdict(self))
|
|
@@ -370,7 +346,7 @@ class TransformersInfo(dict):
|
|
|
370
346
|
|
|
371
347
|
@dataclass
|
|
372
348
|
class SafeTensorsInfo(dict):
|
|
373
|
-
parameters:
|
|
349
|
+
parameters: dict[str, int]
|
|
374
350
|
total: int
|
|
375
351
|
|
|
376
352
|
def __post_init__(self): # hack to make SafeTensorsInfo backward compatible
|
|
@@ -413,12 +389,6 @@ class CommitInfo(str):
|
|
|
413
389
|
|
|
414
390
|
repo_url (`RepoUrl`):
|
|
415
391
|
Repo URL of the commit containing info like repo_id, repo_type, etc.
|
|
416
|
-
|
|
417
|
-
_url (`str`, *optional*):
|
|
418
|
-
Legacy url for `str` compatibility. Can be the url to the uploaded file on the Hub (if returned by
|
|
419
|
-
[`upload_file`]), to the uploaded folder on the Hub (if returned by [`upload_folder`]) or to the commit on
|
|
420
|
-
the Hub (if returned by [`create_commit`]). Defaults to `commit_url`. It is deprecated to use this
|
|
421
|
-
attribute. Please use `commit_url` instead.
|
|
422
392
|
"""
|
|
423
393
|
|
|
424
394
|
commit_url: str
|
|
@@ -434,11 +404,8 @@ class CommitInfo(str):
|
|
|
434
404
|
pr_revision: Optional[str] = field(init=False)
|
|
435
405
|
pr_num: Optional[str] = field(init=False)
|
|
436
406
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
def __new__(cls, *args, commit_url: str, _url: Optional[str] = None, **kwargs):
|
|
441
|
-
return str.__new__(cls, _url or commit_url)
|
|
407
|
+
def __new__(cls, *args, commit_url: str, **kwargs):
|
|
408
|
+
return str.__new__(cls, commit_url)
|
|
442
409
|
|
|
443
410
|
def __post_init__(self):
|
|
444
411
|
"""Populate pr-related fields after initialization.
|
|
@@ -473,7 +440,7 @@ class AccessRequest:
|
|
|
473
440
|
Timestamp of the request.
|
|
474
441
|
status (`Literal["pending", "accepted", "rejected"]`):
|
|
475
442
|
Status of the request. Can be one of `["pending", "accepted", "rejected"]`.
|
|
476
|
-
fields (`
|
|
443
|
+
fields (`dict[str, Any]`, *optional*):
|
|
477
444
|
Additional fields filled by the user in the gate form.
|
|
478
445
|
"""
|
|
479
446
|
|
|
@@ -484,7 +451,7 @@ class AccessRequest:
|
|
|
484
451
|
status: Literal["pending", "accepted", "rejected"]
|
|
485
452
|
|
|
486
453
|
# Additional fields filled by the user in the gate form
|
|
487
|
-
fields: Optional[
|
|
454
|
+
fields: Optional[dict[str, Any]] = None
|
|
488
455
|
|
|
489
456
|
|
|
490
457
|
@dataclass
|
|
@@ -511,9 +478,9 @@ class WebhookInfo:
|
|
|
511
478
|
ID of the webhook.
|
|
512
479
|
url (`str`):
|
|
513
480
|
URL of the webhook.
|
|
514
|
-
watched (`
|
|
481
|
+
watched (`list[WebhookWatchedItem]`):
|
|
515
482
|
List of items watched by the webhook, see [`WebhookWatchedItem`].
|
|
516
|
-
domains (`
|
|
483
|
+
domains (`list[WEBHOOK_DOMAIN_T]`):
|
|
517
484
|
List of domains the webhook is watching. Can be one of `["repo", "discussions"]`.
|
|
518
485
|
secret (`str`, *optional*):
|
|
519
486
|
Secret of the webhook.
|
|
@@ -523,8 +490,8 @@ class WebhookInfo:
|
|
|
523
490
|
|
|
524
491
|
id: str
|
|
525
492
|
url: str
|
|
526
|
-
watched:
|
|
527
|
-
domains:
|
|
493
|
+
watched: list[WebhookWatchedItem]
|
|
494
|
+
domains: list[constants.WEBHOOK_DOMAIN_T]
|
|
528
495
|
secret: Optional[str]
|
|
529
496
|
disabled: bool
|
|
530
497
|
|
|
@@ -775,17 +742,17 @@ class ModelInfo:
|
|
|
775
742
|
gated (`Literal["auto", "manual", False]`, *optional*):
|
|
776
743
|
Is the repo gated.
|
|
777
744
|
If so, whether there is manual or automatic approval.
|
|
778
|
-
gguf (`
|
|
745
|
+
gguf (`dict`, *optional*):
|
|
779
746
|
GGUF information of the model.
|
|
780
747
|
inference (`Literal["warm"]`, *optional*):
|
|
781
748
|
Status of the model on Inference Providers. Warm if the model is served by at least one provider.
|
|
782
|
-
inference_provider_mapping (`
|
|
749
|
+
inference_provider_mapping (`list[InferenceProviderMapping]`, *optional*):
|
|
783
750
|
A list of [`InferenceProviderMapping`] ordered after the user's provider order.
|
|
784
751
|
likes (`int`):
|
|
785
752
|
Number of likes of the model.
|
|
786
753
|
library_name (`str`, *optional*):
|
|
787
754
|
Library associated with the model.
|
|
788
|
-
tags (`
|
|
755
|
+
tags (`list[str]`):
|
|
789
756
|
List of tags of the model. Compared to `card_data.tags`, contains extra tags computed by the Hub
|
|
790
757
|
(e.g. supported libraries, model's arXiv).
|
|
791
758
|
pipeline_tag (`str`, *optional*):
|
|
@@ -794,9 +761,9 @@ class ModelInfo:
|
|
|
794
761
|
Mask token used by the model.
|
|
795
762
|
widget_data (`Any`, *optional*):
|
|
796
763
|
Widget data associated with the model.
|
|
797
|
-
model_index (`
|
|
764
|
+
model_index (`dict`, *optional*):
|
|
798
765
|
Model index for evaluation.
|
|
799
|
-
config (`
|
|
766
|
+
config (`dict`, *optional*):
|
|
800
767
|
Model configuration.
|
|
801
768
|
transformers_info (`TransformersInfo`, *optional*):
|
|
802
769
|
Transformers-specific info (auto class, processor, etc.) associated with the model.
|
|
@@ -804,13 +771,13 @@ class ModelInfo:
|
|
|
804
771
|
Trending score of the model.
|
|
805
772
|
card_data (`ModelCardData`, *optional*):
|
|
806
773
|
Model Card Metadata as a [`huggingface_hub.repocard_data.ModelCardData`] object.
|
|
807
|
-
siblings (`
|
|
774
|
+
siblings (`list[RepoSibling]`):
|
|
808
775
|
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the model.
|
|
809
|
-
spaces (`
|
|
776
|
+
spaces (`list[str]`, *optional*):
|
|
810
777
|
List of spaces using the model.
|
|
811
778
|
safetensors (`SafeTensorsInfo`, *optional*):
|
|
812
779
|
Model's safetensors information.
|
|
813
|
-
security_repo_status (`
|
|
780
|
+
security_repo_status (`dict`, *optional*):
|
|
814
781
|
Model's security scan status.
|
|
815
782
|
"""
|
|
816
783
|
|
|
@@ -824,24 +791,24 @@ class ModelInfo:
|
|
|
824
791
|
downloads: Optional[int]
|
|
825
792
|
downloads_all_time: Optional[int]
|
|
826
793
|
gated: Optional[Literal["auto", "manual", False]]
|
|
827
|
-
gguf: Optional[
|
|
794
|
+
gguf: Optional[dict]
|
|
828
795
|
inference: Optional[Literal["warm"]]
|
|
829
|
-
inference_provider_mapping: Optional[
|
|
796
|
+
inference_provider_mapping: Optional[list[InferenceProviderMapping]]
|
|
830
797
|
likes: Optional[int]
|
|
831
798
|
library_name: Optional[str]
|
|
832
|
-
tags: Optional[
|
|
799
|
+
tags: Optional[list[str]]
|
|
833
800
|
pipeline_tag: Optional[str]
|
|
834
801
|
mask_token: Optional[str]
|
|
835
802
|
card_data: Optional[ModelCardData]
|
|
836
803
|
widget_data: Optional[Any]
|
|
837
|
-
model_index: Optional[
|
|
838
|
-
config: Optional[
|
|
804
|
+
model_index: Optional[dict]
|
|
805
|
+
config: Optional[dict]
|
|
839
806
|
transformers_info: Optional[TransformersInfo]
|
|
840
807
|
trending_score: Optional[int]
|
|
841
|
-
siblings: Optional[
|
|
842
|
-
spaces: Optional[
|
|
808
|
+
siblings: Optional[list[RepoSibling]]
|
|
809
|
+
spaces: Optional[list[str]]
|
|
843
810
|
safetensors: Optional[SafeTensorsInfo]
|
|
844
|
-
security_repo_status: Optional[
|
|
811
|
+
security_repo_status: Optional[dict]
|
|
845
812
|
xet_enabled: Optional[bool]
|
|
846
813
|
|
|
847
814
|
def __init__(self, **kwargs):
|
|
@@ -976,11 +943,11 @@ class DatasetInfo:
|
|
|
976
943
|
Cumulated number of downloads of the model since its creation.
|
|
977
944
|
likes (`int`):
|
|
978
945
|
Number of likes of the dataset.
|
|
979
|
-
tags (`
|
|
946
|
+
tags (`list[str]`):
|
|
980
947
|
List of tags of the dataset.
|
|
981
948
|
card_data (`DatasetCardData`, *optional*):
|
|
982
949
|
Model Card Metadata as a [`huggingface_hub.repocard_data.DatasetCardData`] object.
|
|
983
|
-
siblings (`
|
|
950
|
+
siblings (`list[RepoSibling]`):
|
|
984
951
|
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the dataset.
|
|
985
952
|
paperswithcode_id (`str`, *optional*):
|
|
986
953
|
Papers with code ID of the dataset.
|
|
@@ -1000,10 +967,10 @@ class DatasetInfo:
|
|
|
1000
967
|
downloads_all_time: Optional[int]
|
|
1001
968
|
likes: Optional[int]
|
|
1002
969
|
paperswithcode_id: Optional[str]
|
|
1003
|
-
tags: Optional[
|
|
970
|
+
tags: Optional[list[str]]
|
|
1004
971
|
trending_score: Optional[int]
|
|
1005
972
|
card_data: Optional[DatasetCardData]
|
|
1006
|
-
siblings: Optional[
|
|
973
|
+
siblings: Optional[list[RepoSibling]]
|
|
1007
974
|
xet_enabled: Optional[bool]
|
|
1008
975
|
|
|
1009
976
|
def __init__(self, **kwargs):
|
|
@@ -1095,9 +1062,9 @@ class SpaceInfo:
|
|
|
1095
1062
|
Subdomain of the Space.
|
|
1096
1063
|
likes (`int`):
|
|
1097
1064
|
Number of likes of the Space.
|
|
1098
|
-
tags (`
|
|
1065
|
+
tags (`list[str]`):
|
|
1099
1066
|
List of tags of the Space.
|
|
1100
|
-
siblings (`
|
|
1067
|
+
siblings (`list[RepoSibling]`):
|
|
1101
1068
|
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the Space.
|
|
1102
1069
|
card_data (`SpaceCardData`, *optional*):
|
|
1103
1070
|
Space Card Metadata as a [`huggingface_hub.repocard_data.SpaceCardData`] object.
|
|
@@ -1105,9 +1072,9 @@ class SpaceInfo:
|
|
|
1105
1072
|
Space runtime information as a [`huggingface_hub.hf_api.SpaceRuntime`] object.
|
|
1106
1073
|
sdk (`str`, *optional*):
|
|
1107
1074
|
SDK used by the Space.
|
|
1108
|
-
models (`
|
|
1075
|
+
models (`list[str]`, *optional*):
|
|
1109
1076
|
List of models used by the Space.
|
|
1110
|
-
datasets (`
|
|
1077
|
+
datasets (`list[str]`, *optional*):
|
|
1111
1078
|
List of datasets used by the Space.
|
|
1112
1079
|
trending_score (`int`, *optional*):
|
|
1113
1080
|
Trending score of the Space.
|
|
@@ -1125,13 +1092,13 @@ class SpaceInfo:
|
|
|
1125
1092
|
subdomain: Optional[str]
|
|
1126
1093
|
likes: Optional[int]
|
|
1127
1094
|
sdk: Optional[str]
|
|
1128
|
-
tags: Optional[
|
|
1129
|
-
siblings: Optional[
|
|
1095
|
+
tags: Optional[list[str]]
|
|
1096
|
+
siblings: Optional[list[RepoSibling]]
|
|
1130
1097
|
trending_score: Optional[int]
|
|
1131
1098
|
card_data: Optional[SpaceCardData]
|
|
1132
1099
|
runtime: Optional[SpaceRuntime]
|
|
1133
|
-
models: Optional[
|
|
1134
|
-
datasets: Optional[
|
|
1100
|
+
models: Optional[list[str]]
|
|
1101
|
+
datasets: Optional[list[str]]
|
|
1135
1102
|
xet_enabled: Optional[bool]
|
|
1136
1103
|
|
|
1137
1104
|
def __init__(self, **kwargs):
|
|
@@ -1219,7 +1186,7 @@ class CollectionItem:
|
|
|
1219
1186
|
id: str,
|
|
1220
1187
|
type: CollectionItemType_T,
|
|
1221
1188
|
position: int,
|
|
1222
|
-
note: Optional[
|
|
1189
|
+
note: Optional[dict] = None,
|
|
1223
1190
|
**kwargs,
|
|
1224
1191
|
) -> None:
|
|
1225
1192
|
self.item_object_id: str = _id # id in database
|
|
@@ -1245,7 +1212,7 @@ class Collection:
|
|
|
1245
1212
|
Title of the collection. E.g. `"Recent models"`.
|
|
1246
1213
|
owner (`str`):
|
|
1247
1214
|
Owner of the collection. E.g. `"TheBloke"`.
|
|
1248
|
-
items (`
|
|
1215
|
+
items (`list[CollectionItem]`):
|
|
1249
1216
|
List of items in the collection.
|
|
1250
1217
|
last_updated (`datetime`):
|
|
1251
1218
|
Date of the last update of the collection.
|
|
@@ -1266,7 +1233,7 @@ class Collection:
|
|
|
1266
1233
|
slug: str
|
|
1267
1234
|
title: str
|
|
1268
1235
|
owner: str
|
|
1269
|
-
items:
|
|
1236
|
+
items: list[CollectionItem]
|
|
1270
1237
|
last_updated: datetime
|
|
1271
1238
|
position: int
|
|
1272
1239
|
private: bool
|
|
@@ -1323,22 +1290,22 @@ class GitRefs:
|
|
|
1323
1290
|
Object is returned by [`list_repo_refs`].
|
|
1324
1291
|
|
|
1325
1292
|
Attributes:
|
|
1326
|
-
branches (`
|
|
1293
|
+
branches (`list[GitRefInfo]`):
|
|
1327
1294
|
A list of [`GitRefInfo`] containing information about branches on the repo.
|
|
1328
|
-
converts (`
|
|
1295
|
+
converts (`list[GitRefInfo]`):
|
|
1329
1296
|
A list of [`GitRefInfo`] containing information about "convert" refs on the repo.
|
|
1330
1297
|
Converts are refs used (internally) to push preprocessed data in Dataset repos.
|
|
1331
|
-
tags (`
|
|
1298
|
+
tags (`list[GitRefInfo]`):
|
|
1332
1299
|
A list of [`GitRefInfo`] containing information about tags on the repo.
|
|
1333
|
-
pull_requests (`
|
|
1300
|
+
pull_requests (`list[GitRefInfo]`, *optional*):
|
|
1334
1301
|
A list of [`GitRefInfo`] containing information about pull requests on the repo.
|
|
1335
1302
|
Only returned if `include_prs=True` is set.
|
|
1336
1303
|
"""
|
|
1337
1304
|
|
|
1338
|
-
branches:
|
|
1339
|
-
converts:
|
|
1340
|
-
tags:
|
|
1341
|
-
pull_requests: Optional[
|
|
1305
|
+
branches: list[GitRefInfo]
|
|
1306
|
+
converts: list[GitRefInfo]
|
|
1307
|
+
tags: list[GitRefInfo]
|
|
1308
|
+
pull_requests: Optional[list[GitRefInfo]] = None
|
|
1342
1309
|
|
|
1343
1310
|
|
|
1344
1311
|
@dataclass
|
|
@@ -1349,7 +1316,7 @@ class GitCommitInfo:
|
|
|
1349
1316
|
Attributes:
|
|
1350
1317
|
commit_id (`str`):
|
|
1351
1318
|
OID of the commit (e.g. `"e7da7f221d5bf496a48136c0cd264e630fe9fcc8"`)
|
|
1352
|
-
authors (`
|
|
1319
|
+
authors (`list[str]`):
|
|
1353
1320
|
List of authors of the commit.
|
|
1354
1321
|
created_at (`datetime`):
|
|
1355
1322
|
Datetime when the commit was created.
|
|
@@ -1365,7 +1332,7 @@ class GitCommitInfo:
|
|
|
1365
1332
|
|
|
1366
1333
|
commit_id: str
|
|
1367
1334
|
|
|
1368
|
-
authors:
|
|
1335
|
+
authors: list[str]
|
|
1369
1336
|
created_at: datetime
|
|
1370
1337
|
title: str
|
|
1371
1338
|
message: str
|
|
@@ -1384,11 +1351,11 @@ class UserLikes:
|
|
|
1384
1351
|
Name of the user for which we fetched the likes.
|
|
1385
1352
|
total (`int`):
|
|
1386
1353
|
Total number of likes.
|
|
1387
|
-
datasets (`
|
|
1354
|
+
datasets (`list[str]`):
|
|
1388
1355
|
List of datasets liked by the user (as repo_ids).
|
|
1389
|
-
models (`
|
|
1356
|
+
models (`list[str]`):
|
|
1390
1357
|
List of models liked by the user (as repo_ids).
|
|
1391
|
-
spaces (`
|
|
1358
|
+
spaces (`list[str]`):
|
|
1392
1359
|
List of spaces liked by the user (as repo_ids).
|
|
1393
1360
|
"""
|
|
1394
1361
|
|
|
@@ -1397,9 +1364,9 @@ class UserLikes:
|
|
|
1397
1364
|
total: int
|
|
1398
1365
|
|
|
1399
1366
|
# User likes
|
|
1400
|
-
datasets:
|
|
1401
|
-
models:
|
|
1402
|
-
spaces:
|
|
1367
|
+
datasets: list[str]
|
|
1368
|
+
models: list[str]
|
|
1369
|
+
spaces: list[str]
|
|
1403
1370
|
|
|
1404
1371
|
|
|
1405
1372
|
@dataclass
|
|
@@ -1485,7 +1452,7 @@ class User:
|
|
|
1485
1452
|
num_likes: Optional[int] = None
|
|
1486
1453
|
num_following: Optional[int] = None
|
|
1487
1454
|
num_followers: Optional[int] = None
|
|
1488
|
-
orgs:
|
|
1455
|
+
orgs: list[Organization] = field(default_factory=list)
|
|
1489
1456
|
|
|
1490
1457
|
def __init__(self, **kwargs) -> None:
|
|
1491
1458
|
self.username = kwargs.pop("user", "")
|
|
@@ -1518,7 +1485,7 @@ class PaperInfo:
|
|
|
1518
1485
|
Attributes:
|
|
1519
1486
|
id (`str`):
|
|
1520
1487
|
arXiv paper ID.
|
|
1521
|
-
authors (`
|
|
1488
|
+
authors (`list[str]`, **optional**):
|
|
1522
1489
|
Names of paper authors
|
|
1523
1490
|
published_at (`datetime`, **optional**):
|
|
1524
1491
|
Date paper published.
|
|
@@ -1541,7 +1508,7 @@ class PaperInfo:
|
|
|
1541
1508
|
"""
|
|
1542
1509
|
|
|
1543
1510
|
id: str
|
|
1544
|
-
authors: Optional[
|
|
1511
|
+
authors: Optional[list[str]]
|
|
1545
1512
|
published_at: Optional[datetime]
|
|
1546
1513
|
title: Optional[str]
|
|
1547
1514
|
summary: Optional[str]
|
|
@@ -1705,8 +1672,8 @@ class HfApi:
|
|
|
1705
1672
|
token: Union[str, bool, None] = None,
|
|
1706
1673
|
library_name: Optional[str] = None,
|
|
1707
1674
|
library_version: Optional[str] = None,
|
|
1708
|
-
user_agent: Union[
|
|
1709
|
-
headers: Optional[
|
|
1675
|
+
user_agent: Union[dict, str, None] = None,
|
|
1676
|
+
headers: Optional[dict[str, str]] = None,
|
|
1710
1677
|
) -> None:
|
|
1711
1678
|
self.endpoint = endpoint if endpoint is not None else constants.ENDPOINT
|
|
1712
1679
|
self.token = token
|
|
@@ -1757,7 +1724,7 @@ class HfApi:
|
|
|
1757
1724
|
return self._thread_pool.submit(fn, *args, **kwargs)
|
|
1758
1725
|
|
|
1759
1726
|
@validate_hf_hub_args
|
|
1760
|
-
def whoami(self, token: Union[bool, str, None] = None) ->
|
|
1727
|
+
def whoami(self, token: Union[bool, str, None] = None) -> dict:
|
|
1761
1728
|
"""
|
|
1762
1729
|
Call HF API to know "whoami".
|
|
1763
1730
|
|
|
@@ -1776,62 +1743,24 @@ class HfApi:
|
|
|
1776
1743
|
)
|
|
1777
1744
|
try:
|
|
1778
1745
|
hf_raise_for_status(r)
|
|
1779
|
-
except
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1746
|
+
except HfHubHTTPError as e:
|
|
1747
|
+
if e.response.status_code == 401:
|
|
1748
|
+
error_message = "Invalid user token."
|
|
1749
|
+
# Check which token is the effective one and generate the error message accordingly
|
|
1750
|
+
if effective_token == _get_token_from_google_colab():
|
|
1751
|
+
error_message += " The token from Google Colab vault is invalid. Please update it from the UI."
|
|
1752
|
+
elif effective_token == _get_token_from_environment():
|
|
1753
|
+
error_message += (
|
|
1754
|
+
" The token from HF_TOKEN environment variable is invalid. "
|
|
1755
|
+
"Note that HF_TOKEN takes precedence over `hf auth login`."
|
|
1756
|
+
)
|
|
1757
|
+
elif effective_token == _get_token_from_file():
|
|
1758
|
+
error_message += " The token stored is invalid. Please run `hf auth login` to update it."
|
|
1759
|
+
raise HfHubHTTPError(error_message, response=e.response) from e
|
|
1760
|
+
raise
|
|
1792
1761
|
return r.json()
|
|
1793
1762
|
|
|
1794
|
-
|
|
1795
|
-
version="1.0",
|
|
1796
|
-
message=(
|
|
1797
|
-
"Permissions are more complex than when `get_token_permission` was first introduced. "
|
|
1798
|
-
"OAuth and fine-grain tokens allows for more detailed permissions. "
|
|
1799
|
-
"If you need to know the permissions associated with a token, please use `whoami` and check the `'auth'` key."
|
|
1800
|
-
),
|
|
1801
|
-
)
|
|
1802
|
-
def get_token_permission(
|
|
1803
|
-
self, token: Union[bool, str, None] = None
|
|
1804
|
-
) -> Literal["read", "write", "fineGrained", None]:
|
|
1805
|
-
"""
|
|
1806
|
-
Check if a given `token` is valid and return its permissions.
|
|
1807
|
-
|
|
1808
|
-
<Tip warning={true}>
|
|
1809
|
-
|
|
1810
|
-
This method is deprecated and will be removed in version 1.0. Permissions are more complex than when
|
|
1811
|
-
`get_token_permission` was first introduced. OAuth and fine-grain tokens allows for more detailed permissions.
|
|
1812
|
-
If you need to know the permissions associated with a token, please use `whoami` and check the `'auth'` key.
|
|
1813
|
-
|
|
1814
|
-
</Tip>
|
|
1815
|
-
|
|
1816
|
-
For more details about tokens, please refer to https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens.
|
|
1817
|
-
|
|
1818
|
-
Args:
|
|
1819
|
-
token (Union[bool, str, None], optional):
|
|
1820
|
-
A valid user access token (string). Defaults to the locally saved
|
|
1821
|
-
token, which is the recommended method for authentication (see
|
|
1822
|
-
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1823
|
-
To disable authentication, pass `False`.
|
|
1824
|
-
|
|
1825
|
-
Returns:
|
|
1826
|
-
`Literal["read", "write", "fineGrained", None]`: Permission granted by the token ("read" or "write"). Returns `None` if no
|
|
1827
|
-
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.
|
|
1828
|
-
"""
|
|
1829
|
-
try:
|
|
1830
|
-
return self.whoami(token=token)["auth"]["accessToken"]["role"]
|
|
1831
|
-
except (LocalTokenNotFoundError, HTTPError, KeyError):
|
|
1832
|
-
return None
|
|
1833
|
-
|
|
1834
|
-
def get_model_tags(self) -> Dict:
|
|
1763
|
+
def get_model_tags(self) -> dict:
|
|
1835
1764
|
"""
|
|
1836
1765
|
List all valid model tags as a nested namespace object
|
|
1837
1766
|
"""
|
|
@@ -1840,7 +1769,7 @@ class HfApi:
|
|
|
1840
1769
|
hf_raise_for_status(r)
|
|
1841
1770
|
return r.json()
|
|
1842
1771
|
|
|
1843
|
-
def get_dataset_tags(self) ->
|
|
1772
|
+
def get_dataset_tags(self) -> dict:
|
|
1844
1773
|
"""
|
|
1845
1774
|
List all valid dataset tags as a nested namespace object.
|
|
1846
1775
|
"""
|
|
@@ -1856,24 +1785,21 @@ class HfApi:
|
|
|
1856
1785
|
# Search-query parameter
|
|
1857
1786
|
filter: Union[str, Iterable[str], None] = None,
|
|
1858
1787
|
author: Optional[str] = None,
|
|
1788
|
+
apps: Optional[Union[str, list[str]]] = None,
|
|
1859
1789
|
gated: Optional[bool] = None,
|
|
1860
1790
|
inference: Optional[Literal["warm"]] = None,
|
|
1861
|
-
inference_provider: Optional[Union[Literal["all"], "PROVIDER_T",
|
|
1862
|
-
library: Optional[Union[str, List[str]]] = None,
|
|
1863
|
-
language: Optional[Union[str, List[str]]] = None,
|
|
1791
|
+
inference_provider: Optional[Union[Literal["all"], "PROVIDER_T", list["PROVIDER_T"]]] = None,
|
|
1864
1792
|
model_name: Optional[str] = None,
|
|
1865
|
-
|
|
1866
|
-
trained_dataset: Optional[Union[str, List[str]]] = None,
|
|
1867
|
-
tags: Optional[Union[str, List[str]]] = None,
|
|
1793
|
+
trained_dataset: Optional[Union[str, list[str]]] = None,
|
|
1868
1794
|
search: Optional[str] = None,
|
|
1869
1795
|
pipeline_tag: Optional[str] = None,
|
|
1870
|
-
emissions_thresholds: Optional[
|
|
1796
|
+
emissions_thresholds: Optional[tuple[float, float]] = None,
|
|
1871
1797
|
# Sorting and pagination parameters
|
|
1872
1798
|
sort: Union[Literal["last_modified"], str, None] = None,
|
|
1873
1799
|
direction: Optional[Literal[-1]] = None,
|
|
1874
1800
|
limit: Optional[int] = None,
|
|
1875
1801
|
# Additional data to fetch
|
|
1876
|
-
expand: Optional[
|
|
1802
|
+
expand: Optional[list[ExpandModelProperty_T]] = None,
|
|
1877
1803
|
full: Optional[bool] = None,
|
|
1878
1804
|
cardData: bool = False,
|
|
1879
1805
|
fetch_config: bool = False,
|
|
@@ -1885,9 +1811,13 @@ class HfApi:
|
|
|
1885
1811
|
Args:
|
|
1886
1812
|
filter (`str` or `Iterable[str]`, *optional*):
|
|
1887
1813
|
A string or list of string to filter models on the Hub.
|
|
1814
|
+
Models can be filtered by library, language, task, tags, and more.
|
|
1888
1815
|
author (`str`, *optional*):
|
|
1889
1816
|
A string which identify the author (user or organization) of the
|
|
1890
1817
|
returned models.
|
|
1818
|
+
apps (`str` or `List`, *optional*):
|
|
1819
|
+
A string or list of strings to filter models on the Hub that
|
|
1820
|
+
support the specified apps. Example values include `"ollama"` or `["ollama", "vllm"]`.
|
|
1891
1821
|
gated (`bool`, *optional*):
|
|
1892
1822
|
A boolean to filter models on the Hub that are gated or not. By default, all models are returned.
|
|
1893
1823
|
If `gated=True` is passed, only gated models are returned.
|
|
@@ -1897,24 +1827,12 @@ class HfApi:
|
|
|
1897
1827
|
inference_provider (`Literal["all"]` or `str`, *optional*):
|
|
1898
1828
|
A string to filter models on the Hub that are served by a specific provider.
|
|
1899
1829
|
Pass `"all"` to get all models served by at least one provider.
|
|
1900
|
-
library (`str` or `List`, *optional*):
|
|
1901
|
-
A string or list of strings of foundational libraries models were
|
|
1902
|
-
originally trained from, such as pytorch, tensorflow, or allennlp.
|
|
1903
|
-
language (`str` or `List`, *optional*):
|
|
1904
|
-
A string or list of strings of languages, both by name and country
|
|
1905
|
-
code, such as "en" or "English"
|
|
1906
1830
|
model_name (`str`, *optional*):
|
|
1907
1831
|
A string that contain complete or partial names for models on the
|
|
1908
1832
|
Hub, such as "bert" or "bert-base-cased"
|
|
1909
|
-
task (`str` or `List`, *optional*):
|
|
1910
|
-
A string or list of strings of tasks models were designed for, such
|
|
1911
|
-
as: "fill-mask" or "automatic-speech-recognition"
|
|
1912
1833
|
trained_dataset (`str` or `List`, *optional*):
|
|
1913
1834
|
A string tag or a list of string tags of the trained dataset for a
|
|
1914
1835
|
model on the Hub.
|
|
1915
|
-
tags (`str` or `List`, *optional*):
|
|
1916
|
-
A string tag or a list of tags to filter models on the Hub by, such
|
|
1917
|
-
as `text-generation` or `spacy`.
|
|
1918
1836
|
search (`str`, *optional*):
|
|
1919
1837
|
A string that will be contained in the returned model ids.
|
|
1920
1838
|
pipeline_tag (`str`, *optional*):
|
|
@@ -1931,7 +1849,7 @@ class HfApi:
|
|
|
1931
1849
|
limit (`int`, *optional*):
|
|
1932
1850
|
The limit on the number of models fetched. Leaving this option
|
|
1933
1851
|
to `None` fetches all models.
|
|
1934
|
-
expand (`
|
|
1852
|
+
expand (`list[ExpandModelProperty_T]`, *optional*):
|
|
1935
1853
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
1936
1854
|
This parameter cannot be used if `full`, `cardData` or `fetch_config` are passed.
|
|
1937
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"`.
|
|
@@ -1985,38 +1903,30 @@ class HfApi:
|
|
|
1985
1903
|
if expand and (full or cardData or fetch_config):
|
|
1986
1904
|
raise ValueError("`expand` cannot be used if `full`, `cardData` or `fetch_config` are passed.")
|
|
1987
1905
|
|
|
1988
|
-
if emissions_thresholds is not None and cardData
|
|
1906
|
+
if emissions_thresholds is not None and not cardData:
|
|
1989
1907
|
raise ValueError("`emissions_thresholds` were passed without setting `cardData=True`.")
|
|
1990
1908
|
|
|
1991
1909
|
path = f"{self.endpoint}/api/models"
|
|
1992
1910
|
headers = self._build_hf_headers(token=token)
|
|
1993
|
-
params:
|
|
1911
|
+
params: dict[str, Any] = {}
|
|
1994
1912
|
|
|
1995
1913
|
# Build the filter list
|
|
1996
|
-
filter_list:
|
|
1914
|
+
filter_list: list[str] = []
|
|
1997
1915
|
if filter:
|
|
1998
1916
|
filter_list.extend([filter] if isinstance(filter, str) else filter)
|
|
1999
|
-
if library:
|
|
2000
|
-
filter_list.extend([library] if isinstance(library, str) else library)
|
|
2001
|
-
if task:
|
|
2002
|
-
filter_list.extend([task] if isinstance(task, str) else task)
|
|
2003
1917
|
if trained_dataset:
|
|
2004
|
-
if isinstance(trained_dataset, str)
|
|
2005
|
-
|
|
2006
|
-
for dataset in trained_dataset:
|
|
2007
|
-
if not dataset.startswith("dataset:"):
|
|
2008
|
-
dataset = f"dataset:{dataset}"
|
|
2009
|
-
filter_list.append(dataset)
|
|
2010
|
-
if language:
|
|
2011
|
-
filter_list.extend([language] if isinstance(language, str) else language)
|
|
2012
|
-
if tags:
|
|
2013
|
-
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)
|
|
2014
1920
|
if len(filter_list) > 0:
|
|
2015
1921
|
params["filter"] = filter_list
|
|
2016
1922
|
|
|
2017
1923
|
# Handle other query params
|
|
2018
1924
|
if author:
|
|
2019
1925
|
params["author"] = author
|
|
1926
|
+
if apps:
|
|
1927
|
+
if isinstance(apps, str):
|
|
1928
|
+
apps = [apps]
|
|
1929
|
+
params["apps"] = apps
|
|
2020
1930
|
if gated is not None:
|
|
2021
1931
|
params["gated"] = gated
|
|
2022
1932
|
if inference is not None:
|
|
@@ -2068,6 +1978,7 @@ class HfApi:
|
|
|
2068
1978
|
if emissions_thresholds is None or _is_emission_within_threshold(model_info, *emissions_thresholds):
|
|
2069
1979
|
yield model_info
|
|
2070
1980
|
|
|
1981
|
+
@_deprecate_arguments(version="1.0", deprecated_args=["tags"], custom_message="Use `filter` instead.")
|
|
2071
1982
|
@validate_hf_hub_args
|
|
2072
1983
|
def list_datasets(
|
|
2073
1984
|
self,
|
|
@@ -2075,25 +1986,26 @@ class HfApi:
|
|
|
2075
1986
|
# Search-query parameter
|
|
2076
1987
|
filter: Union[str, Iterable[str], None] = None,
|
|
2077
1988
|
author: Optional[str] = None,
|
|
2078
|
-
benchmark: Optional[Union[str,
|
|
1989
|
+
benchmark: Optional[Union[str, list[str]]] = None,
|
|
2079
1990
|
dataset_name: Optional[str] = None,
|
|
2080
1991
|
gated: Optional[bool] = None,
|
|
2081
|
-
language_creators: Optional[Union[str,
|
|
2082
|
-
language: Optional[Union[str,
|
|
2083
|
-
multilinguality: Optional[Union[str,
|
|
2084
|
-
size_categories: Optional[Union[str,
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
task_ids: Optional[Union[str, List[str]]] = None,
|
|
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,
|
|
2088
1998
|
search: Optional[str] = None,
|
|
2089
1999
|
# Sorting and pagination parameters
|
|
2090
2000
|
sort: Optional[Union[Literal["last_modified"], str]] = None,
|
|
2091
2001
|
direction: Optional[Literal[-1]] = None,
|
|
2092
2002
|
limit: Optional[int] = None,
|
|
2093
2003
|
# Additional data to fetch
|
|
2094
|
-
expand: Optional[
|
|
2004
|
+
expand: Optional[list[ExpandDatasetProperty_T]] = None,
|
|
2095
2005
|
full: Optional[bool] = None,
|
|
2096
2006
|
token: Union[bool, str, None] = None,
|
|
2007
|
+
# Deprecated arguments - use `filter` instead
|
|
2008
|
+
tags: Optional[Union[str, list[str]]] = None,
|
|
2097
2009
|
) -> Iterable[DatasetInfo]:
|
|
2098
2010
|
"""
|
|
2099
2011
|
List datasets hosted on the Huggingface Hub, given some filters.
|
|
@@ -2128,7 +2040,7 @@ class HfApi:
|
|
|
2128
2040
|
the Hub by the size of the dataset such as `100K<n<1M` or
|
|
2129
2041
|
`1M<n<10M`.
|
|
2130
2042
|
tags (`str` or `List`, *optional*):
|
|
2131
|
-
|
|
2043
|
+
Deprecated. Pass tags in `filter` to filter datasets by tags.
|
|
2132
2044
|
task_categories (`str` or `List`, *optional*):
|
|
2133
2045
|
A string or list of strings that can be used to identify datasets on
|
|
2134
2046
|
the Hub by the designed task, such as `audio_classification` or
|
|
@@ -2148,7 +2060,7 @@ class HfApi:
|
|
|
2148
2060
|
limit (`int`, *optional*):
|
|
2149
2061
|
The limit on the number of datasets fetched. Leaving this option
|
|
2150
2062
|
to `None` fetches all datasets.
|
|
2151
|
-
expand (`
|
|
2063
|
+
expand (`list[ExpandDatasetProperty_T]`, *optional*):
|
|
2152
2064
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2153
2065
|
This parameter cannot be used if `full` is passed.
|
|
2154
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"`.
|
|
@@ -2208,7 +2120,7 @@ class HfApi:
|
|
|
2208
2120
|
|
|
2209
2121
|
path = f"{self.endpoint}/api/datasets"
|
|
2210
2122
|
headers = self._build_hf_headers(token=token)
|
|
2211
|
-
params:
|
|
2123
|
+
params: dict[str, Any] = {}
|
|
2212
2124
|
|
|
2213
2125
|
# Build `filter` list
|
|
2214
2126
|
filter_list = []
|
|
@@ -2295,7 +2207,7 @@ class HfApi:
|
|
|
2295
2207
|
direction: Optional[Literal[-1]] = None,
|
|
2296
2208
|
limit: Optional[int] = None,
|
|
2297
2209
|
# Additional data to fetch
|
|
2298
|
-
expand: Optional[
|
|
2210
|
+
expand: Optional[list[ExpandSpaceProperty_T]] = None,
|
|
2299
2211
|
full: Optional[bool] = None,
|
|
2300
2212
|
token: Union[bool, str, None] = None,
|
|
2301
2213
|
) -> Iterable[SpaceInfo]:
|
|
@@ -2326,7 +2238,7 @@ class HfApi:
|
|
|
2326
2238
|
limit (`int`, *optional*):
|
|
2327
2239
|
The limit on the number of Spaces fetched. Leaving this option
|
|
2328
2240
|
to `None` fetches all Spaces.
|
|
2329
|
-
expand (`
|
|
2241
|
+
expand (`list[ExpandSpaceProperty_T]`, *optional*):
|
|
2330
2242
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2331
2243
|
This parameter cannot be used if `full` is passed.
|
|
2332
2244
|
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"`, `"trendingScore"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2347,7 +2259,7 @@ class HfApi:
|
|
|
2347
2259
|
|
|
2348
2260
|
path = f"{self.endpoint}/api/spaces"
|
|
2349
2261
|
headers = self._build_hf_headers(token=token)
|
|
2350
|
-
params:
|
|
2262
|
+
params: dict[str, Any] = {}
|
|
2351
2263
|
if filter is not None:
|
|
2352
2264
|
params["filter"] = filter
|
|
2353
2265
|
if author is not None:
|
|
@@ -2564,7 +2476,7 @@ class HfApi:
|
|
|
2564
2476
|
timeout: Optional[float] = None,
|
|
2565
2477
|
securityStatus: Optional[bool] = None,
|
|
2566
2478
|
files_metadata: bool = False,
|
|
2567
|
-
expand: Optional[
|
|
2479
|
+
expand: Optional[list[ExpandModelProperty_T]] = None,
|
|
2568
2480
|
token: Union[bool, str, None] = None,
|
|
2569
2481
|
) -> ModelInfo:
|
|
2570
2482
|
"""
|
|
@@ -2587,7 +2499,7 @@ class HfApi:
|
|
|
2587
2499
|
files_metadata (`bool`, *optional*):
|
|
2588
2500
|
Whether or not to retrieve metadata for files in the repository
|
|
2589
2501
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2590
|
-
expand (`
|
|
2502
|
+
expand (`list[ExpandModelProperty_T]`, *optional*):
|
|
2591
2503
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2592
2504
|
This parameter cannot be used if `securityStatus` or `files_metadata` are passed.
|
|
2593
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"`.
|
|
@@ -2621,7 +2533,7 @@ class HfApi:
|
|
|
2621
2533
|
if revision is None
|
|
2622
2534
|
else (f"{self.endpoint}/api/models/{repo_id}/revision/{quote(revision, safe='')}")
|
|
2623
2535
|
)
|
|
2624
|
-
params:
|
|
2536
|
+
params: dict = {}
|
|
2625
2537
|
if securityStatus:
|
|
2626
2538
|
params["securityStatus"] = True
|
|
2627
2539
|
if files_metadata:
|
|
@@ -2641,7 +2553,7 @@ class HfApi:
|
|
|
2641
2553
|
revision: Optional[str] = None,
|
|
2642
2554
|
timeout: Optional[float] = None,
|
|
2643
2555
|
files_metadata: bool = False,
|
|
2644
|
-
expand: Optional[
|
|
2556
|
+
expand: Optional[list[ExpandDatasetProperty_T]] = None,
|
|
2645
2557
|
token: Union[bool, str, None] = None,
|
|
2646
2558
|
) -> DatasetInfo:
|
|
2647
2559
|
"""
|
|
@@ -2661,7 +2573,7 @@ class HfApi:
|
|
|
2661
2573
|
files_metadata (`bool`, *optional*):
|
|
2662
2574
|
Whether or not to retrieve metadata for files in the repository
|
|
2663
2575
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2664
|
-
expand (`
|
|
2576
|
+
expand (`list[ExpandDatasetProperty_T]`, *optional*):
|
|
2665
2577
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2666
2578
|
This parameter cannot be used if `files_metadata` is passed.
|
|
2667
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"`.
|
|
@@ -2695,7 +2607,7 @@ class HfApi:
|
|
|
2695
2607
|
if revision is None
|
|
2696
2608
|
else (f"{self.endpoint}/api/datasets/{repo_id}/revision/{quote(revision, safe='')}")
|
|
2697
2609
|
)
|
|
2698
|
-
params:
|
|
2610
|
+
params: dict = {}
|
|
2699
2611
|
if files_metadata:
|
|
2700
2612
|
params["blobs"] = True
|
|
2701
2613
|
if expand:
|
|
@@ -2714,7 +2626,7 @@ class HfApi:
|
|
|
2714
2626
|
revision: Optional[str] = None,
|
|
2715
2627
|
timeout: Optional[float] = None,
|
|
2716
2628
|
files_metadata: bool = False,
|
|
2717
|
-
expand: Optional[
|
|
2629
|
+
expand: Optional[list[ExpandSpaceProperty_T]] = None,
|
|
2718
2630
|
token: Union[bool, str, None] = None,
|
|
2719
2631
|
) -> SpaceInfo:
|
|
2720
2632
|
"""
|
|
@@ -2734,7 +2646,7 @@ class HfApi:
|
|
|
2734
2646
|
files_metadata (`bool`, *optional*):
|
|
2735
2647
|
Whether or not to retrieve metadata for files in the repository
|
|
2736
2648
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2737
|
-
expand (`
|
|
2649
|
+
expand (`list[ExpandSpaceProperty_T]`, *optional*):
|
|
2738
2650
|
List properties to return in the response. When used, only the properties in the list will be returned.
|
|
2739
2651
|
This parameter cannot be used if `full` is passed.
|
|
2740
2652
|
Possible values are `"author"`, `"cardData"`, `"createdAt"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"`, `"trendingScore"`, `"usedStorage"`, `"resourceGroup"` and `"xetEnabled"`.
|
|
@@ -2768,7 +2680,7 @@ class HfApi:
|
|
|
2768
2680
|
if revision is None
|
|
2769
2681
|
else (f"{self.endpoint}/api/spaces/{repo_id}/revision/{quote(revision, safe='')}")
|
|
2770
2682
|
)
|
|
2771
|
-
params:
|
|
2683
|
+
params: dict = {}
|
|
2772
2684
|
if files_metadata:
|
|
2773
2685
|
params["blobs"] = True
|
|
2774
2686
|
if expand:
|
|
@@ -2999,7 +2911,7 @@ class HfApi:
|
|
|
2999
2911
|
return True
|
|
3000
2912
|
except GatedRepoError: # raise specifically on gated repo
|
|
3001
2913
|
raise
|
|
3002
|
-
except (RepositoryNotFoundError,
|
|
2914
|
+
except (RepositoryNotFoundError, RemoteEntryNotFoundError, RevisionNotFoundError):
|
|
3003
2915
|
return False
|
|
3004
2916
|
|
|
3005
2917
|
@validate_hf_hub_args
|
|
@@ -3010,7 +2922,7 @@ class HfApi:
|
|
|
3010
2922
|
revision: Optional[str] = None,
|
|
3011
2923
|
repo_type: Optional[str] = None,
|
|
3012
2924
|
token: Union[str, bool, None] = None,
|
|
3013
|
-
) ->
|
|
2925
|
+
) -> list[str]:
|
|
3014
2926
|
"""
|
|
3015
2927
|
Get the list of files in a given repo.
|
|
3016
2928
|
|
|
@@ -3029,7 +2941,7 @@ class HfApi:
|
|
|
3029
2941
|
To disable authentication, pass `False`.
|
|
3030
2942
|
|
|
3031
2943
|
Returns:
|
|
3032
|
-
`
|
|
2944
|
+
`list[str]`: the list of files in a given repository.
|
|
3033
2945
|
"""
|
|
3034
2946
|
return [
|
|
3035
2947
|
f.rfilename
|
|
@@ -3089,7 +3001,7 @@ class HfApi:
|
|
|
3089
3001
|
does not exist.
|
|
3090
3002
|
[`~utils.RevisionNotFoundError`]:
|
|
3091
3003
|
If revision is not found (error 404) on the repo.
|
|
3092
|
-
[`~utils.
|
|
3004
|
+
[`~utils.RemoteEntryNotFoundError`]:
|
|
3093
3005
|
If the tree (folder) does not exist (error 404) on the repo.
|
|
3094
3006
|
|
|
3095
3007
|
Examples:
|
|
@@ -3231,7 +3143,7 @@ class HfApi:
|
|
|
3231
3143
|
hf_raise_for_status(response)
|
|
3232
3144
|
data = response.json()
|
|
3233
3145
|
|
|
3234
|
-
def _format_as_git_ref_info(item:
|
|
3146
|
+
def _format_as_git_ref_info(item: dict) -> GitRefInfo:
|
|
3235
3147
|
return GitRefInfo(name=item["name"], ref=item["ref"], target_commit=item["targetCommit"])
|
|
3236
3148
|
|
|
3237
3149
|
return GitRefs(
|
|
@@ -3252,7 +3164,7 @@ class HfApi:
|
|
|
3252
3164
|
token: Union[bool, str, None] = None,
|
|
3253
3165
|
revision: Optional[str] = None,
|
|
3254
3166
|
formatted: bool = False,
|
|
3255
|
-
) ->
|
|
3167
|
+
) -> list[GitCommitInfo]:
|
|
3256
3168
|
"""
|
|
3257
3169
|
Get the list of commits of a given revision for a repo on the Hub.
|
|
3258
3170
|
|
|
@@ -3299,7 +3211,7 @@ class HfApi:
|
|
|
3299
3211
|
```
|
|
3300
3212
|
|
|
3301
3213
|
Returns:
|
|
3302
|
-
|
|
3214
|
+
list[[`GitCommitInfo`]]: list of objects containing information about the commits for a repo on the Hub.
|
|
3303
3215
|
|
|
3304
3216
|
Raises:
|
|
3305
3217
|
[`~utils.RepositoryNotFoundError`]:
|
|
@@ -3333,20 +3245,20 @@ class HfApi:
|
|
|
3333
3245
|
def get_paths_info(
|
|
3334
3246
|
self,
|
|
3335
3247
|
repo_id: str,
|
|
3336
|
-
paths: Union[
|
|
3248
|
+
paths: Union[list[str], str],
|
|
3337
3249
|
*,
|
|
3338
3250
|
expand: bool = False,
|
|
3339
3251
|
revision: Optional[str] = None,
|
|
3340
3252
|
repo_type: Optional[str] = None,
|
|
3341
3253
|
token: Union[str, bool, None] = None,
|
|
3342
|
-
) ->
|
|
3254
|
+
) -> list[Union[RepoFile, RepoFolder]]:
|
|
3343
3255
|
"""
|
|
3344
3256
|
Get information about a repo's paths.
|
|
3345
3257
|
|
|
3346
3258
|
Args:
|
|
3347
3259
|
repo_id (`str`):
|
|
3348
3260
|
A namespace (user or an organization) and a repo name separated by a `/`.
|
|
3349
|
-
paths (`Union[
|
|
3261
|
+
paths (`Union[list[str], str]`, *optional*):
|
|
3350
3262
|
The paths to get information about. If a path do not exist, it is ignored without raising
|
|
3351
3263
|
an exception.
|
|
3352
3264
|
expand (`bool`, *optional*, defaults to `False`):
|
|
@@ -3366,7 +3278,7 @@ class HfApi:
|
|
|
3366
3278
|
To disable authentication, pass `False`.
|
|
3367
3279
|
|
|
3368
3280
|
Returns:
|
|
3369
|
-
`
|
|
3281
|
+
`list[Union[RepoFile, RepoFolder]]`:
|
|
3370
3282
|
The information about the paths, as a list of [`RepoFile`] and [`RepoFolder`] objects.
|
|
3371
3283
|
|
|
3372
3284
|
Raises:
|
|
@@ -3631,8 +3543,8 @@ class HfApi:
|
|
|
3631
3543
|
space_hardware: Optional[SpaceHardware] = None,
|
|
3632
3544
|
space_storage: Optional[SpaceStorage] = None,
|
|
3633
3545
|
space_sleep_time: Optional[int] = None,
|
|
3634
|
-
space_secrets: Optional[
|
|
3635
|
-
space_variables: Optional[
|
|
3546
|
+
space_secrets: Optional[list[dict[str, str]]] = None,
|
|
3547
|
+
space_variables: Optional[list[dict[str, str]]] = None,
|
|
3636
3548
|
) -> RepoUrl:
|
|
3637
3549
|
"""Create an empty repo on the HuggingFace Hub.
|
|
3638
3550
|
|
|
@@ -3669,10 +3581,10 @@ class HfApi:
|
|
|
3669
3581
|
your Space to sleep (default behavior for upgraded hardware). For free hardware, you can't configure
|
|
3670
3582
|
the sleep time (value is fixed to 48 hours of inactivity).
|
|
3671
3583
|
See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
|
|
3672
|
-
space_secrets (`
|
|
3584
|
+
space_secrets (`list[dict[str, str]]`, *optional*):
|
|
3673
3585
|
A list of secret keys to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional.
|
|
3674
3586
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets.
|
|
3675
|
-
space_variables (`
|
|
3587
|
+
space_variables (`list[dict[str, str]]`, *optional*):
|
|
3676
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.
|
|
3677
3589
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables.
|
|
3678
3590
|
|
|
@@ -3687,7 +3599,7 @@ class HfApi:
|
|
|
3687
3599
|
if repo_type not in constants.REPO_TYPES:
|
|
3688
3600
|
raise ValueError("Invalid repo type")
|
|
3689
3601
|
|
|
3690
|
-
json:
|
|
3602
|
+
json: dict[str, Any] = {"name": name, "organization": organization}
|
|
3691
3603
|
if private is not None:
|
|
3692
3604
|
json["private"] = private
|
|
3693
3605
|
if repo_type is not None:
|
|
@@ -3747,7 +3659,7 @@ class HfApi:
|
|
|
3747
3659
|
|
|
3748
3660
|
try:
|
|
3749
3661
|
hf_raise_for_status(r)
|
|
3750
|
-
except
|
|
3662
|
+
except HfHubHTTPError as err:
|
|
3751
3663
|
if exist_ok and err.response.status_code == 409:
|
|
3752
3664
|
# Repo already exists and `exist_ok=True`
|
|
3753
3665
|
pass
|
|
@@ -3809,68 +3721,13 @@ class HfApi:
|
|
|
3809
3721
|
json["type"] = repo_type
|
|
3810
3722
|
|
|
3811
3723
|
headers = self._build_hf_headers(token=token)
|
|
3812
|
-
r = get_session().
|
|
3724
|
+
r = get_session().request("DELETE", path, headers=headers, json=json)
|
|
3813
3725
|
try:
|
|
3814
3726
|
hf_raise_for_status(r)
|
|
3815
3727
|
except RepositoryNotFoundError:
|
|
3816
3728
|
if not missing_ok:
|
|
3817
3729
|
raise
|
|
3818
3730
|
|
|
3819
|
-
@_deprecate_method(version="0.32", message="Please use `update_repo_settings` instead.")
|
|
3820
|
-
@validate_hf_hub_args
|
|
3821
|
-
def update_repo_visibility(
|
|
3822
|
-
self,
|
|
3823
|
-
repo_id: str,
|
|
3824
|
-
private: bool = False,
|
|
3825
|
-
*,
|
|
3826
|
-
token: Union[str, bool, None] = None,
|
|
3827
|
-
repo_type: Optional[str] = None,
|
|
3828
|
-
) -> Dict[str, bool]:
|
|
3829
|
-
"""Update the visibility setting of a repository.
|
|
3830
|
-
|
|
3831
|
-
Deprecated. Use `update_repo_settings` instead.
|
|
3832
|
-
|
|
3833
|
-
Args:
|
|
3834
|
-
repo_id (`str`, *optional*):
|
|
3835
|
-
A namespace (user or an organization) and a repo name separated by a `/`.
|
|
3836
|
-
private (`bool`, *optional*, defaults to `False`):
|
|
3837
|
-
Whether the repository should be private.
|
|
3838
|
-
token (Union[bool, str, None], optional):
|
|
3839
|
-
A valid user access token (string). Defaults to the locally saved
|
|
3840
|
-
token, which is the recommended method for authentication (see
|
|
3841
|
-
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3842
|
-
To disable authentication, pass `False`.
|
|
3843
|
-
repo_type (`str`, *optional*):
|
|
3844
|
-
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
3845
|
-
space, `None` or `"model"` if uploading to a model. Default is
|
|
3846
|
-
`None`.
|
|
3847
|
-
|
|
3848
|
-
Returns:
|
|
3849
|
-
The HTTP response in json.
|
|
3850
|
-
|
|
3851
|
-
<Tip>
|
|
3852
|
-
|
|
3853
|
-
Raises the following errors:
|
|
3854
|
-
|
|
3855
|
-
- [`~utils.RepositoryNotFoundError`]
|
|
3856
|
-
If the repository to download from cannot be found. This may be because it doesn't exist,
|
|
3857
|
-
or because it is set to `private` and you do not have access.
|
|
3858
|
-
|
|
3859
|
-
</Tip>
|
|
3860
|
-
"""
|
|
3861
|
-
if repo_type not in constants.REPO_TYPES:
|
|
3862
|
-
raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
|
|
3863
|
-
if repo_type is None:
|
|
3864
|
-
repo_type = constants.REPO_TYPE_MODEL # default repo type
|
|
3865
|
-
|
|
3866
|
-
r = get_session().put(
|
|
3867
|
-
url=f"{self.endpoint}/api/{repo_type}s/{repo_id}/settings",
|
|
3868
|
-
headers=self._build_hf_headers(token=token),
|
|
3869
|
-
json={"private": private},
|
|
3870
|
-
)
|
|
3871
|
-
hf_raise_for_status(r)
|
|
3872
|
-
return r.json()
|
|
3873
|
-
|
|
3874
3731
|
@validate_hf_hub_args
|
|
3875
3732
|
def update_repo_settings(
|
|
3876
3733
|
self,
|
|
@@ -3926,7 +3783,7 @@ class HfApi:
|
|
|
3926
3783
|
repo_type = constants.REPO_TYPE_MODEL # default repo type
|
|
3927
3784
|
|
|
3928
3785
|
# Prepare the JSON payload for the PUT request
|
|
3929
|
-
payload:
|
|
3786
|
+
payload: dict = {}
|
|
3930
3787
|
|
|
3931
3788
|
if gated is not None:
|
|
3932
3789
|
if gated not in ["auto", "manual", False]:
|
|
@@ -4321,12 +4178,12 @@ class HfApi:
|
|
|
4321
4178
|
params = {"create_pr": "1"} if create_pr else None
|
|
4322
4179
|
|
|
4323
4180
|
try:
|
|
4324
|
-
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)
|
|
4325
4182
|
hf_raise_for_status(commit_resp, endpoint_name="commit")
|
|
4326
4183
|
except RepositoryNotFoundError as e:
|
|
4327
4184
|
e.append_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)
|
|
4328
4185
|
raise
|
|
4329
|
-
except
|
|
4186
|
+
except RemoteEntryNotFoundError as e:
|
|
4330
4187
|
if nb_deletions > 0 and "A file with this name doesn't exist" in str(e):
|
|
4331
4188
|
e.append_to_message(
|
|
4332
4189
|
"\nMake sure to differentiate file and folder paths in delete"
|
|
@@ -4636,7 +4493,7 @@ class HfApi:
|
|
|
4636
4493
|
|
|
4637
4494
|
Raises the following errors:
|
|
4638
4495
|
|
|
4639
|
-
- [`
|
|
4496
|
+
- [`HfHubHTTPError`]
|
|
4640
4497
|
if the HuggingFace API returned an error
|
|
4641
4498
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
4642
4499
|
if some parameter value is invalid
|
|
@@ -4670,7 +4527,6 @@ class HfApi:
|
|
|
4670
4527
|
... repo_type="dataset",
|
|
4671
4528
|
... token="my_token",
|
|
4672
4529
|
... )
|
|
4673
|
-
"https://huggingface.co/datasets/username/my-dataset/blob/main/remote/file/path.h5"
|
|
4674
4530
|
|
|
4675
4531
|
>>> upload_file(
|
|
4676
4532
|
... path_or_fileobj=".\\\\local\\\\file\\\\path",
|
|
@@ -4678,7 +4534,6 @@ class HfApi:
|
|
|
4678
4534
|
... repo_id="username/my-model",
|
|
4679
4535
|
... token="my_token",
|
|
4680
4536
|
... )
|
|
4681
|
-
"https://huggingface.co/username/my-model/blob/main/remote/file/path.h5"
|
|
4682
4537
|
|
|
4683
4538
|
>>> upload_file(
|
|
4684
4539
|
... path_or_fileobj=".\\\\local\\\\file\\\\path",
|
|
@@ -4687,7 +4542,6 @@ class HfApi:
|
|
|
4687
4542
|
... token="my_token",
|
|
4688
4543
|
... create_pr=True,
|
|
4689
4544
|
... )
|
|
4690
|
-
"https://huggingface.co/username/my-model/blob/refs%2Fpr%2F1/remote/file/path.h5"
|
|
4691
4545
|
```
|
|
4692
4546
|
"""
|
|
4693
4547
|
if repo_type not in constants.REPO_TYPES:
|
|
@@ -4701,7 +4555,7 @@ class HfApi:
|
|
|
4701
4555
|
path_in_repo=path_in_repo,
|
|
4702
4556
|
)
|
|
4703
4557
|
|
|
4704
|
-
|
|
4558
|
+
return self.create_commit(
|
|
4705
4559
|
repo_id=repo_id,
|
|
4706
4560
|
repo_type=repo_type,
|
|
4707
4561
|
operations=[operation],
|
|
@@ -4713,23 +4567,6 @@ class HfApi:
|
|
|
4713
4567
|
parent_commit=parent_commit,
|
|
4714
4568
|
)
|
|
4715
4569
|
|
|
4716
|
-
if commit_info.pr_url is not None:
|
|
4717
|
-
revision = quote(_parse_revision_from_pr_url(commit_info.pr_url), safe="")
|
|
4718
|
-
if repo_type in constants.REPO_TYPES_URL_PREFIXES:
|
|
4719
|
-
repo_id = constants.REPO_TYPES_URL_PREFIXES[repo_type] + repo_id
|
|
4720
|
-
revision = revision if revision is not None else constants.DEFAULT_REVISION
|
|
4721
|
-
|
|
4722
|
-
return CommitInfo(
|
|
4723
|
-
commit_url=commit_info.commit_url,
|
|
4724
|
-
commit_message=commit_info.commit_message,
|
|
4725
|
-
commit_description=commit_info.commit_description,
|
|
4726
|
-
oid=commit_info.oid,
|
|
4727
|
-
pr_url=commit_info.pr_url,
|
|
4728
|
-
# Similar to `hf_hub_url` but it's "blob" instead of "resolve"
|
|
4729
|
-
# TODO: remove this in v1.0
|
|
4730
|
-
_url=f"{self.endpoint}/{repo_id}/blob/{revision}/{path_in_repo}",
|
|
4731
|
-
)
|
|
4732
|
-
|
|
4733
4570
|
@overload
|
|
4734
4571
|
def upload_folder( # type: ignore
|
|
4735
4572
|
self,
|
|
@@ -4744,9 +4581,9 @@ class HfApi:
|
|
|
4744
4581
|
revision: Optional[str] = None,
|
|
4745
4582
|
create_pr: Optional[bool] = None,
|
|
4746
4583
|
parent_commit: Optional[str] = None,
|
|
4747
|
-
allow_patterns: Optional[Union[
|
|
4748
|
-
ignore_patterns: Optional[Union[
|
|
4749
|
-
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,
|
|
4750
4587
|
run_as_future: Literal[False] = ...,
|
|
4751
4588
|
) -> CommitInfo: ...
|
|
4752
4589
|
|
|
@@ -4764,9 +4601,9 @@ class HfApi:
|
|
|
4764
4601
|
revision: Optional[str] = None,
|
|
4765
4602
|
create_pr: Optional[bool] = None,
|
|
4766
4603
|
parent_commit: Optional[str] = None,
|
|
4767
|
-
allow_patterns: Optional[Union[
|
|
4768
|
-
ignore_patterns: Optional[Union[
|
|
4769
|
-
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,
|
|
4770
4607
|
run_as_future: Literal[True] = ...,
|
|
4771
4608
|
) -> Future[CommitInfo]: ...
|
|
4772
4609
|
|
|
@@ -4785,9 +4622,9 @@ class HfApi:
|
|
|
4785
4622
|
revision: Optional[str] = None,
|
|
4786
4623
|
create_pr: Optional[bool] = None,
|
|
4787
4624
|
parent_commit: Optional[str] = None,
|
|
4788
|
-
allow_patterns: Optional[Union[
|
|
4789
|
-
ignore_patterns: Optional[Union[
|
|
4790
|
-
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,
|
|
4791
4628
|
run_as_future: bool = False,
|
|
4792
4629
|
) -> Union[CommitInfo, Future[CommitInfo]]:
|
|
4793
4630
|
"""
|
|
@@ -4849,11 +4686,11 @@ class HfApi:
|
|
|
4849
4686
|
If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.
|
|
4850
4687
|
Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be
|
|
4851
4688
|
especially useful if the repo is updated / committed to concurrently.
|
|
4852
|
-
allow_patterns (`
|
|
4689
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
4853
4690
|
If provided, only files matching at least one pattern are uploaded.
|
|
4854
|
-
ignore_patterns (`
|
|
4691
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
4855
4692
|
If provided, files matching any of the patterns are not uploaded.
|
|
4856
|
-
delete_patterns (`
|
|
4693
|
+
delete_patterns (`list[str]` or `str`, *optional*):
|
|
4857
4694
|
If provided, remote files matching any of the patterns will be deleted from the repo while committing
|
|
4858
4695
|
new files. This is useful if you don't know which files have already been uploaded.
|
|
4859
4696
|
Note: to avoid discrepancies the `.gitattributes` file is not deleted even if it matches the pattern.
|
|
@@ -4872,7 +4709,7 @@ class HfApi:
|
|
|
4872
4709
|
|
|
4873
4710
|
Raises the following errors:
|
|
4874
4711
|
|
|
4875
|
-
- [`
|
|
4712
|
+
- [`HfHubHTTPError`]
|
|
4876
4713
|
if the HuggingFace API returned an error
|
|
4877
4714
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
4878
4715
|
if some parameter value is invalid
|
|
@@ -4905,7 +4742,6 @@ class HfApi:
|
|
|
4905
4742
|
... token="my_token",
|
|
4906
4743
|
... ignore_patterns="**/logs/*.txt",
|
|
4907
4744
|
... )
|
|
4908
|
-
# "https://huggingface.co/datasets/username/my-dataset/tree/main/remote/experiment/checkpoints"
|
|
4909
4745
|
|
|
4910
4746
|
# Upload checkpoints folder including logs while deleting existing logs from the repo
|
|
4911
4747
|
# Useful if you don't know exactly which log files have already being pushed
|
|
@@ -4917,7 +4753,6 @@ class HfApi:
|
|
|
4917
4753
|
... token="my_token",
|
|
4918
4754
|
... delete_patterns="**/logs/*.txt",
|
|
4919
4755
|
... )
|
|
4920
|
-
"https://huggingface.co/datasets/username/my-dataset/tree/main/remote/experiment/checkpoints"
|
|
4921
4756
|
|
|
4922
4757
|
# Upload checkpoints folder while creating a PR
|
|
4923
4758
|
>>> upload_folder(
|
|
@@ -4928,8 +4763,6 @@ class HfApi:
|
|
|
4928
4763
|
... token="my_token",
|
|
4929
4764
|
... create_pr=True,
|
|
4930
4765
|
... )
|
|
4931
|
-
"https://huggingface.co/datasets/username/my-dataset/tree/refs%2Fpr%2F1/remote/experiment/checkpoints"
|
|
4932
|
-
|
|
4933
4766
|
```
|
|
4934
4767
|
"""
|
|
4935
4768
|
if repo_type not in constants.REPO_TYPES:
|
|
@@ -4973,7 +4806,7 @@ class HfApi:
|
|
|
4973
4806
|
|
|
4974
4807
|
commit_message = commit_message or "Upload folder using huggingface_hub"
|
|
4975
4808
|
|
|
4976
|
-
|
|
4809
|
+
return self.create_commit(
|
|
4977
4810
|
repo_type=repo_type,
|
|
4978
4811
|
repo_id=repo_id,
|
|
4979
4812
|
operations=commit_operations,
|
|
@@ -4985,24 +4818,6 @@ class HfApi:
|
|
|
4985
4818
|
parent_commit=parent_commit,
|
|
4986
4819
|
)
|
|
4987
4820
|
|
|
4988
|
-
# Create url to uploaded folder (for legacy return value)
|
|
4989
|
-
if create_pr and commit_info.pr_url is not None:
|
|
4990
|
-
revision = quote(_parse_revision_from_pr_url(commit_info.pr_url), safe="")
|
|
4991
|
-
if repo_type in constants.REPO_TYPES_URL_PREFIXES:
|
|
4992
|
-
repo_id = constants.REPO_TYPES_URL_PREFIXES[repo_type] + repo_id
|
|
4993
|
-
revision = revision if revision is not None else constants.DEFAULT_REVISION
|
|
4994
|
-
|
|
4995
|
-
return CommitInfo(
|
|
4996
|
-
commit_url=commit_info.commit_url,
|
|
4997
|
-
commit_message=commit_info.commit_message,
|
|
4998
|
-
commit_description=commit_info.commit_description,
|
|
4999
|
-
oid=commit_info.oid,
|
|
5000
|
-
pr_url=commit_info.pr_url,
|
|
5001
|
-
# Similar to `hf_hub_url` but it's "tree" instead of "resolve"
|
|
5002
|
-
# TODO: remove this in v1.0
|
|
5003
|
-
_url=f"{self.endpoint}/{repo_id}/tree/{revision}/{path_in_repo}",
|
|
5004
|
-
)
|
|
5005
|
-
|
|
5006
4821
|
@validate_hf_hub_args
|
|
5007
4822
|
def delete_file(
|
|
5008
4823
|
self,
|
|
@@ -5060,7 +4875,7 @@ class HfApi:
|
|
|
5060
4875
|
|
|
5061
4876
|
Raises the following errors:
|
|
5062
4877
|
|
|
5063
|
-
- [`
|
|
4878
|
+
- [`HfHubHTTPError`]
|
|
5064
4879
|
if the HuggingFace API returned an error
|
|
5065
4880
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
5066
4881
|
if some parameter value is invalid
|
|
@@ -5069,7 +4884,7 @@ class HfApi:
|
|
|
5069
4884
|
or because it is set to `private` and you do not have access.
|
|
5070
4885
|
- [`~utils.RevisionNotFoundError`]
|
|
5071
4886
|
If the revision to download from cannot be found.
|
|
5072
|
-
- [`~utils.
|
|
4887
|
+
- [`~utils.RemoteEntryNotFoundError`]
|
|
5073
4888
|
If the file to download cannot be found.
|
|
5074
4889
|
|
|
5075
4890
|
</Tip>
|
|
@@ -5097,7 +4912,7 @@ class HfApi:
|
|
|
5097
4912
|
def delete_files(
|
|
5098
4913
|
self,
|
|
5099
4914
|
repo_id: str,
|
|
5100
|
-
delete_patterns:
|
|
4915
|
+
delete_patterns: list[str],
|
|
5101
4916
|
*,
|
|
5102
4917
|
token: Union[bool, str, None] = None,
|
|
5103
4918
|
repo_type: Optional[str] = None,
|
|
@@ -5117,7 +4932,7 @@ class HfApi:
|
|
|
5117
4932
|
repo_id (`str`):
|
|
5118
4933
|
The repository from which the folder will be deleted, for example:
|
|
5119
4934
|
`"username/custom_transformers"`
|
|
5120
|
-
delete_patterns (`
|
|
4935
|
+
delete_patterns (`list[str]`):
|
|
5121
4936
|
List of files or folders to delete. Each string can either be
|
|
5122
4937
|
a file path, a folder path or a Unix shell-style wildcard.
|
|
5123
4938
|
E.g. `["file.txt", "folder/", "data/*.parquet"]`
|
|
@@ -5245,8 +5060,8 @@ class HfApi:
|
|
|
5245
5060
|
repo_type: str, # Repo type is required!
|
|
5246
5061
|
revision: Optional[str] = None,
|
|
5247
5062
|
private: Optional[bool] = None,
|
|
5248
|
-
allow_patterns: Optional[Union[
|
|
5249
|
-
ignore_patterns: Optional[Union[
|
|
5063
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
5064
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
5250
5065
|
num_workers: Optional[int] = None,
|
|
5251
5066
|
print_report: bool = True,
|
|
5252
5067
|
print_report_every: int = 60,
|
|
@@ -5274,9 +5089,9 @@ class HfApi:
|
|
|
5274
5089
|
private (`bool`, `optional`):
|
|
5275
5090
|
Whether the repository should be private.
|
|
5276
5091
|
If `None` (default), the repo will be public unless the organization's default is private.
|
|
5277
|
-
allow_patterns (`
|
|
5092
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
5278
5093
|
If provided, only files matching at least one pattern are uploaded.
|
|
5279
|
-
ignore_patterns (`
|
|
5094
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
5280
5095
|
If provided, files matching any of the patterns are not uploaded.
|
|
5281
5096
|
num_workers (`int`, *optional*):
|
|
5282
5097
|
Number of workers to start. Defaults to `os.cpu_count() - 2` (minimum 2).
|
|
@@ -5315,14 +5130,18 @@ class HfApi:
|
|
|
5315
5130
|
1. (Check parameters and setup.)
|
|
5316
5131
|
2. Create repo if missing.
|
|
5317
5132
|
3. List local files to upload.
|
|
5318
|
-
4.
|
|
5133
|
+
4. Run validation checks and display warnings if repository limits might be exceeded:
|
|
5134
|
+
- Warns if the total number of files exceeds 100k (recommended limit).
|
|
5135
|
+
- Warns if any folder contains more than 10k files (recommended limit).
|
|
5136
|
+
- Warns about files larger than 20GB (recommended) or 50GB (hard limit).
|
|
5137
|
+
5. Start workers. Workers can perform the following tasks:
|
|
5319
5138
|
- Hash a file.
|
|
5320
5139
|
- Get upload mode (regular or LFS) for a list of files.
|
|
5321
5140
|
- Pre-upload an LFS file.
|
|
5322
5141
|
- Commit a bunch of files.
|
|
5323
5142
|
Once a worker finishes a task, it will move on to the next task based on the priority list (see below) until
|
|
5324
5143
|
all files are uploaded and committed.
|
|
5325
|
-
|
|
5144
|
+
6. While workers are up, regularly print a report to sys.stdout.
|
|
5326
5145
|
|
|
5327
5146
|
Order of priority:
|
|
5328
5147
|
1. Commit if more than 5 minutes since last commit attempt (and at least 1 file).
|
|
@@ -5362,7 +5181,6 @@ class HfApi:
|
|
|
5362
5181
|
*,
|
|
5363
5182
|
url: str,
|
|
5364
5183
|
token: Union[bool, str, None] = None,
|
|
5365
|
-
proxies: Optional[Dict] = None,
|
|
5366
5184
|
timeout: Optional[float] = constants.DEFAULT_REQUEST_TIMEOUT,
|
|
5367
5185
|
) -> HfFileMetadata:
|
|
5368
5186
|
"""Fetch metadata of a file versioned on the Hub for a given url.
|
|
@@ -5375,8 +5193,6 @@ class HfApi:
|
|
|
5375
5193
|
token, which is the recommended method for authentication (see
|
|
5376
5194
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5377
5195
|
To disable authentication, pass `False`.
|
|
5378
|
-
proxies (`dict`, *optional*):
|
|
5379
|
-
Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
|
|
5380
5196
|
timeout (`float`, *optional*, defaults to 10):
|
|
5381
5197
|
How many seconds to wait for the server to send metadata before giving up.
|
|
5382
5198
|
|
|
@@ -5390,7 +5206,6 @@ class HfApi:
|
|
|
5390
5206
|
return get_hf_file_metadata(
|
|
5391
5207
|
url=url,
|
|
5392
5208
|
token=token,
|
|
5393
|
-
proxies=proxies,
|
|
5394
5209
|
timeout=timeout,
|
|
5395
5210
|
library_name=self.library_name,
|
|
5396
5211
|
library_version=self.library_version,
|
|
@@ -5410,14 +5225,9 @@ class HfApi:
|
|
|
5410
5225
|
cache_dir: Union[str, Path, None] = None,
|
|
5411
5226
|
local_dir: Union[str, Path, None] = None,
|
|
5412
5227
|
force_download: bool = False,
|
|
5413
|
-
proxies: Optional[Dict] = None,
|
|
5414
5228
|
etag_timeout: float = constants.DEFAULT_ETAG_TIMEOUT,
|
|
5415
5229
|
token: Union[bool, str, None] = None,
|
|
5416
5230
|
local_files_only: bool = False,
|
|
5417
|
-
# Deprecated args
|
|
5418
|
-
resume_download: Optional[bool] = None,
|
|
5419
|
-
force_filename: Optional[str] = None,
|
|
5420
|
-
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5421
5231
|
) -> str:
|
|
5422
5232
|
"""Download a given file if it's not already present in the local cache.
|
|
5423
5233
|
|
|
@@ -5474,12 +5284,9 @@ class HfApi:
|
|
|
5474
5284
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
5475
5285
|
Whether the file should be downloaded even if it already exists in
|
|
5476
5286
|
the local cache.
|
|
5477
|
-
proxies (`dict`, *optional*):
|
|
5478
|
-
Dictionary mapping protocol to the URL of the proxy passed to
|
|
5479
|
-
`requests.request`.
|
|
5480
5287
|
etag_timeout (`float`, *optional*, defaults to `10`):
|
|
5481
5288
|
When fetching ETag, how many seconds to wait for the server to send
|
|
5482
|
-
data before giving up which is passed to `
|
|
5289
|
+
data before giving up which is passed to `httpx.request`.
|
|
5483
5290
|
token (Union[bool, str, None], optional):
|
|
5484
5291
|
A valid user access token (string). Defaults to the locally saved
|
|
5485
5292
|
token, which is the recommended method for authentication (see
|
|
@@ -5498,7 +5305,7 @@ class HfApi:
|
|
|
5498
5305
|
or because it is set to `private` and you do not have access.
|
|
5499
5306
|
[`~utils.RevisionNotFoundError`]
|
|
5500
5307
|
If the revision to download from cannot be found.
|
|
5501
|
-
[`~utils.
|
|
5308
|
+
[`~utils.RemoteEntryNotFoundError`]
|
|
5502
5309
|
If the file to download cannot be found.
|
|
5503
5310
|
[`~utils.LocalEntryNotFoundError`]
|
|
5504
5311
|
If network is disabled or unavailable and file is not found in cache.
|
|
@@ -5526,13 +5333,9 @@ class HfApi:
|
|
|
5526
5333
|
library_version=self.library_version,
|
|
5527
5334
|
cache_dir=cache_dir,
|
|
5528
5335
|
local_dir=local_dir,
|
|
5529
|
-
local_dir_use_symlinks=local_dir_use_symlinks,
|
|
5530
5336
|
user_agent=self.user_agent,
|
|
5531
5337
|
force_download=force_download,
|
|
5532
|
-
force_filename=force_filename,
|
|
5533
|
-
proxies=proxies,
|
|
5534
5338
|
etag_timeout=etag_timeout,
|
|
5535
|
-
resume_download=resume_download,
|
|
5536
5339
|
token=token,
|
|
5537
5340
|
headers=self.headers,
|
|
5538
5341
|
local_files_only=local_files_only,
|
|
@@ -5547,18 +5350,14 @@ class HfApi:
|
|
|
5547
5350
|
revision: Optional[str] = None,
|
|
5548
5351
|
cache_dir: Union[str, Path, None] = None,
|
|
5549
5352
|
local_dir: Union[str, Path, None] = None,
|
|
5550
|
-
proxies: Optional[Dict] = None,
|
|
5551
5353
|
etag_timeout: float = constants.DEFAULT_ETAG_TIMEOUT,
|
|
5552
5354
|
force_download: bool = False,
|
|
5553
5355
|
token: Union[bool, str, None] = None,
|
|
5554
5356
|
local_files_only: bool = False,
|
|
5555
|
-
allow_patterns: Optional[Union[
|
|
5556
|
-
ignore_patterns: Optional[Union[
|
|
5357
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
5358
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
5557
5359
|
max_workers: int = 8,
|
|
5558
|
-
tqdm_class: Optional[
|
|
5559
|
-
# Deprecated args
|
|
5560
|
-
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5561
|
-
resume_download: Optional[bool] = None,
|
|
5360
|
+
tqdm_class: Optional[type[base_tqdm]] = None,
|
|
5562
5361
|
) -> str:
|
|
5563
5362
|
"""Download repo files.
|
|
5564
5363
|
|
|
@@ -5588,12 +5387,9 @@ class HfApi:
|
|
|
5588
5387
|
Path to the folder where cached files are stored.
|
|
5589
5388
|
local_dir (`str` or `Path`, *optional*):
|
|
5590
5389
|
If provided, the downloaded files will be placed under this directory.
|
|
5591
|
-
proxies (`dict`, *optional*):
|
|
5592
|
-
Dictionary mapping protocol to the URL of the proxy passed to
|
|
5593
|
-
`requests.request`.
|
|
5594
5390
|
etag_timeout (`float`, *optional*, defaults to `10`):
|
|
5595
5391
|
When fetching ETag, how many seconds to wait for the server to send
|
|
5596
|
-
data before giving up which is passed to `
|
|
5392
|
+
data before giving up which is passed to `httpx.request`.
|
|
5597
5393
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
5598
5394
|
Whether the file should be downloaded even if it already exists in the local cache.
|
|
5599
5395
|
token (Union[bool, str, None], optional):
|
|
@@ -5604,9 +5400,9 @@ class HfApi:
|
|
|
5604
5400
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
5605
5401
|
If `True`, avoid downloading the file and return the path to the
|
|
5606
5402
|
local cached file if it exists.
|
|
5607
|
-
allow_patterns (`
|
|
5403
|
+
allow_patterns (`list[str]` or `str`, *optional*):
|
|
5608
5404
|
If provided, only files matching at least one pattern are downloaded.
|
|
5609
|
-
ignore_patterns (`
|
|
5405
|
+
ignore_patterns (`list[str]` or `str`, *optional*):
|
|
5610
5406
|
If provided, files matching any of the patterns are not downloaded.
|
|
5611
5407
|
max_workers (`int`, *optional*):
|
|
5612
5408
|
Number of concurrent threads to download files (1 thread = 1 file download).
|
|
@@ -5647,13 +5443,10 @@ class HfApi:
|
|
|
5647
5443
|
endpoint=self.endpoint,
|
|
5648
5444
|
cache_dir=cache_dir,
|
|
5649
5445
|
local_dir=local_dir,
|
|
5650
|
-
local_dir_use_symlinks=local_dir_use_symlinks,
|
|
5651
5446
|
library_name=self.library_name,
|
|
5652
5447
|
library_version=self.library_version,
|
|
5653
5448
|
user_agent=self.user_agent,
|
|
5654
|
-
proxies=proxies,
|
|
5655
5449
|
etag_timeout=etag_timeout,
|
|
5656
|
-
resume_download=resume_download,
|
|
5657
5450
|
force_download=force_download,
|
|
5658
5451
|
token=token,
|
|
5659
5452
|
local_files_only=local_files_only,
|
|
@@ -6270,7 +6063,7 @@ class HfApi:
|
|
|
6270
6063
|
headers = self._build_hf_headers(token=token)
|
|
6271
6064
|
path = f"{self.endpoint}/api/{repo_type}s/{repo_id}/discussions"
|
|
6272
6065
|
|
|
6273
|
-
params:
|
|
6066
|
+
params: dict[str, Union[str, int]] = {}
|
|
6274
6067
|
if discussion_type is not None:
|
|
6275
6068
|
params["type"] = discussion_type
|
|
6276
6069
|
if discussion_status is not None:
|
|
@@ -6340,7 +6133,7 @@ class HfApi:
|
|
|
6340
6133
|
|
|
6341
6134
|
Raises the following errors:
|
|
6342
6135
|
|
|
6343
|
-
- [`
|
|
6136
|
+
- [`HfHubHTTPError`]
|
|
6344
6137
|
if the HuggingFace API returned an error
|
|
6345
6138
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6346
6139
|
if some parameter value is invalid
|
|
@@ -6433,7 +6226,7 @@ class HfApi:
|
|
|
6433
6226
|
|
|
6434
6227
|
Raises the following errors:
|
|
6435
6228
|
|
|
6436
|
-
- [`
|
|
6229
|
+
- [`HfHubHTTPError`]
|
|
6437
6230
|
if the HuggingFace API returned an error
|
|
6438
6231
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6439
6232
|
if some parameter value is invalid
|
|
@@ -6521,7 +6314,7 @@ class HfApi:
|
|
|
6521
6314
|
|
|
6522
6315
|
Raises the following errors:
|
|
6523
6316
|
|
|
6524
|
-
- [`
|
|
6317
|
+
- [`HfHubHTTPError`]
|
|
6525
6318
|
if the HuggingFace API returned an error
|
|
6526
6319
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6527
6320
|
if some parameter value is invalid
|
|
@@ -6548,7 +6341,7 @@ class HfApi:
|
|
|
6548
6341
|
body: Optional[dict] = None,
|
|
6549
6342
|
token: Union[bool, str, None] = None,
|
|
6550
6343
|
repo_type: Optional[str] = None,
|
|
6551
|
-
) ->
|
|
6344
|
+
) -> httpx.Response:
|
|
6552
6345
|
"""Internal utility to POST changes to a Discussion or Pull Request"""
|
|
6553
6346
|
if not isinstance(discussion_num, int) or discussion_num <= 0:
|
|
6554
6347
|
raise ValueError("Invalid discussion_num, must be a positive integer")
|
|
@@ -6561,7 +6354,7 @@ class HfApi:
|
|
|
6561
6354
|
path = f"{self.endpoint}/api/{repo_id}/discussions/{discussion_num}/{resource}"
|
|
6562
6355
|
|
|
6563
6356
|
headers = self._build_hf_headers(token=token)
|
|
6564
|
-
resp =
|
|
6357
|
+
resp = get_session().post(path, headers=headers, json=body)
|
|
6565
6358
|
hf_raise_for_status(resp)
|
|
6566
6359
|
return resp
|
|
6567
6360
|
|
|
@@ -6624,7 +6417,7 @@ class HfApi:
|
|
|
6624
6417
|
|
|
6625
6418
|
Raises the following errors:
|
|
6626
6419
|
|
|
6627
|
-
- [`
|
|
6420
|
+
- [`HfHubHTTPError`]
|
|
6628
6421
|
if the HuggingFace API returned an error
|
|
6629
6422
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6630
6423
|
if some parameter value is invalid
|
|
@@ -6694,7 +6487,7 @@ class HfApi:
|
|
|
6694
6487
|
|
|
6695
6488
|
Raises the following errors:
|
|
6696
6489
|
|
|
6697
|
-
- [`
|
|
6490
|
+
- [`HfHubHTTPError`]
|
|
6698
6491
|
if the HuggingFace API returned an error
|
|
6699
6492
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6700
6493
|
if some parameter value is invalid
|
|
@@ -6767,7 +6560,7 @@ class HfApi:
|
|
|
6767
6560
|
|
|
6768
6561
|
Raises the following errors:
|
|
6769
6562
|
|
|
6770
|
-
- [`
|
|
6563
|
+
- [`HfHubHTTPError`]
|
|
6771
6564
|
if the HuggingFace API returned an error
|
|
6772
6565
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6773
6566
|
if some parameter value is invalid
|
|
@@ -6779,7 +6572,7 @@ class HfApi:
|
|
|
6779
6572
|
"""
|
|
6780
6573
|
if new_status not in ["open", "closed"]:
|
|
6781
6574
|
raise ValueError("Invalid status, valid statuses are: 'open' and 'closed'")
|
|
6782
|
-
body:
|
|
6575
|
+
body: dict[str, str] = {"status": new_status}
|
|
6783
6576
|
if comment and comment.strip():
|
|
6784
6577
|
body["comment"] = comment.strip()
|
|
6785
6578
|
resp = self._post_discussion_changes(
|
|
@@ -6829,7 +6622,7 @@ class HfApi:
|
|
|
6829
6622
|
|
|
6830
6623
|
Raises the following errors:
|
|
6831
6624
|
|
|
6832
|
-
- [`
|
|
6625
|
+
- [`HfHubHTTPError`]
|
|
6833
6626
|
if the HuggingFace API returned an error
|
|
6834
6627
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6835
6628
|
if some parameter value is invalid
|
|
@@ -6888,7 +6681,7 @@ class HfApi:
|
|
|
6888
6681
|
|
|
6889
6682
|
Raises the following errors:
|
|
6890
6683
|
|
|
6891
|
-
- [`
|
|
6684
|
+
- [`HfHubHTTPError`]
|
|
6892
6685
|
if the HuggingFace API returned an error
|
|
6893
6686
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6894
6687
|
if some parameter value is invalid
|
|
@@ -6949,7 +6742,7 @@ class HfApi:
|
|
|
6949
6742
|
|
|
6950
6743
|
Raises the following errors:
|
|
6951
6744
|
|
|
6952
|
-
- [`
|
|
6745
|
+
- [`HfHubHTTPError`]
|
|
6953
6746
|
if the HuggingFace API returned an error
|
|
6954
6747
|
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
6955
6748
|
if some parameter value is invalid
|
|
@@ -7030,7 +6823,8 @@ class HfApi:
|
|
|
7030
6823
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7031
6824
|
To disable authentication, pass `False`.
|
|
7032
6825
|
"""
|
|
7033
|
-
r = get_session().
|
|
6826
|
+
r = get_session().request(
|
|
6827
|
+
"DELETE",
|
|
7034
6828
|
f"{self.endpoint}/api/spaces/{repo_id}/secrets",
|
|
7035
6829
|
headers=self._build_hf_headers(token=token),
|
|
7036
6830
|
json={"key": key},
|
|
@@ -7038,7 +6832,7 @@ class HfApi:
|
|
|
7038
6832
|
hf_raise_for_status(r)
|
|
7039
6833
|
|
|
7040
6834
|
@validate_hf_hub_args
|
|
7041
|
-
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]:
|
|
7042
6836
|
"""Gets all variables from a Space.
|
|
7043
6837
|
|
|
7044
6838
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -7069,7 +6863,7 @@ class HfApi:
|
|
|
7069
6863
|
*,
|
|
7070
6864
|
description: Optional[str] = None,
|
|
7071
6865
|
token: Union[bool, str, None] = None,
|
|
7072
|
-
) ->
|
|
6866
|
+
) -> dict[str, SpaceVariable]:
|
|
7073
6867
|
"""Adds or updates a variable in a Space.
|
|
7074
6868
|
|
|
7075
6869
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -7104,7 +6898,7 @@ class HfApi:
|
|
|
7104
6898
|
@validate_hf_hub_args
|
|
7105
6899
|
def delete_space_variable(
|
|
7106
6900
|
self, repo_id: str, key: str, *, token: Union[bool, str, None] = None
|
|
7107
|
-
) ->
|
|
6901
|
+
) -> dict[str, SpaceVariable]:
|
|
7108
6902
|
"""Deletes a variable from a Space.
|
|
7109
6903
|
|
|
7110
6904
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -7121,7 +6915,8 @@ class HfApi:
|
|
|
7121
6915
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7122
6916
|
To disable authentication, pass `False`.
|
|
7123
6917
|
"""
|
|
7124
|
-
r = get_session().
|
|
6918
|
+
r = get_session().request(
|
|
6919
|
+
"DELETE",
|
|
7125
6920
|
f"{self.endpoint}/api/spaces/{repo_id}/variables",
|
|
7126
6921
|
headers=self._build_hf_headers(token=token),
|
|
7127
6922
|
json={"key": key},
|
|
@@ -7192,7 +6987,7 @@ class HfApi:
|
|
|
7192
6987
|
" you want to set a custom sleep time, you need to upgrade to a paid Hardware.",
|
|
7193
6988
|
UserWarning,
|
|
7194
6989
|
)
|
|
7195
|
-
payload:
|
|
6990
|
+
payload: dict[str, Any] = {"flavor": hardware}
|
|
7196
6991
|
if sleep_time is not None:
|
|
7197
6992
|
payload["sleepTimeSeconds"] = sleep_time
|
|
7198
6993
|
r = get_session().post(
|
|
@@ -7351,8 +7146,8 @@ class HfApi:
|
|
|
7351
7146
|
hardware: Optional[SpaceHardware] = None,
|
|
7352
7147
|
storage: Optional[SpaceStorage] = None,
|
|
7353
7148
|
sleep_time: Optional[int] = None,
|
|
7354
|
-
secrets: Optional[
|
|
7355
|
-
variables: Optional[
|
|
7149
|
+
secrets: Optional[list[dict[str, str]]] = None,
|
|
7150
|
+
variables: Optional[list[dict[str, str]]] = None,
|
|
7356
7151
|
) -> RepoUrl:
|
|
7357
7152
|
"""Duplicate a Space.
|
|
7358
7153
|
|
|
@@ -7383,10 +7178,10 @@ class HfApi:
|
|
|
7383
7178
|
your Space to sleep (default behavior for upgraded hardware). For free hardware, you can't configure
|
|
7384
7179
|
the sleep time (value is fixed to 48 hours of inactivity).
|
|
7385
7180
|
See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
|
|
7386
|
-
secrets (`
|
|
7181
|
+
secrets (`list[dict[str, str]]`, *optional*):
|
|
7387
7182
|
A list of secret keys to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional.
|
|
7388
7183
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets.
|
|
7389
|
-
variables (`
|
|
7184
|
+
variables (`list[dict[str, str]]`, *optional*):
|
|
7390
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.
|
|
7391
7186
|
For more details, see https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables.
|
|
7392
7187
|
|
|
@@ -7398,7 +7193,7 @@ class HfApi:
|
|
|
7398
7193
|
[`~utils.RepositoryNotFoundError`]:
|
|
7399
7194
|
If one of `from_id` or `to_id` cannot be found. This may be because it doesn't exist,
|
|
7400
7195
|
or because it is set to `private` and you do not have access.
|
|
7401
|
-
[`
|
|
7196
|
+
[`HfHubHTTPError`]:
|
|
7402
7197
|
If the HuggingFace API returned an error
|
|
7403
7198
|
|
|
7404
7199
|
Example:
|
|
@@ -7426,7 +7221,7 @@ class HfApi:
|
|
|
7426
7221
|
to_repo_name = parsed_to_id.repo_name if to_id is not None else RepoUrl(from_id).repo_name # type: ignore
|
|
7427
7222
|
|
|
7428
7223
|
# repository must be a valid repo_id (namespace/repo_name).
|
|
7429
|
-
payload:
|
|
7224
|
+
payload: dict[str, Any] = {"repository": f"{to_namespace}/{to_repo_name}"}
|
|
7430
7225
|
|
|
7431
7226
|
keys = ["private", "hardware", "storageTier", "sleepTimeSeconds", "secrets", "variables"]
|
|
7432
7227
|
values = [private, hardware, storage, sleep_time, secrets, variables]
|
|
@@ -7448,7 +7243,7 @@ class HfApi:
|
|
|
7448
7243
|
|
|
7449
7244
|
try:
|
|
7450
7245
|
hf_raise_for_status(r)
|
|
7451
|
-
except
|
|
7246
|
+
except HfHubHTTPError as err:
|
|
7452
7247
|
if exist_ok and err.response.status_code == 409:
|
|
7453
7248
|
# Repo already exists and `exist_ok=True`
|
|
7454
7249
|
pass
|
|
@@ -7487,7 +7282,7 @@ class HfApi:
|
|
|
7487
7282
|
|
|
7488
7283
|
</Tip>
|
|
7489
7284
|
"""
|
|
7490
|
-
payload:
|
|
7285
|
+
payload: dict[str, SpaceStorage] = {"tier": storage}
|
|
7491
7286
|
r = get_session().post(
|
|
7492
7287
|
f"{self.endpoint}/api/spaces/{repo_id}/storage",
|
|
7493
7288
|
headers=self._build_hf_headers(token=token),
|
|
@@ -7533,7 +7328,7 @@ class HfApi:
|
|
|
7533
7328
|
|
|
7534
7329
|
def list_inference_endpoints(
|
|
7535
7330
|
self, namespace: Optional[str] = None, *, token: Union[bool, str, None] = None
|
|
7536
|
-
) ->
|
|
7331
|
+
) -> list[InferenceEndpoint]:
|
|
7537
7332
|
"""Lists all inference endpoints for the given namespace.
|
|
7538
7333
|
|
|
7539
7334
|
Args:
|
|
@@ -7547,7 +7342,7 @@ class HfApi:
|
|
|
7547
7342
|
To disable authentication, pass `False`.
|
|
7548
7343
|
|
|
7549
7344
|
Returns:
|
|
7550
|
-
|
|
7345
|
+
list[`InferenceEndpoint`]: A list of all inference endpoints for the given namespace.
|
|
7551
7346
|
|
|
7552
7347
|
Example:
|
|
7553
7348
|
```python
|
|
@@ -7562,7 +7357,7 @@ class HfApi:
|
|
|
7562
7357
|
user = self.whoami(token=token)
|
|
7563
7358
|
|
|
7564
7359
|
# List personal endpoints first
|
|
7565
|
-
endpoints:
|
|
7360
|
+
endpoints: list[InferenceEndpoint] = list_inference_endpoints(namespace=self._get_namespace(token=token))
|
|
7566
7361
|
|
|
7567
7362
|
# Then list endpoints for all orgs the user belongs to and ignore 401 errors (no billing or no access)
|
|
7568
7363
|
for org in user.get("orgs", []):
|
|
@@ -7606,14 +7401,14 @@ class HfApi:
|
|
|
7606
7401
|
scale_to_zero_timeout: Optional[int] = None,
|
|
7607
7402
|
revision: Optional[str] = None,
|
|
7608
7403
|
task: Optional[str] = None,
|
|
7609
|
-
custom_image: Optional[
|
|
7610
|
-
env: Optional[
|
|
7611
|
-
secrets: Optional[
|
|
7404
|
+
custom_image: Optional[dict] = None,
|
|
7405
|
+
env: Optional[dict[str, str]] = None,
|
|
7406
|
+
secrets: Optional[dict[str, str]] = None,
|
|
7612
7407
|
type: InferenceEndpointType = InferenceEndpointType.PROTECTED,
|
|
7613
7408
|
domain: Optional[str] = None,
|
|
7614
7409
|
path: Optional[str] = None,
|
|
7615
7410
|
cache_http_responses: Optional[bool] = None,
|
|
7616
|
-
tags: Optional[
|
|
7411
|
+
tags: Optional[list[str]] = None,
|
|
7617
7412
|
namespace: Optional[str] = None,
|
|
7618
7413
|
token: Union[bool, str, None] = None,
|
|
7619
7414
|
) -> InferenceEndpoint:
|
|
@@ -7650,12 +7445,12 @@ class HfApi:
|
|
|
7650
7445
|
The specific model revision to deploy on the Inference Endpoint (e.g. `"6c0e6080953db56375760c0471a8c5f2929baf11"`).
|
|
7651
7446
|
task (`str`, *optional*):
|
|
7652
7447
|
The task on which to deploy the model (e.g. `"text-classification"`).
|
|
7653
|
-
custom_image (`
|
|
7448
|
+
custom_image (`dict`, *optional*):
|
|
7654
7449
|
A custom Docker image to use for the Inference Endpoint. This is useful if you want to deploy an
|
|
7655
7450
|
Inference Endpoint running on the `text-generation-inference` (TGI) framework (see examples).
|
|
7656
|
-
env (`
|
|
7451
|
+
env (`dict[str, str]`, *optional*):
|
|
7657
7452
|
Non-secret environment variables to inject in the container environment.
|
|
7658
|
-
secrets (`
|
|
7453
|
+
secrets (`dict[str, str]`, *optional*):
|
|
7659
7454
|
Secret values to inject in the container environment.
|
|
7660
7455
|
type ([`InferenceEndpointType]`, *optional*):
|
|
7661
7456
|
The type of the Inference Endpoint, which can be `"protected"` (default), `"public"` or `"private"`.
|
|
@@ -7665,7 +7460,7 @@ class HfApi:
|
|
|
7665
7460
|
The custom path to the deployed model, should start with a `/` (e.g. `"/models/google-bert/bert-base-uncased"`).
|
|
7666
7461
|
cache_http_responses (`bool`, *optional*):
|
|
7667
7462
|
Whether to cache HTTP responses from the Inference Endpoint. Defaults to `False`.
|
|
7668
|
-
tags (`
|
|
7463
|
+
tags (`list[str]`, *optional*):
|
|
7669
7464
|
A list of tags to associate with the Inference Endpoint.
|
|
7670
7465
|
namespace (`str`, *optional*):
|
|
7671
7466
|
The namespace where the Inference Endpoint will be created. Defaults to the current user's namespace.
|
|
@@ -7768,7 +7563,7 @@ class HfApi:
|
|
|
7768
7563
|
else:
|
|
7769
7564
|
image = {"huggingface": {}}
|
|
7770
7565
|
|
|
7771
|
-
payload:
|
|
7566
|
+
payload: dict = {
|
|
7772
7567
|
"accountId": account_id,
|
|
7773
7568
|
"compute": {
|
|
7774
7569
|
"accelerator": accelerator,
|
|
@@ -7857,7 +7652,7 @@ class HfApi:
|
|
|
7857
7652
|
</Tip>
|
|
7858
7653
|
"""
|
|
7859
7654
|
token = token or self.token or get_token()
|
|
7860
|
-
payload:
|
|
7655
|
+
payload: dict = {
|
|
7861
7656
|
"namespace": namespace or self._get_namespace(token=token),
|
|
7862
7657
|
"repoId": repo_id,
|
|
7863
7658
|
}
|
|
@@ -7875,7 +7670,7 @@ class HfApi:
|
|
|
7875
7670
|
|
|
7876
7671
|
@experimental
|
|
7877
7672
|
@validate_hf_hub_args
|
|
7878
|
-
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]:
|
|
7879
7674
|
"""List models available in the Hugging Face Inference Catalog.
|
|
7880
7675
|
|
|
7881
7676
|
The goal of the Inference Catalog is to provide a curated list of models that are optimized for inference
|
|
@@ -7891,7 +7686,7 @@ class HfApi:
|
|
|
7891
7686
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7892
7687
|
|
|
7893
7688
|
Returns:
|
|
7894
|
-
|
|
7689
|
+
list[`str`]: A list of model IDs available in the catalog.
|
|
7895
7690
|
<Tip warning={true}>
|
|
7896
7691
|
|
|
7897
7692
|
`list_inference_catalog` is experimental. Its API is subject to change in the future. Please provide feedback
|
|
@@ -7969,15 +7764,15 @@ class HfApi:
|
|
|
7969
7764
|
framework: Optional[str] = None,
|
|
7970
7765
|
revision: Optional[str] = None,
|
|
7971
7766
|
task: Optional[str] = None,
|
|
7972
|
-
custom_image: Optional[
|
|
7973
|
-
env: Optional[
|
|
7974
|
-
secrets: Optional[
|
|
7767
|
+
custom_image: Optional[dict] = None,
|
|
7768
|
+
env: Optional[dict[str, str]] = None,
|
|
7769
|
+
secrets: Optional[dict[str, str]] = None,
|
|
7975
7770
|
# Route update
|
|
7976
7771
|
domain: Optional[str] = None,
|
|
7977
7772
|
path: Optional[str] = None,
|
|
7978
7773
|
# Other
|
|
7979
7774
|
cache_http_responses: Optional[bool] = None,
|
|
7980
|
-
tags: Optional[
|
|
7775
|
+
tags: Optional[list[str]] = None,
|
|
7981
7776
|
namespace: Optional[str] = None,
|
|
7982
7777
|
token: Union[bool, str, None] = None,
|
|
7983
7778
|
) -> InferenceEndpoint:
|
|
@@ -8013,12 +7808,12 @@ class HfApi:
|
|
|
8013
7808
|
The specific model revision to deploy on the Inference Endpoint (e.g. `"6c0e6080953db56375760c0471a8c5f2929baf11"`).
|
|
8014
7809
|
task (`str`, *optional*):
|
|
8015
7810
|
The task on which to deploy the model (e.g. `"text-classification"`).
|
|
8016
|
-
custom_image (`
|
|
7811
|
+
custom_image (`dict`, *optional*):
|
|
8017
7812
|
A custom Docker image to use for the Inference Endpoint. This is useful if you want to deploy an
|
|
8018
7813
|
Inference Endpoint running on the `text-generation-inference` (TGI) framework (see examples).
|
|
8019
|
-
env (`
|
|
7814
|
+
env (`dict[str, str]`, *optional*):
|
|
8020
7815
|
Non-secret environment variables to inject in the container environment
|
|
8021
|
-
secrets (`
|
|
7816
|
+
secrets (`dict[str, str]`, *optional*):
|
|
8022
7817
|
Secret values to inject in the container environment.
|
|
8023
7818
|
|
|
8024
7819
|
domain (`str`, *optional*):
|
|
@@ -8028,7 +7823,7 @@ class HfApi:
|
|
|
8028
7823
|
|
|
8029
7824
|
cache_http_responses (`bool`, *optional*):
|
|
8030
7825
|
Whether to cache HTTP responses from the Inference Endpoint.
|
|
8031
|
-
tags (`
|
|
7826
|
+
tags (`list[str]`, *optional*):
|
|
8032
7827
|
A list of tags to associate with the Inference Endpoint.
|
|
8033
7828
|
|
|
8034
7829
|
namespace (`str`, *optional*):
|
|
@@ -8045,7 +7840,7 @@ class HfApi:
|
|
|
8045
7840
|
namespace = namespace or self._get_namespace(token=token)
|
|
8046
7841
|
|
|
8047
7842
|
# Populate only the fields that are not None
|
|
8048
|
-
payload:
|
|
7843
|
+
payload: dict = defaultdict(lambda: defaultdict(dict))
|
|
8049
7844
|
if accelerator is not None:
|
|
8050
7845
|
payload["compute"]["accelerator"] = accelerator
|
|
8051
7846
|
if instance_size is not None:
|
|
@@ -8252,8 +8047,8 @@ class HfApi:
|
|
|
8252
8047
|
def list_collections(
|
|
8253
8048
|
self,
|
|
8254
8049
|
*,
|
|
8255
|
-
owner: Union[
|
|
8256
|
-
item: Union[
|
|
8050
|
+
owner: Union[list[str], str, None] = None,
|
|
8051
|
+
item: Union[list[str], str, None] = None,
|
|
8257
8052
|
sort: Optional[Literal["lastModified", "trending", "upvotes"]] = None,
|
|
8258
8053
|
limit: Optional[int] = None,
|
|
8259
8054
|
token: Union[bool, str, None] = None,
|
|
@@ -8268,9 +8063,9 @@ class HfApi:
|
|
|
8268
8063
|
</Tip>
|
|
8269
8064
|
|
|
8270
8065
|
Args:
|
|
8271
|
-
owner (`
|
|
8066
|
+
owner (`list[str]` or `str`, *optional*):
|
|
8272
8067
|
Filter by owner's username.
|
|
8273
|
-
item (`
|
|
8068
|
+
item (`list[str]` or `str`, *optional*):
|
|
8274
8069
|
Filter collections containing a particular items. Example: `"models/teknium/OpenHermes-2.5-Mistral-7B"`, `"datasets/squad"` or `"papers/2311.12983"`.
|
|
8275
8070
|
sort (`Literal["lastModified", "trending", "upvotes"]`, *optional*):
|
|
8276
8071
|
Sort collections by last modified, trending or upvotes.
|
|
@@ -8288,7 +8083,7 @@ class HfApi:
|
|
|
8288
8083
|
# Construct the API endpoint
|
|
8289
8084
|
path = f"{self.endpoint}/api/collections"
|
|
8290
8085
|
headers = self._build_hf_headers(token=token)
|
|
8291
|
-
params:
|
|
8086
|
+
params: dict = {}
|
|
8292
8087
|
if owner is not None:
|
|
8293
8088
|
params.update({"owner": owner})
|
|
8294
8089
|
if item is not None:
|
|
@@ -8405,7 +8200,7 @@ class HfApi:
|
|
|
8405
8200
|
)
|
|
8406
8201
|
try:
|
|
8407
8202
|
hf_raise_for_status(r)
|
|
8408
|
-
except
|
|
8203
|
+
except HfHubHTTPError as err:
|
|
8409
8204
|
if exists_ok and err.response.status_code == 409:
|
|
8410
8205
|
# Collection already exists and `exists_ok=True`
|
|
8411
8206
|
slug = r.json()["slug"]
|
|
@@ -8516,7 +8311,7 @@ class HfApi:
|
|
|
8516
8311
|
)
|
|
8517
8312
|
try:
|
|
8518
8313
|
hf_raise_for_status(r)
|
|
8519
|
-
except
|
|
8314
|
+
except HfHubHTTPError as err:
|
|
8520
8315
|
if missing_ok and err.response.status_code == 404:
|
|
8521
8316
|
# Collection doesn't exists and `missing_ok=True`
|
|
8522
8317
|
return
|
|
@@ -8556,12 +8351,12 @@ class HfApi:
|
|
|
8556
8351
|
Returns: [`Collection`]
|
|
8557
8352
|
|
|
8558
8353
|
Raises:
|
|
8559
|
-
[`
|
|
8354
|
+
[`HfHubHTTPError`]:
|
|
8560
8355
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8561
8356
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8562
|
-
[`
|
|
8357
|
+
[`HfHubHTTPError`]:
|
|
8563
8358
|
HTTP 404 if the item you try to add to the collection does not exist on the Hub.
|
|
8564
|
-
[`
|
|
8359
|
+
[`HfHubHTTPError`]:
|
|
8565
8360
|
HTTP 409 if the item you try to add to the collection is already in the collection (and exists_ok=False)
|
|
8566
8361
|
|
|
8567
8362
|
Example:
|
|
@@ -8587,7 +8382,7 @@ class HfApi:
|
|
|
8587
8382
|
(...)
|
|
8588
8383
|
```
|
|
8589
8384
|
"""
|
|
8590
|
-
payload:
|
|
8385
|
+
payload: dict[str, Any] = {"item": {"id": item_id, "type": item_type}}
|
|
8591
8386
|
if note is not None:
|
|
8592
8387
|
payload["note"] = note
|
|
8593
8388
|
r = get_session().post(
|
|
@@ -8597,7 +8392,7 @@ class HfApi:
|
|
|
8597
8392
|
)
|
|
8598
8393
|
try:
|
|
8599
8394
|
hf_raise_for_status(r)
|
|
8600
|
-
except
|
|
8395
|
+
except HfHubHTTPError as err:
|
|
8601
8396
|
if exists_ok and err.response.status_code == 409:
|
|
8602
8397
|
# Item already exists and `exists_ok=True`
|
|
8603
8398
|
return self.get_collection(collection_slug, token=token)
|
|
@@ -8703,7 +8498,7 @@ class HfApi:
|
|
|
8703
8498
|
)
|
|
8704
8499
|
try:
|
|
8705
8500
|
hf_raise_for_status(r)
|
|
8706
|
-
except
|
|
8501
|
+
except HfHubHTTPError as err:
|
|
8707
8502
|
if missing_ok and err.response.status_code == 404:
|
|
8708
8503
|
# Item already deleted and `missing_ok=True`
|
|
8709
8504
|
return
|
|
@@ -8717,7 +8512,7 @@ class HfApi:
|
|
|
8717
8512
|
@validate_hf_hub_args
|
|
8718
8513
|
def list_pending_access_requests(
|
|
8719
8514
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8720
|
-
) ->
|
|
8515
|
+
) -> list[AccessRequest]:
|
|
8721
8516
|
"""
|
|
8722
8517
|
Get pending access requests for a given gated repo.
|
|
8723
8518
|
|
|
@@ -8740,14 +8535,14 @@ class HfApi:
|
|
|
8740
8535
|
To disable authentication, pass `False`.
|
|
8741
8536
|
|
|
8742
8537
|
Returns:
|
|
8743
|
-
`
|
|
8538
|
+
`list[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
8744
8539
|
`status` and `timestamp` attribute. If the gated repo has a custom form, the `fields` attribute will
|
|
8745
8540
|
be populated with user's answers.
|
|
8746
8541
|
|
|
8747
8542
|
Raises:
|
|
8748
|
-
[`
|
|
8543
|
+
[`HfHubHTTPError`]:
|
|
8749
8544
|
HTTP 400 if the repo is not gated.
|
|
8750
|
-
[`
|
|
8545
|
+
[`HfHubHTTPError`]:
|
|
8751
8546
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8752
8547
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8753
8548
|
|
|
@@ -8781,7 +8576,7 @@ class HfApi:
|
|
|
8781
8576
|
@validate_hf_hub_args
|
|
8782
8577
|
def list_accepted_access_requests(
|
|
8783
8578
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8784
|
-
) ->
|
|
8579
|
+
) -> list[AccessRequest]:
|
|
8785
8580
|
"""
|
|
8786
8581
|
Get accepted access requests for a given gated repo.
|
|
8787
8582
|
|
|
@@ -8806,14 +8601,14 @@ class HfApi:
|
|
|
8806
8601
|
To disable authentication, pass `False`.
|
|
8807
8602
|
|
|
8808
8603
|
Returns:
|
|
8809
|
-
`
|
|
8604
|
+
`list[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
8810
8605
|
`status` and `timestamp` attribute. If the gated repo has a custom form, the `fields` attribute will
|
|
8811
8606
|
be populated with user's answers.
|
|
8812
8607
|
|
|
8813
8608
|
Raises:
|
|
8814
|
-
[`
|
|
8609
|
+
[`HfHubHTTPError`]:
|
|
8815
8610
|
HTTP 400 if the repo is not gated.
|
|
8816
|
-
[`
|
|
8611
|
+
[`HfHubHTTPError`]:
|
|
8817
8612
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8818
8613
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8819
8614
|
|
|
@@ -8843,7 +8638,7 @@ class HfApi:
|
|
|
8843
8638
|
@validate_hf_hub_args
|
|
8844
8639
|
def list_rejected_access_requests(
|
|
8845
8640
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8846
|
-
) ->
|
|
8641
|
+
) -> list[AccessRequest]:
|
|
8847
8642
|
"""
|
|
8848
8643
|
Get rejected access requests for a given gated repo.
|
|
8849
8644
|
|
|
@@ -8868,14 +8663,14 @@ class HfApi:
|
|
|
8868
8663
|
To disable authentication, pass `False`.
|
|
8869
8664
|
|
|
8870
8665
|
Returns:
|
|
8871
|
-
`
|
|
8666
|
+
`list[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
8872
8667
|
`status` and `timestamp` attribute. If the gated repo has a custom form, the `fields` attribute will
|
|
8873
8668
|
be populated with user's answers.
|
|
8874
8669
|
|
|
8875
8670
|
Raises:
|
|
8876
|
-
[`
|
|
8671
|
+
[`HfHubHTTPError`]:
|
|
8877
8672
|
HTTP 400 if the repo is not gated.
|
|
8878
|
-
[`
|
|
8673
|
+
[`HfHubHTTPError`]:
|
|
8879
8674
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8880
8675
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8881
8676
|
|
|
@@ -8908,7 +8703,7 @@ class HfApi:
|
|
|
8908
8703
|
status: Literal["accepted", "rejected", "pending"],
|
|
8909
8704
|
repo_type: Optional[str] = None,
|
|
8910
8705
|
token: Union[bool, str, None] = None,
|
|
8911
|
-
) ->
|
|
8706
|
+
) -> list[AccessRequest]:
|
|
8912
8707
|
if repo_type not in constants.REPO_TYPES:
|
|
8913
8708
|
raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
|
|
8914
8709
|
if repo_type is None:
|
|
@@ -8957,16 +8752,16 @@ class HfApi:
|
|
|
8957
8752
|
To disable authentication, pass `False`.
|
|
8958
8753
|
|
|
8959
8754
|
Raises:
|
|
8960
|
-
[`
|
|
8755
|
+
[`HfHubHTTPError`]:
|
|
8961
8756
|
HTTP 400 if the repo is not gated.
|
|
8962
|
-
[`
|
|
8757
|
+
[`HfHubHTTPError`]:
|
|
8963
8758
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
8964
8759
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
8965
|
-
[`
|
|
8760
|
+
[`HfHubHTTPError`]:
|
|
8966
8761
|
HTTP 404 if the user does not exist on the Hub.
|
|
8967
|
-
[`
|
|
8762
|
+
[`HfHubHTTPError`]:
|
|
8968
8763
|
HTTP 404 if the user access request cannot be found.
|
|
8969
|
-
[`
|
|
8764
|
+
[`HfHubHTTPError`]:
|
|
8970
8765
|
HTTP 404 if the user access request is already in the pending list.
|
|
8971
8766
|
"""
|
|
8972
8767
|
self._handle_access_request(repo_id, user, "pending", repo_type=repo_type, token=token)
|
|
@@ -8999,16 +8794,16 @@ class HfApi:
|
|
|
8999
8794
|
To disable authentication, pass `False`.
|
|
9000
8795
|
|
|
9001
8796
|
Raises:
|
|
9002
|
-
[`
|
|
8797
|
+
[`HfHubHTTPError`]:
|
|
9003
8798
|
HTTP 400 if the repo is not gated.
|
|
9004
|
-
[`
|
|
8799
|
+
[`HfHubHTTPError`]:
|
|
9005
8800
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
9006
8801
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
9007
|
-
[`
|
|
8802
|
+
[`HfHubHTTPError`]:
|
|
9008
8803
|
HTTP 404 if the user does not exist on the Hub.
|
|
9009
|
-
[`
|
|
8804
|
+
[`HfHubHTTPError`]:
|
|
9010
8805
|
HTTP 404 if the user access request cannot be found.
|
|
9011
|
-
[`
|
|
8806
|
+
[`HfHubHTTPError`]:
|
|
9012
8807
|
HTTP 404 if the user access request is already in the accepted list.
|
|
9013
8808
|
"""
|
|
9014
8809
|
self._handle_access_request(repo_id, user, "accepted", repo_type=repo_type, token=token)
|
|
@@ -9049,16 +8844,16 @@ class HfApi:
|
|
|
9049
8844
|
To disable authentication, pass `False`.
|
|
9050
8845
|
|
|
9051
8846
|
Raises:
|
|
9052
|
-
[`
|
|
8847
|
+
[`HfHubHTTPError`]:
|
|
9053
8848
|
HTTP 400 if the repo is not gated.
|
|
9054
|
-
[`
|
|
8849
|
+
[`HfHubHTTPError`]:
|
|
9055
8850
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
9056
8851
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
9057
|
-
[`
|
|
8852
|
+
[`HfHubHTTPError`]:
|
|
9058
8853
|
HTTP 404 if the user does not exist on the Hub.
|
|
9059
|
-
[`
|
|
8854
|
+
[`HfHubHTTPError`]:
|
|
9060
8855
|
HTTP 404 if the user access request cannot be found.
|
|
9061
|
-
[`
|
|
8856
|
+
[`HfHubHTTPError`]:
|
|
9062
8857
|
HTTP 404 if the user access request is already in the rejected list.
|
|
9063
8858
|
"""
|
|
9064
8859
|
self._handle_access_request(
|
|
@@ -9122,14 +8917,14 @@ class HfApi:
|
|
|
9122
8917
|
To disable authentication, pass `False`.
|
|
9123
8918
|
|
|
9124
8919
|
Raises:
|
|
9125
|
-
[`
|
|
8920
|
+
[`HfHubHTTPError`]:
|
|
9126
8921
|
HTTP 400 if the repo is not gated.
|
|
9127
|
-
[`
|
|
8922
|
+
[`HfHubHTTPError`]:
|
|
9128
8923
|
HTTP 400 if the user already has access to the repo.
|
|
9129
|
-
[`
|
|
8924
|
+
[`HfHubHTTPError`]:
|
|
9130
8925
|
HTTP 403 if you only have read-only access to the repo. This can be the case if you don't have `write`
|
|
9131
8926
|
or `admin` role in the organization the repo belongs to or if you passed a `read` token.
|
|
9132
|
-
[`
|
|
8927
|
+
[`HfHubHTTPError`]:
|
|
9133
8928
|
HTTP 404 if the user does not exist on the Hub.
|
|
9134
8929
|
"""
|
|
9135
8930
|
if repo_type not in constants.REPO_TYPES:
|
|
@@ -9201,7 +8996,7 @@ class HfApi:
|
|
|
9201
8996
|
return webhook
|
|
9202
8997
|
|
|
9203
8998
|
@validate_hf_hub_args
|
|
9204
|
-
def list_webhooks(self, *, token: Union[bool, str, None] = None) ->
|
|
8999
|
+
def list_webhooks(self, *, token: Union[bool, str, None] = None) -> list[WebhookInfo]:
|
|
9205
9000
|
"""List all configured webhooks.
|
|
9206
9001
|
|
|
9207
9002
|
Args:
|
|
@@ -9211,7 +9006,7 @@ class HfApi:
|
|
|
9211
9006
|
To disable authentication, pass `False`.
|
|
9212
9007
|
|
|
9213
9008
|
Returns:
|
|
9214
|
-
`
|
|
9009
|
+
`list[WebhookInfo]`:
|
|
9215
9010
|
List of webhook info objects.
|
|
9216
9011
|
|
|
9217
9012
|
Example:
|
|
@@ -9255,8 +9050,8 @@ class HfApi:
|
|
|
9255
9050
|
self,
|
|
9256
9051
|
*,
|
|
9257
9052
|
url: str,
|
|
9258
|
-
watched:
|
|
9259
|
-
domains: Optional[
|
|
9053
|
+
watched: list[Union[dict, WebhookWatchedItem]],
|
|
9054
|
+
domains: Optional[list[constants.WEBHOOK_DOMAIN_T]] = None,
|
|
9260
9055
|
secret: Optional[str] = None,
|
|
9261
9056
|
token: Union[bool, str, None] = None,
|
|
9262
9057
|
) -> WebhookInfo:
|
|
@@ -9265,10 +9060,10 @@ class HfApi:
|
|
|
9265
9060
|
Args:
|
|
9266
9061
|
url (`str`):
|
|
9267
9062
|
URL to send the payload to.
|
|
9268
|
-
watched (`
|
|
9063
|
+
watched (`list[WebhookWatchedItem]`):
|
|
9269
9064
|
List of [`WebhookWatchedItem`] to be watched by the webhook. It can be users, orgs, models, datasets or spaces.
|
|
9270
9065
|
Watched items can also be provided as plain dictionaries.
|
|
9271
|
-
domains (`
|
|
9066
|
+
domains (`list[Literal["repo", "discussion"]]`, optional):
|
|
9272
9067
|
List of domains to watch. It can be "repo", "discussion" or both.
|
|
9273
9068
|
secret (`str`, optional):
|
|
9274
9069
|
A secret to sign the payload with.
|
|
@@ -9329,8 +9124,8 @@ class HfApi:
|
|
|
9329
9124
|
webhook_id: str,
|
|
9330
9125
|
*,
|
|
9331
9126
|
url: Optional[str] = None,
|
|
9332
|
-
watched: Optional[
|
|
9333
|
-
domains: Optional[
|
|
9127
|
+
watched: Optional[list[Union[dict, WebhookWatchedItem]]] = None,
|
|
9128
|
+
domains: Optional[list[constants.WEBHOOK_DOMAIN_T]] = None,
|
|
9334
9129
|
secret: Optional[str] = None,
|
|
9335
9130
|
token: Union[bool, str, None] = None,
|
|
9336
9131
|
) -> WebhookInfo:
|
|
@@ -9341,10 +9136,10 @@ class HfApi:
|
|
|
9341
9136
|
The unique identifier of the webhook to be updated.
|
|
9342
9137
|
url (`str`, optional):
|
|
9343
9138
|
The URL to which the payload will be sent.
|
|
9344
|
-
watched (`
|
|
9139
|
+
watched (`list[WebhookWatchedItem]`, optional):
|
|
9345
9140
|
List of items to watch. It can be users, orgs, models, datasets, or spaces.
|
|
9346
9141
|
Refer to [`WebhookWatchedItem`] for more details. Watched items can also be provided as plain dictionaries.
|
|
9347
|
-
domains (`
|
|
9142
|
+
domains (`list[Literal["repo", "discussion"]]`, optional):
|
|
9348
9143
|
The domains to watch. This can include "repo", "discussion", or both.
|
|
9349
9144
|
secret (`str`, optional):
|
|
9350
9145
|
A secret to sign the payload with, providing an additional layer of security.
|
|
@@ -9540,8 +9335,8 @@ class HfApi:
|
|
|
9540
9335
|
token: Union[bool, str, None] = None,
|
|
9541
9336
|
library_name: Optional[str] = None,
|
|
9542
9337
|
library_version: Optional[str] = None,
|
|
9543
|
-
user_agent: Union[
|
|
9544
|
-
) ->
|
|
9338
|
+
user_agent: Union[dict, str, None] = None,
|
|
9339
|
+
) -> dict[str, str]:
|
|
9545
9340
|
"""
|
|
9546
9341
|
Alias for [`build_hf_headers`] that uses the token from [`HfApi`] client
|
|
9547
9342
|
when `token` is not provided.
|
|
@@ -9563,9 +9358,9 @@ class HfApi:
|
|
|
9563
9358
|
repo_type: Optional[str],
|
|
9564
9359
|
revision: Optional[str],
|
|
9565
9360
|
path_in_repo: str,
|
|
9566
|
-
delete_patterns: Optional[Union[
|
|
9361
|
+
delete_patterns: Optional[Union[list[str], str]],
|
|
9567
9362
|
token: Union[bool, str, None] = None,
|
|
9568
|
-
) ->
|
|
9363
|
+
) -> list[CommitOperationDelete]:
|
|
9569
9364
|
"""Generate the list of Delete operations for a commit to delete files from a repo.
|
|
9570
9365
|
|
|
9571
9366
|
List remote files and match them against the `delete_patterns` constraints. Returns a list of [`CommitOperationDelete`]
|
|
@@ -9601,11 +9396,11 @@ class HfApi:
|
|
|
9601
9396
|
self,
|
|
9602
9397
|
folder_path: Union[str, Path],
|
|
9603
9398
|
path_in_repo: str,
|
|
9604
|
-
allow_patterns: Optional[Union[
|
|
9605
|
-
ignore_patterns: Optional[Union[
|
|
9399
|
+
allow_patterns: Optional[Union[list[str], str]] = None,
|
|
9400
|
+
ignore_patterns: Optional[Union[list[str], str]] = None,
|
|
9606
9401
|
repo_type: Optional[str] = None,
|
|
9607
9402
|
token: Union[bool, str, None] = None,
|
|
9608
|
-
) ->
|
|
9403
|
+
) -> list[CommitOperationAdd]:
|
|
9609
9404
|
"""Generate the list of Add operations for a commit to upload a folder.
|
|
9610
9405
|
|
|
9611
9406
|
Files not matching the `allow_patterns` (allowlist) and `ignore_patterns` (denylist)
|
|
@@ -9720,7 +9515,7 @@ class HfApi:
|
|
|
9720
9515
|
`User`: A [`User`] object with the user's overview.
|
|
9721
9516
|
|
|
9722
9517
|
Raises:
|
|
9723
|
-
[`
|
|
9518
|
+
[`HfHubHTTPError`]:
|
|
9724
9519
|
HTTP 404 If the user does not exist on the Hub.
|
|
9725
9520
|
"""
|
|
9726
9521
|
r = get_session().get(
|
|
@@ -9746,7 +9541,7 @@ class HfApi:
|
|
|
9746
9541
|
`Iterable[User]`: A list of [`User`] objects with the members of the organization.
|
|
9747
9542
|
|
|
9748
9543
|
Raises:
|
|
9749
|
-
[`
|
|
9544
|
+
[`HfHubHTTPError`]:
|
|
9750
9545
|
HTTP 404 If the organization does not exist on the Hub.
|
|
9751
9546
|
|
|
9752
9547
|
"""
|
|
@@ -9774,7 +9569,7 @@ class HfApi:
|
|
|
9774
9569
|
`Iterable[User]`: A list of [`User`] objects with the followers of the user.
|
|
9775
9570
|
|
|
9776
9571
|
Raises:
|
|
9777
|
-
[`
|
|
9572
|
+
[`HfHubHTTPError`]:
|
|
9778
9573
|
HTTP 404 If the user does not exist on the Hub.
|
|
9779
9574
|
|
|
9780
9575
|
"""
|
|
@@ -9802,7 +9597,7 @@ class HfApi:
|
|
|
9802
9597
|
`Iterable[User]`: A list of [`User`] objects with the users followed by the user.
|
|
9803
9598
|
|
|
9804
9599
|
Raises:
|
|
9805
|
-
[`
|
|
9600
|
+
[`HfHubHTTPError`]:
|
|
9806
9601
|
HTTP 404 If the user does not exist on the Hub.
|
|
9807
9602
|
|
|
9808
9603
|
"""
|
|
@@ -9871,7 +9666,7 @@ class HfApi:
|
|
|
9871
9666
|
`PaperInfo`: A `PaperInfo` object.
|
|
9872
9667
|
|
|
9873
9668
|
Raises:
|
|
9874
|
-
[`
|
|
9669
|
+
[`HfHubHTTPError`]:
|
|
9875
9670
|
HTTP 404 If the paper does not exist on the Hub.
|
|
9876
9671
|
"""
|
|
9877
9672
|
path = f"{self.endpoint}/api/papers/{id}"
|
|
@@ -9947,9 +9742,9 @@ class HfApi:
|
|
|
9947
9742
|
self,
|
|
9948
9743
|
*,
|
|
9949
9744
|
image: str,
|
|
9950
|
-
command:
|
|
9951
|
-
env: Optional[
|
|
9952
|
-
secrets: Optional[
|
|
9745
|
+
command: list[str],
|
|
9746
|
+
env: Optional[dict[str, Any]] = None,
|
|
9747
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
9953
9748
|
flavor: Optional[SpaceHardware] = None,
|
|
9954
9749
|
timeout: Optional[Union[int, float, str]] = None,
|
|
9955
9750
|
namespace: Optional[str] = None,
|
|
@@ -9964,13 +9759,13 @@ class HfApi:
|
|
|
9964
9759
|
Examples: `"ubuntu"`, `"python:3.12"`, `"pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel"`.
|
|
9965
9760
|
Example with an image from a Space: `"hf.co/spaces/lhoestq/duckdb"`.
|
|
9966
9761
|
|
|
9967
|
-
command (`
|
|
9762
|
+
command (`list[str]`):
|
|
9968
9763
|
The command to run. Example: `["echo", "hello"]`.
|
|
9969
9764
|
|
|
9970
|
-
env (`
|
|
9765
|
+
env (`dict[str, Any]`, *optional*):
|
|
9971
9766
|
Defines the environment variables for the Job.
|
|
9972
9767
|
|
|
9973
|
-
secrets (`
|
|
9768
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
9974
9769
|
Defines the secret environment variables for the Job.
|
|
9975
9770
|
|
|
9976
9771
|
flavor (`str`, *optional*):
|
|
@@ -9994,7 +9789,7 @@ class HfApi:
|
|
|
9994
9789
|
|
|
9995
9790
|
```python
|
|
9996
9791
|
>>> from huggingface_hub import run_job
|
|
9997
|
-
>>> run_job("python:3.12", ["python", "-c" ,"print('Hello from HF compute!')"])
|
|
9792
|
+
>>> run_job(image="python:3.12", command=["python", "-c" ,"print('Hello from HF compute!')"])
|
|
9998
9793
|
```
|
|
9999
9794
|
|
|
10000
9795
|
Run a GPU Job:
|
|
@@ -10003,47 +9798,23 @@ class HfApi:
|
|
|
10003
9798
|
>>> from huggingface_hub import run_job
|
|
10004
9799
|
>>> image = "pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel"
|
|
10005
9800
|
>>> command = ["python", "-c", "import torch; print(f"This code ran with the following GPU: {torch.cuda.get_device_name()}")"]
|
|
10006
|
-
>>> run_job(image, command, flavor="a10g-small")
|
|
9801
|
+
>>> run_job(image=image, command=command, flavor="a10g-small")
|
|
10007
9802
|
```
|
|
10008
9803
|
|
|
10009
9804
|
"""
|
|
10010
|
-
if flavor is None:
|
|
10011
|
-
flavor = SpaceHardware.CPU_BASIC
|
|
10012
|
-
|
|
10013
|
-
# prepare payload to send to HF Jobs API
|
|
10014
|
-
input_json: Dict[str, Any] = {
|
|
10015
|
-
"command": command,
|
|
10016
|
-
"arguments": [],
|
|
10017
|
-
"environment": env or {},
|
|
10018
|
-
"flavor": flavor,
|
|
10019
|
-
}
|
|
10020
|
-
# secrets are optional
|
|
10021
|
-
if secrets:
|
|
10022
|
-
input_json["secrets"] = secrets
|
|
10023
|
-
# timeout is optional
|
|
10024
|
-
if timeout:
|
|
10025
|
-
time_units_factors = {"s": 1, "m": 60, "h": 3600, "d": 3600 * 24}
|
|
10026
|
-
if isinstance(timeout, str) and timeout[-1] in time_units_factors:
|
|
10027
|
-
input_json["timeoutSeconds"] = int(float(timeout[:-1]) * time_units_factors[timeout[-1]])
|
|
10028
|
-
else:
|
|
10029
|
-
input_json["timeoutSeconds"] = int(timeout)
|
|
10030
|
-
# input is either from docker hub or from HF spaces
|
|
10031
|
-
for prefix in (
|
|
10032
|
-
"https://huggingface.co/spaces/",
|
|
10033
|
-
"https://hf.co/spaces/",
|
|
10034
|
-
"huggingface.co/spaces/",
|
|
10035
|
-
"hf.co/spaces/",
|
|
10036
|
-
):
|
|
10037
|
-
if image.startswith(prefix):
|
|
10038
|
-
input_json["spaceId"] = image[len(prefix) :]
|
|
10039
|
-
break
|
|
10040
|
-
else:
|
|
10041
|
-
input_json["dockerImage"] = image
|
|
10042
9805
|
if namespace is None:
|
|
10043
9806
|
namespace = self.whoami(token=token)["name"]
|
|
9807
|
+
job_spec = _create_job_spec(
|
|
9808
|
+
image=image,
|
|
9809
|
+
command=command,
|
|
9810
|
+
env=env,
|
|
9811
|
+
secrets=secrets,
|
|
9812
|
+
flavor=flavor,
|
|
9813
|
+
timeout=timeout,
|
|
9814
|
+
)
|
|
10044
9815
|
response = get_session().post(
|
|
10045
9816
|
f"https://huggingface.co/api/jobs/{namespace}",
|
|
10046
|
-
json=
|
|
9817
|
+
json=job_spec,
|
|
10047
9818
|
headers=self._build_hf_headers(token=token),
|
|
10048
9819
|
)
|
|
10049
9820
|
hf_raise_for_status(response)
|
|
@@ -10076,8 +9847,8 @@ class HfApi:
|
|
|
10076
9847
|
|
|
10077
9848
|
```python
|
|
10078
9849
|
>>> from huggingface_hub import fetch_job_logs, run_job
|
|
10079
|
-
>>> job = run_job("python:3.12", ["python", "-c" ,"print('Hello from HF compute!')"])
|
|
10080
|
-
>>> for log in fetch_job_logs(job.
|
|
9850
|
+
>>> job = run_job(image="python:3.12", command=["python", "-c" ,"print('Hello from HF compute!')"])
|
|
9851
|
+
>>> for log in fetch_job_logs(job.id):
|
|
10081
9852
|
... print(log)
|
|
10082
9853
|
Hello from HF compute!
|
|
10083
9854
|
```
|
|
@@ -10103,29 +9874,28 @@ class HfApi:
|
|
|
10103
9874
|
time.sleep(sleep_time)
|
|
10104
9875
|
sleep_time = min(max_wait_time, max(min_wait_time, sleep_time * 2))
|
|
10105
9876
|
try:
|
|
10106
|
-
|
|
9877
|
+
with get_session().stream(
|
|
9878
|
+
"GET",
|
|
10107
9879
|
f"https://huggingface.co/api/jobs/{namespace}/{job_id}/logs",
|
|
10108
9880
|
headers=self._build_hf_headers(token=token),
|
|
10109
|
-
stream=True,
|
|
10110
9881
|
timeout=120,
|
|
10111
|
-
)
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
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:
|
|
10124
9894
|
# Response ended prematurely
|
|
10125
9895
|
break
|
|
10126
9896
|
except KeyboardInterrupt:
|
|
10127
9897
|
break
|
|
10128
|
-
except
|
|
9898
|
+
except httpx.NetworkError as err:
|
|
10129
9899
|
is_timeout = err.__context__ and isinstance(getattr(err.__context__, "__cause__", None), TimeoutError)
|
|
10130
9900
|
if logging_started or not is_timeout:
|
|
10131
9901
|
raise
|
|
@@ -10148,7 +9918,7 @@ class HfApi:
|
|
|
10148
9918
|
timeout: Optional[int] = None,
|
|
10149
9919
|
namespace: Optional[str] = None,
|
|
10150
9920
|
token: Union[bool, str, None] = None,
|
|
10151
|
-
) ->
|
|
9921
|
+
) -> list[JobInfo]:
|
|
10152
9922
|
"""
|
|
10153
9923
|
List compute Jobs on Hugging Face infrastructure.
|
|
10154
9924
|
|
|
@@ -10200,8 +9970,8 @@ class HfApi:
|
|
|
10200
9970
|
|
|
10201
9971
|
```python
|
|
10202
9972
|
>>> from huggingface_hub import inspect_job, run_job
|
|
10203
|
-
>>> job = run_job("python:3.12", ["python", "-c" ,"print('Hello from HF compute!')"])
|
|
10204
|
-
>>> inspect_job(job.
|
|
9973
|
+
>>> job = run_job(image="python:3.12", command=["python", "-c" ,"print('Hello from HF compute!')"])
|
|
9974
|
+
>>> inspect_job(job.id)
|
|
10205
9975
|
JobInfo(
|
|
10206
9976
|
id='68780d00bbe36d38803f645f',
|
|
10207
9977
|
created_at=datetime.datetime(2025, 7, 16, 20, 35, 12, 808000, tzinfo=datetime.timezone.utc),
|
|
@@ -10259,12 +10029,12 @@ class HfApi:
|
|
|
10259
10029
|
self,
|
|
10260
10030
|
script: str,
|
|
10261
10031
|
*,
|
|
10262
|
-
script_args: Optional[
|
|
10263
|
-
dependencies: Optional[
|
|
10032
|
+
script_args: Optional[list[str]] = None,
|
|
10033
|
+
dependencies: Optional[list[str]] = None,
|
|
10264
10034
|
python: Optional[str] = None,
|
|
10265
10035
|
image: Optional[str] = None,
|
|
10266
|
-
env: Optional[
|
|
10267
|
-
secrets: Optional[
|
|
10036
|
+
env: Optional[dict[str, Any]] = None,
|
|
10037
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
10268
10038
|
flavor: Optional[SpaceHardware] = None,
|
|
10269
10039
|
timeout: Optional[Union[int, float, str]] = None,
|
|
10270
10040
|
namespace: Optional[str] = None,
|
|
@@ -10276,24 +10046,24 @@ class HfApi:
|
|
|
10276
10046
|
|
|
10277
10047
|
Args:
|
|
10278
10048
|
script (`str`):
|
|
10279
|
-
Path or URL of the UV script.
|
|
10049
|
+
Path or URL of the UV script, or a command.
|
|
10280
10050
|
|
|
10281
|
-
script_args (`
|
|
10282
|
-
Arguments to pass to the script.
|
|
10051
|
+
script_args (`list[str]`, *optional*)
|
|
10052
|
+
Arguments to pass to the script or command.
|
|
10283
10053
|
|
|
10284
|
-
dependencies (`
|
|
10054
|
+
dependencies (`list[str]`, *optional*)
|
|
10285
10055
|
Dependencies to use to run the UV script.
|
|
10286
10056
|
|
|
10287
10057
|
python (`str`, *optional*)
|
|
10288
10058
|
Use a specific Python version. Default is 3.12.
|
|
10289
10059
|
|
|
10290
|
-
image (`str`, *optional*, defaults to "ghcr.io/astral-sh/uv:python3.12-bookworm
|
|
10060
|
+
image (`str`, *optional*, defaults to "ghcr.io/astral-sh/uv:python3.12-bookworm"):
|
|
10291
10061
|
Use a custom Docker image with `uv` installed.
|
|
10292
10062
|
|
|
10293
|
-
env (`
|
|
10063
|
+
env (`dict[str, Any]`, *optional*):
|
|
10294
10064
|
Defines the environment variables for the Job.
|
|
10295
10065
|
|
|
10296
|
-
secrets (`
|
|
10066
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
10297
10067
|
Defines the secret environment variables for the Job.
|
|
10298
10068
|
|
|
10299
10069
|
flavor (`str`, *optional*):
|
|
@@ -10314,13 +10084,474 @@ class HfApi:
|
|
|
10314
10084
|
|
|
10315
10085
|
Example:
|
|
10316
10086
|
|
|
10087
|
+
Run a script from a URL:
|
|
10088
|
+
|
|
10317
10089
|
```python
|
|
10318
10090
|
>>> from huggingface_hub import run_uv_job
|
|
10319
10091
|
>>> script = "https://raw.githubusercontent.com/huggingface/trl/refs/heads/main/trl/scripts/sft.py"
|
|
10320
|
-
>>>
|
|
10092
|
+
>>> script_args = ["--model_name_or_path", "Qwen/Qwen2-0.5B", "--dataset_name", "trl-lib/Capybara", "--push_to_hub"]
|
|
10093
|
+
>>> run_uv_job(script, script_args=script_args, dependencies=["trl"], flavor="a10g-small")
|
|
10094
|
+
```
|
|
10095
|
+
|
|
10096
|
+
Run a local script:
|
|
10097
|
+
|
|
10098
|
+
```python
|
|
10099
|
+
>>> from huggingface_hub import run_uv_job
|
|
10100
|
+
>>> script = "my_sft.py"
|
|
10101
|
+
>>> script_args = ["--model_name_or_path", "Qwen/Qwen2-0.5B", "--dataset_name", "trl-lib/Capybara", "--push_to_hub"]
|
|
10102
|
+
>>> run_uv_job(script, script_args=script_args, dependencies=["trl"], flavor="a10g-small")
|
|
10103
|
+
```
|
|
10104
|
+
|
|
10105
|
+
Run a command:
|
|
10106
|
+
|
|
10107
|
+
```python
|
|
10108
|
+
>>> from huggingface_hub import run_uv_job
|
|
10109
|
+
>>> script = "lighteval"
|
|
10110
|
+
>>> script_args= ["endpoint", "inference-providers", "model_name=openai/gpt-oss-20b,provider=auto", "lighteval|gsm8k|0|0"]
|
|
10111
|
+
>>> run_uv_job(script, script_args=script_args, dependencies=["lighteval"], flavor="a10g-small")
|
|
10321
10112
|
```
|
|
10322
10113
|
"""
|
|
10323
|
-
image = image or "ghcr.io/astral-sh/uv:python3.12-bookworm
|
|
10114
|
+
image = image or "ghcr.io/astral-sh/uv:python3.12-bookworm"
|
|
10115
|
+
env = env or {}
|
|
10116
|
+
secrets = secrets or {}
|
|
10117
|
+
|
|
10118
|
+
# Build command
|
|
10119
|
+
command, env, secrets = self._create_uv_command_env_and_secrets(
|
|
10120
|
+
script=script,
|
|
10121
|
+
script_args=script_args,
|
|
10122
|
+
dependencies=dependencies,
|
|
10123
|
+
python=python,
|
|
10124
|
+
env=env,
|
|
10125
|
+
secrets=secrets,
|
|
10126
|
+
namespace=namespace,
|
|
10127
|
+
token=token,
|
|
10128
|
+
_repo=_repo,
|
|
10129
|
+
)
|
|
10130
|
+
# Create RunCommand args
|
|
10131
|
+
return self.run_job(
|
|
10132
|
+
image=image,
|
|
10133
|
+
command=command,
|
|
10134
|
+
env=env,
|
|
10135
|
+
secrets=secrets,
|
|
10136
|
+
flavor=flavor,
|
|
10137
|
+
timeout=timeout,
|
|
10138
|
+
namespace=namespace,
|
|
10139
|
+
token=token,
|
|
10140
|
+
)
|
|
10141
|
+
|
|
10142
|
+
def create_scheduled_job(
|
|
10143
|
+
self,
|
|
10144
|
+
*,
|
|
10145
|
+
image: str,
|
|
10146
|
+
command: list[str],
|
|
10147
|
+
schedule: str,
|
|
10148
|
+
suspend: Optional[bool] = None,
|
|
10149
|
+
concurrency: Optional[bool] = None,
|
|
10150
|
+
env: Optional[dict[str, Any]] = None,
|
|
10151
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
10152
|
+
flavor: Optional[SpaceHardware] = None,
|
|
10153
|
+
timeout: Optional[Union[int, float, str]] = None,
|
|
10154
|
+
namespace: Optional[str] = None,
|
|
10155
|
+
token: Union[bool, str, None] = None,
|
|
10156
|
+
) -> ScheduledJobInfo:
|
|
10157
|
+
"""
|
|
10158
|
+
Create scheduled compute Jobs on Hugging Face infrastructure.
|
|
10159
|
+
|
|
10160
|
+
Args:
|
|
10161
|
+
image (`str`):
|
|
10162
|
+
The Docker image to use.
|
|
10163
|
+
Examples: `"ubuntu"`, `"python:3.12"`, `"pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel"`.
|
|
10164
|
+
Example with an image from a Space: `"hf.co/spaces/lhoestq/duckdb"`.
|
|
10165
|
+
|
|
10166
|
+
command (`list[str]`):
|
|
10167
|
+
The command to run. Example: `["echo", "hello"]`.
|
|
10168
|
+
|
|
10169
|
+
schedule (`str`):
|
|
10170
|
+
One of "@annually", "@yearly", "@monthly", "@weekly", "@daily", "@hourly", or a
|
|
10171
|
+
CRON schedule expression (e.g., '0 9 * * 1' for 9 AM every Monday).
|
|
10172
|
+
|
|
10173
|
+
suspend (`bool`, *optional*):
|
|
10174
|
+
If True, the scheduled Job is suspended (paused). Defaults to False.
|
|
10175
|
+
|
|
10176
|
+
concurrency (`bool`, *optional*):
|
|
10177
|
+
If True, multiple instances of this Job can run concurrently. Defaults to False.
|
|
10178
|
+
|
|
10179
|
+
env (`dict[str, Any]`, *optional*):
|
|
10180
|
+
Defines the environment variables for the Job.
|
|
10181
|
+
|
|
10182
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
10183
|
+
Defines the secret environment variables for the Job.
|
|
10184
|
+
|
|
10185
|
+
flavor (`str`, *optional*):
|
|
10186
|
+
Flavor for the hardware, as in Hugging Face Spaces. See [`SpaceHardware`] for possible values.
|
|
10187
|
+
Defaults to `"cpu-basic"`.
|
|
10188
|
+
|
|
10189
|
+
timeout (`Union[int, float, str]`, *optional*):
|
|
10190
|
+
Max duration for the Job: int/float with s (seconds, default), m (minutes), h (hours) or d (days).
|
|
10191
|
+
Example: `300` or `"5m"` for 5 minutes.
|
|
10192
|
+
|
|
10193
|
+
namespace (`str`, *optional*):
|
|
10194
|
+
The namespace where the Job will be created. Defaults to the current user's namespace.
|
|
10195
|
+
|
|
10196
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10197
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10198
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10199
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10200
|
+
|
|
10201
|
+
Example:
|
|
10202
|
+
Create your first scheduled Job:
|
|
10203
|
+
|
|
10204
|
+
```python
|
|
10205
|
+
>>> from huggingface_hub import create_scheduled_job
|
|
10206
|
+
>>> create_scheduled_job(image="python:3.12", command=["python", "-c" ,"print('Hello from HF compute!')"], schedule="@hourly")
|
|
10207
|
+
```
|
|
10208
|
+
|
|
10209
|
+
Use a CRON schedule expression:
|
|
10210
|
+
|
|
10211
|
+
```python
|
|
10212
|
+
>>> from huggingface_hub import create_scheduled_job
|
|
10213
|
+
>>> create_scheduled_job(image="python:3.12", command=["python", "-c" ,"print('this runs every 5min')"], schedule="*/5 * * * *")
|
|
10214
|
+
```
|
|
10215
|
+
|
|
10216
|
+
Create a scheduled GPU Job:
|
|
10217
|
+
|
|
10218
|
+
```python
|
|
10219
|
+
>>> from huggingface_hub import create_scheduled_job
|
|
10220
|
+
>>> image = "pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel"
|
|
10221
|
+
>>> command = ["python", "-c", "import torch; print(f"This code ran with the following GPU: {torch.cuda.get_device_name()}")"]
|
|
10222
|
+
>>> create_scheduled_job(image, command, flavor="a10g-small", schedule="@hourly")
|
|
10223
|
+
```
|
|
10224
|
+
|
|
10225
|
+
"""
|
|
10226
|
+
if namespace is None:
|
|
10227
|
+
namespace = self.whoami(token=token)["name"]
|
|
10228
|
+
|
|
10229
|
+
# prepare payload to send to HF Jobs API
|
|
10230
|
+
job_spec = _create_job_spec(
|
|
10231
|
+
image=image,
|
|
10232
|
+
command=command,
|
|
10233
|
+
env=env,
|
|
10234
|
+
secrets=secrets,
|
|
10235
|
+
flavor=flavor,
|
|
10236
|
+
timeout=timeout,
|
|
10237
|
+
)
|
|
10238
|
+
input_json: dict[str, Any] = {
|
|
10239
|
+
"jobSpec": job_spec,
|
|
10240
|
+
"schedule": schedule,
|
|
10241
|
+
}
|
|
10242
|
+
if concurrency is not None:
|
|
10243
|
+
input_json["concurrency"] = concurrency
|
|
10244
|
+
if suspend is not None:
|
|
10245
|
+
input_json["suspend"] = suspend
|
|
10246
|
+
response = get_session().post(
|
|
10247
|
+
f"https://huggingface.co/api/scheduled-jobs/{namespace}",
|
|
10248
|
+
json=input_json,
|
|
10249
|
+
headers=self._build_hf_headers(token=token),
|
|
10250
|
+
)
|
|
10251
|
+
hf_raise_for_status(response)
|
|
10252
|
+
scheduled_job_info = response.json()
|
|
10253
|
+
return ScheduledJobInfo(**scheduled_job_info)
|
|
10254
|
+
|
|
10255
|
+
def list_scheduled_jobs(
|
|
10256
|
+
self,
|
|
10257
|
+
*,
|
|
10258
|
+
timeout: Optional[int] = None,
|
|
10259
|
+
namespace: Optional[str] = None,
|
|
10260
|
+
token: Union[bool, str, None] = None,
|
|
10261
|
+
) -> list[ScheduledJobInfo]:
|
|
10262
|
+
"""
|
|
10263
|
+
List scheduled compute Jobs on Hugging Face infrastructure.
|
|
10264
|
+
|
|
10265
|
+
Args:
|
|
10266
|
+
timeout (`float`, *optional*):
|
|
10267
|
+
Whether to set a timeout for the request to the Hub.
|
|
10268
|
+
|
|
10269
|
+
namespace (`str`, *optional*):
|
|
10270
|
+
The namespace from where it lists the jobs. Defaults to the current user's namespace.
|
|
10271
|
+
|
|
10272
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10273
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10274
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10275
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10276
|
+
"""
|
|
10277
|
+
if namespace is None:
|
|
10278
|
+
namespace = self.whoami(token=token)["name"]
|
|
10279
|
+
response = get_session().get(
|
|
10280
|
+
f"{self.endpoint}/api/scheduled-jobs/{namespace}",
|
|
10281
|
+
headers=self._build_hf_headers(token=token),
|
|
10282
|
+
timeout=timeout,
|
|
10283
|
+
)
|
|
10284
|
+
hf_raise_for_status(response)
|
|
10285
|
+
return [ScheduledJobInfo(**scheduled_job_info) for scheduled_job_info in response.json()]
|
|
10286
|
+
|
|
10287
|
+
def inspect_scheduled_job(
|
|
10288
|
+
self,
|
|
10289
|
+
*,
|
|
10290
|
+
scheduled_job_id: str,
|
|
10291
|
+
namespace: Optional[str] = None,
|
|
10292
|
+
token: Union[bool, str, None] = None,
|
|
10293
|
+
) -> ScheduledJobInfo:
|
|
10294
|
+
"""
|
|
10295
|
+
Inspect a scheduled compute Job on Hugging Face infrastructure.
|
|
10296
|
+
|
|
10297
|
+
Args:
|
|
10298
|
+
scheduled_job_id (`str`):
|
|
10299
|
+
ID of the scheduled Job.
|
|
10300
|
+
|
|
10301
|
+
namespace (`str`, *optional*):
|
|
10302
|
+
The namespace where the scheduled Job is. Defaults to the current user's namespace.
|
|
10303
|
+
|
|
10304
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10305
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10306
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10307
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10308
|
+
|
|
10309
|
+
Example:
|
|
10310
|
+
|
|
10311
|
+
```python
|
|
10312
|
+
>>> from huggingface_hub import inspect_job, create_scheduled_job
|
|
10313
|
+
>>> scheduled_job = create_scheduled_job(image="python:3.12", command=["python", "-c" ,"print('Hello from HF compute!')"], schedule="@hourly")
|
|
10314
|
+
>>> inspect_scheduled_job(scheduled_job.id)
|
|
10315
|
+
```
|
|
10316
|
+
"""
|
|
10317
|
+
if namespace is None:
|
|
10318
|
+
namespace = self.whoami(token=token)["name"]
|
|
10319
|
+
response = get_session().get(
|
|
10320
|
+
f"{self.endpoint}/api/scheduled-jobs/{namespace}/{scheduled_job_id}",
|
|
10321
|
+
headers=self._build_hf_headers(token=token),
|
|
10322
|
+
)
|
|
10323
|
+
hf_raise_for_status(response)
|
|
10324
|
+
return ScheduledJobInfo(**response.json())
|
|
10325
|
+
|
|
10326
|
+
def delete_scheduled_job(
|
|
10327
|
+
self,
|
|
10328
|
+
*,
|
|
10329
|
+
scheduled_job_id: str,
|
|
10330
|
+
namespace: Optional[str] = None,
|
|
10331
|
+
token: Union[bool, str, None] = None,
|
|
10332
|
+
) -> None:
|
|
10333
|
+
"""
|
|
10334
|
+
Delete a scheduled compute Job on Hugging Face infrastructure.
|
|
10335
|
+
|
|
10336
|
+
Args:
|
|
10337
|
+
scheduled_job_id (`str`):
|
|
10338
|
+
ID of the scheduled Job.
|
|
10339
|
+
|
|
10340
|
+
namespace (`str`, *optional*):
|
|
10341
|
+
The namespace where the scheduled Job is. Defaults to the current user's namespace.
|
|
10342
|
+
|
|
10343
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10344
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10345
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10346
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10347
|
+
"""
|
|
10348
|
+
if namespace is None:
|
|
10349
|
+
namespace = self.whoami(token=token)["name"]
|
|
10350
|
+
response = get_session().delete(
|
|
10351
|
+
f"{self.endpoint}/api/scheduled-jobs/{namespace}/{scheduled_job_id}",
|
|
10352
|
+
headers=self._build_hf_headers(token=token),
|
|
10353
|
+
)
|
|
10354
|
+
hf_raise_for_status(response)
|
|
10355
|
+
|
|
10356
|
+
def suspend_scheduled_job(
|
|
10357
|
+
self,
|
|
10358
|
+
*,
|
|
10359
|
+
scheduled_job_id: str,
|
|
10360
|
+
namespace: Optional[str] = None,
|
|
10361
|
+
token: Union[bool, str, None] = None,
|
|
10362
|
+
) -> None:
|
|
10363
|
+
"""
|
|
10364
|
+
Suspend (pause) a scheduled compute Job on Hugging Face infrastructure.
|
|
10365
|
+
|
|
10366
|
+
Args:
|
|
10367
|
+
scheduled_job_id (`str`):
|
|
10368
|
+
ID of the scheduled Job.
|
|
10369
|
+
|
|
10370
|
+
namespace (`str`, *optional*):
|
|
10371
|
+
The namespace where the scheduled Job is. Defaults to the current user's namespace.
|
|
10372
|
+
|
|
10373
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10374
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10375
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10376
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10377
|
+
"""
|
|
10378
|
+
if namespace is None:
|
|
10379
|
+
namespace = self.whoami(token=token)["name"]
|
|
10380
|
+
get_session().post(
|
|
10381
|
+
f"{self.endpoint}/api/scheduled-jobs/{namespace}/{scheduled_job_id}/suspend",
|
|
10382
|
+
headers=self._build_hf_headers(token=token),
|
|
10383
|
+
).raise_for_status()
|
|
10384
|
+
|
|
10385
|
+
def resume_scheduled_job(
|
|
10386
|
+
self,
|
|
10387
|
+
*,
|
|
10388
|
+
scheduled_job_id: str,
|
|
10389
|
+
namespace: Optional[str] = None,
|
|
10390
|
+
token: Union[bool, str, None] = None,
|
|
10391
|
+
) -> None:
|
|
10392
|
+
"""
|
|
10393
|
+
Resume (unpause) a scheduled compute Job on Hugging Face infrastructure.
|
|
10394
|
+
|
|
10395
|
+
Args:
|
|
10396
|
+
scheduled_job_id (`str`):
|
|
10397
|
+
ID of the scheduled Job.
|
|
10398
|
+
|
|
10399
|
+
namespace (`str`, *optional*):
|
|
10400
|
+
The namespace where the scheduled Job is. Defaults to the current user's namespace.
|
|
10401
|
+
|
|
10402
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10403
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10404
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10405
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10406
|
+
"""
|
|
10407
|
+
if namespace is None:
|
|
10408
|
+
namespace = self.whoami(token=token)["name"]
|
|
10409
|
+
get_session().post(
|
|
10410
|
+
f"{self.endpoint}/api/scheduled-jobs/{namespace}/{scheduled_job_id}/resume",
|
|
10411
|
+
headers=self._build_hf_headers(token=token),
|
|
10412
|
+
).raise_for_status()
|
|
10413
|
+
|
|
10414
|
+
@experimental
|
|
10415
|
+
def create_scheduled_uv_job(
|
|
10416
|
+
self,
|
|
10417
|
+
script: str,
|
|
10418
|
+
*,
|
|
10419
|
+
script_args: Optional[list[str]] = None,
|
|
10420
|
+
schedule: str,
|
|
10421
|
+
suspend: Optional[bool] = None,
|
|
10422
|
+
concurrency: Optional[bool] = None,
|
|
10423
|
+
dependencies: Optional[list[str]] = None,
|
|
10424
|
+
python: Optional[str] = None,
|
|
10425
|
+
image: Optional[str] = None,
|
|
10426
|
+
env: Optional[dict[str, Any]] = None,
|
|
10427
|
+
secrets: Optional[dict[str, Any]] = None,
|
|
10428
|
+
flavor: Optional[SpaceHardware] = None,
|
|
10429
|
+
timeout: Optional[Union[int, float, str]] = None,
|
|
10430
|
+
namespace: Optional[str] = None,
|
|
10431
|
+
token: Union[bool, str, None] = None,
|
|
10432
|
+
_repo: Optional[str] = None,
|
|
10433
|
+
) -> ScheduledJobInfo:
|
|
10434
|
+
"""
|
|
10435
|
+
Run a UV script Job on Hugging Face infrastructure.
|
|
10436
|
+
|
|
10437
|
+
Args:
|
|
10438
|
+
script (`str`):
|
|
10439
|
+
Path or URL of the UV script, or a command.
|
|
10440
|
+
|
|
10441
|
+
script_args (`list[str]`, *optional*)
|
|
10442
|
+
Arguments to pass to the script, or a command.
|
|
10443
|
+
|
|
10444
|
+
schedule (`str`):
|
|
10445
|
+
One of "@annually", "@yearly", "@monthly", "@weekly", "@daily", "@hourly", or a
|
|
10446
|
+
CRON schedule expression (e.g., '0 9 * * 1' for 9 AM every Monday).
|
|
10447
|
+
|
|
10448
|
+
suspend (`bool`, *optional*):
|
|
10449
|
+
If True, the scheduled Job is suspended (paused). Defaults to False.
|
|
10450
|
+
|
|
10451
|
+
concurrency (`bool`, *optional*):
|
|
10452
|
+
If True, multiple instances of this Job can run concurrently. Defaults to False.
|
|
10453
|
+
|
|
10454
|
+
dependencies (`list[str]`, *optional*)
|
|
10455
|
+
Dependencies to use to run the UV script.
|
|
10456
|
+
|
|
10457
|
+
python (`str`, *optional*)
|
|
10458
|
+
Use a specific Python version. Default is 3.12.
|
|
10459
|
+
|
|
10460
|
+
image (`str`, *optional*, defaults to "ghcr.io/astral-sh/uv:python3.12-bookworm"):
|
|
10461
|
+
Use a custom Docker image with `uv` installed.
|
|
10462
|
+
|
|
10463
|
+
env (`dict[str, Any]`, *optional*):
|
|
10464
|
+
Defines the environment variables for the Job.
|
|
10465
|
+
|
|
10466
|
+
secrets (`dict[str, Any]`, *optional*):
|
|
10467
|
+
Defines the secret environment variables for the Job.
|
|
10468
|
+
|
|
10469
|
+
flavor (`str`, *optional*):
|
|
10470
|
+
Flavor for the hardware, as in Hugging Face Spaces. See [`SpaceHardware`] for possible values.
|
|
10471
|
+
Defaults to `"cpu-basic"`.
|
|
10472
|
+
|
|
10473
|
+
timeout (`Union[int, float, str]`, *optional*):
|
|
10474
|
+
Max duration for the Job: int/float with s (seconds, default), m (minutes), h (hours) or d (days).
|
|
10475
|
+
Example: `300` or `"5m"` for 5 minutes.
|
|
10476
|
+
|
|
10477
|
+
namespace (`str`, *optional*):
|
|
10478
|
+
The namespace where the Job will be created. Defaults to the current user's namespace.
|
|
10479
|
+
|
|
10480
|
+
token `(Union[bool, str, None]`, *optional*):
|
|
10481
|
+
A valid user access token. If not provided, the locally saved token will be used, which is the
|
|
10482
|
+
recommended authentication method. Set to `False` to disable authentication.
|
|
10483
|
+
Refer to: https://huggingface.co/docs/huggingface_hub/quick-start#authentication.
|
|
10484
|
+
|
|
10485
|
+
Example:
|
|
10486
|
+
|
|
10487
|
+
Schedule a script from a URL:
|
|
10488
|
+
|
|
10489
|
+
```python
|
|
10490
|
+
>>> from huggingface_hub import create_scheduled_uv_job
|
|
10491
|
+
>>> script = "https://raw.githubusercontent.com/huggingface/trl/refs/heads/main/trl/scripts/sft.py"
|
|
10492
|
+
>>> script_args = ["--model_name_or_path", "Qwen/Qwen2-0.5B", "--dataset_name", "trl-lib/Capybara", "--push_to_hub"]
|
|
10493
|
+
>>> create_scheduled_uv_job(script, script_args=script_args, dependencies=["trl"], flavor="a10g-small", schedule="@weekly")
|
|
10494
|
+
```
|
|
10495
|
+
|
|
10496
|
+
Schedule a local script:
|
|
10497
|
+
|
|
10498
|
+
```python
|
|
10499
|
+
>>> from huggingface_hub import create_scheduled_uv_job
|
|
10500
|
+
>>> script = "my_sft.py"
|
|
10501
|
+
>>> script_args = ["--model_name_or_path", "Qwen/Qwen2-0.5B", "--dataset_name", "trl-lib/Capybara", "--push_to_hub"]
|
|
10502
|
+
>>> create_scheduled_uv_job(script, script_args=script_args, dependencies=["trl"], flavor="a10g-small", schedule="@weekly")
|
|
10503
|
+
```
|
|
10504
|
+
|
|
10505
|
+
Schedule a command:
|
|
10506
|
+
|
|
10507
|
+
```python
|
|
10508
|
+
>>> from huggingface_hub import create_scheduled_uv_job
|
|
10509
|
+
>>> script = "lighteval"
|
|
10510
|
+
>>> script_args= ["endpoint", "inference-providers", "model_name=openai/gpt-oss-20b,provider=auto", "lighteval|gsm8k|0|0"]
|
|
10511
|
+
>>> create_scheduled_uv_job(script, script_args=script_args, dependencies=["lighteval"], flavor="a10g-small", schedule="@weekly")
|
|
10512
|
+
```
|
|
10513
|
+
"""
|
|
10514
|
+
image = image or "ghcr.io/astral-sh/uv:python3.12-bookworm"
|
|
10515
|
+
# Build command
|
|
10516
|
+
command, env, secrets = self._create_uv_command_env_and_secrets(
|
|
10517
|
+
script=script,
|
|
10518
|
+
script_args=script_args,
|
|
10519
|
+
dependencies=dependencies,
|
|
10520
|
+
python=python,
|
|
10521
|
+
env=env,
|
|
10522
|
+
secrets=secrets,
|
|
10523
|
+
namespace=namespace,
|
|
10524
|
+
token=token,
|
|
10525
|
+
_repo=_repo,
|
|
10526
|
+
)
|
|
10527
|
+
# Create RunCommand args
|
|
10528
|
+
return self.create_scheduled_job(
|
|
10529
|
+
image=image,
|
|
10530
|
+
command=command,
|
|
10531
|
+
schedule=schedule,
|
|
10532
|
+
suspend=suspend,
|
|
10533
|
+
concurrency=concurrency,
|
|
10534
|
+
env=env,
|
|
10535
|
+
secrets=secrets,
|
|
10536
|
+
flavor=flavor,
|
|
10537
|
+
timeout=timeout,
|
|
10538
|
+
namespace=namespace,
|
|
10539
|
+
token=token,
|
|
10540
|
+
)
|
|
10541
|
+
|
|
10542
|
+
def _create_uv_command_env_and_secrets(
|
|
10543
|
+
self,
|
|
10544
|
+
*,
|
|
10545
|
+
script: str,
|
|
10546
|
+
script_args: Optional[list[str]],
|
|
10547
|
+
dependencies: Optional[list[str]],
|
|
10548
|
+
python: Optional[str],
|
|
10549
|
+
env: Optional[dict[str, Any]],
|
|
10550
|
+
secrets: Optional[dict[str, Any]],
|
|
10551
|
+
namespace: Optional[str],
|
|
10552
|
+
token: Union[bool, str, None],
|
|
10553
|
+
_repo: Optional[str],
|
|
10554
|
+
) -> tuple[list[str], dict[str, Any], dict[str, Any]]:
|
|
10324
10555
|
env = env or {}
|
|
10325
10556
|
secrets = secrets or {}
|
|
10326
10557
|
|
|
@@ -10336,8 +10567,9 @@ class HfApi:
|
|
|
10336
10567
|
if namespace is None:
|
|
10337
10568
|
namespace = self.whoami(token=token)["name"]
|
|
10338
10569
|
|
|
10339
|
-
|
|
10340
|
-
|
|
10570
|
+
is_url = script.startswith("http://") or script.startswith("https://")
|
|
10571
|
+
if is_url or not Path(script).is_file():
|
|
10572
|
+
# Direct URL execution or command - no upload needed
|
|
10341
10573
|
command = ["uv", "run"] + uv_args + [script] + script_args
|
|
10342
10574
|
else:
|
|
10343
10575
|
# Local file - upload to HF
|
|
@@ -10348,7 +10580,6 @@ class HfApi:
|
|
|
10348
10580
|
repo_id = _repo
|
|
10349
10581
|
if "/" not in repo_id:
|
|
10350
10582
|
repo_id = f"{namespace}/{repo_id}"
|
|
10351
|
-
repo_id = _repo
|
|
10352
10583
|
else:
|
|
10353
10584
|
repo_id = f"{namespace}/hf-cli-jobs-uv-run-scripts"
|
|
10354
10585
|
|
|
@@ -10365,15 +10596,15 @@ class HfApi:
|
|
|
10365
10596
|
with open(script_path, "r") as f:
|
|
10366
10597
|
script_content = f.read()
|
|
10367
10598
|
|
|
10368
|
-
self.upload_file(
|
|
10599
|
+
commit_hash = self.upload_file(
|
|
10369
10600
|
path_or_fileobj=script_content.encode(),
|
|
10370
10601
|
path_in_repo=filename,
|
|
10371
10602
|
repo_id=repo_id,
|
|
10372
10603
|
repo_type="dataset",
|
|
10373
|
-
)
|
|
10604
|
+
).oid
|
|
10374
10605
|
|
|
10375
|
-
script_url = f"
|
|
10376
|
-
repo_url = f"
|
|
10606
|
+
script_url = f"{self.endpoint}/datasets/{repo_id}/resolve/{commit_hash}/{filename}"
|
|
10607
|
+
repo_url = f"{self.endpoint}/datasets/{repo_id}"
|
|
10377
10608
|
|
|
10378
10609
|
logger.debug(f"✓ Script uploaded to: {repo_url}/blob/main/{filename}")
|
|
10379
10610
|
|
|
@@ -10430,18 +10661,7 @@ class HfApi:
|
|
|
10430
10661
|
pre_command = ["python", "-c", '"' + "; ".join(pre_command) + '"']
|
|
10431
10662
|
command = ["uv", "run"] + uv_args + ["/tmp/script.py"] + script_args
|
|
10432
10663
|
command = ["bash", "-c", " ".join(pre_command) + " && " + " ".join(command)]
|
|
10433
|
-
|
|
10434
|
-
# Create RunCommand args
|
|
10435
|
-
return self.run_job(
|
|
10436
|
-
image=image,
|
|
10437
|
-
command=command,
|
|
10438
|
-
env=env,
|
|
10439
|
-
secrets=secrets,
|
|
10440
|
-
flavor=flavor,
|
|
10441
|
-
timeout=timeout,
|
|
10442
|
-
namespace=namespace,
|
|
10443
|
-
token=token,
|
|
10444
|
-
)
|
|
10664
|
+
return command, env, secrets
|
|
10445
10665
|
|
|
10446
10666
|
|
|
10447
10667
|
def _parse_revision_from_pr_url(pr_url: str) -> str:
|
|
@@ -10463,7 +10683,6 @@ api = HfApi()
|
|
|
10463
10683
|
|
|
10464
10684
|
whoami = api.whoami
|
|
10465
10685
|
auth_check = api.auth_check
|
|
10466
|
-
get_token_permission = api.get_token_permission
|
|
10467
10686
|
|
|
10468
10687
|
list_models = api.list_models
|
|
10469
10688
|
model_info = api.model_info
|
|
@@ -10493,7 +10712,6 @@ get_dataset_tags = api.get_dataset_tags
|
|
|
10493
10712
|
create_commit = api.create_commit
|
|
10494
10713
|
create_repo = api.create_repo
|
|
10495
10714
|
delete_repo = api.delete_repo
|
|
10496
|
-
update_repo_visibility = api.update_repo_visibility
|
|
10497
10715
|
update_repo_settings = api.update_repo_settings
|
|
10498
10716
|
move_repo = api.move_repo
|
|
10499
10717
|
upload_file = api.upload_file
|
|
@@ -10607,3 +10825,10 @@ list_jobs = api.list_jobs
|
|
|
10607
10825
|
inspect_job = api.inspect_job
|
|
10608
10826
|
cancel_job = api.cancel_job
|
|
10609
10827
|
run_uv_job = api.run_uv_job
|
|
10828
|
+
create_scheduled_job = api.create_scheduled_job
|
|
10829
|
+
list_scheduled_jobs = api.list_scheduled_jobs
|
|
10830
|
+
inspect_scheduled_job = api.inspect_scheduled_job
|
|
10831
|
+
delete_scheduled_job = api.delete_scheduled_job
|
|
10832
|
+
suspend_scheduled_job = api.suspend_scheduled_job
|
|
10833
|
+
resume_scheduled_job = api.resume_scheduled_job
|
|
10834
|
+
create_scheduled_uv_job = api.create_scheduled_uv_job
|