Corey Morris commited on
Commit
88c2b27
·
1 Parent(s): d701f12

Using data from repository to create leaderboard

Browse files
Files changed (1) hide show
  1. app.py +24 -26
app.py CHANGED
@@ -1,52 +1,50 @@
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
- print(f"dype df {type(df)}")
32
 
33
- dataframes.append(df[[column_name]]) # keep only the column of interest
34
 
35
- # Merge the dataframes
36
  # Merge the dataframes on index
37
  data = pd.concat(dataframes, axis=1)
38
- print(f"dype data {type(data)}")
39
 
40
  # Transpose the dataframe to swap rows and columns
41
  data = data.transpose()
42
-
43
- # Select only columns 'moral_scenarios' and 'moral_disputes'
44
- data = data[['moral_scenarios', 'moral_disputes']]
45
-
46
- ## add a column with the index of the dataframe
47
  data['Model Name'] = data.index
48
-
49
- # move the column to the front of the dataframe
50
  cols = data.columns.tolist()
51
  cols = cols[-1:] + cols[:-1]
52
  data = data[cols]
 
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
4
+ import os
5
+ import fnmatch
6
+ import json
7
+
8
 
9
  class MultiURLData:
10
  def __init__(self, file_path):
11
  self.file_path = file_path
12
 
13
  def fetch_data(self):
 
 
 
14
 
15
  dataframes = []
 
 
 
16
 
17
+ def find_files(directory, pattern):
18
+ for root, dirs, files in os.walk(directory):
19
+ for basename in files:
20
+ if fnmatch.fnmatch(basename, pattern):
21
+ filename = os.path.join(root, basename)
22
+ yield filename
23
+
24
+ for filename in find_files('results', 'results*.json'):
25
+ model_name = filename.split('/')[2]
26
+ with open(filename) as f:
27
+ data = json.load(f)
28
+ df = pd.DataFrame(data['results']).T
29
+
30
+ # Rename 'acc' column to respective file names
31
+ df = df.rename(columns={'acc': model_name})
32
 
33
+ # Remove 'hendrycksTest-' from the index
34
+ df.index = df.index.str.replace('hendrycksTest-', '')
35
 
36
+ # Remove'harness|' from the index
37
+ df.index = df.index.str.replace('harness|', '')
38
 
 
 
 
39
 
40
+ dataframes.append(df[[model_name]]) # keep only the column of interest
41
 
 
42
  # Merge the dataframes on index
43
  data = pd.concat(dataframes, axis=1)
 
44
 
45
  # Transpose the dataframe to swap rows and columns
46
  data = data.transpose()
 
 
 
 
 
47
  data['Model Name'] = data.index
 
 
48
  cols = data.columns.tolist()
49
  cols = cols[-1:] + cols[:-1]
50
  data = data[cols]