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