merve/notebooks
0
1 2__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']3 4import gradio as gr5import pandas as pd6from huggingface_hub import HfApi, repocard7 8 9#def is_duplicated(space_id:str)->None:10# card = repocard.RepoCard.load(space_id, repo_type="space")11# return getattr(card.data, "duplicated_from", None) is not None12 13 14 15def make_clickable_model(model_name, repo_type, link=None):16 if link is None:17 if repo_type == "Dataset":18 link = "https://huggingface.co/" + "datasets/" + model_name19 else:20 link = "https://huggingface.co/" + model_name21 return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'22 23def get_repo_ids(repo_type):24 api = HfApi()25 if repo_type == "Model":26 notebooks = api.list_models(filter=["notebook-favorites"])27 elif repo_type == "Dataset":28 notebooks = api.list_datasets(filter=["notebook-favorites"])29 print(notebooks)30 notebook_ids = [x for x in notebooks]31 return notebook_ids32 33 34def make_clickable_user(user_id):35 link = "https://huggingface.co/" + user_id36 return f'<a target="_blank" href="{link}">{user_id}</a>'37 38def get_submissions(repo_type):39 submissions = get_repo_ids(repo_type)40 leaderboard_models = []41 42 for submission in submissions:43 # user, model, likes44 #if not is_duplicated(submission.id):45 user_id = submission.id.split("/")[0]46 leaderboard_models.append(47 (48 make_clickable_user(user_id),49 make_clickable_model(submission.id, repo_type),50 submission.likes,51 )52 )53 54 df = pd.DataFrame(data=leaderboard_models, columns=["User", "Repository", "Likes"])55 df.sort_values(by=["Likes"], ascending=False, inplace=True)56 df.insert(0, "Rank", list(range(1, len(df) + 1)))57 return df58 59 60 61block = gr.Blocks()62 63with block:64 gr.Markdown(65 """# Notebooks Leaderboard66 67 This Space compiles coolest model and dataset repositories that contain notebooks!68 """69 )70 with gr.Tabs():71 with gr.TabItem("Notebooks in Model Repositories ๐ค"):72 with gr.Row():73 model_data = gr.components.Dataframe(74 type="pandas", datatype=["number", "markdown", "markdown", "number"]75 )76 with gr.Row():77 data_run = gr.Button("Refresh")78 data_run.click(79 get_submissions, inputs=gr.Variable("Model"), outputs=model_data80 )81 with gr.TabItem("Notebooks in Dataset Repositories ๐"):82 with gr.Row():83 dataset_data = gr.components.Dataframe(84 type="pandas", datatype=["number", "markdown", "markdown", "number"]85 )86 with gr.Row():87 data_run = gr.Button("Refresh")88 data_run.click(89 get_submissions, inputs=gr.Variable("Dataset"), outputs=dataset_data90 )91 92 block.load(get_submissions, inputs=gr.Variable("Model"), outputs=model_data)93 block.load(get_submissions, inputs=gr.Variable("Dataset"), outputs=dataset_data)94 95 96block.launch(debug=True)