Spaces:
Runtime error
Runtime error
Corey Morris
commited on
Commit
·
6c46ed2
1
Parent(s):
1b89da7
example code refactored to make it easier to swap out data source
Browse files- mmlu_data_to_example.py +43 -0
mmlu_data_to_example.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import pandas as pd
|
4 |
+
from huggingface_hub.hf_api import SpaceInfo
|
5 |
+
|
6 |
+
class BlocksSpace:
|
7 |
+
def __init__(self, url, name):
|
8 |
+
self.url = url
|
9 |
+
self.name = name
|
10 |
+
|
11 |
+
def fetch_spaces(self):
|
12 |
+
r = requests.get(self.url)
|
13 |
+
d = r.json()
|
14 |
+
spaces = [SpaceInfo(**x) for x in d]
|
15 |
+
blocks_spaces = {}
|
16 |
+
for i in range(0,len(spaces)):
|
17 |
+
if spaces[i].id.split('/')[0] == self.name and hasattr(spaces[i], 'likes') and spaces[i].id != f'{self.name}/Leaderboard' and spaces[i].id != f'{self.name}/README':
|
18 |
+
blocks_spaces[spaces[i].id]=spaces[i].likes
|
19 |
+
return blocks_spaces
|
20 |
+
|
21 |
+
def get_spaces_dataframe(self):
|
22 |
+
blocks_spaces = self.fetch_spaces()
|
23 |
+
df = pd.DataFrame(
|
24 |
+
[{"Spaces_Name": Spaces, "likes": likes} for Spaces,likes in blocks_spaces.items()])
|
25 |
+
df = df.sort_values(by=['likes'],ascending=False)
|
26 |
+
return df
|
27 |
+
|
28 |
+
block = gr.Blocks()
|
29 |
+
my_blocks_space = BlocksSpace("https://huggingface.co/api/spaces", "Gradio-Blocks")
|
30 |
+
|
31 |
+
with block:
|
32 |
+
gr.Markdown("""Leaderboard for the most popular Blocks Event Spaces. To learn more and join, see Blocks Party Event""")
|
33 |
+
with gr.Tabs():
|
34 |
+
with gr.TabItem("Blocks Party Leaderboard"):
|
35 |
+
with gr.Row():
|
36 |
+
data = gr.outputs.Dataframe(type="pandas")
|
37 |
+
with gr.Row():
|
38 |
+
data_run = gr.Button("Refresh")
|
39 |
+
data_run.click(my_blocks_space.get_spaces_dataframe, inputs=None, outputs=data)
|
40 |
+
# running the function on page load in addition to when the button is clicked
|
41 |
+
block.load(my_blocks_space.get_spaces_dataframe, inputs=None, outputs=data)
|
42 |
+
|
43 |
+
block.launch()
|