File size: 3,185 Bytes
299a6bc 8ac54c7 299a6bc 8ac54c7 299a6bc 43bad97 299a6bc 32938db 299a6bc 32938db 299a6bc 6210d83 299a6bc 6210d83 299a6bc 8f99d94 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
import gradio as gr
import pandas as pd
from huggingface_hub import HfApi, repocard
#def is_duplicated(space_id:str)->None:
# card = repocard.RepoCard.load(space_id, repo_type="space")
# return getattr(card.data, "duplicated_from", None) is not None
def make_clickable_model(model_name, repo_type, link=None):
if link is None:
if repo_type == "Dataset":
link = "https://huggingface.co/" + "datasets/" + model_name
else:
link = "https://huggingface.co/" + model_name
return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
def get_repo_ids(repo_type):
api = HfApi()
if repo_type == "Model":
notebooks = api.list_models(filter=["notebook-favorites"])
elif repo_type == "Dataset":
notebooks = api.list_datasets(filter=["notebook-favorites"])
print(notebooks)
notebook_ids = [x for x in notebooks]
return notebook_ids
def make_clickable_user(user_id):
link = "https://huggingface.co/" + user_id
return f'<a target="_blank" href="{link}">{user_id}</a>'
def get_submissions(repo_type):
submissions = get_repo_ids(repo_type)
leaderboard_models = []
for submission in submissions:
# user, model, likes
#if not is_duplicated(submission.id):
user_id = submission.id.split("/")[0]
leaderboard_models.append(
(
make_clickable_user(user_id),
make_clickable_model(submission.id, repo_type),
submission.likes,
)
)
df = pd.DataFrame(data=leaderboard_models, columns=["User", "Repository", "Likes"])
df.sort_values(by=["Likes"], ascending=False, inplace=True)
df.insert(0, "Rank", list(range(1, len(df) + 1)))
return df
block = gr.Blocks()
with block:
gr.Markdown(
"""# Notebooks Leaderboard
This Space compiles coolest model and dataset repositories that contain notebooks!
"""
)
with gr.Tabs():
with gr.TabItem("Notebooks in Model Repositories π€"):
with gr.Row():
model_data = gr.components.Dataframe(
type="pandas", datatype=["number", "markdown", "markdown", "number"]
)
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(
get_submissions, inputs=gr.Variable("Model"), outputs=model_data
)
with gr.TabItem("Notebooks in Dataset Repositories π"):
with gr.Row():
dataset_data = gr.components.Dataframe(
type="pandas", datatype=["number", "markdown", "markdown", "number"]
)
with gr.Row():
data_run = gr.Button("Refresh")
data_run.click(
get_submissions, inputs=gr.Variable("Dataset"), outputs=dataset_data
)
block.load(get_submissions, inputs=gr.Variable("Model"), outputs=model_data)
block.load(get_submissions, inputs=gr.Variable("Dataset"), outputs=dataset_data)
block.launch(debug=True) |