Model_Memory_and_Popularity / hub_model_stats_utils.py
brwillia's picture
Upload folder using huggingface_hub
7ff7aab verified
raw
history blame contribute delete
866 Bytes
import pandas as pd
from huggingface_hub import HfApi, ModelFilter
def call_hub_api(model_task: str):
api = HfApi()
models = api.list_models(
filter=ModelFilter(
task=model_task
)
)
return list(models)
def get_model_type_downloads(model_task: str):
models = call_hub_api(model_task)
dict_list = []
for cur_model in models:
this_dict = {"id":cur_model.id, "downloads":cur_model.downloads, "likes":cur_model.likes, "author": cur_model.author, "created": cur_model.created_at, "modified": cur_model.last_modified}
dict_list.append(this_dict)
df = pd.DataFrame(dict_list)
return df.sort_values("downloads", ascending=False).head(50)
# df_likes_desc = df.sort_values("likes", ascending=False)
# df_likes_desc.head(10)
# df_likes_desc['id'].str.split('/', n=1, expand=True)