mariagrandury commited on
Commit
0384ea1
1 Parent(s): f375e2c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __all__ = ['block', 'make_clickable_repo', 'get_submissions']
2
+
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from huggingface_hub import HfApi
6
+
7
+ def make_clickable_repo(name, repo_type):
8
+ if repo_type == "spaces":
9
+ link = "https://huggingface.co/" + "spaces/" + name
10
+ elif repo_type == "models":
11
+ link = "https://huggingface.co/" + name
12
+ else:
13
+ link = "https://huggingface.co/" + "datasets/" + name
14
+ return f'<a target="_blank" href="{link}">{name.split("/")[-1]}</a>'
15
+
16
+ def get_repo_ids(repo_type):
17
+ api = HfApi()
18
+ if repo_type == "spaces":
19
+ repos = api.list_spaces(author="somosnlp")
20
+ repos = [s for s in repos if s.id not in ["somosnlp", "somosnlp/likes_leaderboard"]]
21
+ elif repo_type == "models":
22
+ repos = api.list_models(author="somosnlp", full=True)
23
+ else:
24
+ repos = api.list_datasets(author="somosnlp")
25
+ return repos
26
+
27
+ def get_submissions(repo_type):
28
+ submissions = get_repo_ids(repo_type)
29
+ leaderboard = []
30
+
31
+ for submission in submissions:
32
+ leaderboard.append(
33
+ (
34
+ make_clickable_repo(submission.id, repo_type),
35
+ submission.likes,
36
+ )
37
+ )
38
+
39
+ df = pd.DataFrame(data=leaderboard, columns=["Repo", "Likes"])
40
+ df.sort_values(by=["Likes"], ascending=False, inplace=True)
41
+ df.insert(0, "Rank", list(range(1, len(df) + 1)))
42
+ return df
43
+
44
+ block = gr.Blocks()
45
+
46
+ with block:
47
+ gr.Markdown(
48
+ """# Somos NLP ❤️ Leaderboard
49
+ """
50
+ )
51
+ with gr.Tabs():
52
+ with gr.TabItem("Spaces (ML apps)"):
53
+ with gr.Row():
54
+ spaces_data = gr.components.Dataframe(
55
+ type="pandas", datatype=["number", "markdown", "number"]
56
+ )
57
+ with gr.Row():
58
+ data_run = gr.Button("Refresh")
59
+ data_run.click(
60
+ get_submissions, inputs=gr.Variable("spaces"), outputs=spaces_data
61
+ )
62
+ with gr.TabItem("Models"):
63
+ with gr.Row():
64
+ models_data = gr.components.Dataframe(
65
+ type="pandas", datatype=["number", "markdown", "number"]
66
+ )
67
+ with gr.Row():
68
+ data_run = gr.Button("Refresh")
69
+ data_run.click(
70
+ get_submissions, inputs=gr.Variable("models"), outputs=models_data
71
+ )
72
+ with gr.TabItem("Datasets"):
73
+ with gr.Row():
74
+ datasets_data = gr.components.Dataframe(
75
+ type="pandas", datatype=["number", "markdown", "number"]
76
+ )
77
+ with gr.Row():
78
+ data_run = gr.Button("Refresh")
79
+ data_run.click(
80
+ get_submissions, inputs=gr.Variable("datasets"), outputs=datasets_data
81
+ )
82
+
83
+
84
+ block.load(get_submissions, inputs=gr.Variable("spaces"), outputs=spaces_data)
85
+ block.load(get_submissions, inputs=gr.Variable("models"), outputs=models_data)
86
+ block.load(get_submissions, inputs=gr.Variable("datasets"), outputs=datasets_data)
87
+
88
+
89
+ block.launch(debug=True)