Spaces:
Sleeping
Sleeping
Commit
•
c2c9efa
1
Parent(s):
460930f
Fix latest_result_path_per_model variable and refactor
Browse files- app.py +6 -3
- src/results.py +6 -16
app.py
CHANGED
@@ -1,15 +1,18 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
from src.constants import SUBTASKS, TASKS
|
4 |
from src.details import update_subtasks_component, update_load_details_component, load_details_dataframes, \
|
5 |
display_details, update_sample_idx_component, clear_details
|
6 |
-
from src.results import
|
7 |
-
load_results_dataframes, display_results, update_tasks_component, clear_results
|
8 |
-
|
9 |
|
10 |
|
11 |
# if __name__ == "__main__":
|
12 |
latest_result_path_per_model = filter_latest_result_path_per_model(fetch_result_paths())
|
|
|
13 |
|
14 |
with gr.Blocks(fill_height=True) as demo:
|
15 |
gr.HTML("<h1 style='text-align: center;'>Compare Results of the 🤗 Open LLM Leaderboard</h1>")
|
|
|
1 |
+
from functools import partial
|
2 |
+
|
3 |
import gradio as gr
|
4 |
|
5 |
from src.constants import SUBTASKS, TASKS
|
6 |
from src.details import update_subtasks_component, update_load_details_component, load_details_dataframes, \
|
7 |
display_details, update_sample_idx_component, clear_details
|
8 |
+
from src.results import update_load_results_component, \
|
9 |
+
load_results_dataframes, display_results, update_tasks_component, clear_results, \
|
10 |
+
filter_latest_result_path_per_model, fetch_result_paths
|
11 |
|
12 |
|
13 |
# if __name__ == "__main__":
|
14 |
latest_result_path_per_model = filter_latest_result_path_per_model(fetch_result_paths())
|
15 |
+
load_results_dataframes = partial(load_results_dataframes, result_path_per_model=latest_result_path_per_model)
|
16 |
|
17 |
with gr.Blocks(fill_height=True) as demo:
|
18 |
gr.HTML("<h1 style='text-align: center;'>Compare Results of the 🤗 Open LLM Leaderboard</h1>")
|
src/results.py
CHANGED
@@ -4,7 +4,6 @@ import gradio as gr
|
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import HfFileSystem
|
6 |
|
7 |
-
from app import latest_result_path_per_model
|
8 |
from src.constants import RESULTS_DATASET_ID, TASKS
|
9 |
|
10 |
|
@@ -24,34 +23,25 @@ def filter_latest_result_path_per_model(paths):
|
|
24 |
return {model_id: max(paths) for model_id, paths in d.items()}
|
25 |
|
26 |
|
27 |
-
def get_result_path_from_model(model_id, result_path_per_model):
|
28 |
-
return result_path_per_model[model_id]
|
29 |
-
|
30 |
-
|
31 |
def update_load_results_component():
|
32 |
return gr.Button("Load Results", interactive=True)
|
33 |
|
34 |
|
35 |
-
def
|
|
|
|
|
|
|
36 |
fs = HfFileSystem()
|
37 |
with fs.open(result_path, "r") as f:
|
38 |
data = json.load(f)
|
39 |
-
return data
|
40 |
-
|
41 |
-
|
42 |
-
def load_results_dataframe(model_id):
|
43 |
-
if not model_id:
|
44 |
-
return
|
45 |
-
result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
|
46 |
-
data = load_data(result_path)
|
47 |
model_name = data.get("model_name", "Model")
|
48 |
df = pd.json_normalize([{key: value for key, value in data.items()}])
|
49 |
# df.columns = df.columns.str.split(".") # .split return a list instead of a tuple
|
50 |
return df.set_index(pd.Index([model_name])).reset_index()
|
51 |
|
52 |
|
53 |
-
def load_results_dataframes(*model_ids):
|
54 |
-
return [load_results_dataframe(model_id) for model_id in model_ids]
|
55 |
|
56 |
|
57 |
def display_results(task, *dfs):
|
|
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import HfFileSystem
|
6 |
|
|
|
7 |
from src.constants import RESULTS_DATASET_ID, TASKS
|
8 |
|
9 |
|
|
|
23 |
return {model_id: max(paths) for model_id, paths in d.items()}
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
26 |
def update_load_results_component():
|
27 |
return gr.Button("Load Results", interactive=True)
|
28 |
|
29 |
|
30 |
+
def load_results_dataframe(model_id, result_path_per_model=None):
|
31 |
+
if not model_id or not result_path_per_model:
|
32 |
+
return
|
33 |
+
result_path = result_path_per_model[model_id]
|
34 |
fs = HfFileSystem()
|
35 |
with fs.open(result_path, "r") as f:
|
36 |
data = json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
model_name = data.get("model_name", "Model")
|
38 |
df = pd.json_normalize([{key: value for key, value in data.items()}])
|
39 |
# df.columns = df.columns.str.split(".") # .split return a list instead of a tuple
|
40 |
return df.set_index(pd.Index([model_name])).reset_index()
|
41 |
|
42 |
|
43 |
+
def load_results_dataframes(*model_ids, result_path_per_model=None):
|
44 |
+
return [load_results_dataframe(model_id, result_path_per_model=result_path_per_model) for model_id in model_ids]
|
45 |
|
46 |
|
47 |
def display_results(task, *dfs):
|