Skip to content

Commit fe39a96

Browse files
authored
Better support for trending score (#2513)
1 parent 63353cf commit fe39a96

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
"spaces",
169169
"tags",
170170
"transformersInfo",
171+
"trendingScore",
171172
"widgetData",
172173
]
173174

@@ -187,25 +188,27 @@
187188
"private",
188189
"siblings",
189190
"sha",
191+
"trendingScore",
190192
"tags",
191193
]
192194

193195
ExpandSpaceProperty_T = Literal[
194196
"author",
195197
"cardData",
198+
"createdAt",
196199
"datasets",
197200
"disabled",
198201
"lastModified",
199-
"createdAt",
200202
"likes",
203+
"models",
201204
"private",
202205
"runtime",
203206
"sdk",
204207
"siblings",
205208
"sha",
206209
"subdomain",
207210
"tags",
208-
"models",
211+
"trendingScore",
209212
]
210213

211214
USERNAME_PLACEHOLDER = "hf_user"
@@ -748,6 +751,8 @@ class ModelInfo:
748751
Model configuration.
749752
transformers_info (`TransformersInfo`, *optional*):
750753
Transformers-specific info (auto class, processor, etc.) associated with the model.
754+
trending_score (`int`, *optional*):
755+
Trending score of the model.
751756
card_data (`ModelCardData`, *optional*):
752757
Model Card Metadata as a [`huggingface_hub.repocard_data.ModelCardData`] object.
753758
siblings (`List[RepoSibling]`):
@@ -779,6 +784,7 @@ class ModelInfo:
779784
model_index: Optional[Dict]
780785
config: Optional[Dict]
781786
transformers_info: Optional[TransformersInfo]
787+
trending_score: Optional[int]
782788
siblings: Optional[List[RepoSibling]]
783789
spaces: Optional[List[str]]
784790
safetensors: Optional[SafeTensorsInfo]
@@ -802,6 +808,8 @@ def __init__(self, **kwargs):
802808
self.tags = kwargs.pop("tags", None)
803809
self.pipeline_tag = kwargs.pop("pipeline_tag", None)
804810
self.mask_token = kwargs.pop("mask_token", None)
811+
self.trending_score = kwargs.pop("trendingScore", None)
812+
805813
card_data = kwargs.pop("cardData", None) or kwargs.pop("card_data", None)
806814
self.card_data = (
807815
ModelCardData(**card_data, ignore_metadata_errors=True) if isinstance(card_data, dict) else card_data
@@ -896,6 +904,10 @@ class DatasetInfo:
896904
Model Card Metadata as a [`huggingface_hub.repocard_data.DatasetCardData`] object.
897905
siblings (`List[RepoSibling]`):
898906
List of [`huggingface_hub.hf_api.RepoSibling`] objects that constitute the dataset.
907+
paperswithcode_id (`str`, *optional*):
908+
Papers with code ID of the dataset.
909+
trending_score (`int`, *optional*):
910+
Trending score of the dataset.
899911
"""
900912

901913
id: str
@@ -911,6 +923,7 @@ class DatasetInfo:
911923
likes: Optional[int]
912924
paperswithcode_id: Optional[str]
913925
tags: Optional[List[str]]
926+
trending_score: Optional[int]
914927
card_data: Optional[DatasetCardData]
915928
siblings: Optional[List[RepoSibling]]
916929

@@ -930,6 +943,8 @@ def __init__(self, **kwargs):
930943
self.likes = kwargs.pop("likes", None)
931944
self.paperswithcode_id = kwargs.pop("paperswithcode_id", None)
932945
self.tags = kwargs.pop("tags", None)
946+
self.trending_score = kwargs.pop("trendingScore", None)
947+
933948
card_data = kwargs.pop("cardData", None) or kwargs.pop("card_data", None)
934949
self.card_data = (
935950
DatasetCardData(**card_data, ignore_metadata_errors=True) if isinstance(card_data, dict) else card_data
@@ -1015,6 +1030,8 @@ class SpaceInfo:
10151030
List of models used by the Space.
10161031
datasets (`List[str]`, *optional*):
10171032
List of datasets used by the Space.
1033+
trending_score (`int`, *optional*):
1034+
Trending score of the Space.
10181035
"""
10191036

10201037
id: str
@@ -1031,6 +1048,7 @@ class SpaceInfo:
10311048
sdk: Optional[str]
10321049
tags: Optional[List[str]]
10331050
siblings: Optional[List[RepoSibling]]
1051+
trending_score: Optional[int]
10341052
card_data: Optional[SpaceCardData]
10351053
runtime: Optional[SpaceRuntime]
10361054
models: Optional[List[str]]
@@ -1052,6 +1070,7 @@ def __init__(self, **kwargs):
10521070
self.likes = kwargs.pop("likes", None)
10531071
self.sdk = kwargs.pop("sdk", None)
10541072
self.tags = kwargs.pop("tags", None)
1073+
self.trending_score = kwargs.pop("trendingScore", None)
10551074
card_data = kwargs.pop("cardData", None) or kwargs.pop("card_data", None)
10561075
self.card_data = (
10571076
SpaceCardData(**card_data, ignore_metadata_errors=True) if isinstance(card_data, dict) else card_data
@@ -1692,7 +1711,7 @@ def list_models(
16921711
expand (`List[ExpandModelProperty_T]`, *optional*):
16931712
List properties to return in the response. When used, only the properties in the list will be returned.
16941713
This parameter cannot be used if `full`, `cardData` or `fetch_config` are passed.
1695-
Possible values are `"author"`, `"baseModels"`, `"cardData"`, `"childrenModelCount"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"` and `"widgetData"`.
1714+
Possible values are `"author"`, `"baseModels"`, `"cardData"`, `"childrenModelCount"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"`, `"trendingScore"` and `"widgetData"`.
16961715
full (`bool`, *optional*):
16971716
Whether to fetch all model data, including the `last_modified`,
16981717
the `sha`, the files and the `tags`. This is set to `True` by
@@ -1904,7 +1923,7 @@ def list_datasets(
19041923
expand (`List[ExpandDatasetProperty_T]`, *optional*):
19051924
List properties to return in the response. When used, only the properties in the list will be returned.
19061925
This parameter cannot be used if `full` is passed.
1907-
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"` and `"tags"`.
1926+
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"`, `"tags"` and `"trendingScore"`.
19081927
full (`bool`, *optional*):
19091928
Whether to fetch all dataset data, including the `last_modified`,
19101929
the `card_data` and the files. Can contain useful information such as the
@@ -2087,7 +2106,7 @@ def list_spaces(
20872106
expand (`List[ExpandSpaceProperty_T]`, *optional*):
20882107
List properties to return in the response. When used, only the properties in the list will be returned.
20892108
This parameter cannot be used if `full` is passed.
2090-
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"models"`.
2109+
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"trendingScore"`.
20912110
full (`bool`, *optional*):
20922111
Whether to fetch all Spaces data, including the `last_modified`, `siblings`
20932112
and `card_data` fields.
@@ -2404,7 +2423,7 @@ def model_info(
24042423
expand (`List[ExpandModelProperty_T]`, *optional*):
24052424
List properties to return in the response. When used, only the properties in the list will be returned.
24062425
This parameter cannot be used if `securityStatus` or `files_metadata` are passed.
2407-
Possible values are `"author"`, `"baseModels"`, `"cardData"`, `"childrenModelCount"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"` and `"widgetData"`.
2426+
Possible values are `"author"`, `"baseModels"`, `"cardData"`, `"childrenModelCount"`, `"config"`, `"createdAt"`, `"disabled"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"inference"`, `"lastModified"`, `"library_name"`, `"likes"`, `"mask_token"`, `"model-index"`, `"pipeline_tag"`, `"private"`, `"safetensors"`, `"sha"`, `"siblings"`, `"spaces"`, `"tags"`, `"transformersInfo"`, `"trendingScore"` and `"widgetData"`.
24082427
token (Union[bool, str, None], optional):
24092428
A valid user access token (string). Defaults to the locally saved
24102429
token, which is the recommended method for authentication (see
@@ -2478,7 +2497,7 @@ def dataset_info(
24782497
expand (`List[ExpandDatasetProperty_T]`, *optional*):
24792498
List properties to return in the response. When used, only the properties in the list will be returned.
24802499
This parameter cannot be used if `files_metadata` is passed.
2481-
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"` and `"tags"`.
2500+
Possible values are `"author"`, `"cardData"`, `"citation"`, `"createdAt"`, `"disabled"`, `"description"`, `"downloads"`, `"downloadsAllTime"`, `"gated"`, `"lastModified"`, `"likes"`, `"paperswithcode_id"`, `"private"`, `"siblings"`, `"sha"`, `"tags"` and `"trendingScore"`.
24822501
token (Union[bool, str, None], optional):
24832502
A valid user access token (string). Defaults to the locally saved
24842503
token, which is the recommended method for authentication (see
@@ -2551,7 +2570,7 @@ def space_info(
25512570
expand (`List[ExpandSpaceProperty_T]`, *optional*):
25522571
List properties to return in the response. When used, only the properties in the list will be returned.
25532572
This parameter cannot be used if `full` is passed.
2554-
Possible values are `"author"`, `"cardData"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"createdAt"`, `"likes"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"models"`.
2573+
Possible values are `"author"`, `"cardData"`, `"createdAt"`, `"datasets"`, `"disabled"`, `"lastModified"`, `"likes"`, `"models"`, `"private"`, `"runtime"`, `"sdk"`, `"siblings"`, `"sha"`, `"subdomain"`, `"tags"` and `"trendingScore"`.
25552574
token (Union[bool, str, None], optional):
25562575
A valid user access token (string). Defaults to the locally saved
25572576
token, which is the recommended method for authentication (see

0 commit comments

Comments
 (0)