huggingface-hub 0.22.1__py3-none-any.whl → 0.23.0__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 +51 -19
- huggingface_hub/_commit_api.py +10 -9
- huggingface_hub/_commit_scheduler.py +2 -2
- huggingface_hub/_inference_endpoints.py +10 -17
- huggingface_hub/_local_folder.py +229 -0
- huggingface_hub/_login.py +4 -3
- huggingface_hub/_multi_commits.py +1 -1
- huggingface_hub/_snapshot_download.py +16 -38
- huggingface_hub/_tensorboard_logger.py +16 -6
- huggingface_hub/_webhooks_payload.py +22 -1
- huggingface_hub/_webhooks_server.py +24 -20
- huggingface_hub/commands/download.py +11 -34
- huggingface_hub/commands/huggingface_cli.py +2 -0
- huggingface_hub/commands/tag.py +159 -0
- huggingface_hub/constants.py +3 -5
- huggingface_hub/errors.py +58 -0
- huggingface_hub/file_download.py +545 -376
- huggingface_hub/hf_api.py +758 -629
- huggingface_hub/hf_file_system.py +14 -5
- huggingface_hub/hub_mixin.py +127 -43
- huggingface_hub/inference/_client.py +402 -183
- huggingface_hub/inference/_common.py +19 -29
- huggingface_hub/inference/_generated/_async_client.py +402 -184
- huggingface_hub/inference/_generated/types/__init__.py +23 -6
- huggingface_hub/inference/_generated/types/chat_completion.py +197 -43
- huggingface_hub/inference/_generated/types/text_generation.py +57 -79
- huggingface_hub/inference/_templating.py +2 -4
- huggingface_hub/keras_mixin.py +0 -3
- huggingface_hub/lfs.py +16 -4
- huggingface_hub/repository.py +1 -0
- huggingface_hub/utils/__init__.py +19 -6
- huggingface_hub/utils/_fixes.py +1 -0
- huggingface_hub/utils/_headers.py +2 -4
- huggingface_hub/utils/_http.py +16 -5
- huggingface_hub/utils/_paths.py +13 -1
- huggingface_hub/utils/_runtime.py +10 -0
- huggingface_hub/utils/_safetensors.py +0 -13
- huggingface_hub/utils/_validators.py +2 -7
- huggingface_hub/utils/tqdm.py +124 -46
- {huggingface_hub-0.22.1.dist-info → huggingface_hub-0.23.0.dist-info}/METADATA +5 -1
- {huggingface_hub-0.22.1.dist-info → huggingface_hub-0.23.0.dist-info}/RECORD +45 -43
- {huggingface_hub-0.22.1.dist-info → huggingface_hub-0.23.0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.22.1.dist-info → huggingface_hub-0.23.0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.22.1.dist-info → huggingface_hub-0.23.0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.22.1.dist-info → huggingface_hub-0.23.0.dist-info}/top_level.txt +0 -0
huggingface_hub/hf_api.py
CHANGED
|
@@ -82,8 +82,6 @@ from .community import (
|
|
|
82
82
|
deserialize_event,
|
|
83
83
|
)
|
|
84
84
|
from .constants import (
|
|
85
|
-
_HF_DEFAULT_ENDPOINT,
|
|
86
|
-
_HF_DEFAULT_STAGING_ENDPOINT,
|
|
87
85
|
DEFAULT_ETAG_TIMEOUT,
|
|
88
86
|
DEFAULT_REQUEST_TIMEOUT,
|
|
89
87
|
DEFAULT_REVISION,
|
|
@@ -106,7 +104,7 @@ from .constants import (
|
|
|
106
104
|
from .file_download import HfFileMetadata, get_hf_file_metadata, hf_hub_url
|
|
107
105
|
from .repocard_data import DatasetCardData, ModelCardData, SpaceCardData
|
|
108
106
|
from .utils import ( # noqa: F401 # imported for backward compatibility
|
|
109
|
-
|
|
107
|
+
DEFAULT_IGNORE_PATTERNS,
|
|
110
108
|
BadRequestError,
|
|
111
109
|
EntryNotFoundError,
|
|
112
110
|
GatedRepoError,
|
|
@@ -123,6 +121,7 @@ from .utils import ( # noqa: F401 # imported for backward compatibility
|
|
|
123
121
|
build_hf_headers,
|
|
124
122
|
experimental,
|
|
125
123
|
filter_repo_objects,
|
|
124
|
+
fix_hf_endpoint_in_url,
|
|
126
125
|
get_session,
|
|
127
126
|
hf_raise_for_status,
|
|
128
127
|
logging,
|
|
@@ -131,7 +130,7 @@ from .utils import ( # noqa: F401 # imported for backward compatibility
|
|
|
131
130
|
validate_hf_hub_args,
|
|
132
131
|
)
|
|
133
132
|
from .utils import tqdm as hf_tqdm
|
|
134
|
-
from .utils._deprecation import _deprecate_arguments
|
|
133
|
+
from .utils._deprecation import _deprecate_arguments
|
|
135
134
|
from .utils._typing import CallableT
|
|
136
135
|
from .utils.endpoint_helpers import (
|
|
137
136
|
DatasetFilter,
|
|
@@ -185,11 +184,6 @@ def repo_type_and_id_from_hf_id(hf_id: str, hub_url: Optional[str] = None) -> Tu
|
|
|
185
184
|
"""
|
|
186
185
|
input_hf_id = hf_id
|
|
187
186
|
|
|
188
|
-
# check if a proxy has been set => if yes, update the returned URL to use the proxy
|
|
189
|
-
if ENDPOINT not in (_HF_DEFAULT_ENDPOINT, _HF_DEFAULT_STAGING_ENDPOINT):
|
|
190
|
-
hf_id = hf_id.replace(_HF_DEFAULT_ENDPOINT, ENDPOINT)
|
|
191
|
-
hf_id = hf_id.replace(_HF_DEFAULT_STAGING_ENDPOINT, ENDPOINT)
|
|
192
|
-
|
|
193
187
|
hub_url = re.sub(r"https?://", "", hub_url if hub_url is not None else ENDPOINT)
|
|
194
188
|
is_hf_url = hub_url in hf_id and "@" not in hf_id
|
|
195
189
|
|
|
@@ -436,6 +430,7 @@ class RepoUrl(str):
|
|
|
436
430
|
"""
|
|
437
431
|
|
|
438
432
|
def __new__(cls, url: Any, endpoint: Optional[str] = None):
|
|
433
|
+
url = fix_hf_endpoint_in_url(url, endpoint=endpoint)
|
|
439
434
|
return super(RepoUrl, cls).__new__(cls, url)
|
|
440
435
|
|
|
441
436
|
def __init__(self, url: Any, endpoint: Optional[str] = None) -> None:
|
|
@@ -505,10 +500,10 @@ class RepoFile:
|
|
|
505
500
|
lfs (`BlobLfsInfo`):
|
|
506
501
|
The file's LFS metadata.
|
|
507
502
|
last_commit (`LastCommitInfo`, *optional*):
|
|
508
|
-
The file's last commit metadata. Only defined if [`
|
|
503
|
+
The file's last commit metadata. Only defined if [`list_repo_tree`] and [`get_paths_info`]
|
|
509
504
|
are called with `expand=True`.
|
|
510
505
|
security (`BlobSecurityInfo`, *optional*):
|
|
511
|
-
The file's security scan metadata. Only defined if [`
|
|
506
|
+
The file's security scan metadata. Only defined if [`list_repo_tree`] and [`get_paths_info`]
|
|
512
507
|
are called with `expand=True`.
|
|
513
508
|
"""
|
|
514
509
|
|
|
@@ -608,7 +603,7 @@ class ModelInfo:
|
|
|
608
603
|
Is the repo gated.
|
|
609
604
|
If so, whether there is manual or automatic approval.
|
|
610
605
|
downloads (`int`):
|
|
611
|
-
Number of downloads of the model.
|
|
606
|
+
Number of downloads of the model over the last 30 days.
|
|
612
607
|
likes (`int`):
|
|
613
608
|
Number of likes of the model.
|
|
614
609
|
library_name (`str`, *optional*):
|
|
@@ -712,7 +707,14 @@ class ModelInfo:
|
|
|
712
707
|
)
|
|
713
708
|
self.spaces = kwargs.pop("spaces", None)
|
|
714
709
|
safetensors = kwargs.pop("safetensors", None)
|
|
715
|
-
self.safetensors =
|
|
710
|
+
self.safetensors = (
|
|
711
|
+
SafeTensorsInfo(
|
|
712
|
+
parameters=safetensors["parameters"],
|
|
713
|
+
total=safetensors["total"],
|
|
714
|
+
)
|
|
715
|
+
if safetensors
|
|
716
|
+
else None
|
|
717
|
+
)
|
|
716
718
|
|
|
717
719
|
# backwards compatibility
|
|
718
720
|
self.lastModified = self.last_modified
|
|
@@ -754,7 +756,7 @@ class DatasetInfo:
|
|
|
754
756
|
Is the repo gated.
|
|
755
757
|
If so, whether there is manual or automatic approval.
|
|
756
758
|
downloads (`int`):
|
|
757
|
-
Number of downloads of the dataset.
|
|
759
|
+
Number of downloads of the dataset over the last 30 days.
|
|
758
760
|
likes (`int`):
|
|
759
761
|
Number of likes of the dataset.
|
|
760
762
|
tags (`List[str]`):
|
|
@@ -1197,12 +1199,61 @@ class User:
|
|
|
1197
1199
|
Name of the user on the Hub (unique).
|
|
1198
1200
|
fullname (`str`):
|
|
1199
1201
|
User's full name.
|
|
1202
|
+
is_pro (`bool`, *optional*):
|
|
1203
|
+
Whether the user is a pro user.
|
|
1204
|
+
num_models (`int`, *optional*):
|
|
1205
|
+
Number of models created by the user.
|
|
1206
|
+
num_datasets (`int`, *optional*):
|
|
1207
|
+
Number of datasets created by the user.
|
|
1208
|
+
num_spaces (`int`, *optional*):
|
|
1209
|
+
Number of spaces created by the user.
|
|
1210
|
+
num_discussions (`int`, *optional*):
|
|
1211
|
+
Number of discussions initiated by the user.
|
|
1212
|
+
num_papers (`int`, *optional*):
|
|
1213
|
+
Number of papers authored by the user.
|
|
1214
|
+
num_upvotes (`int`, *optional*):
|
|
1215
|
+
Number of upvotes received by the user.
|
|
1216
|
+
num_likes (`int`, *optional*):
|
|
1217
|
+
Number of likes given by the user.
|
|
1218
|
+
is_following (`bool`, *optional*):
|
|
1219
|
+
Whether the authenticated user is following this user.
|
|
1220
|
+
details (`str`, *optional*):
|
|
1221
|
+
User's details.
|
|
1200
1222
|
"""
|
|
1201
1223
|
|
|
1202
1224
|
# Metadata
|
|
1203
1225
|
avatar_url: str
|
|
1204
1226
|
username: str
|
|
1205
1227
|
fullname: str
|
|
1228
|
+
is_pro: Optional[bool] = None
|
|
1229
|
+
num_models: Optional[int] = None
|
|
1230
|
+
num_datasets: Optional[int] = None
|
|
1231
|
+
num_spaces: Optional[int] = None
|
|
1232
|
+
num_discussions: Optional[int] = None
|
|
1233
|
+
num_papers: Optional[int] = None
|
|
1234
|
+
num_upvotes: Optional[int] = None
|
|
1235
|
+
num_likes: Optional[int] = None
|
|
1236
|
+
is_following: Optional[bool] = None
|
|
1237
|
+
details: Optional[str] = None
|
|
1238
|
+
|
|
1239
|
+
def __init__(self, **kwargs) -> None:
|
|
1240
|
+
self.avatar_url = kwargs.get("avatarUrl", "")
|
|
1241
|
+
self.username = kwargs.get("user", "")
|
|
1242
|
+
self.fullname = kwargs.get("fullname", "")
|
|
1243
|
+
self.is_pro = kwargs.get("isPro")
|
|
1244
|
+
self.num_models = kwargs.get("numModels")
|
|
1245
|
+
self.num_datasets = kwargs.get("numDatasets")
|
|
1246
|
+
self.num_spaces = kwargs.get("numSpaces")
|
|
1247
|
+
self.num_discussions = kwargs.get("numDiscussions")
|
|
1248
|
+
self.num_papers = kwargs.get("numPapers")
|
|
1249
|
+
self.num_upvotes = kwargs.get("numUpvotes")
|
|
1250
|
+
self.num_likes = kwargs.get("numLikes")
|
|
1251
|
+
self.user_type = kwargs.get("type")
|
|
1252
|
+
self.is_following = kwargs.get("isFollowing")
|
|
1253
|
+
self.details = kwargs.get("details")
|
|
1254
|
+
|
|
1255
|
+
# forward compatibility
|
|
1256
|
+
self.__dict__.update(**kwargs)
|
|
1206
1257
|
|
|
1207
1258
|
|
|
1208
1259
|
def future_compatible(fn: CallableT) -> CallableT:
|
|
@@ -1256,9 +1307,11 @@ class HfApi:
|
|
|
1256
1307
|
directly at the root of `huggingface_hub`.
|
|
1257
1308
|
|
|
1258
1309
|
Args:
|
|
1259
|
-
token (
|
|
1260
|
-
|
|
1261
|
-
|
|
1310
|
+
token (Union[bool, str, None], optional):
|
|
1311
|
+
A valid user access token (string). Defaults to the locally saved
|
|
1312
|
+
token, which is the recommended method for authentication (see
|
|
1313
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1314
|
+
To disable authentication, pass `False`.
|
|
1262
1315
|
library_name (`str`, *optional*):
|
|
1263
1316
|
The name of the library that is making the HTTP request. Will be added to
|
|
1264
1317
|
the user-agent header. Example: `"transformers"`.
|
|
@@ -1321,14 +1374,16 @@ class HfApi:
|
|
|
1321
1374
|
return self._thread_pool.submit(fn, *args, **kwargs)
|
|
1322
1375
|
|
|
1323
1376
|
@validate_hf_hub_args
|
|
1324
|
-
def whoami(self, token:
|
|
1377
|
+
def whoami(self, token: Union[bool, str, None] = None) -> Dict:
|
|
1325
1378
|
"""
|
|
1326
1379
|
Call HF API to know "whoami".
|
|
1327
1380
|
|
|
1328
1381
|
Args:
|
|
1329
|
-
token (
|
|
1330
|
-
|
|
1331
|
-
|
|
1382
|
+
token (Union[bool, str, None], optional):
|
|
1383
|
+
A valid user access token (string). Defaults to the locally saved
|
|
1384
|
+
token, which is the recommended method for authentication (see
|
|
1385
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1386
|
+
To disable authentication, pass `False`.
|
|
1332
1387
|
"""
|
|
1333
1388
|
r = get_session().get(
|
|
1334
1389
|
f"{self.endpoint}/api/whoami-v2",
|
|
@@ -1350,15 +1405,18 @@ class HfApi:
|
|
|
1350
1405
|
) from e
|
|
1351
1406
|
return r.json()
|
|
1352
1407
|
|
|
1353
|
-
def get_token_permission(self, token:
|
|
1408
|
+
def get_token_permission(self, token: Union[bool, str, None] = None) -> Literal["read", "write", None]:
|
|
1354
1409
|
"""
|
|
1355
1410
|
Check if a given `token` is valid and return its permissions.
|
|
1356
1411
|
|
|
1357
1412
|
For more details about tokens, please refer to https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens.
|
|
1358
1413
|
|
|
1359
1414
|
Args:
|
|
1360
|
-
token (
|
|
1361
|
-
|
|
1415
|
+
token (Union[bool, str, None], optional):
|
|
1416
|
+
A valid user access token (string). Defaults to the locally saved
|
|
1417
|
+
token, which is the recommended method for authentication (see
|
|
1418
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1419
|
+
To disable authentication, pass `False`.
|
|
1362
1420
|
|
|
1363
1421
|
Returns:
|
|
1364
1422
|
`Literal["read", "write", None]`: Permission granted by the token ("read" or "write"). Returns `None` if no
|
|
@@ -1407,7 +1465,7 @@ class HfApi:
|
|
|
1407
1465
|
full: Optional[bool] = None,
|
|
1408
1466
|
cardData: bool = False,
|
|
1409
1467
|
fetch_config: bool = False,
|
|
1410
|
-
token:
|
|
1468
|
+
token: Union[bool, str, None] = None,
|
|
1411
1469
|
pipeline_tag: Optional[str] = None,
|
|
1412
1470
|
) -> Iterable[ModelInfo]:
|
|
1413
1471
|
"""
|
|
@@ -1463,11 +1521,11 @@ class HfApi:
|
|
|
1463
1521
|
fetch_config (`bool`, *optional*):
|
|
1464
1522
|
Whether to fetch the model configs as well. This is not included
|
|
1465
1523
|
in `full` due to its size.
|
|
1466
|
-
token (
|
|
1467
|
-
A valid
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1524
|
+
token (Union[bool, str, None], optional):
|
|
1525
|
+
A valid user access token (string). Defaults to the locally saved
|
|
1526
|
+
token, which is the recommended method for authentication (see
|
|
1527
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1528
|
+
To disable authentication, pass `False`.
|
|
1471
1529
|
pipeline_tag (`str`, *optional*):
|
|
1472
1530
|
A string pipeline tag to filter models on the Hub by, such as `summarization`
|
|
1473
1531
|
|
|
@@ -1647,7 +1705,7 @@ class HfApi:
|
|
|
1647
1705
|
direction: Optional[Literal[-1]] = None,
|
|
1648
1706
|
limit: Optional[int] = None,
|
|
1649
1707
|
full: Optional[bool] = None,
|
|
1650
|
-
token:
|
|
1708
|
+
token: Union[bool, str, None] = None,
|
|
1651
1709
|
) -> Iterable[DatasetInfo]:
|
|
1652
1710
|
"""
|
|
1653
1711
|
List datasets hosted on the Huggingface Hub, given some filters.
|
|
@@ -1701,11 +1759,11 @@ class HfApi:
|
|
|
1701
1759
|
Whether to fetch all dataset data, including the `last_modified`,
|
|
1702
1760
|
the `card_data` and the files. Can contain useful information such as the
|
|
1703
1761
|
PapersWithCode ID.
|
|
1704
|
-
token (
|
|
1705
|
-
A valid
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1762
|
+
token (Union[bool, str, None], optional):
|
|
1763
|
+
A valid user access token (string). Defaults to the locally saved
|
|
1764
|
+
token, which is the recommended method for authentication (see
|
|
1765
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1766
|
+
To disable authentication, pass `False`.
|
|
1709
1767
|
|
|
1710
1768
|
Returns:
|
|
1711
1769
|
`Iterable[DatasetInfo]`: an iterable of [`huggingface_hub.hf_api.DatasetInfo`] objects.
|
|
@@ -1873,7 +1931,7 @@ class HfApi:
|
|
|
1873
1931
|
models: Union[str, Iterable[str], None] = None,
|
|
1874
1932
|
linked: bool = False,
|
|
1875
1933
|
full: Optional[bool] = None,
|
|
1876
|
-
token:
|
|
1934
|
+
token: Union[bool, str, None] = None,
|
|
1877
1935
|
) -> Iterable[SpaceInfo]:
|
|
1878
1936
|
"""
|
|
1879
1937
|
List spaces hosted on the Huggingface Hub, given some filters.
|
|
@@ -1905,11 +1963,11 @@ class HfApi:
|
|
|
1905
1963
|
full (`bool`, *optional*):
|
|
1906
1964
|
Whether to fetch all Spaces data, including the `last_modified`, `siblings`
|
|
1907
1965
|
and `card_data` fields.
|
|
1908
|
-
token (
|
|
1909
|
-
A valid
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1966
|
+
token (Union[bool, str, None], optional):
|
|
1967
|
+
A valid user access token (string). Defaults to the locally saved
|
|
1968
|
+
token, which is the recommended method for authentication (see
|
|
1969
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
1970
|
+
To disable authentication, pass `False`.
|
|
1913
1971
|
|
|
1914
1972
|
Returns:
|
|
1915
1973
|
`Iterable[SpaceInfo]`: an iterable of [`huggingface_hub.hf_api.SpaceInfo`] objects.
|
|
@@ -1951,7 +2009,7 @@ class HfApi:
|
|
|
1951
2009
|
self,
|
|
1952
2010
|
repo_id: str,
|
|
1953
2011
|
*,
|
|
1954
|
-
token:
|
|
2012
|
+
token: Union[bool, str, None] = None,
|
|
1955
2013
|
repo_type: Optional[str] = None,
|
|
1956
2014
|
) -> None:
|
|
1957
2015
|
"""
|
|
@@ -1963,8 +2021,11 @@ class HfApi:
|
|
|
1963
2021
|
repo_id (`str`):
|
|
1964
2022
|
The repository to like. Example: `"user/my-cool-model"`.
|
|
1965
2023
|
|
|
1966
|
-
token (
|
|
1967
|
-
|
|
2024
|
+
token (Union[bool, str, None], optional):
|
|
2025
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2026
|
+
token, which is the recommended method for authentication (see
|
|
2027
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2028
|
+
To disable authentication, pass `False`.
|
|
1968
2029
|
|
|
1969
2030
|
repo_type (`str`, *optional*):
|
|
1970
2031
|
Set to `"dataset"` or `"space"` if liking a dataset or space, `None` or
|
|
@@ -1999,7 +2060,7 @@ class HfApi:
|
|
|
1999
2060
|
self,
|
|
2000
2061
|
repo_id: str,
|
|
2001
2062
|
*,
|
|
2002
|
-
token:
|
|
2063
|
+
token: Union[bool, str, None] = None,
|
|
2003
2064
|
repo_type: Optional[str] = None,
|
|
2004
2065
|
) -> None:
|
|
2005
2066
|
"""
|
|
@@ -2011,8 +2072,11 @@ class HfApi:
|
|
|
2011
2072
|
repo_id (`str`):
|
|
2012
2073
|
The repository to unlike. Example: `"user/my-cool-model"`.
|
|
2013
2074
|
|
|
2014
|
-
token (
|
|
2015
|
-
|
|
2075
|
+
token (Union[bool, str, None], optional):
|
|
2076
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2077
|
+
token, which is the recommended method for authentication (see
|
|
2078
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2079
|
+
To disable authentication, pass `False`.
|
|
2016
2080
|
|
|
2017
2081
|
repo_type (`str`, *optional*):
|
|
2018
2082
|
Set to `"dataset"` or `"space"` if unliking a dataset or space, `None` or
|
|
@@ -2046,7 +2110,7 @@ class HfApi:
|
|
|
2046
2110
|
self,
|
|
2047
2111
|
user: Optional[str] = None,
|
|
2048
2112
|
*,
|
|
2049
|
-
token:
|
|
2113
|
+
token: Union[bool, str, None] = None,
|
|
2050
2114
|
) -> UserLikes:
|
|
2051
2115
|
"""
|
|
2052
2116
|
List all public repos liked by a user on huggingface.co.
|
|
@@ -2059,10 +2123,11 @@ class HfApi:
|
|
|
2059
2123
|
Args:
|
|
2060
2124
|
user (`str`, *optional*):
|
|
2061
2125
|
Name of the user for which you want to fetch the likes.
|
|
2062
|
-
token (
|
|
2063
|
-
A valid
|
|
2064
|
-
|
|
2065
|
-
|
|
2126
|
+
token (Union[bool, str, None], optional):
|
|
2127
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2128
|
+
token, which is the recommended method for authentication (see
|
|
2129
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2130
|
+
To disable authentication, pass `False`.
|
|
2066
2131
|
|
|
2067
2132
|
Returns:
|
|
2068
2133
|
[`UserLikes`]: object containing the user name and 3 lists of repo ids (1 for
|
|
@@ -2122,7 +2187,7 @@ class HfApi:
|
|
|
2122
2187
|
repo_id: str,
|
|
2123
2188
|
*,
|
|
2124
2189
|
repo_type: Optional[str] = None,
|
|
2125
|
-
token:
|
|
2190
|
+
token: Union[bool, str, None] = None,
|
|
2126
2191
|
) -> List[User]:
|
|
2127
2192
|
"""
|
|
2128
2193
|
List all users who liked a given repo on the hugging Face Hub.
|
|
@@ -2133,8 +2198,11 @@ class HfApi:
|
|
|
2133
2198
|
repo_id (`str`):
|
|
2134
2199
|
The repository to retrieve . Example: `"user/my-cool-model"`.
|
|
2135
2200
|
|
|
2136
|
-
token (
|
|
2137
|
-
|
|
2201
|
+
token (Union[bool, str, None], optional):
|
|
2202
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2203
|
+
token, which is the recommended method for authentication (see
|
|
2204
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2205
|
+
To disable authentication, pass `False`.
|
|
2138
2206
|
|
|
2139
2207
|
repo_type (`str`, *optional*):
|
|
2140
2208
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
@@ -2175,7 +2243,7 @@ class HfApi:
|
|
|
2175
2243
|
timeout: Optional[float] = None,
|
|
2176
2244
|
securityStatus: Optional[bool] = None,
|
|
2177
2245
|
files_metadata: bool = False,
|
|
2178
|
-
token:
|
|
2246
|
+
token: Union[bool, str, None] = None,
|
|
2179
2247
|
) -> ModelInfo:
|
|
2180
2248
|
"""
|
|
2181
2249
|
Get info on one specific model on huggingface.co
|
|
@@ -2197,11 +2265,11 @@ class HfApi:
|
|
|
2197
2265
|
files_metadata (`bool`, *optional*):
|
|
2198
2266
|
Whether or not to retrieve metadata for files in the repository
|
|
2199
2267
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2200
|
-
token (
|
|
2201
|
-
A valid
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2268
|
+
token (Union[bool, str, None], optional):
|
|
2269
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2270
|
+
token, which is the recommended method for authentication (see
|
|
2271
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2272
|
+
To disable authentication, pass `False`.
|
|
2205
2273
|
|
|
2206
2274
|
Returns:
|
|
2207
2275
|
[`huggingface_hub.hf_api.ModelInfo`]: The model repository information.
|
|
@@ -2242,7 +2310,7 @@ class HfApi:
|
|
|
2242
2310
|
revision: Optional[str] = None,
|
|
2243
2311
|
timeout: Optional[float] = None,
|
|
2244
2312
|
files_metadata: bool = False,
|
|
2245
|
-
token:
|
|
2313
|
+
token: Union[bool, str, None] = None,
|
|
2246
2314
|
) -> DatasetInfo:
|
|
2247
2315
|
"""
|
|
2248
2316
|
Get info on one specific dataset on huggingface.co.
|
|
@@ -2261,11 +2329,11 @@ class HfApi:
|
|
|
2261
2329
|
files_metadata (`bool`, *optional*):
|
|
2262
2330
|
Whether or not to retrieve metadata for files in the repository
|
|
2263
2331
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2264
|
-
token (
|
|
2265
|
-
A valid
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2332
|
+
token (Union[bool, str, None], optional):
|
|
2333
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2334
|
+
token, which is the recommended method for authentication (see
|
|
2335
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2336
|
+
To disable authentication, pass `False`.
|
|
2269
2337
|
|
|
2270
2338
|
Returns:
|
|
2271
2339
|
[`hf_api.DatasetInfo`]: The dataset repository information.
|
|
@@ -2305,7 +2373,7 @@ class HfApi:
|
|
|
2305
2373
|
revision: Optional[str] = None,
|
|
2306
2374
|
timeout: Optional[float] = None,
|
|
2307
2375
|
files_metadata: bool = False,
|
|
2308
|
-
token:
|
|
2376
|
+
token: Union[bool, str, None] = None,
|
|
2309
2377
|
) -> SpaceInfo:
|
|
2310
2378
|
"""
|
|
2311
2379
|
Get info on one specific Space on huggingface.co.
|
|
@@ -2324,11 +2392,11 @@ class HfApi:
|
|
|
2324
2392
|
files_metadata (`bool`, *optional*):
|
|
2325
2393
|
Whether or not to retrieve metadata for files in the repository
|
|
2326
2394
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2327
|
-
token (
|
|
2328
|
-
A valid
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2395
|
+
token (Union[bool, str, None], optional):
|
|
2396
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2397
|
+
token, which is the recommended method for authentication (see
|
|
2398
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2399
|
+
To disable authentication, pass `False`.
|
|
2332
2400
|
|
|
2333
2401
|
Returns:
|
|
2334
2402
|
[`~hf_api.SpaceInfo`]: The space repository information.
|
|
@@ -2369,7 +2437,7 @@ class HfApi:
|
|
|
2369
2437
|
repo_type: Optional[str] = None,
|
|
2370
2438
|
timeout: Optional[float] = None,
|
|
2371
2439
|
files_metadata: bool = False,
|
|
2372
|
-
token:
|
|
2440
|
+
token: Union[bool, str, None] = None,
|
|
2373
2441
|
) -> Union[ModelInfo, DatasetInfo, SpaceInfo]:
|
|
2374
2442
|
"""
|
|
2375
2443
|
Get the info object for a given repo of a given type.
|
|
@@ -2389,11 +2457,11 @@ class HfApi:
|
|
|
2389
2457
|
files_metadata (`bool`, *optional*):
|
|
2390
2458
|
Whether or not to retrieve metadata for files in the repository
|
|
2391
2459
|
(size, LFS metadata, etc). Defaults to `False`.
|
|
2392
|
-
token (
|
|
2393
|
-
A valid
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2460
|
+
token (Union[bool, str, None], optional):
|
|
2461
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2462
|
+
token, which is the recommended method for authentication (see
|
|
2463
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2464
|
+
To disable authentication, pass `False`.
|
|
2397
2465
|
|
|
2398
2466
|
Returns:
|
|
2399
2467
|
`Union[SpaceInfo, DatasetInfo, ModelInfo]`: The repository information, as a
|
|
@@ -2434,7 +2502,7 @@ class HfApi:
|
|
|
2434
2502
|
repo_id: str,
|
|
2435
2503
|
*,
|
|
2436
2504
|
repo_type: Optional[str] = None,
|
|
2437
|
-
token:
|
|
2505
|
+
token: Union[str, bool, None] = None,
|
|
2438
2506
|
) -> bool:
|
|
2439
2507
|
"""
|
|
2440
2508
|
Checks if a repository exists on the Hugging Face Hub.
|
|
@@ -2446,11 +2514,11 @@ class HfApi:
|
|
|
2446
2514
|
repo_type (`str`, *optional*):
|
|
2447
2515
|
Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space,
|
|
2448
2516
|
`None` or `"model"` if getting repository info from a model. Default is `None`.
|
|
2449
|
-
token (
|
|
2450
|
-
A valid
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2517
|
+
token (Union[bool, str, None], optional):
|
|
2518
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2519
|
+
token, which is the recommended method for authentication (see
|
|
2520
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2521
|
+
To disable authentication, pass `False`.
|
|
2454
2522
|
|
|
2455
2523
|
Returns:
|
|
2456
2524
|
True if the repository exists, False otherwise.
|
|
@@ -2479,7 +2547,7 @@ class HfApi:
|
|
|
2479
2547
|
revision: str,
|
|
2480
2548
|
*,
|
|
2481
2549
|
repo_type: Optional[str] = None,
|
|
2482
|
-
token:
|
|
2550
|
+
token: Union[str, bool, None] = None,
|
|
2483
2551
|
) -> bool:
|
|
2484
2552
|
"""
|
|
2485
2553
|
Checks if a specific revision exists on a repo on the Hugging Face Hub.
|
|
@@ -2493,11 +2561,11 @@ class HfApi:
|
|
|
2493
2561
|
repo_type (`str`, *optional*):
|
|
2494
2562
|
Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space,
|
|
2495
2563
|
`None` or `"model"` if getting repository info from a model. Default is `None`.
|
|
2496
|
-
token (
|
|
2497
|
-
A valid
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2564
|
+
token (Union[bool, str, None], optional):
|
|
2565
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2566
|
+
token, which is the recommended method for authentication (see
|
|
2567
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2568
|
+
To disable authentication, pass `False`.
|
|
2501
2569
|
|
|
2502
2570
|
Returns:
|
|
2503
2571
|
True if the repository and the revision exists, False otherwise.
|
|
@@ -2544,11 +2612,11 @@ class HfApi:
|
|
|
2544
2612
|
`None` or `"model"` if getting repository info from a model. Default is `None`.
|
|
2545
2613
|
revision (`str`, *optional*):
|
|
2546
2614
|
The revision of the repository from which to get the information. Defaults to `"main"` branch.
|
|
2547
|
-
token (
|
|
2548
|
-
A valid
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2615
|
+
token (Union[bool, str, None], optional):
|
|
2616
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2617
|
+
token, which is the recommended method for authentication (see
|
|
2618
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2619
|
+
To disable authentication, pass `False`.
|
|
2552
2620
|
|
|
2553
2621
|
Returns:
|
|
2554
2622
|
True if the file exists, False otherwise.
|
|
@@ -2577,190 +2645,6 @@ class HfApi:
|
|
|
2577
2645
|
except (RepositoryNotFoundError, EntryNotFoundError, RevisionNotFoundError):
|
|
2578
2646
|
return False
|
|
2579
2647
|
|
|
2580
|
-
@validate_hf_hub_args
|
|
2581
|
-
@_deprecate_method(version="0.23", message="Use `list_repo_tree` and `get_paths_info` instead.")
|
|
2582
|
-
def list_files_info(
|
|
2583
|
-
self,
|
|
2584
|
-
repo_id: str,
|
|
2585
|
-
paths: Union[List[str], str, None] = None,
|
|
2586
|
-
*,
|
|
2587
|
-
expand: bool = False,
|
|
2588
|
-
revision: Optional[str] = None,
|
|
2589
|
-
repo_type: Optional[str] = None,
|
|
2590
|
-
token: Optional[Union[bool, str]] = None,
|
|
2591
|
-
) -> Iterable[RepoFile]:
|
|
2592
|
-
"""
|
|
2593
|
-
List files on a repo and get information about them.
|
|
2594
|
-
|
|
2595
|
-
Takes as input a list of paths. Those paths can be either files or folders. Two server endpoints are called:
|
|
2596
|
-
1. POST "/paths-info" to get information about the provided paths. Called once.
|
|
2597
|
-
2. GET "/tree?recursive=True" to paginate over the input folders. Called only if a folder path is provided as
|
|
2598
|
-
input. Will be called multiple times to follow pagination.
|
|
2599
|
-
If no path is provided as input, step 1. is ignored and all files from the repo are listed.
|
|
2600
|
-
|
|
2601
|
-
Args:
|
|
2602
|
-
repo_id (`str`):
|
|
2603
|
-
A namespace (user or an organization) and a repo name separated by a `/`.
|
|
2604
|
-
paths (`Union[List[str], str, None]`, *optional*):
|
|
2605
|
-
The paths to get information about. Paths to files are directly resolved. Paths to folders are resolved
|
|
2606
|
-
recursively which means that information is returned about all files in the folder and its subfolders.
|
|
2607
|
-
If `None`, all files are returned (the default). If a path do not exist, it is ignored without raising
|
|
2608
|
-
an exception.
|
|
2609
|
-
expand (`bool`, *optional*, defaults to `False`):
|
|
2610
|
-
Whether to fetch more information about the files (e.g. last commit and security scan results). This
|
|
2611
|
-
operation is more expensive for the server so only 50 results are returned per page (instead of 1000).
|
|
2612
|
-
As pagination is implemented in `huggingface_hub`, this is transparent for you except for the time it
|
|
2613
|
-
takes to get the results.
|
|
2614
|
-
revision (`str`, *optional*):
|
|
2615
|
-
The revision of the repository from which to get the information. Defaults to `"main"` branch.
|
|
2616
|
-
repo_type (`str`, *optional*):
|
|
2617
|
-
The type of the repository from which to get the information (`"model"`, `"dataset"` or `"space"`.
|
|
2618
|
-
Defaults to `"model"`.
|
|
2619
|
-
token (`bool` or `str`, *optional*):
|
|
2620
|
-
A valid authentication token (see https://huggingface.co/settings/token). If `None` or `True` and
|
|
2621
|
-
machine is logged in (through `huggingface-cli login` or [`~huggingface_hub.login`]), token will be
|
|
2622
|
-
retrieved from the cache. If `False`, token is not sent in the request header.
|
|
2623
|
-
|
|
2624
|
-
Returns:
|
|
2625
|
-
`Iterable[RepoFile]`:
|
|
2626
|
-
The information about the files, as an iterable of [`RepoFile`] objects. The order of the files is
|
|
2627
|
-
not guaranteed.
|
|
2628
|
-
|
|
2629
|
-
Raises:
|
|
2630
|
-
[`~utils.RepositoryNotFoundError`]:
|
|
2631
|
-
If repository is not found (error 404): wrong repo_id/repo_type, private but not authenticated or repo
|
|
2632
|
-
does not exist.
|
|
2633
|
-
[`~utils.RevisionNotFoundError`]:
|
|
2634
|
-
If revision is not found (error 404) on the repo.
|
|
2635
|
-
|
|
2636
|
-
Examples:
|
|
2637
|
-
|
|
2638
|
-
Get information about files on a repo.
|
|
2639
|
-
```py
|
|
2640
|
-
>>> from huggingface_hub import list_files_info
|
|
2641
|
-
>>> files_info = list_files_info("lysandre/arxiv-nlp", ["README.md", "config.json"])
|
|
2642
|
-
>>> files_info
|
|
2643
|
-
<generator object HfApi.list_files_info at 0x7f93b848e730>
|
|
2644
|
-
>>> list(files_info)
|
|
2645
|
-
[
|
|
2646
|
-
RepoFile(path='README.md', size=391, blob_id='43bd404b159de6fba7c2f4d3264347668d43af25', lfs=None, last_commit=None, security=None),
|
|
2647
|
-
RepoFile(path='config.json', size=554, blob_id='2f9618c3a19b9a61add74f70bfb121335aeef666', lfs=None, last_commit=None, security=None)
|
|
2648
|
-
]
|
|
2649
|
-
```
|
|
2650
|
-
|
|
2651
|
-
Get even more information about files on a repo (last commit and security scan results)
|
|
2652
|
-
```py
|
|
2653
|
-
>>> from huggingface_hub import list_files_info
|
|
2654
|
-
>>> files_info = list_files_info("prompthero/openjourney-v4", expand=True)
|
|
2655
|
-
>>> list(files_info)
|
|
2656
|
-
[
|
|
2657
|
-
RepoFile(
|
|
2658
|
-
path='safety_checker/pytorch_model.bin',
|
|
2659
|
-
size=1216064769,
|
|
2660
|
-
blob_id='c8835557a0d3af583cb06c7c154b7e54a069c41d',
|
|
2661
|
-
lfs={
|
|
2662
|
-
'size': 1216064769,
|
|
2663
|
-
'sha256': '16d28f2b37109f222cdc33620fdd262102ac32112be0352a7f77e9614b35a394',
|
|
2664
|
-
'pointer_size': 135
|
|
2665
|
-
},
|
|
2666
|
-
last_commit={
|
|
2667
|
-
'oid': '47b62b20b20e06b9de610e840282b7e6c3d51190',
|
|
2668
|
-
'title': 'Upload diffusers weights (#48)',
|
|
2669
|
-
'date': datetime.datetime(2023, 3, 21, 10, 5, 27, tzinfo=datetime.timezone.utc)
|
|
2670
|
-
},
|
|
2671
|
-
security={
|
|
2672
|
-
'safe': True,
|
|
2673
|
-
'av_scan': {
|
|
2674
|
-
'virusFound': False,
|
|
2675
|
-
'virusNames': None
|
|
2676
|
-
},
|
|
2677
|
-
'pickle_import_scan': {
|
|
2678
|
-
'highestSafetyLevel': 'innocuous',
|
|
2679
|
-
'imports': [
|
|
2680
|
-
{'module': 'torch', 'name': 'FloatStorage', 'safety': 'innocuous'},
|
|
2681
|
-
{'module': 'collections', 'name': 'OrderedDict', 'safety': 'innocuous'},
|
|
2682
|
-
{'module': 'torch', 'name': 'LongStorage', 'safety': 'innocuous'},
|
|
2683
|
-
{'module': 'torch._utils', 'name': '_rebuild_tensor_v2', 'safety': 'innocuous'}
|
|
2684
|
-
]
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
),
|
|
2688
|
-
RepoFile(
|
|
2689
|
-
path='scheduler/scheduler_config.json',
|
|
2690
|
-
size=465,
|
|
2691
|
-
blob_id='70d55e3e9679f41cbc66222831b38d5abce683dd',
|
|
2692
|
-
lfs=None,
|
|
2693
|
-
last_commit={
|
|
2694
|
-
'oid': '47b62b20b20e06b9de610e840282b7e6c3d51190',
|
|
2695
|
-
'title': 'Upload diffusers weights (#48)',
|
|
2696
|
-
'date': datetime.datetime(2023, 3, 21, 10, 5, 27, tzinfo=datetime.timezone.utc)},
|
|
2697
|
-
security={
|
|
2698
|
-
'safe': True,
|
|
2699
|
-
'av_scan': {
|
|
2700
|
-
'virusFound': False,
|
|
2701
|
-
'virusNames': None
|
|
2702
|
-
},
|
|
2703
|
-
'pickle_import_scan': None
|
|
2704
|
-
}
|
|
2705
|
-
),
|
|
2706
|
-
...
|
|
2707
|
-
]
|
|
2708
|
-
```
|
|
2709
|
-
|
|
2710
|
-
List LFS files from the "vae/" folder in "stabilityai/stable-diffusion-2" repository.
|
|
2711
|
-
|
|
2712
|
-
```py
|
|
2713
|
-
>>> from huggingface_hub import list_files_info
|
|
2714
|
-
>>> [info.path for info in list_files_info("stabilityai/stable-diffusion-2", "vae") if info.lfs is not None]
|
|
2715
|
-
['vae/diffusion_pytorch_model.bin', 'vae/diffusion_pytorch_model.safetensors']
|
|
2716
|
-
```
|
|
2717
|
-
|
|
2718
|
-
List all files on a repo.
|
|
2719
|
-
```py
|
|
2720
|
-
>>> from huggingface_hub import list_files_info
|
|
2721
|
-
>>> [info.path for info in list_files_info("glue", repo_type="dataset")]
|
|
2722
|
-
['.gitattributes', 'README.md', 'dataset_infos.json', 'glue.py']
|
|
2723
|
-
```
|
|
2724
|
-
"""
|
|
2725
|
-
repo_type = repo_type or REPO_TYPE_MODEL
|
|
2726
|
-
revision = quote(revision, safe="") if revision is not None else DEFAULT_REVISION
|
|
2727
|
-
headers = self._build_hf_headers(token=token)
|
|
2728
|
-
|
|
2729
|
-
folder_paths = []
|
|
2730
|
-
if paths is None:
|
|
2731
|
-
# `paths` is not provided => list all files from the repo
|
|
2732
|
-
folder_paths.append("")
|
|
2733
|
-
elif paths == []:
|
|
2734
|
-
# corner case: server would return a 400 error if `paths` is an empty list. Let's return early.
|
|
2735
|
-
return
|
|
2736
|
-
else:
|
|
2737
|
-
# `paths` is provided => get info about those
|
|
2738
|
-
response = get_session().post(
|
|
2739
|
-
f"{self.endpoint}/api/{repo_type}s/{repo_id}/paths-info/{revision}",
|
|
2740
|
-
data={
|
|
2741
|
-
"paths": paths if isinstance(paths, list) else [paths],
|
|
2742
|
-
"expand": expand,
|
|
2743
|
-
},
|
|
2744
|
-
headers=headers,
|
|
2745
|
-
)
|
|
2746
|
-
hf_raise_for_status(response)
|
|
2747
|
-
paths_info = response.json()
|
|
2748
|
-
|
|
2749
|
-
# List top-level files first
|
|
2750
|
-
for path_info in paths_info:
|
|
2751
|
-
if path_info["type"] == "file":
|
|
2752
|
-
yield RepoFile(**path_info)
|
|
2753
|
-
else:
|
|
2754
|
-
folder_paths.append(path_info["path"])
|
|
2755
|
-
|
|
2756
|
-
# List files in subdirectories
|
|
2757
|
-
for path in folder_paths:
|
|
2758
|
-
encoded_path = "/" + quote(path, safe="") if path else ""
|
|
2759
|
-
tree_url = f"{self.endpoint}/api/{repo_type}s/{repo_id}/tree/{revision}{encoded_path}"
|
|
2760
|
-
for subpath_info in paginate(path=tree_url, headers=headers, params={"recursive": True, "expand": expand}):
|
|
2761
|
-
if subpath_info["type"] == "file":
|
|
2762
|
-
yield RepoFile(**subpath_info)
|
|
2763
|
-
|
|
2764
2648
|
@validate_hf_hub_args
|
|
2765
2649
|
def list_repo_files(
|
|
2766
2650
|
self,
|
|
@@ -2768,7 +2652,7 @@ class HfApi:
|
|
|
2768
2652
|
*,
|
|
2769
2653
|
revision: Optional[str] = None,
|
|
2770
2654
|
repo_type: Optional[str] = None,
|
|
2771
|
-
token:
|
|
2655
|
+
token: Union[str, bool, None] = None,
|
|
2772
2656
|
) -> List[str]:
|
|
2773
2657
|
"""
|
|
2774
2658
|
Get the list of files in a given repo.
|
|
@@ -2781,10 +2665,11 @@ class HfApi:
|
|
|
2781
2665
|
repo_type (`str`, *optional*):
|
|
2782
2666
|
Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to
|
|
2783
2667
|
a model. Default is `None`.
|
|
2784
|
-
token (
|
|
2785
|
-
A valid
|
|
2786
|
-
|
|
2787
|
-
|
|
2668
|
+
token (Union[bool, str, None], optional):
|
|
2669
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2670
|
+
token, which is the recommended method for authentication (see
|
|
2671
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2672
|
+
To disable authentication, pass `False`.
|
|
2788
2673
|
|
|
2789
2674
|
Returns:
|
|
2790
2675
|
`List[str]`: the list of files in a given repository.
|
|
@@ -2807,7 +2692,7 @@ class HfApi:
|
|
|
2807
2692
|
expand: bool = False,
|
|
2808
2693
|
revision: Optional[str] = None,
|
|
2809
2694
|
repo_type: Optional[str] = None,
|
|
2810
|
-
token:
|
|
2695
|
+
token: Union[str, bool, None] = None,
|
|
2811
2696
|
) -> Iterable[Union[RepoFile, RepoFolder]]:
|
|
2812
2697
|
"""
|
|
2813
2698
|
List a repo tree's files and folders and get information about them.
|
|
@@ -2830,10 +2715,11 @@ class HfApi:
|
|
|
2830
2715
|
repo_type (`str`, *optional*):
|
|
2831
2716
|
The type of the repository from which to get the tree (`"model"`, `"dataset"` or `"space"`.
|
|
2832
2717
|
Defaults to `"model"`.
|
|
2833
|
-
token (
|
|
2834
|
-
A valid
|
|
2835
|
-
|
|
2836
|
-
|
|
2718
|
+
token (Union[bool, str, None], optional):
|
|
2719
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2720
|
+
token, which is the recommended method for authentication (see
|
|
2721
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2722
|
+
To disable authentication, pass `False`.
|
|
2837
2723
|
|
|
2838
2724
|
Returns:
|
|
2839
2725
|
`Iterable[Union[RepoFile, RepoFolder]]`:
|
|
@@ -2935,7 +2821,7 @@ class HfApi:
|
|
|
2935
2821
|
*,
|
|
2936
2822
|
repo_type: Optional[str] = None,
|
|
2937
2823
|
include_pull_requests: bool = False,
|
|
2938
|
-
token:
|
|
2824
|
+
token: Union[str, bool, None] = None,
|
|
2939
2825
|
) -> GitRefs:
|
|
2940
2826
|
"""
|
|
2941
2827
|
Get the list of refs of a given repo (both tags and branches).
|
|
@@ -2949,11 +2835,11 @@ class HfApi:
|
|
|
2949
2835
|
`None` or `"model"` if listing from a model. Default is `None`.
|
|
2950
2836
|
include_pull_requests (`bool`, *optional*):
|
|
2951
2837
|
Whether to include refs from pull requests in the list. Defaults to `False`.
|
|
2952
|
-
token (
|
|
2953
|
-
A valid
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2838
|
+
token (Union[bool, str, None], optional):
|
|
2839
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2840
|
+
token, which is the recommended method for authentication (see
|
|
2841
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2842
|
+
To disable authentication, pass `False`.
|
|
2957
2843
|
|
|
2958
2844
|
Example:
|
|
2959
2845
|
```py
|
|
@@ -3006,7 +2892,7 @@ class HfApi:
|
|
|
3006
2892
|
repo_id: str,
|
|
3007
2893
|
*,
|
|
3008
2894
|
repo_type: Optional[str] = None,
|
|
3009
|
-
token:
|
|
2895
|
+
token: Union[bool, str, None] = None,
|
|
3010
2896
|
revision: Optional[str] = None,
|
|
3011
2897
|
formatted: bool = False,
|
|
3012
2898
|
) -> List[GitCommitInfo]:
|
|
@@ -3021,11 +2907,11 @@ class HfApi:
|
|
|
3021
2907
|
repo_type (`str`, *optional*):
|
|
3022
2908
|
Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if
|
|
3023
2909
|
listing from a model. Default is `None`.
|
|
3024
|
-
token (
|
|
3025
|
-
A valid
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
2910
|
+
token (Union[bool, str, None], optional):
|
|
2911
|
+
A valid user access token (string). Defaults to the locally saved
|
|
2912
|
+
token, which is the recommended method for authentication (see
|
|
2913
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
2914
|
+
To disable authentication, pass `False`.
|
|
3029
2915
|
revision (`str`, *optional*):
|
|
3030
2916
|
The git revision to commit from. Defaults to the head of the `"main"` branch.
|
|
3031
2917
|
formatted (`bool`):
|
|
@@ -3095,7 +2981,7 @@ class HfApi:
|
|
|
3095
2981
|
expand: bool = False,
|
|
3096
2982
|
revision: Optional[str] = None,
|
|
3097
2983
|
repo_type: Optional[str] = None,
|
|
3098
|
-
token:
|
|
2984
|
+
token: Union[str, bool, None] = None,
|
|
3099
2985
|
) -> List[Union[RepoFile, RepoFolder]]:
|
|
3100
2986
|
"""
|
|
3101
2987
|
Get information about a repo's paths.
|
|
@@ -3116,10 +3002,11 @@ class HfApi:
|
|
|
3116
3002
|
repo_type (`str`, *optional*):
|
|
3117
3003
|
The type of the repository from which to get the information (`"model"`, `"dataset"` or `"space"`.
|
|
3118
3004
|
Defaults to `"model"`.
|
|
3119
|
-
token (
|
|
3120
|
-
A valid
|
|
3121
|
-
|
|
3122
|
-
|
|
3005
|
+
token (Union[bool, str, None], optional):
|
|
3006
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3007
|
+
token, which is the recommended method for authentication (see
|
|
3008
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3009
|
+
To disable authentication, pass `False`.
|
|
3123
3010
|
|
|
3124
3011
|
Returns:
|
|
3125
3012
|
`List[Union[RepoFile, RepoFolder]]`:
|
|
@@ -3170,7 +3057,7 @@ class HfApi:
|
|
|
3170
3057
|
branch: Optional[str] = None,
|
|
3171
3058
|
commit_message: Optional[str] = None,
|
|
3172
3059
|
repo_type: Optional[str] = None,
|
|
3173
|
-
token:
|
|
3060
|
+
token: Union[str, bool, None] = None,
|
|
3174
3061
|
) -> None:
|
|
3175
3062
|
"""Squash commit history on a branch for a repo on the Hub.
|
|
3176
3063
|
|
|
@@ -3200,10 +3087,11 @@ class HfApi:
|
|
|
3200
3087
|
repo_type (`str`, *optional*):
|
|
3201
3088
|
Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if
|
|
3202
3089
|
listing from a model. Default is `None`.
|
|
3203
|
-
token (
|
|
3204
|
-
A valid
|
|
3205
|
-
|
|
3206
|
-
|
|
3090
|
+
token (Union[bool, str, None], optional):
|
|
3091
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3092
|
+
token, which is the recommended method for authentication (see
|
|
3093
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3094
|
+
To disable authentication, pass `False`.
|
|
3207
3095
|
|
|
3208
3096
|
Raises:
|
|
3209
3097
|
[`~utils.RepositoryNotFoundError`]:
|
|
@@ -3252,7 +3140,7 @@ class HfApi:
|
|
|
3252
3140
|
self,
|
|
3253
3141
|
repo_id: str,
|
|
3254
3142
|
*,
|
|
3255
|
-
token:
|
|
3143
|
+
token: Union[str, bool, None] = None,
|
|
3256
3144
|
private: bool = False,
|
|
3257
3145
|
repo_type: Optional[str] = None,
|
|
3258
3146
|
exist_ok: bool = False,
|
|
@@ -3269,8 +3157,11 @@ class HfApi:
|
|
|
3269
3157
|
repo_id (`str`):
|
|
3270
3158
|
A namespace (user or an organization) and a repo name separated
|
|
3271
3159
|
by a `/`.
|
|
3272
|
-
token (
|
|
3273
|
-
|
|
3160
|
+
token (Union[bool, str, None], optional):
|
|
3161
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3162
|
+
token, which is the recommended method for authentication (see
|
|
3163
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3164
|
+
To disable authentication, pass `False`.
|
|
3274
3165
|
private (`bool`, *optional*, defaults to `False`):
|
|
3275
3166
|
Whether the model repo should be private.
|
|
3276
3167
|
repo_type (`str`, *optional*):
|
|
@@ -3375,7 +3266,7 @@ class HfApi:
|
|
|
3375
3266
|
return RepoUrl(f"{self.endpoint}/{repo_id}")
|
|
3376
3267
|
return RepoUrl(f"{self.endpoint}/{repo_type}/{repo_id}")
|
|
3377
3268
|
except HfHubHTTPError:
|
|
3378
|
-
raise
|
|
3269
|
+
raise err
|
|
3379
3270
|
else:
|
|
3380
3271
|
raise
|
|
3381
3272
|
|
|
@@ -3387,7 +3278,7 @@ class HfApi:
|
|
|
3387
3278
|
self,
|
|
3388
3279
|
repo_id: str,
|
|
3389
3280
|
*,
|
|
3390
|
-
token:
|
|
3281
|
+
token: Union[str, bool, None] = None,
|
|
3391
3282
|
repo_type: Optional[str] = None,
|
|
3392
3283
|
missing_ok: bool = False,
|
|
3393
3284
|
) -> None:
|
|
@@ -3398,8 +3289,11 @@ class HfApi:
|
|
|
3398
3289
|
repo_id (`str`):
|
|
3399
3290
|
A namespace (user or an organization) and a repo name separated
|
|
3400
3291
|
by a `/`.
|
|
3401
|
-
token (
|
|
3402
|
-
|
|
3292
|
+
token (Union[bool, str, None], optional):
|
|
3293
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3294
|
+
token, which is the recommended method for authentication (see
|
|
3295
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3296
|
+
To disable authentication, pass `False`.
|
|
3403
3297
|
repo_type (`str`, *optional*):
|
|
3404
3298
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
3405
3299
|
space, `None` or `"model"` if uploading to a model.
|
|
@@ -3438,7 +3332,7 @@ class HfApi:
|
|
|
3438
3332
|
repo_id: str,
|
|
3439
3333
|
private: bool = False,
|
|
3440
3334
|
*,
|
|
3441
|
-
token:
|
|
3335
|
+
token: Union[str, bool, None] = None,
|
|
3442
3336
|
organization: Optional[str] = None,
|
|
3443
3337
|
repo_type: Optional[str] = None,
|
|
3444
3338
|
name: Optional[str] = None,
|
|
@@ -3451,8 +3345,11 @@ class HfApi:
|
|
|
3451
3345
|
by a `/`.
|
|
3452
3346
|
private (`bool`, *optional*, defaults to `False`):
|
|
3453
3347
|
Whether the model repo should be private.
|
|
3454
|
-
token (
|
|
3455
|
-
|
|
3348
|
+
token (Union[bool, str, None], optional):
|
|
3349
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3350
|
+
token, which is the recommended method for authentication (see
|
|
3351
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3352
|
+
To disable authentication, pass `False`.
|
|
3456
3353
|
repo_type (`str`, *optional*):
|
|
3457
3354
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
3458
3355
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
@@ -3498,7 +3395,7 @@ class HfApi:
|
|
|
3498
3395
|
to_id: str,
|
|
3499
3396
|
*,
|
|
3500
3397
|
repo_type: Optional[str] = None,
|
|
3501
|
-
token:
|
|
3398
|
+
token: Union[str, bool, None] = None,
|
|
3502
3399
|
):
|
|
3503
3400
|
"""
|
|
3504
3401
|
Moving a repository from namespace1/repo_name1 to namespace2/repo_name2
|
|
@@ -3518,8 +3415,11 @@ class HfApi:
|
|
|
3518
3415
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
3519
3416
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
3520
3417
|
`None`.
|
|
3521
|
-
token (
|
|
3522
|
-
|
|
3418
|
+
token (Union[bool, str, None], optional):
|
|
3419
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3420
|
+
token, which is the recommended method for authentication (see
|
|
3421
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3422
|
+
To disable authentication, pass `False`.
|
|
3523
3423
|
|
|
3524
3424
|
<Tip>
|
|
3525
3425
|
|
|
@@ -3562,7 +3462,7 @@ class HfApi:
|
|
|
3562
3462
|
*,
|
|
3563
3463
|
commit_message: str,
|
|
3564
3464
|
commit_description: Optional[str] = None,
|
|
3565
|
-
token:
|
|
3465
|
+
token: Union[str, bool, None] = None,
|
|
3566
3466
|
repo_type: Optional[str] = None,
|
|
3567
3467
|
revision: Optional[str] = None,
|
|
3568
3468
|
create_pr: Optional[bool] = None,
|
|
@@ -3579,7 +3479,7 @@ class HfApi:
|
|
|
3579
3479
|
*,
|
|
3580
3480
|
commit_message: str,
|
|
3581
3481
|
commit_description: Optional[str] = None,
|
|
3582
|
-
token:
|
|
3482
|
+
token: Union[str, bool, None] = None,
|
|
3583
3483
|
repo_type: Optional[str] = None,
|
|
3584
3484
|
revision: Optional[str] = None,
|
|
3585
3485
|
create_pr: Optional[bool] = None,
|
|
@@ -3597,7 +3497,7 @@ class HfApi:
|
|
|
3597
3497
|
*,
|
|
3598
3498
|
commit_message: str,
|
|
3599
3499
|
commit_description: Optional[str] = None,
|
|
3600
|
-
token:
|
|
3500
|
+
token: Union[str, bool, None] = None,
|
|
3601
3501
|
repo_type: Optional[str] = None,
|
|
3602
3502
|
revision: Optional[str] = None,
|
|
3603
3503
|
create_pr: Optional[bool] = None,
|
|
@@ -3651,9 +3551,11 @@ class HfApi:
|
|
|
3651
3551
|
commit_description (`str`, *optional*):
|
|
3652
3552
|
The description of the commit that will be created
|
|
3653
3553
|
|
|
3654
|
-
token (
|
|
3655
|
-
|
|
3656
|
-
|
|
3554
|
+
token (Union[bool, str, None], optional):
|
|
3555
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3556
|
+
token, which is the recommended method for authentication (see
|
|
3557
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3558
|
+
To disable authentication, pass `False`.
|
|
3657
3559
|
|
|
3658
3560
|
repo_type (`str`, *optional*):
|
|
3659
3561
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
@@ -3849,7 +3751,7 @@ class HfApi:
|
|
|
3849
3751
|
deletion_commits: List[List[CommitOperationDelete]],
|
|
3850
3752
|
commit_message: str,
|
|
3851
3753
|
commit_description: Optional[str] = None,
|
|
3852
|
-
token:
|
|
3754
|
+
token: Union[str, bool, None] = None,
|
|
3853
3755
|
repo_type: Optional[str] = None,
|
|
3854
3756
|
merge_pr: bool = True,
|
|
3855
3757
|
num_threads: int = 5, # TODO: use to multithread uploads
|
|
@@ -3897,8 +3799,11 @@ class HfApi:
|
|
|
3897
3799
|
commit_description (`str`, *optional*):
|
|
3898
3800
|
The description of the commit that will be created. The description will be added to the PR.
|
|
3899
3801
|
|
|
3900
|
-
token (
|
|
3901
|
-
|
|
3802
|
+
token (Union[bool, str, None], optional):
|
|
3803
|
+
A valid user access token (string). Defaults to the locally saved
|
|
3804
|
+
token, which is the recommended method for authentication (see
|
|
3805
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3806
|
+
To disable authentication, pass `False`.
|
|
3902
3807
|
|
|
3903
3808
|
repo_type (`str`, *optional*):
|
|
3904
3809
|
Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to
|
|
@@ -4144,7 +4049,7 @@ class HfApi:
|
|
|
4144
4049
|
repo_id: str,
|
|
4145
4050
|
additions: Iterable[CommitOperationAdd],
|
|
4146
4051
|
*,
|
|
4147
|
-
token:
|
|
4052
|
+
token: Union[str, bool, None] = None,
|
|
4148
4053
|
repo_type: Optional[str] = None,
|
|
4149
4054
|
revision: Optional[str] = None,
|
|
4150
4055
|
create_pr: Optional[bool] = None,
|
|
@@ -4181,8 +4086,11 @@ class HfApi:
|
|
|
4181
4086
|
The list of files to upload. Warning: the objects in this list will be mutated to include information
|
|
4182
4087
|
relative to the upload. Do not reuse the same objects for multiple commits.
|
|
4183
4088
|
|
|
4184
|
-
token (
|
|
4185
|
-
|
|
4089
|
+
token (Union[bool, str, None], optional):
|
|
4090
|
+
A valid user access token (string). Defaults to the locally saved
|
|
4091
|
+
token, which is the recommended method for authentication (see
|
|
4092
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
4093
|
+
To disable authentication, pass `False`.
|
|
4186
4094
|
|
|
4187
4095
|
repo_type (`str`, *optional*):
|
|
4188
4096
|
The type of repository to upload to (e.g. `"model"` -default-, `"dataset"` or `"space"`).
|
|
@@ -4297,7 +4205,7 @@ class HfApi:
|
|
|
4297
4205
|
path_or_fileobj: Union[str, Path, bytes, BinaryIO],
|
|
4298
4206
|
path_in_repo: str,
|
|
4299
4207
|
repo_id: str,
|
|
4300
|
-
token:
|
|
4208
|
+
token: Union[str, bool, None] = None,
|
|
4301
4209
|
repo_type: Optional[str] = None,
|
|
4302
4210
|
revision: Optional[str] = None,
|
|
4303
4211
|
commit_message: Optional[str] = None,
|
|
@@ -4314,7 +4222,7 @@ class HfApi:
|
|
|
4314
4222
|
path_or_fileobj: Union[str, Path, bytes, BinaryIO],
|
|
4315
4223
|
path_in_repo: str,
|
|
4316
4224
|
repo_id: str,
|
|
4317
|
-
token:
|
|
4225
|
+
token: Union[str, bool, None] = None,
|
|
4318
4226
|
repo_type: Optional[str] = None,
|
|
4319
4227
|
revision: Optional[str] = None,
|
|
4320
4228
|
commit_message: Optional[str] = None,
|
|
@@ -4332,7 +4240,7 @@ class HfApi:
|
|
|
4332
4240
|
path_or_fileobj: Union[str, Path, bytes, BinaryIO],
|
|
4333
4241
|
path_in_repo: str,
|
|
4334
4242
|
repo_id: str,
|
|
4335
|
-
token:
|
|
4243
|
+
token: Union[str, bool, None] = None,
|
|
4336
4244
|
repo_type: Optional[str] = None,
|
|
4337
4245
|
revision: Optional[str] = None,
|
|
4338
4246
|
commit_message: Optional[str] = None,
|
|
@@ -4356,9 +4264,11 @@ class HfApi:
|
|
|
4356
4264
|
repo_id (`str`):
|
|
4357
4265
|
The repository to which the file will be uploaded, for example:
|
|
4358
4266
|
`"username/custom_transformers"`
|
|
4359
|
-
token (
|
|
4360
|
-
|
|
4361
|
-
|
|
4267
|
+
token (Union[bool, str, None], optional):
|
|
4268
|
+
A valid user access token (string). Defaults to the locally saved
|
|
4269
|
+
token, which is the recommended method for authentication (see
|
|
4270
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
4271
|
+
To disable authentication, pass `False`.
|
|
4362
4272
|
repo_type (`str`, *optional*):
|
|
4363
4273
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
4364
4274
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
@@ -4499,7 +4409,7 @@ class HfApi:
|
|
|
4499
4409
|
path_in_repo: Optional[str] = None,
|
|
4500
4410
|
commit_message: Optional[str] = None,
|
|
4501
4411
|
commit_description: Optional[str] = None,
|
|
4502
|
-
token:
|
|
4412
|
+
token: Union[str, bool, None] = None,
|
|
4503
4413
|
repo_type: Optional[str] = None,
|
|
4504
4414
|
revision: Optional[str] = None,
|
|
4505
4415
|
create_pr: Optional[bool] = None,
|
|
@@ -4521,7 +4431,7 @@ class HfApi:
|
|
|
4521
4431
|
path_in_repo: Optional[str] = None,
|
|
4522
4432
|
commit_message: Optional[str] = None,
|
|
4523
4433
|
commit_description: Optional[str] = None,
|
|
4524
|
-
token:
|
|
4434
|
+
token: Union[str, bool, None] = None,
|
|
4525
4435
|
repo_type: Optional[str] = None,
|
|
4526
4436
|
revision: Optional[str] = None,
|
|
4527
4437
|
create_pr: Optional[bool] = None,
|
|
@@ -4544,7 +4454,7 @@ class HfApi:
|
|
|
4544
4454
|
path_in_repo: Optional[str] = None,
|
|
4545
4455
|
commit_message: Optional[str] = None,
|
|
4546
4456
|
commit_description: Optional[str] = None,
|
|
4547
|
-
token:
|
|
4457
|
+
token: Union[str, bool, None] = None,
|
|
4548
4458
|
repo_type: Optional[str] = None,
|
|
4549
4459
|
revision: Optional[str] = None,
|
|
4550
4460
|
create_pr: Optional[bool] = None,
|
|
@@ -4566,7 +4476,7 @@ class HfApi:
|
|
|
4566
4476
|
path_in_repo: Optional[str] = None,
|
|
4567
4477
|
commit_message: Optional[str] = None,
|
|
4568
4478
|
commit_description: Optional[str] = None,
|
|
4569
|
-
token:
|
|
4479
|
+
token: Union[str, bool, None] = None,
|
|
4570
4480
|
repo_type: Optional[str] = None,
|
|
4571
4481
|
revision: Optional[str] = None,
|
|
4572
4482
|
create_pr: Optional[bool] = None,
|
|
@@ -4590,7 +4500,7 @@ class HfApi:
|
|
|
4590
4500
|
path_in_repo: Optional[str] = None,
|
|
4591
4501
|
commit_message: Optional[str] = None,
|
|
4592
4502
|
commit_description: Optional[str] = None,
|
|
4593
|
-
token:
|
|
4503
|
+
token: Union[str, bool, None] = None,
|
|
4594
4504
|
repo_type: Optional[str] = None,
|
|
4595
4505
|
revision: Optional[str] = None,
|
|
4596
4506
|
create_pr: Optional[bool] = None,
|
|
@@ -4634,9 +4544,11 @@ class HfApi:
|
|
|
4634
4544
|
path_in_repo (`str`, *optional*):
|
|
4635
4545
|
Relative path of the directory in the repo, for example:
|
|
4636
4546
|
`"checkpoints/1fec34a/results"`. Will default to the root folder of the repository.
|
|
4637
|
-
token (
|
|
4638
|
-
|
|
4639
|
-
|
|
4547
|
+
token (Union[bool, str, None], optional):
|
|
4548
|
+
A valid user access token (string). Defaults to the locally saved
|
|
4549
|
+
token, which is the recommended method for authentication (see
|
|
4550
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
4551
|
+
To disable authentication, pass `False`.
|
|
4640
4552
|
repo_type (`str`, *optional*):
|
|
4641
4553
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
4642
4554
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
@@ -4766,7 +4678,7 @@ class HfApi:
|
|
|
4766
4678
|
ignore_patterns = []
|
|
4767
4679
|
elif isinstance(ignore_patterns, str):
|
|
4768
4680
|
ignore_patterns = [ignore_patterns]
|
|
4769
|
-
ignore_patterns +=
|
|
4681
|
+
ignore_patterns += DEFAULT_IGNORE_PATTERNS
|
|
4770
4682
|
|
|
4771
4683
|
delete_operations = self._prepare_upload_folder_deletions(
|
|
4772
4684
|
repo_id=repo_id,
|
|
@@ -4845,7 +4757,7 @@ class HfApi:
|
|
|
4845
4757
|
path_in_repo: str,
|
|
4846
4758
|
repo_id: str,
|
|
4847
4759
|
*,
|
|
4848
|
-
token:
|
|
4760
|
+
token: Union[str, bool, None] = None,
|
|
4849
4761
|
repo_type: Optional[str] = None,
|
|
4850
4762
|
revision: Optional[str] = None,
|
|
4851
4763
|
commit_message: Optional[str] = None,
|
|
@@ -4863,9 +4775,11 @@ class HfApi:
|
|
|
4863
4775
|
repo_id (`str`):
|
|
4864
4776
|
The repository from which the file will be deleted, for example:
|
|
4865
4777
|
`"username/custom_transformers"`
|
|
4866
|
-
token (
|
|
4867
|
-
|
|
4868
|
-
|
|
4778
|
+
token (Union[bool, str, None], optional):
|
|
4779
|
+
A valid user access token (string). Defaults to the locally saved
|
|
4780
|
+
token, which is the recommended method for authentication (see
|
|
4781
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
4782
|
+
To disable authentication, pass `False`.
|
|
4869
4783
|
repo_type (`str`, *optional*):
|
|
4870
4784
|
Set to `"dataset"` or `"space"` if the file is in a dataset or
|
|
4871
4785
|
space, `None` or `"model"` if in a model. Default is `None`.
|
|
@@ -4933,7 +4847,7 @@ class HfApi:
|
|
|
4933
4847
|
path_in_repo: str,
|
|
4934
4848
|
repo_id: str,
|
|
4935
4849
|
*,
|
|
4936
|
-
token:
|
|
4850
|
+
token: Union[bool, str, None] = None,
|
|
4937
4851
|
repo_type: Optional[str] = None,
|
|
4938
4852
|
revision: Optional[str] = None,
|
|
4939
4853
|
commit_message: Optional[str] = None,
|
|
@@ -4952,8 +4866,11 @@ class HfApi:
|
|
|
4952
4866
|
repo_id (`str`):
|
|
4953
4867
|
The repository from which the folder will be deleted, for example:
|
|
4954
4868
|
`"username/custom_transformers"`
|
|
4955
|
-
token (
|
|
4956
|
-
|
|
4869
|
+
token (Union[bool, str, None], optional):
|
|
4870
|
+
A valid user access token (string). Defaults to the locally saved
|
|
4871
|
+
token, which is the recommended method for authentication (see
|
|
4872
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
4873
|
+
To disable authentication, pass `False`.
|
|
4957
4874
|
to the stored token.
|
|
4958
4875
|
repo_type (`str`, *optional*):
|
|
4959
4876
|
Set to `"dataset"` or `"space"` if the folder is in a dataset or
|
|
@@ -5006,12 +4923,11 @@ class HfApi:
|
|
|
5006
4923
|
Args:
|
|
5007
4924
|
url (`str`):
|
|
5008
4925
|
File url, for example returned by [`hf_hub_url`].
|
|
5009
|
-
token (
|
|
5010
|
-
A token
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
- If a string, it's used as the authentication token.
|
|
4926
|
+
token (Union[bool, str, None], optional):
|
|
4927
|
+
A valid user access token (string). Defaults to the locally saved
|
|
4928
|
+
token, which is the recommended method for authentication (see
|
|
4929
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
4930
|
+
To disable authentication, pass `False`.
|
|
5015
4931
|
proxies (`dict`, *optional*):
|
|
5016
4932
|
Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
|
|
5017
4933
|
timeout (`float`, *optional*, defaults to 10):
|
|
@@ -5045,15 +4961,16 @@ class HfApi:
|
|
|
5045
4961
|
revision: Optional[str] = None,
|
|
5046
4962
|
cache_dir: Union[str, Path, None] = None,
|
|
5047
4963
|
local_dir: Union[str, Path, None] = None,
|
|
5048
|
-
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5049
4964
|
force_download: bool = False,
|
|
5050
|
-
force_filename: Optional[str] = None,
|
|
5051
4965
|
proxies: Optional[Dict] = None,
|
|
5052
4966
|
etag_timeout: float = DEFAULT_ETAG_TIMEOUT,
|
|
5053
|
-
|
|
5054
|
-
token: Optional[Union[str, bool]] = None,
|
|
4967
|
+
token: Union[bool, str, None] = None,
|
|
5055
4968
|
local_files_only: bool = False,
|
|
4969
|
+
# Deprecated args
|
|
4970
|
+
resume_download: Optional[bool] = None,
|
|
5056
4971
|
legacy_cache_layout: bool = False,
|
|
4972
|
+
force_filename: Optional[str] = None,
|
|
4973
|
+
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5057
4974
|
) -> str:
|
|
5058
4975
|
"""Download a given file if it's not already present in the local cache.
|
|
5059
4976
|
|
|
@@ -5067,21 +4984,6 @@ class HfApi:
|
|
|
5067
4984
|
that have been resolved at that particular commit. Each filename is a symlink to the blob
|
|
5068
4985
|
at that particular commit.
|
|
5069
4986
|
|
|
5070
|
-
If `local_dir` is provided, the file structure from the repo will be replicated in this location. You can configure
|
|
5071
|
-
how you want to move those files:
|
|
5072
|
-
- If `local_dir_use_symlinks="auto"` (default), files are downloaded and stored in the cache directory as blob
|
|
5073
|
-
files. Small files (<5MB) are duplicated in `local_dir` while a symlink is created for bigger files. The goal
|
|
5074
|
-
is to be able to manually edit and save small files without corrupting the cache while saving disk space for
|
|
5075
|
-
binary files. The 5MB threshold can be configured with the `HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD`
|
|
5076
|
-
environment variable.
|
|
5077
|
-
- If `local_dir_use_symlinks=True`, files are downloaded, stored in the cache directory and symlinked in `local_dir`.
|
|
5078
|
-
This is optimal in term of disk usage but files must not be manually edited.
|
|
5079
|
-
- If `local_dir_use_symlinks=False` and the blob files exist in the cache directory, they are duplicated in the
|
|
5080
|
-
local dir. This means disk usage is not optimized.
|
|
5081
|
-
- Finally, if `local_dir_use_symlinks=False` and the blob files do not exist in the cache directory, then the
|
|
5082
|
-
files are downloaded and directly placed under `local_dir`. This means if you need to download them again later,
|
|
5083
|
-
they will be re-downloaded entirely.
|
|
5084
|
-
|
|
5085
4987
|
```
|
|
5086
4988
|
[ 96] .
|
|
5087
4989
|
└── [ 160] models--julien-c--EsperBERTo-small
|
|
@@ -5100,6 +5002,11 @@ class HfApi:
|
|
|
5100
5002
|
└── [ 76] pytorch_model.bin -> ../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
|
|
5101
5003
|
```
|
|
5102
5004
|
|
|
5005
|
+
If `local_dir` is provided, the file structure from the repo will be replicated in this location. When using this
|
|
5006
|
+
option, the `cache_dir` will not be used and a `.huggingface/` folder will be created at the root of `local_dir`
|
|
5007
|
+
to store some metadata related to the downloaded files. While this mechanism is not as robust as the main
|
|
5008
|
+
cache-system, it's optimized for regularly pulling the latest version of a repository.
|
|
5009
|
+
|
|
5103
5010
|
Args:
|
|
5104
5011
|
repo_id (`str`):
|
|
5105
5012
|
A user or an organization name and a repo name separated by a `/`.
|
|
@@ -5116,13 +5023,7 @@ class HfApi:
|
|
|
5116
5023
|
cache_dir (`str`, `Path`, *optional*):
|
|
5117
5024
|
Path to the folder where cached files are stored.
|
|
5118
5025
|
local_dir (`str` or `Path`, *optional*):
|
|
5119
|
-
If provided, the downloaded file will be placed under this directory
|
|
5120
|
-
a regular file (see description for more details).
|
|
5121
|
-
local_dir_use_symlinks (`"auto"` or `bool`, defaults to `"auto"`):
|
|
5122
|
-
To be used with `local_dir`. If set to "auto", the cache directory will be used and the file will be either
|
|
5123
|
-
duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be
|
|
5124
|
-
created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if
|
|
5125
|
-
already exists) or downloaded from the Hub and not cached. See description for more details.
|
|
5026
|
+
If provided, the downloaded file will be placed under this directory.
|
|
5126
5027
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
5127
5028
|
Whether the file should be downloaded even if it already exists in
|
|
5128
5029
|
the local cache.
|
|
@@ -5132,29 +5033,19 @@ class HfApi:
|
|
|
5132
5033
|
etag_timeout (`float`, *optional*, defaults to `10`):
|
|
5133
5034
|
When fetching ETag, how many seconds to wait for the server to send
|
|
5134
5035
|
data before giving up which is passed to `requests.request`.
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
or [`~huggingface_hub.login`]), token will be retrieved from the cache.
|
|
5141
|
-
If `False`, token is not sent in the request header.
|
|
5036
|
+
token (Union[bool, str, None], optional):
|
|
5037
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5038
|
+
token, which is the recommended method for authentication (see
|
|
5039
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5040
|
+
To disable authentication, pass `False`.
|
|
5142
5041
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
5143
5042
|
If `True`, avoid downloading the file and return the path to the
|
|
5144
5043
|
local cached file if it exists.
|
|
5145
|
-
legacy_cache_layout (`bool`, *optional*, defaults to `False`):
|
|
5146
|
-
If `True`, uses the legacy file cache layout i.e. just call [`hf_hub_url`]
|
|
5147
|
-
then `cached_download`. This is deprecated as the new cache layout is
|
|
5148
|
-
more powerful.
|
|
5149
5044
|
|
|
5150
5045
|
Returns:
|
|
5151
|
-
Local path
|
|
5152
|
-
file cached on disk.
|
|
5153
|
-
|
|
5154
|
-
<Tip>
|
|
5155
|
-
|
|
5156
|
-
Raises the following errors:
|
|
5046
|
+
`str`: Local path of file or if networking is off, last version of file cached on disk.
|
|
5157
5047
|
|
|
5048
|
+
Raises:
|
|
5158
5049
|
- [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
|
|
5159
5050
|
if `token=True` and the token cannot be found.
|
|
5160
5051
|
- [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError)
|
|
@@ -5170,8 +5061,6 @@ class HfApi:
|
|
|
5170
5061
|
If the file to download cannot be found.
|
|
5171
5062
|
- [`~utils.LocalEntryNotFoundError`]
|
|
5172
5063
|
If network is disabled or unavailable and file is not found in cache.
|
|
5173
|
-
|
|
5174
|
-
</Tip>
|
|
5175
5064
|
"""
|
|
5176
5065
|
from .file_download import hf_hub_download
|
|
5177
5066
|
|
|
@@ -5212,17 +5101,18 @@ class HfApi:
|
|
|
5212
5101
|
revision: Optional[str] = None,
|
|
5213
5102
|
cache_dir: Union[str, Path, None] = None,
|
|
5214
5103
|
local_dir: Union[str, Path, None] = None,
|
|
5215
|
-
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5216
5104
|
proxies: Optional[Dict] = None,
|
|
5217
5105
|
etag_timeout: float = DEFAULT_ETAG_TIMEOUT,
|
|
5218
|
-
resume_download: bool = False,
|
|
5219
5106
|
force_download: bool = False,
|
|
5220
|
-
token:
|
|
5107
|
+
token: Union[bool, str, None] = None,
|
|
5221
5108
|
local_files_only: bool = False,
|
|
5222
5109
|
allow_patterns: Optional[Union[List[str], str]] = None,
|
|
5223
5110
|
ignore_patterns: Optional[Union[List[str], str]] = None,
|
|
5224
5111
|
max_workers: int = 8,
|
|
5225
5112
|
tqdm_class: Optional[base_tqdm] = None,
|
|
5113
|
+
# Deprecated args
|
|
5114
|
+
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5115
|
+
resume_download: Optional[bool] = None,
|
|
5226
5116
|
) -> str:
|
|
5227
5117
|
"""Download repo files.
|
|
5228
5118
|
|
|
@@ -5231,20 +5121,10 @@ class HfApi:
|
|
|
5231
5121
|
to keep their actual filename relative to that folder. You can also filter which files to download using
|
|
5232
5122
|
`allow_patterns` and `ignore_patterns`.
|
|
5233
5123
|
|
|
5234
|
-
If `local_dir` is provided, the file structure from the repo will be replicated in this location.
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
is to be able to manually edit and save small files without corrupting the cache while saving disk space for
|
|
5239
|
-
binary files. The 5MB threshold can be configured with the `HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD`
|
|
5240
|
-
environment variable.
|
|
5241
|
-
- If `local_dir_use_symlinks=True`, files are downloaded, stored in the cache directory and symlinked in `local_dir`.
|
|
5242
|
-
This is optimal in term of disk usage but files must not be manually edited.
|
|
5243
|
-
- If `local_dir_use_symlinks=False` and the blob files exist in the cache directory, they are duplicated in the
|
|
5244
|
-
local dir. This means disk usage is not optimized.
|
|
5245
|
-
- Finally, if `local_dir_use_symlinks=False` and the blob files do not exist in the cache directory, then the
|
|
5246
|
-
files are downloaded and directly placed under `local_dir`. This means if you need to download them again later,
|
|
5247
|
-
they will be re-downloaded entirely.
|
|
5124
|
+
If `local_dir` is provided, the file structure from the repo will be replicated in this location. When using this
|
|
5125
|
+
option, the `cache_dir` will not be used and a `.huggingface/` folder will be created at the root of `local_dir`
|
|
5126
|
+
to store some metadata related to the downloaded files.While this mechanism is not as robust as the main
|
|
5127
|
+
cache-system, it's optimized for regularly pulling the latest version of a repository.
|
|
5248
5128
|
|
|
5249
5129
|
An alternative would be to clone the repo but this requires git and git-lfs to be installed and properly
|
|
5250
5130
|
configured. It is also not possible to filter which files to download when cloning a repository using git.
|
|
@@ -5261,28 +5141,20 @@ class HfApi:
|
|
|
5261
5141
|
cache_dir (`str`, `Path`, *optional*):
|
|
5262
5142
|
Path to the folder where cached files are stored.
|
|
5263
5143
|
local_dir (`str` or `Path`, *optional*):
|
|
5264
|
-
If provided, the downloaded files will be placed under this directory
|
|
5265
|
-
regular files (see description for more details).
|
|
5266
|
-
local_dir_use_symlinks (`"auto"` or `bool`, defaults to `"auto"`):
|
|
5267
|
-
To be used with `local_dir`. If set to "auto", the cache directory will be used and the file will be either
|
|
5268
|
-
duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be
|
|
5269
|
-
created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if
|
|
5270
|
-
already exists) or downloaded from the Hub and not cached. See description for more details.
|
|
5144
|
+
If provided, the downloaded files will be placed under this directory.
|
|
5271
5145
|
proxies (`dict`, *optional*):
|
|
5272
5146
|
Dictionary mapping protocol to the URL of the proxy passed to
|
|
5273
5147
|
`requests.request`.
|
|
5274
5148
|
etag_timeout (`float`, *optional*, defaults to `10`):
|
|
5275
5149
|
When fetching ETag, how many seconds to wait for the server to send
|
|
5276
5150
|
data before giving up which is passed to `requests.request`.
|
|
5277
|
-
resume_download (`bool`, *optional*, defaults to `False):
|
|
5278
|
-
If `True`, resume a previously interrupted download.
|
|
5279
5151
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
5280
5152
|
Whether the file should be downloaded even if it already exists in the local cache.
|
|
5281
|
-
token (
|
|
5282
|
-
A valid
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5153
|
+
token (Union[bool, str, None], optional):
|
|
5154
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5155
|
+
token, which is the recommended method for authentication (see
|
|
5156
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5157
|
+
To disable authentication, pass `False`.
|
|
5286
5158
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
5287
5159
|
If `True`, avoid downloading the file and return the path to the
|
|
5288
5160
|
local cached file if it exists.
|
|
@@ -5301,20 +5173,15 @@ class HfApi:
|
|
|
5301
5173
|
`HF_HUB_DISABLE_PROGRESS_BARS` environment variable.
|
|
5302
5174
|
|
|
5303
5175
|
Returns:
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
<Tip>
|
|
5176
|
+
`str`: folder path of the repo snapshot.
|
|
5307
5177
|
|
|
5308
|
-
Raises
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
if some parameter value is invalid
|
|
5316
|
-
|
|
5317
|
-
</Tip>
|
|
5178
|
+
Raises:
|
|
5179
|
+
- [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
|
|
5180
|
+
if `token=True` and the token cannot be found.
|
|
5181
|
+
- [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if
|
|
5182
|
+
ETag cannot be determined.
|
|
5183
|
+
- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
|
|
5184
|
+
if some parameter value is invalid
|
|
5318
5185
|
"""
|
|
5319
5186
|
from ._snapshot_download import snapshot_download
|
|
5320
5187
|
|
|
@@ -5351,7 +5218,7 @@ class HfApi:
|
|
|
5351
5218
|
*,
|
|
5352
5219
|
repo_type: Optional[str] = None,
|
|
5353
5220
|
revision: Optional[str] = None,
|
|
5354
|
-
token:
|
|
5221
|
+
token: Union[bool, str, None] = None,
|
|
5355
5222
|
) -> SafetensorsRepoMetadata:
|
|
5356
5223
|
"""
|
|
5357
5224
|
Parse metadata for a safetensors repo on the Hub.
|
|
@@ -5375,10 +5242,11 @@ class HfApi:
|
|
|
5375
5242
|
revision (`str`, *optional*):
|
|
5376
5243
|
The git revision to fetch the file from. Can be a branch name, a tag, or a commit hash. Defaults to the
|
|
5377
5244
|
head of the `"main"` branch.
|
|
5378
|
-
token (
|
|
5379
|
-
A valid
|
|
5380
|
-
|
|
5381
|
-
|
|
5245
|
+
token (Union[bool, str, None], optional):
|
|
5246
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5247
|
+
token, which is the recommended method for authentication (see
|
|
5248
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5249
|
+
To disable authentication, pass `False`.
|
|
5382
5250
|
|
|
5383
5251
|
Returns:
|
|
5384
5252
|
[`SafetensorsRepoMetadata`]: information related to safetensors repo.
|
|
@@ -5473,7 +5341,7 @@ class HfApi:
|
|
|
5473
5341
|
*,
|
|
5474
5342
|
repo_type: Optional[str] = None,
|
|
5475
5343
|
revision: Optional[str] = None,
|
|
5476
|
-
token:
|
|
5344
|
+
token: Union[bool, str, None] = None,
|
|
5477
5345
|
) -> SafetensorsFileMetadata:
|
|
5478
5346
|
"""
|
|
5479
5347
|
Parse metadata from a safetensors file on the Hub.
|
|
@@ -5493,10 +5361,11 @@ class HfApi:
|
|
|
5493
5361
|
revision (`str`, *optional*):
|
|
5494
5362
|
The git revision to fetch the file from. Can be a branch name, a tag, or a commit hash. Defaults to the
|
|
5495
5363
|
head of the `"main"` branch.
|
|
5496
|
-
token (
|
|
5497
|
-
A valid
|
|
5498
|
-
|
|
5499
|
-
|
|
5364
|
+
token (Union[bool, str, None], optional):
|
|
5365
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5366
|
+
token, which is the recommended method for authentication (see
|
|
5367
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5368
|
+
To disable authentication, pass `False`.
|
|
5500
5369
|
|
|
5501
5370
|
Returns:
|
|
5502
5371
|
[`SafetensorsFileMetadata`]: information related to a safetensors file.
|
|
@@ -5573,7 +5442,7 @@ class HfApi:
|
|
|
5573
5442
|
*,
|
|
5574
5443
|
branch: str,
|
|
5575
5444
|
revision: Optional[str] = None,
|
|
5576
|
-
token:
|
|
5445
|
+
token: Union[bool, str, None] = None,
|
|
5577
5446
|
repo_type: Optional[str] = None,
|
|
5578
5447
|
exist_ok: bool = False,
|
|
5579
5448
|
) -> None:
|
|
@@ -5594,8 +5463,11 @@ class HfApi:
|
|
|
5594
5463
|
the OID/SHA of a commit, as a hexadecimal string. Defaults to the head
|
|
5595
5464
|
of the `"main"` branch.
|
|
5596
5465
|
|
|
5597
|
-
token (
|
|
5598
|
-
|
|
5466
|
+
token (Union[bool, str, None], optional):
|
|
5467
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5468
|
+
token, which is the recommended method for authentication (see
|
|
5469
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5470
|
+
To disable authentication, pass `False`.
|
|
5599
5471
|
|
|
5600
5472
|
repo_type (`str`, *optional*):
|
|
5601
5473
|
Set to `"dataset"` or `"space"` if creating a branch on a dataset or
|
|
@@ -5639,7 +5511,7 @@ class HfApi:
|
|
|
5639
5511
|
repo_id: str,
|
|
5640
5512
|
*,
|
|
5641
5513
|
branch: str,
|
|
5642
|
-
token:
|
|
5514
|
+
token: Union[bool, str, None] = None,
|
|
5643
5515
|
repo_type: Optional[str] = None,
|
|
5644
5516
|
) -> None:
|
|
5645
5517
|
"""
|
|
@@ -5653,8 +5525,11 @@ class HfApi:
|
|
|
5653
5525
|
branch (`str`):
|
|
5654
5526
|
The name of the branch to delete.
|
|
5655
5527
|
|
|
5656
|
-
token (
|
|
5657
|
-
|
|
5528
|
+
token (Union[bool, str, None], optional):
|
|
5529
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5530
|
+
token, which is the recommended method for authentication (see
|
|
5531
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5532
|
+
To disable authentication, pass `False`.
|
|
5658
5533
|
|
|
5659
5534
|
repo_type (`str`, *optional*):
|
|
5660
5535
|
Set to `"dataset"` or `"space"` if creating a branch on a dataset or
|
|
@@ -5690,7 +5565,7 @@ class HfApi:
|
|
|
5690
5565
|
tag: str,
|
|
5691
5566
|
tag_message: Optional[str] = None,
|
|
5692
5567
|
revision: Optional[str] = None,
|
|
5693
|
-
token:
|
|
5568
|
+
token: Union[bool, str, None] = None,
|
|
5694
5569
|
repo_type: Optional[str] = None,
|
|
5695
5570
|
exist_ok: bool = False,
|
|
5696
5571
|
) -> None:
|
|
@@ -5713,8 +5588,11 @@ class HfApi:
|
|
|
5713
5588
|
commit, as a hexadecimal string. Shorthands (7 first characters) are
|
|
5714
5589
|
also supported. Defaults to the head of the `"main"` branch.
|
|
5715
5590
|
|
|
5716
|
-
token (
|
|
5717
|
-
|
|
5591
|
+
token (Union[bool, str, None], optional):
|
|
5592
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5593
|
+
token, which is the recommended method for authentication (see
|
|
5594
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5595
|
+
To disable authentication, pass `False`.
|
|
5718
5596
|
|
|
5719
5597
|
repo_type (`str`, *optional*):
|
|
5720
5598
|
Set to `"dataset"` or `"space"` if tagging a dataset or
|
|
@@ -5759,7 +5637,7 @@ class HfApi:
|
|
|
5759
5637
|
repo_id: str,
|
|
5760
5638
|
*,
|
|
5761
5639
|
tag: str,
|
|
5762
|
-
token:
|
|
5640
|
+
token: Union[bool, str, None] = None,
|
|
5763
5641
|
repo_type: Optional[str] = None,
|
|
5764
5642
|
) -> None:
|
|
5765
5643
|
"""
|
|
@@ -5773,8 +5651,11 @@ class HfApi:
|
|
|
5773
5651
|
tag (`str`):
|
|
5774
5652
|
The name of the tag to delete.
|
|
5775
5653
|
|
|
5776
|
-
token (
|
|
5777
|
-
|
|
5654
|
+
token (Union[bool, str, None], optional):
|
|
5655
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5656
|
+
token, which is the recommended method for authentication (see
|
|
5657
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5658
|
+
To disable authentication, pass `False`.
|
|
5778
5659
|
|
|
5779
5660
|
repo_type (`str`, *optional*):
|
|
5780
5661
|
Set to `"dataset"` or `"space"` if tagging a dataset or space, `None` or
|
|
@@ -5805,7 +5686,7 @@ class HfApi:
|
|
|
5805
5686
|
model_id: str,
|
|
5806
5687
|
*,
|
|
5807
5688
|
organization: Optional[str] = None,
|
|
5808
|
-
token:
|
|
5689
|
+
token: Union[bool, str, None] = None,
|
|
5809
5690
|
):
|
|
5810
5691
|
"""
|
|
5811
5692
|
Returns the repository name for a given model ID and optional
|
|
@@ -5817,11 +5698,11 @@ class HfApi:
|
|
|
5817
5698
|
organization (`str`, *optional*):
|
|
5818
5699
|
If passed, the repository name will be in the organization
|
|
5819
5700
|
namespace instead of the user namespace.
|
|
5820
|
-
token (
|
|
5821
|
-
A valid
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5701
|
+
token (Union[bool, str, None], optional):
|
|
5702
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5703
|
+
token, which is the recommended method for authentication (see
|
|
5704
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5705
|
+
To disable authentication, pass `False`.
|
|
5825
5706
|
|
|
5826
5707
|
Returns:
|
|
5827
5708
|
`str`: The repository name in the user's namespace
|
|
@@ -5846,7 +5727,7 @@ class HfApi:
|
|
|
5846
5727
|
discussion_type: Optional[DiscussionTypeFilter] = None,
|
|
5847
5728
|
discussion_status: Optional[DiscussionStatusFilter] = None,
|
|
5848
5729
|
repo_type: Optional[str] = None,
|
|
5849
|
-
token:
|
|
5730
|
+
token: Union[bool, str, None] = None,
|
|
5850
5731
|
) -> Iterator[Discussion]:
|
|
5851
5732
|
"""
|
|
5852
5733
|
Fetches Discussions and Pull Requests for the given repo.
|
|
@@ -5871,8 +5752,11 @@ class HfApi:
|
|
|
5871
5752
|
Set to `"dataset"` or `"space"` if fetching from a dataset or
|
|
5872
5753
|
space, `None` or `"model"` if fetching from a model. Default is
|
|
5873
5754
|
`None`.
|
|
5874
|
-
token (
|
|
5875
|
-
|
|
5755
|
+
token (Union[bool, str, None], optional):
|
|
5756
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5757
|
+
token, which is the recommended method for authentication (see
|
|
5758
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5759
|
+
To disable authentication, pass `False`.
|
|
5876
5760
|
|
|
5877
5761
|
Returns:
|
|
5878
5762
|
`Iterator[Discussion]`: An iterator of [`Discussion`] objects.
|
|
@@ -5949,7 +5833,7 @@ class HfApi:
|
|
|
5949
5833
|
discussion_num: int,
|
|
5950
5834
|
*,
|
|
5951
5835
|
repo_type: Optional[str] = None,
|
|
5952
|
-
token:
|
|
5836
|
+
token: Union[bool, str, None] = None,
|
|
5953
5837
|
) -> DiscussionWithDetails:
|
|
5954
5838
|
"""Fetches a Discussion's / Pull Request 's details from the Hub.
|
|
5955
5839
|
|
|
@@ -5963,8 +5847,11 @@ class HfApi:
|
|
|
5963
5847
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
5964
5848
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
5965
5849
|
`None`.
|
|
5966
|
-
token (
|
|
5967
|
-
|
|
5850
|
+
token (Union[bool, str, None], optional):
|
|
5851
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5852
|
+
token, which is the recommended method for authentication (see
|
|
5853
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5854
|
+
To disable authentication, pass `False`.
|
|
5968
5855
|
|
|
5969
5856
|
Returns: [`DiscussionWithDetails`]
|
|
5970
5857
|
|
|
@@ -6024,7 +5911,7 @@ class HfApi:
|
|
|
6024
5911
|
repo_id: str,
|
|
6025
5912
|
title: str,
|
|
6026
5913
|
*,
|
|
6027
|
-
token:
|
|
5914
|
+
token: Union[bool, str, None] = None,
|
|
6028
5915
|
description: Optional[str] = None,
|
|
6029
5916
|
repo_type: Optional[str] = None,
|
|
6030
5917
|
pull_request: bool = False,
|
|
@@ -6043,8 +5930,11 @@ class HfApi:
|
|
|
6043
5930
|
The title of the discussion. It can be up to 200 characters long,
|
|
6044
5931
|
and must be at least 3 characters long. Leading and trailing whitespaces
|
|
6045
5932
|
will be stripped.
|
|
6046
|
-
token (
|
|
6047
|
-
|
|
5933
|
+
token (Union[bool, str, None], optional):
|
|
5934
|
+
A valid user access token (string). Defaults to the locally saved
|
|
5935
|
+
token, which is the recommended method for authentication (see
|
|
5936
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
5937
|
+
To disable authentication, pass `False`.
|
|
6048
5938
|
description (`str`, *optional*):
|
|
6049
5939
|
An optional description for the Pull Request.
|
|
6050
5940
|
Defaults to `"Discussion opened with the huggingface_hub Python library"`
|
|
@@ -6113,7 +6003,7 @@ class HfApi:
|
|
|
6113
6003
|
repo_id: str,
|
|
6114
6004
|
title: str,
|
|
6115
6005
|
*,
|
|
6116
|
-
token:
|
|
6006
|
+
token: Union[bool, str, None] = None,
|
|
6117
6007
|
description: Optional[str] = None,
|
|
6118
6008
|
repo_type: Optional[str] = None,
|
|
6119
6009
|
) -> DiscussionWithDetails:
|
|
@@ -6131,8 +6021,11 @@ class HfApi:
|
|
|
6131
6021
|
The title of the discussion. It can be up to 200 characters long,
|
|
6132
6022
|
and must be at least 3 characters long. Leading and trailing whitespaces
|
|
6133
6023
|
will be stripped.
|
|
6134
|
-
token (
|
|
6135
|
-
|
|
6024
|
+
token (Union[bool, str, None], optional):
|
|
6025
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6026
|
+
token, which is the recommended method for authentication (see
|
|
6027
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6028
|
+
To disable authentication, pass `False`.
|
|
6136
6029
|
description (`str`, *optional*):
|
|
6137
6030
|
An optional description for the Pull Request.
|
|
6138
6031
|
Defaults to `"Discussion opened with the huggingface_hub Python library"`
|
|
@@ -6172,7 +6065,7 @@ class HfApi:
|
|
|
6172
6065
|
discussion_num: int,
|
|
6173
6066
|
resource: str,
|
|
6174
6067
|
body: Optional[dict] = None,
|
|
6175
|
-
token:
|
|
6068
|
+
token: Union[bool, str, None] = None,
|
|
6176
6069
|
repo_type: Optional[str] = None,
|
|
6177
6070
|
) -> requests.Response:
|
|
6178
6071
|
"""Internal utility to POST changes to a Discussion or Pull Request"""
|
|
@@ -6198,7 +6091,7 @@ class HfApi:
|
|
|
6198
6091
|
discussion_num: int,
|
|
6199
6092
|
comment: str,
|
|
6200
6093
|
*,
|
|
6201
|
-
token:
|
|
6094
|
+
token: Union[bool, str, None] = None,
|
|
6202
6095
|
repo_type: Optional[str] = None,
|
|
6203
6096
|
) -> DiscussionComment:
|
|
6204
6097
|
"""Creates a new comment on the given Discussion.
|
|
@@ -6215,8 +6108,11 @@ class HfApi:
|
|
|
6215
6108
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
6216
6109
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
6217
6110
|
`None`.
|
|
6218
|
-
token (
|
|
6219
|
-
|
|
6111
|
+
token (Union[bool, str, None], optional):
|
|
6112
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6113
|
+
token, which is the recommended method for authentication (see
|
|
6114
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6115
|
+
To disable authentication, pass `False`.
|
|
6220
6116
|
|
|
6221
6117
|
Returns:
|
|
6222
6118
|
[`DiscussionComment`]: the newly created comment
|
|
@@ -6274,7 +6170,7 @@ class HfApi:
|
|
|
6274
6170
|
discussion_num: int,
|
|
6275
6171
|
new_title: str,
|
|
6276
6172
|
*,
|
|
6277
|
-
token:
|
|
6173
|
+
token: Union[bool, str, None] = None,
|
|
6278
6174
|
repo_type: Optional[str] = None,
|
|
6279
6175
|
) -> DiscussionTitleChange:
|
|
6280
6176
|
"""Renames a Discussion.
|
|
@@ -6291,8 +6187,11 @@ class HfApi:
|
|
|
6291
6187
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
6292
6188
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
6293
6189
|
`None`.
|
|
6294
|
-
token (
|
|
6295
|
-
|
|
6190
|
+
token (Union[bool, str, None], optional):
|
|
6191
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6192
|
+
token, which is the recommended method for authentication (see
|
|
6193
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6194
|
+
To disable authentication, pass `False`.
|
|
6296
6195
|
|
|
6297
6196
|
Returns:
|
|
6298
6197
|
[`DiscussionTitleChange`]: the title change event
|
|
@@ -6341,7 +6240,7 @@ class HfApi:
|
|
|
6341
6240
|
discussion_num: int,
|
|
6342
6241
|
new_status: Literal["open", "closed"],
|
|
6343
6242
|
*,
|
|
6344
|
-
token:
|
|
6243
|
+
token: Union[bool, str, None] = None,
|
|
6345
6244
|
comment: Optional[str] = None,
|
|
6346
6245
|
repo_type: Optional[str] = None,
|
|
6347
6246
|
) -> DiscussionStatusChange:
|
|
@@ -6361,8 +6260,11 @@ class HfApi:
|
|
|
6361
6260
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
6362
6261
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
6363
6262
|
`None`.
|
|
6364
|
-
token (
|
|
6365
|
-
|
|
6263
|
+
token (Union[bool, str, None], optional):
|
|
6264
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6265
|
+
token, which is the recommended method for authentication (see
|
|
6266
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6267
|
+
To disable authentication, pass `False`.
|
|
6366
6268
|
|
|
6367
6269
|
Returns:
|
|
6368
6270
|
[`DiscussionStatusChange`]: the status change event
|
|
@@ -6415,7 +6317,7 @@ class HfApi:
|
|
|
6415
6317
|
repo_id: str,
|
|
6416
6318
|
discussion_num: int,
|
|
6417
6319
|
*,
|
|
6418
|
-
token:
|
|
6320
|
+
token: Union[bool, str, None] = None,
|
|
6419
6321
|
comment: Optional[str] = None,
|
|
6420
6322
|
repo_type: Optional[str] = None,
|
|
6421
6323
|
):
|
|
@@ -6433,8 +6335,11 @@ class HfApi:
|
|
|
6433
6335
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
6434
6336
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
6435
6337
|
`None`.
|
|
6436
|
-
token (
|
|
6437
|
-
|
|
6338
|
+
token (Union[bool, str, None], optional):
|
|
6339
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6340
|
+
token, which is the recommended method for authentication (see
|
|
6341
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6342
|
+
To disable authentication, pass `False`.
|
|
6438
6343
|
|
|
6439
6344
|
Returns:
|
|
6440
6345
|
[`DiscussionStatusChange`]: the status change event
|
|
@@ -6470,7 +6375,7 @@ class HfApi:
|
|
|
6470
6375
|
comment_id: str,
|
|
6471
6376
|
new_content: str,
|
|
6472
6377
|
*,
|
|
6473
|
-
token:
|
|
6378
|
+
token: Union[bool, str, None] = None,
|
|
6474
6379
|
repo_type: Optional[str] = None,
|
|
6475
6380
|
) -> DiscussionComment:
|
|
6476
6381
|
"""Edits a comment on a Discussion / Pull Request.
|
|
@@ -6489,8 +6394,11 @@ class HfApi:
|
|
|
6489
6394
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
6490
6395
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
6491
6396
|
`None`.
|
|
6492
|
-
token (
|
|
6493
|
-
|
|
6397
|
+
token (Union[bool, str, None], optional):
|
|
6398
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6399
|
+
token, which is the recommended method for authentication (see
|
|
6400
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6401
|
+
To disable authentication, pass `False`.
|
|
6494
6402
|
|
|
6495
6403
|
Returns:
|
|
6496
6404
|
[`DiscussionComment`]: the edited comment
|
|
@@ -6526,7 +6434,7 @@ class HfApi:
|
|
|
6526
6434
|
discussion_num: int,
|
|
6527
6435
|
comment_id: str,
|
|
6528
6436
|
*,
|
|
6529
|
-
token:
|
|
6437
|
+
token: Union[bool, str, None] = None,
|
|
6530
6438
|
repo_type: Optional[str] = None,
|
|
6531
6439
|
) -> DiscussionComment:
|
|
6532
6440
|
"""Hides a comment on a Discussion / Pull Request.
|
|
@@ -6547,8 +6455,11 @@ class HfApi:
|
|
|
6547
6455
|
Set to `"dataset"` or `"space"` if uploading to a dataset or
|
|
6548
6456
|
space, `None` or `"model"` if uploading to a model. Default is
|
|
6549
6457
|
`None`.
|
|
6550
|
-
token (
|
|
6551
|
-
|
|
6458
|
+
token (Union[bool, str, None], optional):
|
|
6459
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6460
|
+
token, which is the recommended method for authentication (see
|
|
6461
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6462
|
+
To disable authentication, pass `False`.
|
|
6552
6463
|
|
|
6553
6464
|
Returns:
|
|
6554
6465
|
[`DiscussionComment`]: the hidden comment
|
|
@@ -6582,7 +6493,13 @@ class HfApi:
|
|
|
6582
6493
|
|
|
6583
6494
|
@validate_hf_hub_args
|
|
6584
6495
|
def add_space_secret(
|
|
6585
|
-
self,
|
|
6496
|
+
self,
|
|
6497
|
+
repo_id: str,
|
|
6498
|
+
key: str,
|
|
6499
|
+
value: str,
|
|
6500
|
+
*,
|
|
6501
|
+
description: Optional[str] = None,
|
|
6502
|
+
token: Union[bool, str, None] = None,
|
|
6586
6503
|
) -> None:
|
|
6587
6504
|
"""Adds or updates a secret in a Space.
|
|
6588
6505
|
|
|
@@ -6598,8 +6515,11 @@ class HfApi:
|
|
|
6598
6515
|
Secret value. Example: `"your_github_api_key"`.
|
|
6599
6516
|
description (`str`, *optional*):
|
|
6600
6517
|
Secret description. Example: `"Github API key to access the Github API"`.
|
|
6601
|
-
token (
|
|
6602
|
-
|
|
6518
|
+
token (Union[bool, str, None], optional):
|
|
6519
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6520
|
+
token, which is the recommended method for authentication (see
|
|
6521
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6522
|
+
To disable authentication, pass `False`.
|
|
6603
6523
|
"""
|
|
6604
6524
|
payload = {"key": key, "value": value}
|
|
6605
6525
|
if description is not None:
|
|
@@ -6612,7 +6532,7 @@ class HfApi:
|
|
|
6612
6532
|
hf_raise_for_status(r)
|
|
6613
6533
|
|
|
6614
6534
|
@validate_hf_hub_args
|
|
6615
|
-
def delete_space_secret(self, repo_id: str, key: str, *, token:
|
|
6535
|
+
def delete_space_secret(self, repo_id: str, key: str, *, token: Union[bool, str, None] = None) -> None:
|
|
6616
6536
|
"""Deletes a secret from a Space.
|
|
6617
6537
|
|
|
6618
6538
|
Secrets allow to set secret keys or tokens to a Space without hardcoding them.
|
|
@@ -6623,8 +6543,11 @@ class HfApi:
|
|
|
6623
6543
|
ID of the repo to update. Example: `"bigcode/in-the-stack"`.
|
|
6624
6544
|
key (`str`):
|
|
6625
6545
|
Secret key. Example: `"GITHUB_API_KEY"`.
|
|
6626
|
-
token (
|
|
6627
|
-
|
|
6546
|
+
token (Union[bool, str, None], optional):
|
|
6547
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6548
|
+
token, which is the recommended method for authentication (see
|
|
6549
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6550
|
+
To disable authentication, pass `False`.
|
|
6628
6551
|
"""
|
|
6629
6552
|
r = get_session().delete(
|
|
6630
6553
|
f"{self.endpoint}/api/spaces/{repo_id}/secrets",
|
|
@@ -6634,7 +6557,7 @@ class HfApi:
|
|
|
6634
6557
|
hf_raise_for_status(r)
|
|
6635
6558
|
|
|
6636
6559
|
@validate_hf_hub_args
|
|
6637
|
-
def get_space_variables(self, repo_id: str, *, token:
|
|
6560
|
+
def get_space_variables(self, repo_id: str, *, token: Union[bool, str, None] = None) -> Dict[str, SpaceVariable]:
|
|
6638
6561
|
"""Gets all variables from a Space.
|
|
6639
6562
|
|
|
6640
6563
|
Variables allow to set environment variables to a Space without hardcoding them.
|
|
@@ -6643,8 +6566,11 @@ class HfApi:
|
|
|
6643
6566
|
Args:
|
|
6644
6567
|
repo_id (`str`):
|
|
6645
6568
|
ID of the repo to query. Example: `"bigcode/in-the-stack"`.
|
|
6646
|
-
token (
|
|
6647
|
-
|
|
6569
|
+
token (Union[bool, str, None], optional):
|
|
6570
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6571
|
+
token, which is the recommended method for authentication (see
|
|
6572
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6573
|
+
To disable authentication, pass `False`.
|
|
6648
6574
|
"""
|
|
6649
6575
|
r = get_session().get(
|
|
6650
6576
|
f"{self.endpoint}/api/spaces/{repo_id}/variables",
|
|
@@ -6655,7 +6581,13 @@ class HfApi:
|
|
|
6655
6581
|
|
|
6656
6582
|
@validate_hf_hub_args
|
|
6657
6583
|
def add_space_variable(
|
|
6658
|
-
self,
|
|
6584
|
+
self,
|
|
6585
|
+
repo_id: str,
|
|
6586
|
+
key: str,
|
|
6587
|
+
value: str,
|
|
6588
|
+
*,
|
|
6589
|
+
description: Optional[str] = None,
|
|
6590
|
+
token: Union[bool, str, None] = None,
|
|
6659
6591
|
) -> Dict[str, SpaceVariable]:
|
|
6660
6592
|
"""Adds or updates a variable in a Space.
|
|
6661
6593
|
|
|
@@ -6671,8 +6603,11 @@ class HfApi:
|
|
|
6671
6603
|
Variable value. Example: `"the_model_repo_id"`.
|
|
6672
6604
|
description (`str`):
|
|
6673
6605
|
Description of the variable. Example: `"Model Repo ID of the implemented model"`.
|
|
6674
|
-
token (
|
|
6675
|
-
|
|
6606
|
+
token (Union[bool, str, None], optional):
|
|
6607
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6608
|
+
token, which is the recommended method for authentication (see
|
|
6609
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6610
|
+
To disable authentication, pass `False`.
|
|
6676
6611
|
"""
|
|
6677
6612
|
payload = {"key": key, "value": value}
|
|
6678
6613
|
if description is not None:
|
|
@@ -6687,7 +6622,7 @@ class HfApi:
|
|
|
6687
6622
|
|
|
6688
6623
|
@validate_hf_hub_args
|
|
6689
6624
|
def delete_space_variable(
|
|
6690
|
-
self, repo_id: str, key: str, *, token:
|
|
6625
|
+
self, repo_id: str, key: str, *, token: Union[bool, str, None] = None
|
|
6691
6626
|
) -> Dict[str, SpaceVariable]:
|
|
6692
6627
|
"""Deletes a variable from a Space.
|
|
6693
6628
|
|
|
@@ -6699,8 +6634,11 @@ class HfApi:
|
|
|
6699
6634
|
ID of the repo to update. Example: `"bigcode/in-the-stack"`.
|
|
6700
6635
|
key (`str`):
|
|
6701
6636
|
Variable key. Example: `"MODEL_REPO_ID"`
|
|
6702
|
-
token (
|
|
6703
|
-
|
|
6637
|
+
token (Union[bool, str, None], optional):
|
|
6638
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6639
|
+
token, which is the recommended method for authentication (see
|
|
6640
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6641
|
+
To disable authentication, pass `False`.
|
|
6704
6642
|
"""
|
|
6705
6643
|
r = get_session().delete(
|
|
6706
6644
|
f"{self.endpoint}/api/spaces/{repo_id}/variables",
|
|
@@ -6711,15 +6649,17 @@ class HfApi:
|
|
|
6711
6649
|
return {k: SpaceVariable(k, v) for k, v in r.json().items()}
|
|
6712
6650
|
|
|
6713
6651
|
@validate_hf_hub_args
|
|
6714
|
-
def get_space_runtime(self, repo_id: str, *, token:
|
|
6652
|
+
def get_space_runtime(self, repo_id: str, *, token: Union[bool, str, None] = None) -> SpaceRuntime:
|
|
6715
6653
|
"""Gets runtime information about a Space.
|
|
6716
6654
|
|
|
6717
6655
|
Args:
|
|
6718
6656
|
repo_id (`str`):
|
|
6719
6657
|
ID of the repo to update. Example: `"bigcode/in-the-stack"`.
|
|
6720
|
-
token (
|
|
6721
|
-
|
|
6722
|
-
|
|
6658
|
+
token (Union[bool, str, None], optional):
|
|
6659
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6660
|
+
token, which is the recommended method for authentication (see
|
|
6661
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6662
|
+
To disable authentication, pass `False`.
|
|
6723
6663
|
Returns:
|
|
6724
6664
|
[`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
|
|
6725
6665
|
"""
|
|
@@ -6735,7 +6675,7 @@ class HfApi:
|
|
|
6735
6675
|
repo_id: str,
|
|
6736
6676
|
hardware: SpaceHardware,
|
|
6737
6677
|
*,
|
|
6738
|
-
token:
|
|
6678
|
+
token: Union[bool, str, None] = None,
|
|
6739
6679
|
sleep_time: Optional[int] = None,
|
|
6740
6680
|
) -> SpaceRuntime:
|
|
6741
6681
|
"""Request new hardware for a Space.
|
|
@@ -6745,8 +6685,11 @@ class HfApi:
|
|
|
6745
6685
|
ID of the repo to update. Example: `"bigcode/in-the-stack"`.
|
|
6746
6686
|
hardware (`str` or [`SpaceHardware`]):
|
|
6747
6687
|
Hardware on which to run the Space. Example: `"t4-medium"`.
|
|
6748
|
-
token (
|
|
6749
|
-
|
|
6688
|
+
token (Union[bool, str, None], optional):
|
|
6689
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6690
|
+
token, which is the recommended method for authentication (see
|
|
6691
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6692
|
+
To disable authentication, pass `False`.
|
|
6750
6693
|
sleep_time (`int`, *optional*):
|
|
6751
6694
|
Number of seconds of inactivity to wait before a Space is put to sleep. Set to `-1` if you don't want
|
|
6752
6695
|
your Space to sleep (default behavior for upgraded hardware). For free hardware, you can't configure
|
|
@@ -6780,7 +6723,9 @@ class HfApi:
|
|
|
6780
6723
|
return SpaceRuntime(r.json())
|
|
6781
6724
|
|
|
6782
6725
|
@validate_hf_hub_args
|
|
6783
|
-
def set_space_sleep_time(
|
|
6726
|
+
def set_space_sleep_time(
|
|
6727
|
+
self, repo_id: str, sleep_time: int, *, token: Union[bool, str, None] = None
|
|
6728
|
+
) -> SpaceRuntime:
|
|
6784
6729
|
"""Set a custom sleep time for a Space running on upgraded hardware..
|
|
6785
6730
|
|
|
6786
6731
|
Your Space will go to sleep after X seconds of inactivity. You are not billed when your Space is in "sleep"
|
|
@@ -6796,8 +6741,11 @@ class HfApi:
|
|
|
6796
6741
|
your Space to pause (default behavior for upgraded hardware). For free hardware, you can't configure
|
|
6797
6742
|
the sleep time (value is fixed to 48 hours of inactivity).
|
|
6798
6743
|
See https://huggingface.co/docs/hub/spaces-gpus#sleep-time for more details.
|
|
6799
|
-
token (
|
|
6800
|
-
|
|
6744
|
+
token (Union[bool, str, None], optional):
|
|
6745
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6746
|
+
token, which is the recommended method for authentication (see
|
|
6747
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6748
|
+
To disable authentication, pass `False`.
|
|
6801
6749
|
Returns:
|
|
6802
6750
|
[`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
|
|
6803
6751
|
|
|
@@ -6826,7 +6774,7 @@ class HfApi:
|
|
|
6826
6774
|
return runtime
|
|
6827
6775
|
|
|
6828
6776
|
@validate_hf_hub_args
|
|
6829
|
-
def pause_space(self, repo_id: str, *, token:
|
|
6777
|
+
def pause_space(self, repo_id: str, *, token: Union[bool, str, None] = None) -> SpaceRuntime:
|
|
6830
6778
|
"""Pause your Space.
|
|
6831
6779
|
|
|
6832
6780
|
A paused Space stops executing until manually restarted by its owner. This is different from the sleeping
|
|
@@ -6838,8 +6786,11 @@ class HfApi:
|
|
|
6838
6786
|
Args:
|
|
6839
6787
|
repo_id (`str`):
|
|
6840
6788
|
ID of the Space to pause. Example: `"Salesforce/BLIP2"`.
|
|
6841
|
-
token (
|
|
6842
|
-
|
|
6789
|
+
token (Union[bool, str, None], optional):
|
|
6790
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6791
|
+
token, which is the recommended method for authentication (see
|
|
6792
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6793
|
+
To disable authentication, pass `False`.
|
|
6843
6794
|
|
|
6844
6795
|
Returns:
|
|
6845
6796
|
[`SpaceRuntime`]: Runtime information about your Space including `stage=PAUSED` and requested hardware.
|
|
@@ -6863,7 +6814,7 @@ class HfApi:
|
|
|
6863
6814
|
|
|
6864
6815
|
@validate_hf_hub_args
|
|
6865
6816
|
def restart_space(
|
|
6866
|
-
self, repo_id: str, *, token:
|
|
6817
|
+
self, repo_id: str, *, token: Union[bool, str, None] = None, factory_reboot: bool = False
|
|
6867
6818
|
) -> SpaceRuntime:
|
|
6868
6819
|
"""Restart your Space.
|
|
6869
6820
|
|
|
@@ -6876,8 +6827,11 @@ class HfApi:
|
|
|
6876
6827
|
Args:
|
|
6877
6828
|
repo_id (`str`):
|
|
6878
6829
|
ID of the Space to restart. Example: `"Salesforce/BLIP2"`.
|
|
6879
|
-
token (
|
|
6880
|
-
|
|
6830
|
+
token (Union[bool, str, None], optional):
|
|
6831
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6832
|
+
token, which is the recommended method for authentication (see
|
|
6833
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6834
|
+
To disable authentication, pass `False`.
|
|
6881
6835
|
factory_reboot (`bool`, *optional*):
|
|
6882
6836
|
If `True`, the Space will be rebuilt from scratch without caching any requirements.
|
|
6883
6837
|
|
|
@@ -6911,7 +6865,7 @@ class HfApi:
|
|
|
6911
6865
|
to_id: Optional[str] = None,
|
|
6912
6866
|
*,
|
|
6913
6867
|
private: Optional[bool] = None,
|
|
6914
|
-
token:
|
|
6868
|
+
token: Union[bool, str, None] = None,
|
|
6915
6869
|
exist_ok: bool = False,
|
|
6916
6870
|
hardware: Optional[SpaceHardware] = None,
|
|
6917
6871
|
storage: Optional[SpaceStorage] = None,
|
|
@@ -6932,8 +6886,11 @@ class HfApi:
|
|
|
6932
6886
|
name as the original Space, but in your account.
|
|
6933
6887
|
private (`bool`, *optional*):
|
|
6934
6888
|
Whether the new Space should be private or not. Defaults to the same privacy as the original Space.
|
|
6935
|
-
token (
|
|
6936
|
-
|
|
6889
|
+
token (Union[bool, str, None], optional):
|
|
6890
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6891
|
+
token, which is the recommended method for authentication (see
|
|
6892
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6893
|
+
To disable authentication, pass `False`.
|
|
6937
6894
|
exist_ok (`bool`, *optional*, defaults to `False`):
|
|
6938
6895
|
If `True`, do not raise an error if repo already exists.
|
|
6939
6896
|
hardware (`SpaceHardware` or `str`, *optional*):
|
|
@@ -7025,7 +6982,7 @@ class HfApi:
|
|
|
7025
6982
|
repo_id: str,
|
|
7026
6983
|
storage: SpaceStorage,
|
|
7027
6984
|
*,
|
|
7028
|
-
token:
|
|
6985
|
+
token: Union[bool, str, None] = None,
|
|
7029
6986
|
) -> SpaceRuntime:
|
|
7030
6987
|
"""Request persistent storage for a Space.
|
|
7031
6988
|
|
|
@@ -7034,8 +6991,11 @@ class HfApi:
|
|
|
7034
6991
|
ID of the Space to update. Example: `"HuggingFaceH4/open_llm_leaderboard"`.
|
|
7035
6992
|
storage (`str` or [`SpaceStorage`]):
|
|
7036
6993
|
Storage tier. Either 'small', 'medium', or 'large'.
|
|
7037
|
-
token (
|
|
7038
|
-
|
|
6994
|
+
token (Union[bool, str, None], optional):
|
|
6995
|
+
A valid user access token (string). Defaults to the locally saved
|
|
6996
|
+
token, which is the recommended method for authentication (see
|
|
6997
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
6998
|
+
To disable authentication, pass `False`.
|
|
7039
6999
|
Returns:
|
|
7040
7000
|
[`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
|
|
7041
7001
|
|
|
@@ -7060,15 +7020,18 @@ class HfApi:
|
|
|
7060
7020
|
self,
|
|
7061
7021
|
repo_id: str,
|
|
7062
7022
|
*,
|
|
7063
|
-
token:
|
|
7023
|
+
token: Union[bool, str, None] = None,
|
|
7064
7024
|
) -> SpaceRuntime:
|
|
7065
7025
|
"""Delete persistent storage for a Space.
|
|
7066
7026
|
|
|
7067
7027
|
Args:
|
|
7068
7028
|
repo_id (`str`):
|
|
7069
7029
|
ID of the Space to update. Example: `"HuggingFaceH4/open_llm_leaderboard"`.
|
|
7070
|
-
token (
|
|
7071
|
-
|
|
7030
|
+
token (Union[bool, str, None], optional):
|
|
7031
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7032
|
+
token, which is the recommended method for authentication (see
|
|
7033
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7034
|
+
To disable authentication, pass `False`.
|
|
7072
7035
|
Returns:
|
|
7073
7036
|
[`SpaceRuntime`]: Runtime information about a Space including Space stage and hardware.
|
|
7074
7037
|
Raises:
|
|
@@ -7088,7 +7051,7 @@ class HfApi:
|
|
|
7088
7051
|
#######################
|
|
7089
7052
|
|
|
7090
7053
|
def list_inference_endpoints(
|
|
7091
|
-
self, namespace: Optional[str] = None, *, token:
|
|
7054
|
+
self, namespace: Optional[str] = None, *, token: Union[bool, str, None] = None
|
|
7092
7055
|
) -> List[InferenceEndpoint]:
|
|
7093
7056
|
"""Lists all inference endpoints for the given namespace.
|
|
7094
7057
|
|
|
@@ -7096,8 +7059,11 @@ class HfApi:
|
|
|
7096
7059
|
namespace (`str`, *optional*):
|
|
7097
7060
|
The namespace to list endpoints for. Defaults to the current user. Set to `"*"` to list all endpoints
|
|
7098
7061
|
from all namespaces (i.e. personal namespace and all orgs the user belongs to).
|
|
7099
|
-
token (
|
|
7100
|
-
|
|
7062
|
+
token (Union[bool, str, None], optional):
|
|
7063
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7064
|
+
token, which is the recommended method for authentication (see
|
|
7065
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7066
|
+
To disable authentication, pass `False`.
|
|
7101
7067
|
|
|
7102
7068
|
Returns:
|
|
7103
7069
|
List[`InferenceEndpoint`]: A list of all inference endpoints for the given namespace.
|
|
@@ -7161,7 +7127,7 @@ class HfApi:
|
|
|
7161
7127
|
custom_image: Optional[Dict] = None,
|
|
7162
7128
|
type: InferenceEndpointType = InferenceEndpointType.PROTECTED,
|
|
7163
7129
|
namespace: Optional[str] = None,
|
|
7164
|
-
token:
|
|
7130
|
+
token: Union[bool, str, None] = None,
|
|
7165
7131
|
) -> InferenceEndpoint:
|
|
7166
7132
|
"""Create a new Inference Endpoint.
|
|
7167
7133
|
|
|
@@ -7199,8 +7165,11 @@ class HfApi:
|
|
|
7199
7165
|
The type of the Inference Endpoint, which can be `"protected"` (default), `"public"` or `"private"`.
|
|
7200
7166
|
namespace (`str`, *optional*):
|
|
7201
7167
|
The namespace where the Inference Endpoint will be created. Defaults to the current user's namespace.
|
|
7202
|
-
token (
|
|
7203
|
-
|
|
7168
|
+
token (Union[bool, str, None], optional):
|
|
7169
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7170
|
+
token, which is the recommended method for authentication (see
|
|
7171
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7172
|
+
To disable authentication, pass `False`.
|
|
7204
7173
|
|
|
7205
7174
|
Returns:
|
|
7206
7175
|
[`InferenceEndpoint`]: information about the updated Inference Endpoint.
|
|
@@ -7297,7 +7266,7 @@ class HfApi:
|
|
|
7297
7266
|
return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
|
|
7298
7267
|
|
|
7299
7268
|
def get_inference_endpoint(
|
|
7300
|
-
self, name: str, *, namespace: Optional[str] = None, token:
|
|
7269
|
+
self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
|
|
7301
7270
|
) -> InferenceEndpoint:
|
|
7302
7271
|
"""Get information about an Inference Endpoint.
|
|
7303
7272
|
|
|
@@ -7306,8 +7275,11 @@ class HfApi:
|
|
|
7306
7275
|
The name of the Inference Endpoint to retrieve information about.
|
|
7307
7276
|
namespace (`str`, *optional*):
|
|
7308
7277
|
The namespace in which the Inference Endpoint is located. Defaults to the current user.
|
|
7309
|
-
token (
|
|
7310
|
-
|
|
7278
|
+
token (Union[bool, str, None], optional):
|
|
7279
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7280
|
+
token, which is the recommended method for authentication (see
|
|
7281
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7282
|
+
To disable authentication, pass `False`.
|
|
7311
7283
|
|
|
7312
7284
|
Returns:
|
|
7313
7285
|
[`InferenceEndpoint`]: information about the requested Inference Endpoint.
|
|
@@ -7357,7 +7329,7 @@ class HfApi:
|
|
|
7357
7329
|
task: Optional[str] = None,
|
|
7358
7330
|
# Other
|
|
7359
7331
|
namespace: Optional[str] = None,
|
|
7360
|
-
token:
|
|
7332
|
+
token: Union[bool, str, None] = None,
|
|
7361
7333
|
) -> InferenceEndpoint:
|
|
7362
7334
|
"""Update an Inference Endpoint.
|
|
7363
7335
|
|
|
@@ -7392,8 +7364,11 @@ class HfApi:
|
|
|
7392
7364
|
|
|
7393
7365
|
namespace (`str`, *optional*):
|
|
7394
7366
|
The namespace where the Inference Endpoint will be updated. Defaults to the current user's namespace.
|
|
7395
|
-
token (
|
|
7396
|
-
|
|
7367
|
+
token (Union[bool, str, None], optional):
|
|
7368
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7369
|
+
token, which is the recommended method for authentication (see
|
|
7370
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7371
|
+
To disable authentication, pass `False`.
|
|
7397
7372
|
|
|
7398
7373
|
Returns:
|
|
7399
7374
|
[`InferenceEndpoint`]: information about the updated Inference Endpoint.
|
|
@@ -7430,7 +7405,7 @@ class HfApi:
|
|
|
7430
7405
|
return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
|
|
7431
7406
|
|
|
7432
7407
|
def delete_inference_endpoint(
|
|
7433
|
-
self, name: str, *, namespace: Optional[str] = None, token:
|
|
7408
|
+
self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
|
|
7434
7409
|
) -> None:
|
|
7435
7410
|
"""Delete an Inference Endpoint.
|
|
7436
7411
|
|
|
@@ -7444,8 +7419,11 @@ class HfApi:
|
|
|
7444
7419
|
The name of the Inference Endpoint to delete.
|
|
7445
7420
|
namespace (`str`, *optional*):
|
|
7446
7421
|
The namespace in which the Inference Endpoint is located. Defaults to the current user.
|
|
7447
|
-
token (
|
|
7448
|
-
|
|
7422
|
+
token (Union[bool, str, None], optional):
|
|
7423
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7424
|
+
token, which is the recommended method for authentication (see
|
|
7425
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7426
|
+
To disable authentication, pass `False`.
|
|
7449
7427
|
"""
|
|
7450
7428
|
namespace = namespace or self._get_namespace(token=token)
|
|
7451
7429
|
response = get_session().delete(
|
|
@@ -7455,7 +7433,7 @@ class HfApi:
|
|
|
7455
7433
|
hf_raise_for_status(response)
|
|
7456
7434
|
|
|
7457
7435
|
def pause_inference_endpoint(
|
|
7458
|
-
self, name: str, *, namespace: Optional[str] = None, token:
|
|
7436
|
+
self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
|
|
7459
7437
|
) -> InferenceEndpoint:
|
|
7460
7438
|
"""Pause an Inference Endpoint.
|
|
7461
7439
|
|
|
@@ -7470,8 +7448,11 @@ class HfApi:
|
|
|
7470
7448
|
The name of the Inference Endpoint to pause.
|
|
7471
7449
|
namespace (`str`, *optional*):
|
|
7472
7450
|
The namespace in which the Inference Endpoint is located. Defaults to the current user.
|
|
7473
|
-
token (
|
|
7474
|
-
|
|
7451
|
+
token (Union[bool, str, None], optional):
|
|
7452
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7453
|
+
token, which is the recommended method for authentication (see
|
|
7454
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7455
|
+
To disable authentication, pass `False`.
|
|
7475
7456
|
|
|
7476
7457
|
Returns:
|
|
7477
7458
|
[`InferenceEndpoint`]: information about the paused Inference Endpoint.
|
|
@@ -7487,7 +7468,7 @@ class HfApi:
|
|
|
7487
7468
|
return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
|
|
7488
7469
|
|
|
7489
7470
|
def resume_inference_endpoint(
|
|
7490
|
-
self, name: str, *, namespace: Optional[str] = None, token:
|
|
7471
|
+
self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
|
|
7491
7472
|
) -> InferenceEndpoint:
|
|
7492
7473
|
"""Resume an Inference Endpoint.
|
|
7493
7474
|
|
|
@@ -7498,8 +7479,11 @@ class HfApi:
|
|
|
7498
7479
|
The name of the Inference Endpoint to resume.
|
|
7499
7480
|
namespace (`str`, *optional*):
|
|
7500
7481
|
The namespace in which the Inference Endpoint is located. Defaults to the current user.
|
|
7501
|
-
token (
|
|
7502
|
-
|
|
7482
|
+
token (Union[bool, str, None], optional):
|
|
7483
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7484
|
+
token, which is the recommended method for authentication (see
|
|
7485
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7486
|
+
To disable authentication, pass `False`.
|
|
7503
7487
|
|
|
7504
7488
|
Returns:
|
|
7505
7489
|
[`InferenceEndpoint`]: information about the resumed Inference Endpoint.
|
|
@@ -7515,7 +7499,7 @@ class HfApi:
|
|
|
7515
7499
|
return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
|
|
7516
7500
|
|
|
7517
7501
|
def scale_to_zero_inference_endpoint(
|
|
7518
|
-
self, name: str, *, namespace: Optional[str] = None, token:
|
|
7502
|
+
self, name: str, *, namespace: Optional[str] = None, token: Union[bool, str, None] = None
|
|
7519
7503
|
) -> InferenceEndpoint:
|
|
7520
7504
|
"""Scale Inference Endpoint to zero.
|
|
7521
7505
|
|
|
@@ -7530,8 +7514,11 @@ class HfApi:
|
|
|
7530
7514
|
The name of the Inference Endpoint to scale to zero.
|
|
7531
7515
|
namespace (`str`, *optional*):
|
|
7532
7516
|
The namespace in which the Inference Endpoint is located. Defaults to the current user.
|
|
7533
|
-
token (
|
|
7534
|
-
|
|
7517
|
+
token (Union[bool, str, None], optional):
|
|
7518
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7519
|
+
token, which is the recommended method for authentication (see
|
|
7520
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7521
|
+
To disable authentication, pass `False`.
|
|
7535
7522
|
|
|
7536
7523
|
Returns:
|
|
7537
7524
|
[`InferenceEndpoint`]: information about the scaled-to-zero Inference Endpoint.
|
|
@@ -7546,7 +7533,7 @@ class HfApi:
|
|
|
7546
7533
|
|
|
7547
7534
|
return InferenceEndpoint.from_raw(response.json(), namespace=namespace, token=token)
|
|
7548
7535
|
|
|
7549
|
-
def _get_namespace(self, token:
|
|
7536
|
+
def _get_namespace(self, token: Union[bool, str, None] = None) -> str:
|
|
7550
7537
|
"""Get the default namespace for the current user."""
|
|
7551
7538
|
me = self.whoami(token=token)
|
|
7552
7539
|
if me["type"] == "user":
|
|
@@ -7568,7 +7555,7 @@ class HfApi:
|
|
|
7568
7555
|
item: Union[List[str], str, None] = None,
|
|
7569
7556
|
sort: Optional[Literal["lastModified", "trending", "upvotes"]] = None,
|
|
7570
7557
|
limit: Optional[int] = None,
|
|
7571
|
-
token:
|
|
7558
|
+
token: Union[bool, str, None] = None,
|
|
7572
7559
|
) -> Iterable[Collection]:
|
|
7573
7560
|
"""List collections on the Huggingface Hub, given some filters.
|
|
7574
7561
|
|
|
@@ -7588,8 +7575,11 @@ class HfApi:
|
|
|
7588
7575
|
Sort collections by last modified, trending or upvotes.
|
|
7589
7576
|
limit (`int`, *optional*):
|
|
7590
7577
|
Maximum number of collections to be returned.
|
|
7591
|
-
token (
|
|
7592
|
-
|
|
7578
|
+
token (Union[bool, str, None], optional):
|
|
7579
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7580
|
+
token, which is the recommended method for authentication (see
|
|
7581
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7582
|
+
To disable authentication, pass `False`.
|
|
7593
7583
|
|
|
7594
7584
|
Returns:
|
|
7595
7585
|
`Iterable[Collection]`: an iterable of [`Collection`] objects.
|
|
@@ -7616,14 +7606,17 @@ class HfApi:
|
|
|
7616
7606
|
for position, collection_data in enumerate(items):
|
|
7617
7607
|
yield Collection(position=position, **collection_data)
|
|
7618
7608
|
|
|
7619
|
-
def get_collection(self, collection_slug: str, *, token:
|
|
7609
|
+
def get_collection(self, collection_slug: str, *, token: Union[bool, str, None] = None) -> Collection:
|
|
7620
7610
|
"""Gets information about a Collection on the Hub.
|
|
7621
7611
|
|
|
7622
7612
|
Args:
|
|
7623
7613
|
collection_slug (`str`):
|
|
7624
7614
|
Slug of the collection of the Hub. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
|
|
7625
|
-
token (
|
|
7626
|
-
|
|
7615
|
+
token (Union[bool, str, None], optional):
|
|
7616
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7617
|
+
token, which is the recommended method for authentication (see
|
|
7618
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7619
|
+
To disable authentication, pass `False`.
|
|
7627
7620
|
|
|
7628
7621
|
Returns: [`Collection`]
|
|
7629
7622
|
|
|
@@ -7660,7 +7653,7 @@ class HfApi:
|
|
|
7660
7653
|
description: Optional[str] = None,
|
|
7661
7654
|
private: bool = False,
|
|
7662
7655
|
exists_ok: bool = False,
|
|
7663
|
-
token:
|
|
7656
|
+
token: Union[bool, str, None] = None,
|
|
7664
7657
|
) -> Collection:
|
|
7665
7658
|
"""Create a new Collection on the Hub.
|
|
7666
7659
|
|
|
@@ -7675,8 +7668,11 @@ class HfApi:
|
|
|
7675
7668
|
Whether the collection should be private or not. Defaults to `False` (i.e. public collection).
|
|
7676
7669
|
exists_ok (`bool`, *optional*):
|
|
7677
7670
|
If `True`, do not raise an error if collection already exists.
|
|
7678
|
-
token (
|
|
7679
|
-
|
|
7671
|
+
token (Union[bool, str, None], optional):
|
|
7672
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7673
|
+
token, which is the recommended method for authentication (see
|
|
7674
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7675
|
+
To disable authentication, pass `False`.
|
|
7680
7676
|
|
|
7681
7677
|
Returns: [`Collection`]
|
|
7682
7678
|
|
|
@@ -7726,7 +7722,7 @@ class HfApi:
|
|
|
7726
7722
|
position: Optional[int] = None,
|
|
7727
7723
|
private: Optional[bool] = None,
|
|
7728
7724
|
theme: Optional[str] = None,
|
|
7729
|
-
token:
|
|
7725
|
+
token: Union[bool, str, None] = None,
|
|
7730
7726
|
) -> Collection:
|
|
7731
7727
|
"""Update metadata of a collection on the Hub.
|
|
7732
7728
|
|
|
@@ -7745,8 +7741,11 @@ class HfApi:
|
|
|
7745
7741
|
Whether the collection should be private or not.
|
|
7746
7742
|
theme (`str`, *optional*):
|
|
7747
7743
|
Theme of the collection on the Hub.
|
|
7748
|
-
token (
|
|
7749
|
-
|
|
7744
|
+
token (Union[bool, str, None], optional):
|
|
7745
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7746
|
+
token, which is the recommended method for authentication (see
|
|
7747
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7748
|
+
To disable authentication, pass `False`.
|
|
7750
7749
|
|
|
7751
7750
|
Returns: [`Collection`]
|
|
7752
7751
|
|
|
@@ -7783,7 +7782,7 @@ class HfApi:
|
|
|
7783
7782
|
return Collection(**{**r.json()["data"], "endpoint": self.endpoint})
|
|
7784
7783
|
|
|
7785
7784
|
def delete_collection(
|
|
7786
|
-
self, collection_slug: str, *, missing_ok: bool = False, token:
|
|
7785
|
+
self, collection_slug: str, *, missing_ok: bool = False, token: Union[bool, str, None] = None
|
|
7787
7786
|
) -> None:
|
|
7788
7787
|
"""Delete a collection on the Hub.
|
|
7789
7788
|
|
|
@@ -7792,8 +7791,11 @@ class HfApi:
|
|
|
7792
7791
|
Slug of the collection to delete. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
|
|
7793
7792
|
missing_ok (`bool`, *optional*):
|
|
7794
7793
|
If `True`, do not raise an error if collection doesn't exists.
|
|
7795
|
-
token (
|
|
7796
|
-
|
|
7794
|
+
token (Union[bool, str, None], optional):
|
|
7795
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7796
|
+
token, which is the recommended method for authentication (see
|
|
7797
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7798
|
+
To disable authentication, pass `False`.
|
|
7797
7799
|
|
|
7798
7800
|
Example:
|
|
7799
7801
|
|
|
@@ -7828,7 +7830,7 @@ class HfApi:
|
|
|
7828
7830
|
*,
|
|
7829
7831
|
note: Optional[str] = None,
|
|
7830
7832
|
exists_ok: bool = False,
|
|
7831
|
-
token:
|
|
7833
|
+
token: Union[bool, str, None] = None,
|
|
7832
7834
|
) -> Collection:
|
|
7833
7835
|
"""Add an item to a collection on the Hub.
|
|
7834
7836
|
|
|
@@ -7844,8 +7846,11 @@ class HfApi:
|
|
|
7844
7846
|
A note to attach to the item in the collection. The maximum size for a note is 500 characters.
|
|
7845
7847
|
exists_ok (`bool`, *optional*):
|
|
7846
7848
|
If `True`, do not raise an error if item already exists.
|
|
7847
|
-
token (
|
|
7848
|
-
|
|
7849
|
+
token (Union[bool, str, None], optional):
|
|
7850
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7851
|
+
token, which is the recommended method for authentication (see
|
|
7852
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7853
|
+
To disable authentication, pass `False`.
|
|
7849
7854
|
|
|
7850
7855
|
Returns: [`Collection`]
|
|
7851
7856
|
|
|
@@ -7906,7 +7911,7 @@ class HfApi:
|
|
|
7906
7911
|
*,
|
|
7907
7912
|
note: Optional[str] = None,
|
|
7908
7913
|
position: Optional[int] = None,
|
|
7909
|
-
token:
|
|
7914
|
+
token: Union[bool, str, None] = None,
|
|
7910
7915
|
) -> None:
|
|
7911
7916
|
"""Update an item in a collection.
|
|
7912
7917
|
|
|
@@ -7920,8 +7925,11 @@ class HfApi:
|
|
|
7920
7925
|
A note to attach to the item in the collection. The maximum size for a note is 500 characters.
|
|
7921
7926
|
position (`int`, *optional*):
|
|
7922
7927
|
New position of the item in the collection.
|
|
7923
|
-
token (
|
|
7924
|
-
|
|
7928
|
+
token (Union[bool, str, None], optional):
|
|
7929
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7930
|
+
token, which is the recommended method for authentication (see
|
|
7931
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7932
|
+
To disable authentication, pass `False`.
|
|
7925
7933
|
|
|
7926
7934
|
Example:
|
|
7927
7935
|
|
|
@@ -7955,7 +7963,7 @@ class HfApi:
|
|
|
7955
7963
|
item_object_id: str,
|
|
7956
7964
|
*,
|
|
7957
7965
|
missing_ok: bool = False,
|
|
7958
|
-
token:
|
|
7966
|
+
token: Union[bool, str, None] = None,
|
|
7959
7967
|
) -> None:
|
|
7960
7968
|
"""Delete an item from a collection.
|
|
7961
7969
|
|
|
@@ -7967,8 +7975,11 @@ class HfApi:
|
|
|
7967
7975
|
It must be retrieved from a [`CollectionItem`] object. Example: `collection.items[0]._id`.
|
|
7968
7976
|
missing_ok (`bool`, *optional*):
|
|
7969
7977
|
If `True`, do not raise an error if item doesn't exists.
|
|
7970
|
-
token (
|
|
7971
|
-
|
|
7978
|
+
token (Union[bool, str, None], optional):
|
|
7979
|
+
A valid user access token (string). Defaults to the locally saved
|
|
7980
|
+
token, which is the recommended method for authentication (see
|
|
7981
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
7982
|
+
To disable authentication, pass `False`.
|
|
7972
7983
|
|
|
7973
7984
|
Example:
|
|
7974
7985
|
|
|
@@ -8004,7 +8015,7 @@ class HfApi:
|
|
|
8004
8015
|
|
|
8005
8016
|
@validate_hf_hub_args
|
|
8006
8017
|
def list_pending_access_requests(
|
|
8007
|
-
self, repo_id: str, *, repo_type: Optional[str] = None, token:
|
|
8018
|
+
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8008
8019
|
) -> List[AccessRequest]:
|
|
8009
8020
|
"""
|
|
8010
8021
|
Get pending access requests for a given gated repo.
|
|
@@ -8021,8 +8032,11 @@ class HfApi:
|
|
|
8021
8032
|
repo_type (`str`, *optional*):
|
|
8022
8033
|
The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
|
|
8023
8034
|
Defaults to `model`.
|
|
8024
|
-
token (
|
|
8025
|
-
A valid
|
|
8035
|
+
token (Union[bool, str, None], optional):
|
|
8036
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8037
|
+
token, which is the recommended method for authentication (see
|
|
8038
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8039
|
+
To disable authentication, pass `False`.
|
|
8026
8040
|
|
|
8027
8041
|
Returns:
|
|
8028
8042
|
`List[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
@@ -8065,7 +8079,7 @@ class HfApi:
|
|
|
8065
8079
|
|
|
8066
8080
|
@validate_hf_hub_args
|
|
8067
8081
|
def list_accepted_access_requests(
|
|
8068
|
-
self, repo_id: str, *, repo_type: Optional[str] = None, token:
|
|
8082
|
+
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8069
8083
|
) -> List[AccessRequest]:
|
|
8070
8084
|
"""
|
|
8071
8085
|
Get accepted access requests for a given gated repo.
|
|
@@ -8084,8 +8098,11 @@ class HfApi:
|
|
|
8084
8098
|
repo_type (`str`, *optional*):
|
|
8085
8099
|
The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
|
|
8086
8100
|
Defaults to `model`.
|
|
8087
|
-
token (
|
|
8088
|
-
A valid
|
|
8101
|
+
token (Union[bool, str, None], optional):
|
|
8102
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8103
|
+
token, which is the recommended method for authentication (see
|
|
8104
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8105
|
+
To disable authentication, pass `False`.
|
|
8089
8106
|
|
|
8090
8107
|
Returns:
|
|
8091
8108
|
`List[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
@@ -8124,7 +8141,7 @@ class HfApi:
|
|
|
8124
8141
|
|
|
8125
8142
|
@validate_hf_hub_args
|
|
8126
8143
|
def list_rejected_access_requests(
|
|
8127
|
-
self, repo_id: str, *, repo_type: Optional[str] = None, token:
|
|
8144
|
+
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8128
8145
|
) -> List[AccessRequest]:
|
|
8129
8146
|
"""
|
|
8130
8147
|
Get rejected access requests for a given gated repo.
|
|
@@ -8143,8 +8160,11 @@ class HfApi:
|
|
|
8143
8160
|
repo_type (`str`, *optional*):
|
|
8144
8161
|
The type of the repo to get access requests for. Must be one of `model`, `dataset` or `space`.
|
|
8145
8162
|
Defaults to `model`.
|
|
8146
|
-
token (
|
|
8147
|
-
A valid
|
|
8163
|
+
token (Union[bool, str, None], optional):
|
|
8164
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8165
|
+
token, which is the recommended method for authentication (see
|
|
8166
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8167
|
+
To disable authentication, pass `False`.
|
|
8148
8168
|
|
|
8149
8169
|
Returns:
|
|
8150
8170
|
`List[AccessRequest]`: A list of [`AccessRequest`] objects. Each time contains a `username`, `email`,
|
|
@@ -8186,7 +8206,7 @@ class HfApi:
|
|
|
8186
8206
|
repo_id: str,
|
|
8187
8207
|
status: Literal["accepted", "rejected", "pending"],
|
|
8188
8208
|
repo_type: Optional[str] = None,
|
|
8189
|
-
token:
|
|
8209
|
+
token: Union[bool, str, None] = None,
|
|
8190
8210
|
) -> List[AccessRequest]:
|
|
8191
8211
|
if repo_type not in REPO_TYPES:
|
|
8192
8212
|
raise ValueError(f"Invalid repo type, must be one of {REPO_TYPES}")
|
|
@@ -8212,7 +8232,7 @@ class HfApi:
|
|
|
8212
8232
|
|
|
8213
8233
|
@validate_hf_hub_args
|
|
8214
8234
|
def cancel_access_request(
|
|
8215
|
-
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token:
|
|
8235
|
+
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8216
8236
|
) -> None:
|
|
8217
8237
|
"""
|
|
8218
8238
|
Cancel an access request from a user for a given gated repo.
|
|
@@ -8229,8 +8249,11 @@ class HfApi:
|
|
|
8229
8249
|
repo_type (`str`, *optional*):
|
|
8230
8250
|
The type of the repo to cancel access request for. Must be one of `model`, `dataset` or `space`.
|
|
8231
8251
|
Defaults to `model`.
|
|
8232
|
-
token (
|
|
8233
|
-
A valid
|
|
8252
|
+
token (Union[bool, str, None], optional):
|
|
8253
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8254
|
+
token, which is the recommended method for authentication (see
|
|
8255
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8256
|
+
To disable authentication, pass `False`.
|
|
8234
8257
|
|
|
8235
8258
|
Raises:
|
|
8236
8259
|
`HTTPError`:
|
|
@@ -8249,7 +8272,7 @@ class HfApi:
|
|
|
8249
8272
|
|
|
8250
8273
|
@validate_hf_hub_args
|
|
8251
8274
|
def accept_access_request(
|
|
8252
|
-
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token:
|
|
8275
|
+
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8253
8276
|
) -> None:
|
|
8254
8277
|
"""
|
|
8255
8278
|
Accept an access request from a user for a given gated repo.
|
|
@@ -8268,8 +8291,11 @@ class HfApi:
|
|
|
8268
8291
|
repo_type (`str`, *optional*):
|
|
8269
8292
|
The type of the repo to accept access request for. Must be one of `model`, `dataset` or `space`.
|
|
8270
8293
|
Defaults to `model`.
|
|
8271
|
-
token (
|
|
8272
|
-
A valid
|
|
8294
|
+
token (Union[bool, str, None], optional):
|
|
8295
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8296
|
+
token, which is the recommended method for authentication (see
|
|
8297
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8298
|
+
To disable authentication, pass `False`.
|
|
8273
8299
|
|
|
8274
8300
|
Raises:
|
|
8275
8301
|
`HTTPError`:
|
|
@@ -8288,7 +8314,7 @@ class HfApi:
|
|
|
8288
8314
|
|
|
8289
8315
|
@validate_hf_hub_args
|
|
8290
8316
|
def reject_access_request(
|
|
8291
|
-
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token:
|
|
8317
|
+
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8292
8318
|
) -> None:
|
|
8293
8319
|
"""
|
|
8294
8320
|
Reject an access request from a user for a given gated repo.
|
|
@@ -8307,8 +8333,11 @@ class HfApi:
|
|
|
8307
8333
|
repo_type (`str`, *optional*):
|
|
8308
8334
|
The type of the repo to reject access request for. Must be one of `model`, `dataset` or `space`.
|
|
8309
8335
|
Defaults to `model`.
|
|
8310
|
-
token (
|
|
8311
|
-
A valid
|
|
8336
|
+
token (Union[bool, str, None], optional):
|
|
8337
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8338
|
+
token, which is the recommended method for authentication (see
|
|
8339
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8340
|
+
To disable authentication, pass `False`.
|
|
8312
8341
|
|
|
8313
8342
|
Raises:
|
|
8314
8343
|
`HTTPError`:
|
|
@@ -8332,7 +8361,7 @@ class HfApi:
|
|
|
8332
8361
|
user: str,
|
|
8333
8362
|
status: Literal["accepted", "rejected", "pending"],
|
|
8334
8363
|
repo_type: Optional[str] = None,
|
|
8335
|
-
token:
|
|
8364
|
+
token: Union[bool, str, None] = None,
|
|
8336
8365
|
) -> None:
|
|
8337
8366
|
if repo_type not in REPO_TYPES:
|
|
8338
8367
|
raise ValueError(f"Invalid repo type, must be one of {REPO_TYPES}")
|
|
@@ -8348,7 +8377,7 @@ class HfApi:
|
|
|
8348
8377
|
|
|
8349
8378
|
@validate_hf_hub_args
|
|
8350
8379
|
def grant_access(
|
|
8351
|
-
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token:
|
|
8380
|
+
self, repo_id: str, user: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
8352
8381
|
) -> None:
|
|
8353
8382
|
"""
|
|
8354
8383
|
Grant access to a user for a given gated repo.
|
|
@@ -8367,8 +8396,11 @@ class HfApi:
|
|
|
8367
8396
|
repo_type (`str`, *optional*):
|
|
8368
8397
|
The type of the repo to grant access to. Must be one of `model`, `dataset` or `space`.
|
|
8369
8398
|
Defaults to `model`.
|
|
8370
|
-
token (
|
|
8371
|
-
A valid
|
|
8399
|
+
token (Union[bool, str, None], optional):
|
|
8400
|
+
A valid user access token (string). Defaults to the locally saved
|
|
8401
|
+
token, which is the recommended method for authentication (see
|
|
8402
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
8403
|
+
To disable authentication, pass `False`.
|
|
8372
8404
|
|
|
8373
8405
|
Raises:
|
|
8374
8406
|
`HTTPError`:
|
|
@@ -8400,7 +8432,7 @@ class HfApi:
|
|
|
8400
8432
|
|
|
8401
8433
|
def _build_hf_headers(
|
|
8402
8434
|
self,
|
|
8403
|
-
token:
|
|
8435
|
+
token: Union[bool, str, None] = None,
|
|
8404
8436
|
is_write_action: bool = False,
|
|
8405
8437
|
library_name: Optional[str] = None,
|
|
8406
8438
|
library_version: Optional[str] = None,
|
|
@@ -8427,9 +8459,9 @@ class HfApi:
|
|
|
8427
8459
|
repo_id: str,
|
|
8428
8460
|
repo_type: Optional[str],
|
|
8429
8461
|
revision: Optional[str],
|
|
8430
|
-
token: Optional[str],
|
|
8431
8462
|
path_in_repo: str,
|
|
8432
8463
|
delete_patterns: Optional[Union[List[str], str]],
|
|
8464
|
+
token: Union[bool, str, None] = None,
|
|
8433
8465
|
) -> List[CommitOperationDelete]:
|
|
8434
8466
|
"""Generate the list of Delete operations for a commit to delete files from a repo.
|
|
8435
8467
|
|
|
@@ -8462,6 +8494,98 @@ class HfApi:
|
|
|
8462
8494
|
if relpath_to_abspath[relpath] != ".gitattributes"
|
|
8463
8495
|
]
|
|
8464
8496
|
|
|
8497
|
+
def get_user_overview(self, username: str) -> User:
|
|
8498
|
+
"""
|
|
8499
|
+
Get an overview of a user on the Hub.
|
|
8500
|
+
|
|
8501
|
+
Args:
|
|
8502
|
+
username (`str`):
|
|
8503
|
+
Username of the user to get an overview of.
|
|
8504
|
+
|
|
8505
|
+
Returns:
|
|
8506
|
+
`User`: A [`User`] object with the user's overview.
|
|
8507
|
+
|
|
8508
|
+
Raises:
|
|
8509
|
+
`HTTPError`:
|
|
8510
|
+
HTTP 404 If the user does not exist on the Hub.
|
|
8511
|
+
"""
|
|
8512
|
+
r = get_session().get(f"{ENDPOINT}/api/users/{username}/overview")
|
|
8513
|
+
|
|
8514
|
+
hf_raise_for_status(r)
|
|
8515
|
+
return User(**r.json())
|
|
8516
|
+
|
|
8517
|
+
def list_organization_members(self, organization: str) -> Iterable[User]:
|
|
8518
|
+
"""
|
|
8519
|
+
List of members of an organization on the Hub.
|
|
8520
|
+
|
|
8521
|
+
Args:
|
|
8522
|
+
organization (`str`):
|
|
8523
|
+
Name of the organization to get the members of.
|
|
8524
|
+
|
|
8525
|
+
Returns:
|
|
8526
|
+
`Iterable[User]`: A list of [`User`] objects with the members of the organization.
|
|
8527
|
+
|
|
8528
|
+
Raises:
|
|
8529
|
+
`HTTPError`:
|
|
8530
|
+
HTTP 404 If the organization does not exist on the Hub.
|
|
8531
|
+
|
|
8532
|
+
"""
|
|
8533
|
+
|
|
8534
|
+
r = get_session().get(f"{ENDPOINT}/api/organizations/{organization}/members")
|
|
8535
|
+
|
|
8536
|
+
hf_raise_for_status(r)
|
|
8537
|
+
|
|
8538
|
+
for member in r.json():
|
|
8539
|
+
yield User(**member)
|
|
8540
|
+
|
|
8541
|
+
def list_user_followers(self, username: str) -> Iterable[User]:
|
|
8542
|
+
"""
|
|
8543
|
+
Get the list of followers of a user on the Hub.
|
|
8544
|
+
|
|
8545
|
+
Args:
|
|
8546
|
+
username (`str`):
|
|
8547
|
+
Username of the user to get the followers of.
|
|
8548
|
+
|
|
8549
|
+
Returns:
|
|
8550
|
+
`Iterable[User]`: A list of [`User`] objects with the followers of the user.
|
|
8551
|
+
|
|
8552
|
+
Raises:
|
|
8553
|
+
`HTTPError`:
|
|
8554
|
+
HTTP 404 If the user does not exist on the Hub.
|
|
8555
|
+
|
|
8556
|
+
"""
|
|
8557
|
+
|
|
8558
|
+
r = get_session().get(f"{ENDPOINT}/api/users/{username}/followers")
|
|
8559
|
+
|
|
8560
|
+
hf_raise_for_status(r)
|
|
8561
|
+
|
|
8562
|
+
for follower in r.json():
|
|
8563
|
+
yield User(**follower)
|
|
8564
|
+
|
|
8565
|
+
def list_user_following(self, username: str) -> Iterable[User]:
|
|
8566
|
+
"""
|
|
8567
|
+
Get the list of users followed by a user on the Hub.
|
|
8568
|
+
|
|
8569
|
+
Args:
|
|
8570
|
+
username (`str`):
|
|
8571
|
+
Username of the user to get the users followed by.
|
|
8572
|
+
|
|
8573
|
+
Returns:
|
|
8574
|
+
`Iterable[User]`: A list of [`User`] objects with the users followed by the user.
|
|
8575
|
+
|
|
8576
|
+
Raises:
|
|
8577
|
+
`HTTPError`:
|
|
8578
|
+
HTTP 404 If the user does not exist on the Hub.
|
|
8579
|
+
|
|
8580
|
+
"""
|
|
8581
|
+
|
|
8582
|
+
r = get_session().get(f"{ENDPOINT}/api/users/{username}/following")
|
|
8583
|
+
|
|
8584
|
+
hf_raise_for_status(r)
|
|
8585
|
+
|
|
8586
|
+
for followed_user in r.json():
|
|
8587
|
+
yield User(**followed_user)
|
|
8588
|
+
|
|
8465
8589
|
|
|
8466
8590
|
def _prepare_upload_folder_additions(
|
|
8467
8591
|
folder_path: Union[str, Path],
|
|
@@ -8535,7 +8659,6 @@ repo_info = api.repo_info
|
|
|
8535
8659
|
list_repo_files = api.list_repo_files
|
|
8536
8660
|
list_repo_refs = api.list_repo_refs
|
|
8537
8661
|
list_repo_commits = api.list_repo_commits
|
|
8538
|
-
list_files_info = api.list_files_info
|
|
8539
8662
|
list_repo_tree = api.list_repo_tree
|
|
8540
8663
|
get_paths_info = api.get_paths_info
|
|
8541
8664
|
|
|
@@ -8630,3 +8753,9 @@ cancel_access_request = api.cancel_access_request
|
|
|
8630
8753
|
accept_access_request = api.accept_access_request
|
|
8631
8754
|
reject_access_request = api.reject_access_request
|
|
8632
8755
|
grant_access = api.grant_access
|
|
8756
|
+
|
|
8757
|
+
# User API
|
|
8758
|
+
get_user_overview = api.get_user_overview
|
|
8759
|
+
list_organization_members = api.list_organization_members
|
|
8760
|
+
list_user_followers = api.list_user_followers
|
|
8761
|
+
list_user_following = api.list_user_following
|