Spaces:
Sleeping
Sleeping
Clémentine
commited on
Commit
•
c212cb7
1
Parent(s):
f2bc0a5
should update index in collection as it goes
Browse files- src/manage_collections.py +16 -6
src/manage_collections.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
from pandas import DataFrame
|
4 |
-
from
|
|
|
5 |
from huggingface_hub.utils._errors import HfHubHTTPError
|
6 |
|
7 |
from src.display_models.model_metadata_type import ModelType
|
@@ -23,10 +24,12 @@ def update_collections(df: DataFrame):
|
|
23 |
"""This function updates the Open LLM Leaderboard model collection with the latest best models for
|
24 |
each size category and type.
|
25 |
"""
|
|
|
26 |
params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")
|
27 |
|
28 |
cur_best_models = []
|
29 |
|
|
|
30 |
for type in ModelType:
|
31 |
if type.value.name == "": continue
|
32 |
for size in intervals:
|
@@ -43,17 +46,21 @@ def update_collections(df: DataFrame):
|
|
43 |
|
44 |
# We add them one by one to the leaderboard
|
45 |
for model in best_models:
|
46 |
-
|
47 |
-
|
48 |
try:
|
49 |
-
add_collection_item(
|
50 |
path_to_collection,
|
51 |
item_id=model,
|
52 |
item_type="model",
|
53 |
-
exists_ok=True,
|
54 |
note=f"Best {type.to_str(' ')} model of around {size} on the leaderboard today!",
|
55 |
token=H4_TOKEN
|
56 |
)
|
|
|
|
|
|
|
|
|
57 |
cur_best_models.append(model)
|
58 |
break
|
59 |
except HfHubHTTPError:
|
@@ -62,5 +69,8 @@ def update_collections(df: DataFrame):
|
|
62 |
collection = get_collection(path_to_collection, token=H4_TOKEN)
|
63 |
for item in collection.items:
|
64 |
if item.item_id not in cur_best_models:
|
65 |
-
|
|
|
|
|
|
|
66 |
|
|
|
1 |
import os
|
2 |
import pandas as pd
|
3 |
from pandas import DataFrame
|
4 |
+
from requests.exceptions import HTTPError
|
5 |
+
from huggingface_hub import get_collection, add_collection_item, update_collection_item, delete_collection_item
|
6 |
from huggingface_hub.utils._errors import HfHubHTTPError
|
7 |
|
8 |
from src.display_models.model_metadata_type import ModelType
|
|
|
24 |
"""This function updates the Open LLM Leaderboard model collection with the latest best models for
|
25 |
each size category and type.
|
26 |
"""
|
27 |
+
collection = get_collection(collection_slug=path_to_collection, token=H4_TOKEN)
|
28 |
params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")
|
29 |
|
30 |
cur_best_models = []
|
31 |
|
32 |
+
ix = 0
|
33 |
for type in ModelType:
|
34 |
if type.value.name == "": continue
|
35 |
for size in intervals:
|
|
|
46 |
|
47 |
# We add them one by one to the leaderboard
|
48 |
for model in best_models:
|
49 |
+
ix += 1
|
50 |
+
cur_len_collection = len(collection.items)
|
51 |
try:
|
52 |
+
collection = add_collection_item(
|
53 |
path_to_collection,
|
54 |
item_id=model,
|
55 |
item_type="model",
|
56 |
+
exists_ok=True,
|
57 |
note=f"Best {type.to_str(' ')} model of around {size} on the leaderboard today!",
|
58 |
token=H4_TOKEN
|
59 |
)
|
60 |
+
if len(collection.items) > cur_len_collection: # we added an item - we make sure its position is correct
|
61 |
+
item_object_id = collection.items[-1].item_object_id
|
62 |
+
update_collection_item(collection_slug=path_to_collection, item_object_id=item_object_id, position=ix)
|
63 |
+
cur_len_collection = len(collection.items)
|
64 |
cur_best_models.append(model)
|
65 |
break
|
66 |
except HfHubHTTPError:
|
|
|
69 |
collection = get_collection(path_to_collection, token=H4_TOKEN)
|
70 |
for item in collection.items:
|
71 |
if item.item_id not in cur_best_models:
|
72 |
+
try:
|
73 |
+
delete_collection_item(collection_slug=path_to_collection, item_object_id=item.item_object_id, token=H4_TOKEN)
|
74 |
+
except HfHubHTTPError:
|
75 |
+
continue
|
76 |
|