Spaces:
Runtime error
Runtime error
Clémentine commited on
Commit ·
238e793
1
Parent(s): 7e8ac0e
should update index in collection as it goes
Browse files123456715 unmodified lines2324252627282930313210 unmodified lines43444546474849505152535455565758592 unmodified lines6263646566import osimport pandas as pdfrom pandas import DataFramefrom huggingface_hub import get_collection, add_collection_item, delete_collection_itemfrom huggingface_hub.utils._errors import HfHubHTTPErrorfrom src.display_models.model_metadata_type import ModelType15 unmodified lines"""This function updates the Open LLM Leaderboard model collection with the latest best models foreach size category and type."""params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")cur_best_models = []for type in ModelType:if type.value.name == "": continuefor size in intervals:10 unmodified lines# We add them one by one to the leaderboardfor model in best_models:# We can use collection = get_collection to grab the id of the last item, then place it where we want using update_collection but it's costly...# We could also remove exists_ok to update the note to include the date of apparition of the model for ex.try:add_collection_item(path_to_collection,item_id=model,item_type="model",exists_ok=True,note=f"Best {type.to_str(' ')} model of around {size} on the leaderboard today!",token=H4_TOKEN)cur_best_models.append(model)breakexcept HfHubHTTPError:2 unmodified linescollection = get_collection(path_to_collection, token=H4_TOKEN)for item in collection.items:if item.item_id not in cur_best_models:delete_collection_item(collection_slug=path_to_collection, item_object_id=item.item_object_id, token=H4_TOKEN)1234567815 unmodified lines24252627282930313233343510 unmodified lines4647484950515253545556575859606162636465662 unmodified lines6970717273747576import osimport pandas as pdfrom pandas import DataFramefrom requests.exceptions import HTTPErrorfrom huggingface_hub import get_collection, add_collection_item, update_collection_item, delete_collection_itemfrom huggingface_hub.utils._errors import HfHubHTTPErrorfrom src.display_models.model_metadata_type import ModelType15 unmodified lines"""This function updates the Open LLM Leaderboard model collection with the latest best models foreach size category and type."""collection = get_collection(collection_slug=path_to_collection, token=H4_TOKEN)params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")cur_best_models = []ix = 0for type in ModelType:if type.value.name == "": continuefor size in intervals:10 unmodified lines# We add them one by one to the leaderboardfor model in best_models:ix += 1cur_len_collection = len(collection.items)try:collection = add_collection_item(path_to_collection,item_id=model,item_type="model",exists_ok=True,note=f"Best {type.to_str(' ')} model of around {size} on the leaderboard today!",token=H4_TOKEN)if len(collection.items) > cur_len_collection: # we added an item - we make sure its position is correctitem_object_id = collection.items[-1].item_object_idupdate_collection_item(collection_slug=path_to_collection, item_object_id=item_object_id, position=ix)cur_len_collection = len(collection.items)cur_best_models.append(model)breakexcept HfHubHTTPError:2 unmodified linescollection = get_collection(path_to_collection, token=H4_TOKEN)for item in collection.items:if item.item_id not in cur_best_models:try:delete_collection_item(collection_slug=path_to_collection, item_object_id=item.item_object_id, token=H4_TOKEN)except HfHubHTTPError:continue
src/manage_collections.py+16-6