huggingface-hub 0.25.2__py3-none-any.whl → 0.26.0rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +45 -11
- huggingface_hub/_login.py +172 -33
- huggingface_hub/commands/user.py +125 -9
- huggingface_hub/constants.py +1 -1
- huggingface_hub/errors.py +6 -9
- huggingface_hub/file_download.py +2 -372
- huggingface_hub/hf_api.py +170 -13
- huggingface_hub/hf_file_system.py +3 -3
- huggingface_hub/hub_mixin.py +2 -1
- huggingface_hub/inference/_client.py +500 -145
- huggingface_hub/inference/_common.py +42 -4
- huggingface_hub/inference/_generated/_async_client.py +499 -144
- huggingface_hub/inference/_generated/types/__init__.py +37 -7
- huggingface_hub/inference/_generated/types/audio_classification.py +8 -5
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +9 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +23 -4
- huggingface_hub/inference/_generated/types/image_classification.py +8 -5
- huggingface_hub/inference/_generated/types/image_segmentation.py +9 -7
- huggingface_hub/inference/_generated/types/image_to_image.py +7 -5
- huggingface_hub/inference/_generated/types/image_to_text.py +4 -4
- huggingface_hub/inference/_generated/types/object_detection.py +11 -5
- huggingface_hub/inference/_generated/types/summarization.py +11 -13
- huggingface_hub/inference/_generated/types/text_classification.py +10 -5
- huggingface_hub/inference/_generated/types/text_generation.py +1 -0
- huggingface_hub/inference/_generated/types/text_to_audio.py +2 -2
- huggingface_hub/inference/_generated/types/text_to_image.py +9 -7
- huggingface_hub/inference/_generated/types/text_to_speech.py +107 -0
- huggingface_hub/inference/_generated/types/translation.py +17 -11
- huggingface_hub/inference/_generated/types/video_classification.py +2 -2
- huggingface_hub/repocard.py +2 -1
- huggingface_hub/repocard_data.py +10 -2
- huggingface_hub/serialization/_torch.py +7 -4
- huggingface_hub/utils/__init__.py +4 -20
- huggingface_hub/utils/{_token.py → _auth.py} +86 -3
- huggingface_hub/utils/_headers.py +1 -1
- huggingface_hub/utils/_hf_folder.py +1 -1
- huggingface_hub/utils/_http.py +10 -4
- huggingface_hub/utils/_runtime.py +1 -10
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.0rc0.dist-info}/METADATA +12 -12
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.0rc0.dist-info}/RECORD +44 -44
- huggingface_hub/inference/_templating.py +0 -102
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.25.2.dist-info → huggingface_hub-0.26.0rc0.dist-info}/top_level.txt +0 -0
huggingface_hub/hf_api.py
CHANGED
|
@@ -358,7 +358,7 @@ class TransformersInfo(dict):
|
|
|
358
358
|
|
|
359
359
|
@dataclass
|
|
360
360
|
class SafeTensorsInfo(dict):
|
|
361
|
-
parameters:
|
|
361
|
+
parameters: Dict[str, int]
|
|
362
362
|
total: int
|
|
363
363
|
|
|
364
364
|
def __post_init__(self): # hack to make SafeTensorsInfo backward compatible
|
|
@@ -734,6 +734,8 @@ class ModelInfo:
|
|
|
734
734
|
gated (`Literal["auto", "manual", False]`, *optional*):
|
|
735
735
|
Is the repo gated.
|
|
736
736
|
If so, whether there is manual or automatic approval.
|
|
737
|
+
gguf (`Dict`, *optional*):
|
|
738
|
+
GGUF information of the model.
|
|
737
739
|
inference (`Literal["cold", "frozen", "warm"]`, *optional*):
|
|
738
740
|
Status of the model on the inference API.
|
|
739
741
|
Warm models are available for immediate use. Cold models will be loaded on first inference call.
|
|
@@ -1455,6 +1457,70 @@ class User:
|
|
|
1455
1457
|
self.__dict__.update(**kwargs)
|
|
1456
1458
|
|
|
1457
1459
|
|
|
1460
|
+
@dataclass
|
|
1461
|
+
class PaperInfo:
|
|
1462
|
+
"""
|
|
1463
|
+
Contains information about a paper on the Hub.
|
|
1464
|
+
|
|
1465
|
+
Attributes:
|
|
1466
|
+
id (`str`):
|
|
1467
|
+
arXiv paper ID.
|
|
1468
|
+
authors (`List[str]`, **optional**):
|
|
1469
|
+
Names of paper authors
|
|
1470
|
+
published_at (`datetime`, **optional**):
|
|
1471
|
+
Date paper published.
|
|
1472
|
+
title (`str`, **optional**):
|
|
1473
|
+
Title of the paper.
|
|
1474
|
+
summary (`str`, **optional**):
|
|
1475
|
+
Summary of the paper.
|
|
1476
|
+
upvotes (`int`, **optional**):
|
|
1477
|
+
Number of upvotes for the paper on the Hub.
|
|
1478
|
+
discussion_id (`str`, **optional**):
|
|
1479
|
+
Discussion ID for the paper on the Hub.
|
|
1480
|
+
source (`str`, **optional**):
|
|
1481
|
+
Source of the paper.
|
|
1482
|
+
comments (`int`, **optional**):
|
|
1483
|
+
Number of comments for the paper on the Hub.
|
|
1484
|
+
submitted_at (`datetime`, **optional**):
|
|
1485
|
+
Date paper appeared in daily papers on the Hub.
|
|
1486
|
+
submitted_by (`User`, **optional**):
|
|
1487
|
+
Information about who submitted the daily paper.
|
|
1488
|
+
"""
|
|
1489
|
+
|
|
1490
|
+
id: str
|
|
1491
|
+
authors: Optional[List[str]]
|
|
1492
|
+
published_at: Optional[datetime]
|
|
1493
|
+
title: Optional[str]
|
|
1494
|
+
summary: Optional[str]
|
|
1495
|
+
upvotes: Optional[int]
|
|
1496
|
+
discussion_id: Optional[str]
|
|
1497
|
+
source: Optional[str]
|
|
1498
|
+
comments: Optional[int]
|
|
1499
|
+
submitted_at: Optional[datetime]
|
|
1500
|
+
submitted_by: Optional[User]
|
|
1501
|
+
|
|
1502
|
+
def __init__(self, **kwargs) -> None:
|
|
1503
|
+
paper = kwargs.pop("paper", {})
|
|
1504
|
+
self.id = kwargs.pop("id", None) or paper.pop("id", None)
|
|
1505
|
+
authors = paper.pop("authors", None) or kwargs.pop("authors", None)
|
|
1506
|
+
self.authors = [author.pop("name", None) for author in authors] if authors else None
|
|
1507
|
+
published_at = paper.pop("publishedAt", None) or kwargs.pop("publishedAt", None)
|
|
1508
|
+
self.published_at = parse_datetime(published_at) if published_at else None
|
|
1509
|
+
self.title = kwargs.pop("title", None)
|
|
1510
|
+
self.source = kwargs.pop("source", None)
|
|
1511
|
+
self.summary = paper.pop("summary", None) or kwargs.pop("summary", None)
|
|
1512
|
+
self.upvotes = paper.pop("upvotes", None) or kwargs.pop("upvotes", None)
|
|
1513
|
+
self.discussion_id = paper.pop("discussionId", None) or kwargs.pop("discussionId", None)
|
|
1514
|
+
self.comments = kwargs.pop("numComments", 0)
|
|
1515
|
+
submitted_at = kwargs.pop("publishedAt", None) or kwargs.pop("submittedOnDailyAt", None)
|
|
1516
|
+
self.submitted_at = parse_datetime(submitted_at) if submitted_at else None
|
|
1517
|
+
submitted_by = kwargs.pop("submittedBy", None) or kwargs.pop("submittedOnDailyBy", None)
|
|
1518
|
+
self.submitted_by = User(**submitted_by) if submitted_by else None
|
|
1519
|
+
|
|
1520
|
+
# forward compatibility
|
|
1521
|
+
self.__dict__.update(**kwargs)
|
|
1522
|
+
|
|
1523
|
+
|
|
1458
1524
|
def future_compatible(fn: CallableT) -> CallableT:
|
|
1459
1525
|
"""Wrap a method of `HfApi` to handle `run_as_future=True`.
|
|
1460
1526
|
|
|
@@ -3524,6 +3590,7 @@ class HfApi:
|
|
|
3524
3590
|
if not missing_ok:
|
|
3525
3591
|
raise
|
|
3526
3592
|
|
|
3593
|
+
@_deprecate_method(version="0.29", message="Please use `update_repo_settings` instead.")
|
|
3527
3594
|
@validate_hf_hub_args
|
|
3528
3595
|
def update_repo_visibility(
|
|
3529
3596
|
self,
|
|
@@ -3535,6 +3602,8 @@ class HfApi:
|
|
|
3535
3602
|
) -> Dict[str, bool]:
|
|
3536
3603
|
"""Update the visibility setting of a repository.
|
|
3537
3604
|
|
|
3605
|
+
Deprecated. Use `update_repo_settings` instead.
|
|
3606
|
+
|
|
3538
3607
|
Args:
|
|
3539
3608
|
repo_id (`str`, *optional*):
|
|
3540
3609
|
A namespace (user or an organization) and a repo name separated by a `/`.
|
|
@@ -3581,29 +3650,34 @@ class HfApi:
|
|
|
3581
3650
|
self,
|
|
3582
3651
|
repo_id: str,
|
|
3583
3652
|
*,
|
|
3584
|
-
gated: Literal["auto", "manual", False] =
|
|
3653
|
+
gated: Optional[Literal["auto", "manual", False]] = None,
|
|
3654
|
+
private: Optional[bool] = None,
|
|
3585
3655
|
token: Union[str, bool, None] = None,
|
|
3586
3656
|
repo_type: Optional[str] = None,
|
|
3587
3657
|
) -> None:
|
|
3588
3658
|
"""
|
|
3589
|
-
Update the
|
|
3590
|
-
|
|
3659
|
+
Update the settings of a repository, including gated access and visibility.
|
|
3660
|
+
|
|
3661
|
+
To give more control over how repos are used, the Hub allows repo authors to enable
|
|
3662
|
+
access requests for their repos, and also to set the visibility of the repo to private.
|
|
3591
3663
|
|
|
3592
3664
|
Args:
|
|
3593
3665
|
repo_id (`str`):
|
|
3594
3666
|
A namespace (user or an organization) and a repo name separated by a /.
|
|
3595
3667
|
gated (`Literal["auto", "manual", False]`, *optional*):
|
|
3596
|
-
The gated
|
|
3668
|
+
The gated status for the repository. If set to `None` (default), the `gated` setting of the repository won't be updated.
|
|
3597
3669
|
* "auto": The repository is gated, and access requests are automatically approved or denied based on predefined criteria.
|
|
3598
3670
|
* "manual": The repository is gated, and access requests require manual approval.
|
|
3599
|
-
* False
|
|
3671
|
+
* False : The repository is not gated, and anyone can access it.
|
|
3672
|
+
private (`bool`, *optional*):
|
|
3673
|
+
Whether the model repo should be private.
|
|
3600
3674
|
token (`Union[str, bool, None]`, *optional*):
|
|
3601
3675
|
A valid user access token (string). Defaults to the locally saved token,
|
|
3602
3676
|
which is the recommended method for authentication (see
|
|
3603
3677
|
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
3604
3678
|
To disable authentication, pass False.
|
|
3605
3679
|
repo_type (`str`, *optional*):
|
|
3606
|
-
The type of the repository to update settings from (`"model"`, `"dataset"` or `"space"
|
|
3680
|
+
The type of the repository to update settings from (`"model"`, `"dataset"` or `"space"`).
|
|
3607
3681
|
Defaults to `"model"`.
|
|
3608
3682
|
|
|
3609
3683
|
Raises:
|
|
@@ -3613,22 +3687,38 @@ class HfApi:
|
|
|
3613
3687
|
If repo_type is not one of the values in constants.REPO_TYPES.
|
|
3614
3688
|
[`~utils.HfHubHTTPError`]:
|
|
3615
3689
|
If the request to the Hugging Face Hub API fails.
|
|
3690
|
+
[`~utils.RepositoryNotFoundError`]
|
|
3691
|
+
If the repository to download from cannot be found. This may be because it doesn't exist,
|
|
3692
|
+
or because it is set to `private` and you do not have access.
|
|
3616
3693
|
"""
|
|
3617
|
-
if gated not in ["auto", "manual", False]:
|
|
3618
|
-
raise ValueError(f"Invalid gated status, must be one of 'auto', 'manual', or False. Got '{gated}'.")
|
|
3619
3694
|
|
|
3620
3695
|
if repo_type not in constants.REPO_TYPES:
|
|
3621
3696
|
raise ValueError(f"Invalid repo type, must be one of {constants.REPO_TYPES}")
|
|
3622
3697
|
if repo_type is None:
|
|
3623
3698
|
repo_type = constants.REPO_TYPE_MODEL # default repo type
|
|
3624
3699
|
|
|
3700
|
+
# Check if both gated and private are None
|
|
3701
|
+
if gated is None and private is None:
|
|
3702
|
+
raise ValueError("At least one of 'gated' or 'private' must be provided.")
|
|
3703
|
+
|
|
3625
3704
|
# Build headers
|
|
3626
3705
|
headers = self._build_hf_headers(token=token)
|
|
3627
3706
|
|
|
3707
|
+
# Prepare the JSON payload for the PUT request
|
|
3708
|
+
payload: Dict = {}
|
|
3709
|
+
|
|
3710
|
+
if gated is not None:
|
|
3711
|
+
if gated not in ["auto", "manual", False]:
|
|
3712
|
+
raise ValueError(f"Invalid gated status, must be one of 'auto', 'manual', or False. Got '{gated}'.")
|
|
3713
|
+
payload["gated"] = gated
|
|
3714
|
+
|
|
3715
|
+
if private is not None:
|
|
3716
|
+
payload["private"] = private
|
|
3717
|
+
|
|
3628
3718
|
r = get_session().put(
|
|
3629
3719
|
url=f"{self.endpoint}/api/{repo_type}s/{repo_id}/settings",
|
|
3630
3720
|
headers=headers,
|
|
3631
|
-
json=
|
|
3721
|
+
json=payload,
|
|
3632
3722
|
)
|
|
3633
3723
|
hf_raise_for_status(r)
|
|
3634
3724
|
|
|
@@ -5445,7 +5535,6 @@ class HfApi:
|
|
|
5445
5535
|
local_files_only: bool = False,
|
|
5446
5536
|
# Deprecated args
|
|
5447
5537
|
resume_download: Optional[bool] = None,
|
|
5448
|
-
legacy_cache_layout: bool = False,
|
|
5449
5538
|
force_filename: Optional[str] = None,
|
|
5450
5539
|
local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
|
|
5451
5540
|
) -> str:
|
|
@@ -5566,7 +5655,6 @@ class HfApi:
|
|
|
5566
5655
|
token=token,
|
|
5567
5656
|
headers=self.headers,
|
|
5568
5657
|
local_files_only=local_files_only,
|
|
5569
|
-
legacy_cache_layout=legacy_cache_layout,
|
|
5570
5658
|
)
|
|
5571
5659
|
|
|
5572
5660
|
@validate_hf_hub_args
|
|
@@ -8973,7 +9061,7 @@ class HfApi:
|
|
|
8973
9061
|
repo_type = constants.REPO_TYPE_MODEL
|
|
8974
9062
|
|
|
8975
9063
|
response = get_session().post(
|
|
8976
|
-
f"{constants.ENDPOINT}/api/
|
|
9064
|
+
f"{constants.ENDPOINT}/api/{repo_type}s/{repo_id}/user-access-request/grant",
|
|
8977
9065
|
headers=self._build_hf_headers(token=token),
|
|
8978
9066
|
json={"user": user},
|
|
8979
9067
|
)
|
|
@@ -9649,6 +9737,72 @@ class HfApi:
|
|
|
9649
9737
|
):
|
|
9650
9738
|
yield User(**followed_user)
|
|
9651
9739
|
|
|
9740
|
+
def list_papers(
|
|
9741
|
+
self,
|
|
9742
|
+
*,
|
|
9743
|
+
query: Optional[str] = None,
|
|
9744
|
+
token: Union[bool, str, None] = None,
|
|
9745
|
+
) -> Iterable[PaperInfo]:
|
|
9746
|
+
"""
|
|
9747
|
+
List daily papers on the Hugging Face Hub given a search query.
|
|
9748
|
+
|
|
9749
|
+
Args:
|
|
9750
|
+
query (`str`, *optional*):
|
|
9751
|
+
A search query string to find papers.
|
|
9752
|
+
If provided, returns papers that match the query.
|
|
9753
|
+
token (Union[bool, str, None], *optional*):
|
|
9754
|
+
A valid user access token (string). Defaults to the locally saved
|
|
9755
|
+
token, which is the recommended method for authentication (see
|
|
9756
|
+
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
|
|
9757
|
+
To disable authentication, pass `False`.
|
|
9758
|
+
|
|
9759
|
+
Returns:
|
|
9760
|
+
`Iterable[PaperInfo]`: an iterable of [`huggingface_hub.hf_api.PaperInfo`] objects.
|
|
9761
|
+
|
|
9762
|
+
Example:
|
|
9763
|
+
|
|
9764
|
+
```python
|
|
9765
|
+
>>> from huggingface_hub import HfApi
|
|
9766
|
+
|
|
9767
|
+
>>> api = HfApi()
|
|
9768
|
+
|
|
9769
|
+
# List all papers with "attention" in their title
|
|
9770
|
+
>>> api.list_papers(query="attention")
|
|
9771
|
+
```
|
|
9772
|
+
"""
|
|
9773
|
+
path = f"{self.endpoint}/api/papers/search"
|
|
9774
|
+
params = {}
|
|
9775
|
+
if query:
|
|
9776
|
+
params["q"] = query
|
|
9777
|
+
r = get_session().get(
|
|
9778
|
+
path,
|
|
9779
|
+
params=params,
|
|
9780
|
+
headers=self._build_hf_headers(token=token),
|
|
9781
|
+
)
|
|
9782
|
+
hf_raise_for_status(r)
|
|
9783
|
+
for paper in r.json():
|
|
9784
|
+
yield PaperInfo(**paper)
|
|
9785
|
+
|
|
9786
|
+
def paper_info(self, id: str) -> PaperInfo:
|
|
9787
|
+
"""
|
|
9788
|
+
Get information for a paper on the Hub.
|
|
9789
|
+
|
|
9790
|
+
Args:
|
|
9791
|
+
id (`str`, **optional**):
|
|
9792
|
+
ArXiv id of the paper.
|
|
9793
|
+
|
|
9794
|
+
Returns:
|
|
9795
|
+
`PaperInfo`: A `PaperInfo` object.
|
|
9796
|
+
|
|
9797
|
+
Raises:
|
|
9798
|
+
[`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError):
|
|
9799
|
+
HTTP 404 If the paper does not exist on the Hub.
|
|
9800
|
+
"""
|
|
9801
|
+
path = f"{self.endpoint}/api/papers/{id}"
|
|
9802
|
+
r = get_session().get(path)
|
|
9803
|
+
hf_raise_for_status(r)
|
|
9804
|
+
return PaperInfo(**r.json())
|
|
9805
|
+
|
|
9652
9806
|
def auth_check(
|
|
9653
9807
|
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
|
|
9654
9808
|
) -> None:
|
|
@@ -9744,6 +9898,9 @@ dataset_info = api.dataset_info
|
|
|
9744
9898
|
list_spaces = api.list_spaces
|
|
9745
9899
|
space_info = api.space_info
|
|
9746
9900
|
|
|
9901
|
+
list_papers = api.list_papers
|
|
9902
|
+
paper_info = api.paper_info
|
|
9903
|
+
|
|
9747
9904
|
repo_exists = api.repo_exists
|
|
9748
9905
|
revision_exists = api.revision_exists
|
|
9749
9906
|
file_exists = api.file_exists
|
|
@@ -714,7 +714,7 @@ class HfFileSystemFile(fsspec.spec.AbstractBufferedFile):
|
|
|
714
714
|
"GET",
|
|
715
715
|
url,
|
|
716
716
|
headers=headers,
|
|
717
|
-
retry_on_status_codes=(502, 503, 504),
|
|
717
|
+
retry_on_status_codes=(500, 502, 503, 504),
|
|
718
718
|
timeout=constants.HF_HUB_DOWNLOAD_TIMEOUT,
|
|
719
719
|
)
|
|
720
720
|
hf_raise_for_status(r)
|
|
@@ -813,7 +813,7 @@ class HfFileSystemStreamFile(fsspec.spec.AbstractBufferedFile):
|
|
|
813
813
|
"GET",
|
|
814
814
|
url,
|
|
815
815
|
headers=self.fs._api._build_hf_headers(),
|
|
816
|
-
retry_on_status_codes=(502, 503, 504),
|
|
816
|
+
retry_on_status_codes=(500, 502, 503, 504),
|
|
817
817
|
stream=True,
|
|
818
818
|
timeout=constants.HF_HUB_DOWNLOAD_TIMEOUT,
|
|
819
819
|
)
|
|
@@ -835,7 +835,7 @@ class HfFileSystemStreamFile(fsspec.spec.AbstractBufferedFile):
|
|
|
835
835
|
"GET",
|
|
836
836
|
url,
|
|
837
837
|
headers={"Range": "bytes=%d-" % self.loc, **self.fs._api._build_hf_headers()},
|
|
838
|
-
retry_on_status_codes=(502, 503, 504),
|
|
838
|
+
retry_on_status_codes=(500, 502, 503, 504),
|
|
839
839
|
stream=True,
|
|
840
840
|
timeout=constants.HF_HUB_DOWNLOAD_TIMEOUT,
|
|
841
841
|
)
|
huggingface_hub/hub_mixin.py
CHANGED
|
@@ -17,6 +17,8 @@ from typing import (
|
|
|
17
17
|
Union,
|
|
18
18
|
)
|
|
19
19
|
|
|
20
|
+
import packaging.version
|
|
21
|
+
|
|
20
22
|
from . import constants
|
|
21
23
|
from .errors import EntryNotFoundError, HfHubHTTPError
|
|
22
24
|
from .file_download import hf_hub_download
|
|
@@ -41,7 +43,6 @@ if is_torch_available():
|
|
|
41
43
|
import torch # type: ignore
|
|
42
44
|
|
|
43
45
|
if is_safetensors_available():
|
|
44
|
-
import packaging.version
|
|
45
46
|
import safetensors
|
|
46
47
|
from safetensors.torch import load_model as load_model_as_safetensor
|
|
47
48
|
from safetensors.torch import save_model as save_model_as_safetensor
|