Commit
db1341d
1 Parent(s): 9f383fe

update populate

Browse files
Files changed (1) hide show
  1. src/populate.py +52 -25
src/populate.py CHANGED
@@ -1,33 +1,60 @@
1
- import json
2
- import os
3
 
 
4
  import pandas as pd
 
5
 
6
- from src.display.formatting import has_no_nan_values, make_clickable_model
7
- from src.display.utils import AutoEvalColumn, EvalQueueColumn
8
- from src.leaderboard.read_evals import get_raw_eval_results
9
-
10
 
11
  def get_leaderboard_df(eval_results_path, eval_requests_path, cols, benchmark_cols):
12
- # Load evaluation results into a DataFrame
13
- df = load_evaluation_results(eval_results_path)
14
-
15
- # Check if the DataFrame is empty
16
- if df.empty:
17
- print("No evaluation results found. The leaderboard is currently empty.")
18
- # Create an empty DataFrame with the required columns
19
- df = pd.DataFrame(columns=cols)
20
- return df
21
-
22
- # Proceed to sort the DataFrame by 'average' if it's not empty
23
- df = df.sort_values(by=['average'], ascending=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  return df
26
 
27
-
28
- def get_evaluation_queue_df(save_path: str, cols: list) -> list[pd.DataFrame]:
29
- """Creates the different dataframes for the evaluation queues requests"""
30
- # Since evaluations are performed immediately, the queues will be empty
31
- # We'll return empty DataFrames for compatibility
32
- df_empty = pd.DataFrame(columns=cols)
33
- return df_empty, df_empty, df_empty
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # src/populate.py
 
2
 
3
+ import os
4
  import pandas as pd
5
+ import json
6
 
7
+ from src.display.utils import COLUMNS, EVAL_COLS
 
 
 
8
 
9
  def get_leaderboard_df(eval_results_path, eval_requests_path, cols, benchmark_cols):
10
+ # Initialize an empty DataFrame
11
+ df = pd.DataFrame(columns=cols)
12
+
13
+ # Load evaluation results from JSON files
14
+ if os.path.exists(eval_results_path):
15
+ result_files = [os.path.join(eval_results_path, f) for f in os.listdir(eval_results_path) if f.endswith('.json')]
16
+ data_list = []
17
+ for file in result_files:
18
+ with open(file, 'r') as f:
19
+ data = json.load(f)
20
+ # Flatten the JSON structure if needed
21
+ flattened_data = {}
22
+ flattened_data.update(data.get('config', {}))
23
+ flattened_data.update(data.get('results', {}))
24
+ data_list.append(flattened_data)
25
+ if data_list:
26
+ df = pd.DataFrame(data_list)
27
+
28
+ # Ensure DataFrame has all columns
29
+ for col in cols:
30
+ if col not in df.columns:
31
+ df[col] = None
32
+
33
+ # Sort by 'average' column if it exists
34
+ if 'average' in df.columns:
35
+ df = df.sort_values(by=['average'], ascending=False)
36
 
37
  return df
38
 
39
+ def get_evaluation_queue_df(eval_requests_path, eval_cols):
40
+ # Initialize empty DataFrames
41
+ finished_df = pd.DataFrame(columns=eval_cols)
42
+ running_df = pd.DataFrame(columns=eval_cols)
43
+ pending_df = pd.DataFrame(columns=eval_cols)
44
+
45
+ # Load evaluation requests from JSON files
46
+ if os.path.exists(eval_requests_path):
47
+ request_files = [os.path.join(eval_requests_path, f) for f in os.listdir(eval_requests_path) if f.endswith('.json')]
48
+ data_list = []
49
+ for file in request_files:
50
+ with open(file, 'r') as f:
51
+ data = json.load(f)
52
+ data_list.append(data)
53
+ if data_list:
54
+ df = pd.DataFrame(data_list)
55
+ # Split DataFrame based on status
56
+ finished_df = df[df['status'] == 'finished']
57
+ running_df = df[df['status'] == 'running']
58
+ pending_df = df[df['status'] == 'pending']
59
+
60
+ return finished_df, running_df, pending_df