qiantong-xu commited on
Commit
eb33210
1 Parent(s): ff999bb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def is_duplicated(space_id:str)->None:
9
+ card = repocard.RepoCard.load(space_id, repo_type="space")
10
+ return getattr(card.data, "duplicated_from", None) is not None
11
+
12
+
13
+
14
+ def make_clickable_model(model_name, link=None):
15
+ if link is None:
16
+ link = "https://huggingface.co/" + "spaces/" + model_name
17
+ return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
18
+
19
+ def get_space_ids():
20
+ api = HfApi()
21
+ spaces = api.list_spaces(filter="making-demos")
22
+ print(spaces)
23
+ space_ids = [x for x in spaces]
24
+ return space_ids
25
+
26
+
27
+ def make_clickable_user(user_id):
28
+ link = "https://huggingface.co/" + user_id
29
+ return f'<a target="_blank" href="{link}">{user_id}</a>'
30
+
31
+ def get_submissions():
32
+ submissions = get_space_ids()
33
+ leaderboard_models = []
34
+
35
+ for submission in submissions:
36
+ # user, model, likes
37
+ if not is_duplicated(submission.id):
38
+ user_id = submission.id.split("/")[0]
39
+ leaderboard_models.append(
40
+ (
41
+ make_clickable_user(user_id),
42
+ make_clickable_model(submission.id),
43
+ submission.likes,
44
+ )
45
+ )
46
+
47
+ df = pd.DataFrame(data=leaderboard_models, columns=["User", "Space", "Likes"])
48
+ df.sort_values(by=["Likes"], ascending=False, inplace=True)
49
+ df.insert(0, "Rank", list(range(1, len(df) + 1)))
50
+ return df
51
+
52
+ block = gr.Blocks()
53
+
54
+ with block:
55
+ gr.Markdown(
56
+ """# Making Demos Leaderboard
57
+
58
+ Welcome to the leaderboard for the ever-running Making Demos Event! 🏆
59
+ This is a community event where participants create demos of recently released machine learning models, or combine multiple demos to make cool apps!
60
+ To attend the event, simply join us in [Discord](https://huggingface.co/join/discord), take the role #collaborate and write under one of the paper posts under #making-demos forum.
61
+ You can add `making-demos` to tags in your Spaces' README.md's metadata section to add your demo to this leaderboard.
62
+ At the end of every week, winners of this leaderboard will earn special prizes! 🎁
63
+ """
64
+ )
65
+
66
+ with gr.Row():
67
+ data = gr.components.Dataframe(
68
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
69
+ )
70
+ with gr.Row():
71
+ data_run = gr.Button("Refresh")
72
+ data_run.click(
73
+ get_submissions, outputs=data
74
+ )
75
+
76
+ block.load(get_submissions, outputs=data)
77
+
78
+ block.launch()