Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import pandas as pd
|
6 |
+
from huggingface_hub import HfApi, repocard
|
7 |
+
|
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 None
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
def 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_name
|
19 |
+
else:
|
20 |
+
link = "https://huggingface.co/" + model_name
|
21 |
+
return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
|
22 |
+
|
23 |
+
def get_repo_ids(repo_type):
|
24 |
+
api = HfApi()
|
25 |
+
if repo_type is "Model":
|
26 |
+
notebooks = api.list_models(filter=["notebook-favorites"])
|
27 |
+
elif repo_type is "Dataset":
|
28 |
+
notebooks = api.list_datasets(filter=["notebook-favorites"])
|
29 |
+
print(notebooks)
|
30 |
+
notebook_ids = [x for x in notebooks]
|
31 |
+
return notebook_ids_ids
|
32 |
+
|
33 |
+
|
34 |
+
def make_clickable_user(user_id):
|
35 |
+
link = "https://huggingface.co/" + user_id
|
36 |
+
return f'<a target="_blank" href="{link}">{user_id}</a>'
|
37 |
+
|
38 |
+
def get_submissions(repo_type):
|
39 |
+
submissions = get_repo_ids(repo_type)
|
40 |
+
leaderboard_models = []
|
41 |
+
|
42 |
+
for submission in submissions:
|
43 |
+
# user, model, likes
|
44 |
+
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 df
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
block = gr.Blocks()
|
62 |
+
|
63 |
+
with block:
|
64 |
+
gr.Markdown(
|
65 |
+
"""# Notebooks Leaderboard
|
66 |
+
|
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("nature"), outputs=nature_data
|
80 |
+
)
|
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("scifi"), outputs=scifi_data
|
90 |
+
)
|
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 |
+
|
96 |
+
block.launch()
|