File size: 866 Bytes
7ff7aab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)