Corey Morris commited on
Commit
cd2dfb2
1 Parent(s): 6c46ed2

has data and is sortable, but does not have the model names as a row

Browse files
Files changed (1) hide show
  1. mmlu_data_to_example.py +47 -28
mmlu_data_to_example.py CHANGED
@@ -1,43 +1,62 @@
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()
 
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
4
+
5
+ class MultiURLData:
6
+ def __init__(self, file_path):
7
+ self.file_path = file_path
8
+
9
+ def fetch_data(self):
10
+ # Read URLs from a file, one per line
11
+ with open(self.file_path, 'r') as f:
12
+ file_urls = [line.strip() for line in f.readlines()]
13
+
14
+ dataframes = []
15
+ for url in file_urls:
16
+ # Derive column names from the URLs
17
+ column_name = url.split('/')[-1].split('_')[0]
18
+
19
+ # Load data from URL
20
+ response = requests.get(url)
21
+ data = response.json()
22
+
23
+ # Convert data into a DataFrame
24
+ df = pd.DataFrame(data['results']).T
25
+
26
+ # Rename 'acc' column to respective file names
27
+ df = df.rename(columns={'acc': column_name})
28
+
29
+ # Remove 'hendrycksTest-' from the index
30
+ df.index = df.index.str.replace('hendrycksTest-', '')
31
+
32
+ dataframes.append(df[[column_name]]) # keep only the column of interest
33
+
34
+ # Merge the dataframes
35
+ # Merge the dataframes on index
36
+ data = pd.concat(dataframes, axis=1)
37
+
38
+ # Transpose the dataframe to swap rows and columns
39
+ data = data.transpose()
40
+
41
+ # Select only columns 'moral_scenarios' and 'moral_disputes'
42
+ data = data[['moral_scenarios', 'moral_disputes']]
43
+
44
+ return data
45
+
46
+ data_provider = MultiURLData("file_urls.txt")
47
 
48
  block = gr.Blocks()
 
49
 
50
  with block:
51
+ gr.Markdown("""Leaderboard""")
52
  with gr.Tabs():
53
+ with gr.TabItem("Leaderboard"):
54
  with gr.Row():
55
  data = gr.outputs.Dataframe(type="pandas")
56
  with gr.Row():
57
  data_run = gr.Button("Refresh")
58
+ data_run.click(data_provider.fetch_data, inputs=None, outputs=data)
59
  # running the function on page load in addition to when the button is clicked
60
+ block.load(data_provider.fetch_data, inputs=None, outputs=data)
61
 
62
  block.launch()