merve HF staff commited on
Commit
de1fc5c
1 Parent(s): 40d0d65

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
2
+
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from huggingface_hub import HfApi, repocard
6
+
7
+ def is_duplicated(space_id:str)->None:
8
+ card = repocard.RepoCard.load(space_id, repo_type="space")
9
+ return getattr(card.data, "duplicated_from", None) is not None
10
+
11
+
12
+
13
+ def make_clickable_model(model_name, link=None):
14
+ if link is None:
15
+ link = "https://huggingface.co/" + "spaces/" + model_name
16
+ return f'<a target="_blank" href="{link}">{model_name.split("/")[-1]}</a>'
17
+
18
+ def get_space_ids():
19
+ api = HfApi()
20
+ spaces = api.list_spaces(filter="jax-diffusers-event")
21
+ print(spaces)
22
+ space_ids = [x for x in spaces]
23
+ return space_ids
24
+
25
+
26
+ def make_clickable_user(user_id):
27
+ link = "https://huggingface.co/" + user_id
28
+ return f'<a target="_blank" href="{link}">{user_id}</a>'
29
+
30
+ def get_submissions():
31
+ submissions = get_space_ids()
32
+ leaderboard_models = []
33
+
34
+ for submission in submissions:
35
+ # user, model, likes
36
+ if not is_duplicated(submission.id):
37
+ user_id = submission.id.split("/")[0]
38
+ leaderboard_models.append(
39
+ (
40
+ make_clickable_user(user_id),
41
+ make_clickable_model(submission.id),
42
+ submission.likes,
43
+ )
44
+ )
45
+
46
+ df = pd.DataFrame(data=leaderboard_models, columns=["User", "Space", "Likes"])
47
+ df.sort_values(by=["Likes"], ascending=False, inplace=True)
48
+ df.insert(0, "Rank", list(range(1, len(df) + 1)))
49
+ return df
50
+
51
+ block = gr.Blocks()
52
+
53
+ with block:
54
+ gr.Markdown(
55
+ """# JAX Diffusers Event Leaderboard
56
+
57
+ Welcome to the leaderboard for the JAX Diffusers Event 💗🏆
58
+ This is a community event where participants are creating applications based on Stable Diffusion using JAX and 🧨diffusers using v4 TPUs provided by Google Cloud.
59
+ To attend the event, simply follow the instructions in [this guide](https://github.com/huggingface/community-events/tree/main/jax-controlnet-sprint).
60
+ To submit your Space and add it to the leaderboard, simply add `jax-diffusers-event` under tags section in your Space's README.
61
+ At the end of the event, demos with most likes will be evaluated by the jury for special prizes! 🎁
62
+ """
63
+ )
64
+
65
+ with gr.Row():
66
+ data = gr.components.Dataframe(
67
+ type="pandas", datatype=["number", "markdown", "markdown", "number"]
68
+ )
69
+ with gr.Row():
70
+ data_run = gr.Button("Refresh")
71
+ data_run.click(
72
+ get_submissions, outputs=data
73
+ )
74
+
75
+ block.load(get_submissions, outputs=data)
76
+
77
+ block.launch()