albertvillanova HF staff commited on
Commit
e29ab28
1 Parent(s): 5b0b818

Use tuples and simplify views

Browse files
Files changed (1) hide show
  1. app.py +36 -23
app.py CHANGED
@@ -53,9 +53,10 @@ def load_result(model_id):
53
  result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
54
  data = load_data(result_path)
55
  model_name = data.get("model_name", "Model")
 
56
  result = [
57
- to_vertical(to_dataframe_all(data), model_name),
58
- to_vertical(to_dataframe_results(data), model_name)
59
  ]
60
  return result
61
 
@@ -65,30 +66,42 @@ def to_dataframe(data):
65
 
66
 
67
  def to_vertical(df, model_name):
68
- return df.iloc[0].rename_axis("Parameters").rename(model_name).to_frame() # .reset_index()
 
 
69
 
70
 
71
  def to_dataframe_all(data):
72
- return pd.json_normalize([{key: value for key, value in data.items() if key not in EXCLUDED_KEYS}])
73
-
74
-
75
- def to_dataframe_results(data):
76
- dfs = {}
77
- for key in data["results"]:
78
- if key not in EXCLUDED_RESULTS_KEYS: # key.startswith("leaderboard_"):
79
- name = key[len("leaderboard_"):]
80
- df = to_dataframe(
81
- {
82
- key: value
83
- for key, value in data["results"][key].items()
84
- if key not in EXCLUDED_RESULTS_LEADERBOARDS_KEYS
85
- }
86
- )
87
- # df.drop(columns=["alias"])
88
- # df.columns = pd.MultiIndex.from_product([[name], df.columns])
89
- df.columns = [f"{name}.{column}" for column in df.columns]
90
- dfs[name] = df
91
- return pd.concat(dfs.values(), axis="columns")
 
 
 
 
 
 
 
 
 
 
92
 
93
 
94
  def concat_result_1(result_1, results):
 
53
  result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
54
  data = load_data(result_path)
55
  model_name = data.get("model_name", "Model")
56
+ df = to_dataframe_all(data)
57
  result = [
58
+ to_vertical(df, model_name),
59
+ to_vertical(to_dataframe_results(df), model_name)
60
  ]
61
  return result
62
 
 
66
 
67
 
68
  def to_vertical(df, model_name):
69
+ df = df.iloc[0].rename_axis("Parameters").rename(model_name).to_frame() # .reset_index()
70
+ df.index = df.index.str.join(".")
71
+ return df
72
 
73
 
74
  def to_dataframe_all(data):
75
+ df = pd.json_normalize([{key: value for key, value in data.items() if key not in EXCLUDED_KEYS}])
76
+ # df.columns = df.columns.str.split(".") # .split return a list instead of a tuple
77
+ df.columns = list(map(lambda x: tuple(x.split(".")), df.columns))
78
+ return df
79
+
80
+ #
81
+ # def to_dataframe_results(data):
82
+ # dfs = {}
83
+ # for key in data["results"]:
84
+ # if key not in EXCLUDED_RESULTS_KEYS: # key.startswith("leaderboard_"):
85
+ # name = key[len("leaderboard_"):]
86
+ # df = to_dataframe(
87
+ # {
88
+ # key: value
89
+ # for key, value in data["results"][key].items()
90
+ # if key not in EXCLUDED_RESULTS_LEADERBOARDS_KEYS
91
+ # }
92
+ # )
93
+ # # df.drop(columns=["alias"])
94
+ # # df.columns = pd.MultiIndex.from_product([[name], df.columns])
95
+ # df.columns = [f"{name}.{column}" for column in df.columns]
96
+ # dfs[name] = df
97
+ # return pd.concat(dfs.values(), axis="columns")
98
+
99
+
100
+ def to_dataframe_results(df):
101
+ df = df.loc[:, df.columns.str[0] == "results"]
102
+ df = df.loc[:, ~df.columns.str[1].isin(EXCLUDED_RESULTS_KEYS)]
103
+ df = df.loc[:, ~df.columns.str[2].isin(EXCLUDED_RESULTS_LEADERBOARDS_KEYS)]
104
+ return df
105
 
106
 
107
  def concat_result_1(result_1, results):