Omartificial-Intelligence-Space
commited on
Commit
•
db1341d
1
Parent(s):
9f383fe
update populate
Browse files- src/populate.py +52 -25
src/populate.py
CHANGED
@@ -1,33 +1,60 @@
|
|
1 |
-
|
2 |
-
import os
|
3 |
|
|
|
4 |
import pandas as pd
|
|
|
5 |
|
6 |
-
from src.display.
|
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 |
-
#
|
13 |
-
df =
|
14 |
-
|
15 |
-
#
|
16 |
-
if
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
return df
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|