Muennighoff commited on
Commit
b4966ee
1 Parent(s): 0ffe84e
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import pandas as pd
4
+ from huggingface_hub.hf_api import SpaceInfo
5
+ path = f"https://huggingface.co/api/spaces"
6
+
7
+
8
+ def get_blocks_party_spaces():
9
+ r = requests.get(path)
10
+ d = r.json()
11
+ spaces = [SpaceInfo(**x) for x in d]
12
+ blocks_spaces = {}
13
+ for i in range(0,len(spaces)):
14
+ if spaces[i].id.split('/')[0] == 'Gradio-Blocks' and hasattr(spaces[i], 'likes') and spaces[i].id != 'Gradio-Blocks/Leaderboard' and spaces[i].id != 'Gradio-Blocks/README':
15
+ blocks_spaces[spaces[i].id]=spaces[i].likes
16
+ df = pd.DataFrame(
17
+ [{"Spaces_Name": Spaces, "likes": likes} for Spaces,likes in blocks_spaces.items()])
18
+ df = df.sort_values(by=['likes'],ascending=False)
19
+ return df
20
+
21
+ block = gr.Blocks()
22
+
23
+ with block:
24
+ gr.Markdown("""Leaderboard for the most popular Blocks Event Spaces. To learn more and join, see <a href="https://huggingface.co/Gradio-Blocks" target="_blank" style="text-decoration: underline">Blocks Party Event</a>""")
25
+ with gr.Tabs():
26
+ with gr.TabItem("Blocks Party Leaderboard"):
27
+ with gr.Row():
28
+ data = gr.outputs.Dataframe(type="pandas")
29
+ with gr.Row():
30
+ data_run = gr.Button("Refresh")
31
+ data_run.click(get_blocks_party_spaces, inputs=None, outputs=data)
32
+ # running the function on page load in addition to when the button is clicked
33
+ block.load(get_blocks_party_spaces, inputs=None, outputs=data)
34
+
35
+ block.launch()
36
+