Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Optimize data loading and filter in display
Browse files- app.py +80 -139
- requirements.txt +0 -2
app.py
CHANGED
|
@@ -12,26 +12,13 @@ EXCLUDED_KEYS = {
|
|
| 12 |
"chat_template",
|
| 13 |
"group_subtasks",
|
| 14 |
}
|
| 15 |
-
EXCLUDED_RESULTS_KEYS = {
|
| 16 |
-
|
| 17 |
-
}
|
| 18 |
-
EXCLUDED_RESULTS_LEADERBOARDS_KEYS = {
|
| 19 |
-
|
| 20 |
-
}
|
| 21 |
|
| 22 |
-
DEFAULT_HTML_TABLE = """
|
| 23 |
-
<table>
|
| 24 |
-
<thead>
|
| 25 |
-
<tr>
|
| 26 |
-
<th>Parameters</th>
|
| 27 |
-
<th>Model-1</th>
|
| 28 |
-
<th>Model-2</th>
|
| 29 |
-
</tr>
|
| 30 |
-
</thead>
|
| 31 |
-
<tbody>
|
| 32 |
-
</tbody>
|
| 33 |
-
</table>
|
| 34 |
-
"""
|
| 35 |
|
| 36 |
TASKS = {
|
| 37 |
"leaderboard_arc_challenge": ("ARC", "leaderboard_arc_challenge"),
|
|
@@ -71,98 +58,64 @@ def load_data(result_path) -> pd.DataFrame:
|
|
| 71 |
return data
|
| 72 |
|
| 73 |
|
| 74 |
-
def
|
| 75 |
result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
|
| 76 |
data = load_data(result_path)
|
| 77 |
-
|
| 78 |
-
result = [
|
| 79 |
-
# to_vertical(df),
|
| 80 |
-
to_vertical(filter_results(df)),
|
| 81 |
-
to_vertical(filter_configs(df)),
|
| 82 |
-
]
|
| 83 |
-
return result
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
def to_vertical(df):
|
| 87 |
-
df = df.T.rename_axis("Parameters")
|
| 88 |
-
df.index = df.index.str.join(".")
|
| 89 |
-
return df
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
def to_dataframe(data):
|
| 93 |
df = pd.json_normalize([{key: value for key, value in data.items() if key not in EXCLUDED_KEYS}])
|
| 94 |
# df.columns = df.columns.str.split(".") # .split return a list instead of a tuple
|
| 95 |
-
df.
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
#
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
return
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
| 124 |
)
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
)
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
def concat_result_2(result_2, results):
|
| 139 |
-
results = pd.read_html(io.StringIO(results))[0]
|
| 140 |
-
df = (
|
| 141 |
-
pd.concat([results.iloc[:, [0, 1]].set_index("Parameters"), result_2], axis=1)
|
| 142 |
-
.reset_index()
|
| 143 |
-
)
|
| 144 |
-
return df
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
def render_result_1(model_id, task, *results):
|
| 148 |
-
result = load_result(model_id)
|
| 149 |
-
concat_results = [concat_result_1(*result_args) for result_args in zip(result, results)]
|
| 150 |
-
if task:
|
| 151 |
-
concat_results = [df[df["Parameters"].str.startswith(task[len("leaderboard_"):])] for df in concat_results]
|
| 152 |
-
return [display_dataframe(df) for df in concat_results]
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
def render_result_2(model_id, task, *results):
|
| 156 |
-
result = load_result(model_id)
|
| 157 |
-
concat_results = [concat_result_2(*result_args) for result_args in zip(result, results)]
|
| 158 |
-
if task:
|
| 159 |
-
concat_results = [df[df["Parameters"].str.startswith(task[len("leaderboard_"):])] for df in concat_results]
|
| 160 |
-
return [display_dataframe(df) for df in concat_results]
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
def render_results(model_id_1, model_id_2, task, *results):
|
| 164 |
-
results = render_result_1(model_id_1, task, *results)
|
| 165 |
-
return render_result_2(model_id_2, task, *results)
|
| 166 |
|
| 167 |
|
| 168 |
# if __name__ == "__main__":
|
|
@@ -176,9 +129,11 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 176 |
with gr.Column():
|
| 177 |
model_id_1 = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
|
| 178 |
load_btn_1 = gr.Button("Load")
|
|
|
|
| 179 |
with gr.Column():
|
| 180 |
model_id_2 = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
|
| 181 |
load_btn_2 = gr.Button("Load")
|
|
|
|
| 182 |
with gr.Row():
|
| 183 |
task = gr.Radio(
|
| 184 |
["All"] + list(TASKS.values()),
|
|
@@ -187,50 +142,36 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 187 |
value="All",
|
| 188 |
)
|
| 189 |
|
| 190 |
-
results = []
|
| 191 |
with gr.Row():
|
| 192 |
# with gr.Tab("All"):
|
| 193 |
-
#
|
| 194 |
-
# # label="Results",
|
| 195 |
-
# # headers=["Parameters", "Model-1", "Model-2"],
|
| 196 |
-
# # interactive=False,
|
| 197 |
-
# # column_widths=["30%", "30%", "30%"],
|
| 198 |
-
# # wrap=True,
|
| 199 |
-
# # ))
|
| 200 |
-
# results.append(gr.HTML(value=DEFAULT_HTML_TABLE))
|
| 201 |
with gr.Tab("Results"):
|
| 202 |
-
|
| 203 |
-
# label="Results",
|
| 204 |
-
# headers=["Parameters", "Model-1", "Model-2"],
|
| 205 |
-
# interactive=False,
|
| 206 |
-
# column_widths=["30%", "30%", "30%"],
|
| 207 |
-
# wrap=True,
|
| 208 |
-
# ))
|
| 209 |
-
results.append(gr.HTML(value=DEFAULT_HTML_TABLE))
|
| 210 |
with gr.Tab("Configs"):
|
| 211 |
-
|
| 212 |
-
# label="Results",
|
| 213 |
-
# headers=["Parameters", "Model-1", "Model-2"],
|
| 214 |
-
# interactive=False,
|
| 215 |
-
# column_widths=["30%", "30%", "30%"],
|
| 216 |
-
# wrap=True,
|
| 217 |
-
# ))
|
| 218 |
-
results.append(gr.HTML(value=DEFAULT_HTML_TABLE))
|
| 219 |
|
| 220 |
load_btn_1.click(
|
| 221 |
-
fn=
|
| 222 |
-
inputs=
|
| 223 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
)
|
| 225 |
load_btn_2.click(
|
| 226 |
-
fn=
|
| 227 |
-
inputs=
|
| 228 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
)
|
| 230 |
task.change(
|
| 231 |
-
fn=
|
| 232 |
-
inputs=[
|
| 233 |
-
outputs=[
|
| 234 |
)
|
| 235 |
|
| 236 |
demo.launch()
|
|
|
|
| 12 |
"chat_template",
|
| 13 |
"group_subtasks",
|
| 14 |
}
|
| 15 |
+
# EXCLUDED_RESULTS_KEYS = {
|
| 16 |
+
# "leaderboard",
|
| 17 |
+
# }
|
| 18 |
+
# EXCLUDED_RESULTS_LEADERBOARDS_KEYS = {
|
| 19 |
+
# "alias",
|
| 20 |
+
# }
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
TASKS = {
|
| 24 |
"leaderboard_arc_challenge": ("ARC", "leaderboard_arc_challenge"),
|
|
|
|
| 58 |
return data
|
| 59 |
|
| 60 |
|
| 61 |
+
def load_result_dataframe(model_id):
|
| 62 |
result_path = get_result_path_from_model(model_id, latest_result_path_per_model)
|
| 63 |
data = load_data(result_path)
|
| 64 |
+
model_name = data.get("model_name", "Model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
df = pd.json_normalize([{key: value for key, value in data.items() if key not in EXCLUDED_KEYS}])
|
| 66 |
# df.columns = df.columns.str.split(".") # .split return a list instead of a tuple
|
| 67 |
+
return df.set_index(pd.Index([model_name])).reset_index()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def display_results(df_1, df_2, task):
|
| 71 |
+
df = pd.concat([df.set_index("index") for df in [df_1, df_2] if "index" in df.columns])
|
| 72 |
+
df = df.T.rename_axis(columns=None) # index="Parameters", # .reset_index()
|
| 73 |
+
# return display_dataframe(df)
|
| 74 |
+
# d = df.set_index(df.index.str.split(".")) # .split return a list instead of a tuple
|
| 75 |
+
# results = d.loc[d.index.str[0] == "results"]
|
| 76 |
+
# results.index = results.index.str.join(".")
|
| 77 |
+
# configs = d.loc[d.index.str[0] == "configs"]
|
| 78 |
+
# configs.index = configs.index.str.join(".")
|
| 79 |
+
# return display_dataframe(results), display_dataframe(configs)
|
| 80 |
+
return display_results_tab(df, task), display_configs_tab(df, task)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def display_results_tab(df, task):
|
| 84 |
+
df = df.style.format(na_rep="")
|
| 85 |
+
df.hide(
|
| 86 |
+
[
|
| 87 |
+
row
|
| 88 |
+
for row in df.index
|
| 89 |
+
if (
|
| 90 |
+
not row.startswith("results.")
|
| 91 |
+
or row.startswith("results.leaderboard.")
|
| 92 |
+
or row.endswith(".alias")
|
| 93 |
+
or (not row.startswith(f"results.{task}") if task != "All" else False)
|
| 94 |
+
)
|
| 95 |
+
],
|
| 96 |
+
axis="index",
|
| 97 |
)
|
| 98 |
+
df.format_index(lambda idx: idx[len("results.leaderboard_"):].removesuffix(",none"), axis="index")
|
| 99 |
+
return df.to_html()
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def display_configs_tab(df, task):
|
| 103 |
+
df = df.style.format(na_rep="")
|
| 104 |
+
df.hide(
|
| 105 |
+
[
|
| 106 |
+
row
|
| 107 |
+
for row in df.index
|
| 108 |
+
if (
|
| 109 |
+
not row.startswith("configs.")
|
| 110 |
+
or row.startswith("configs.leaderboard.")
|
| 111 |
+
or row.endswith(".alias")
|
| 112 |
+
or (not row.startswith(f"configs.{task}") if task != "All" else False)
|
| 113 |
+
)
|
| 114 |
+
],
|
| 115 |
+
axis="index",
|
| 116 |
)
|
| 117 |
+
df.format_index(lambda idx: idx[len("configs.leaderboard_"):], axis="index")
|
| 118 |
+
return df.to_html()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
# if __name__ == "__main__":
|
|
|
|
| 129 |
with gr.Column():
|
| 130 |
model_id_1 = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
|
| 131 |
load_btn_1 = gr.Button("Load")
|
| 132 |
+
dataframe_1 = gr.Dataframe(visible=False)
|
| 133 |
with gr.Column():
|
| 134 |
model_id_2 = gr.Dropdown(choices=list(latest_result_path_per_model.keys()), label="Results")
|
| 135 |
load_btn_2 = gr.Button("Load")
|
| 136 |
+
dataframe_2 = gr.Dataframe(visible=False)
|
| 137 |
with gr.Row():
|
| 138 |
task = gr.Radio(
|
| 139 |
["All"] + list(TASKS.values()),
|
|
|
|
| 142 |
value="All",
|
| 143 |
)
|
| 144 |
|
|
|
|
| 145 |
with gr.Row():
|
| 146 |
# with gr.Tab("All"):
|
| 147 |
+
# pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
with gr.Tab("Results"):
|
| 149 |
+
results = gr.HTML()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
with gr.Tab("Configs"):
|
| 151 |
+
configs = gr.HTML()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
load_btn_1.click(
|
| 154 |
+
fn=load_result_dataframe,
|
| 155 |
+
inputs=model_id_1,
|
| 156 |
+
outputs=dataframe_1,
|
| 157 |
+
).then(
|
| 158 |
+
fn=display_results,
|
| 159 |
+
inputs=[dataframe_1, dataframe_2, task],
|
| 160 |
+
outputs=[results, configs],
|
| 161 |
)
|
| 162 |
load_btn_2.click(
|
| 163 |
+
fn=load_result_dataframe,
|
| 164 |
+
inputs=model_id_2,
|
| 165 |
+
outputs=dataframe_2,
|
| 166 |
+
).then(
|
| 167 |
+
fn=display_results,
|
| 168 |
+
inputs=[dataframe_1, dataframe_2, task],
|
| 169 |
+
outputs=[results, configs],
|
| 170 |
)
|
| 171 |
task.change(
|
| 172 |
+
fn=display_results,
|
| 173 |
+
inputs=[dataframe_1, dataframe_2, task],
|
| 174 |
+
outputs=[results, configs],
|
| 175 |
)
|
| 176 |
|
| 177 |
demo.launch()
|
requirements.txt
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
lxml
|
| 2 |
-
|
|
|
|
|
|
|
|
|