Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -60,7 +60,7 @@ def add_new_eval(
|
|
60 |
gr.Warning("Your submission has not been processed. Please check your representation files!")
|
61 |
return -1
|
62 |
|
63 |
-
# Even if save is False, store the submission (e.g
|
64 |
if save:
|
65 |
save_results(representation_name, benchmark_types, results)
|
66 |
else:
|
@@ -100,27 +100,31 @@ def generate_plots_based_on_submission(benchmark_types, similarity_tasks, functi
|
|
100 |
for btype in benchmark_types:
|
101 |
# For each benchmark type, choose plotting parameters based on additional selections.
|
102 |
if btype == "similarity":
|
|
|
103 |
x_metric = similarity_tasks[0] if similarity_tasks and len(similarity_tasks) > 0 else None
|
104 |
y_metric = similarity_tasks[1] if similarity_tasks and len(similarity_tasks) > 1 else None
|
105 |
elif btype == "function":
|
106 |
x_metric = function_prediction_aspect if function_prediction_aspect else None
|
107 |
y_metric = function_prediction_dataset if function_prediction_dataset else None
|
108 |
elif btype == "family":
|
|
|
109 |
x_metric = family_prediction_dataset[0] if family_prediction_dataset and len(family_prediction_dataset) > 0 else None
|
110 |
y_metric = family_prediction_dataset[1] if family_prediction_dataset and len(family_prediction_dataset) > 1 else None
|
111 |
elif btype == "affinity":
|
112 |
-
|
|
|
113 |
else:
|
114 |
x_metric, y_metric = None, None
|
115 |
|
116 |
# Generate the plot using your benchmark_plot function.
|
|
|
117 |
plot_img = benchmark_plot(btype, method_names, x_metric, y_metric, None, None, None)
|
118 |
plot_file = os.path.join(tmp_dir, f"{btype}.png")
|
119 |
if isinstance(plot_img, plt.Figure):
|
120 |
plot_img.savefig(plot_file)
|
121 |
plt.close(plot_img)
|
122 |
else:
|
123 |
-
#
|
124 |
plot_file = plot_img
|
125 |
plot_files.append(plot_file)
|
126 |
|
@@ -143,11 +147,11 @@ def submission_callback(
|
|
143 |
function_prediction_dataset,
|
144 |
family_prediction_dataset,
|
145 |
save_checkbox,
|
146 |
-
|
147 |
-
return_plots # Checkbox: if checked, return plot results ZIP
|
148 |
):
|
149 |
"""
|
150 |
-
Runs the evaluation and returns
|
|
|
151 |
"""
|
152 |
eval_status = add_new_eval(
|
153 |
human_file,
|
@@ -163,26 +167,22 @@ def submission_callback(
|
|
163 |
)
|
164 |
|
165 |
if eval_status == -1:
|
166 |
-
return "Submission failed. Please check your files and selections.", None
|
167 |
-
|
168 |
-
csv_file = None
|
169 |
-
plots_file = None
|
170 |
-
msg = "Submission processed. "
|
171 |
|
172 |
-
if
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
benchmark_types,
|
178 |
similarity_tasks,
|
179 |
function_prediction_aspect,
|
180 |
function_prediction_dataset,
|
181 |
family_prediction_dataset,
|
182 |
)
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
|
187 |
|
188 |
# --------------------------
|
@@ -195,7 +195,7 @@ with block:
|
|
195 |
|
196 |
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
197 |
with gr.TabItem("🏅 PROBE Leaderboard", elem_id="probe-benchmark-tab-table", id=1):
|
198 |
-
# Leaderboard
|
199 |
leaderboard = get_baseline_df(None, None)
|
200 |
method_names = leaderboard['Method'].unique().tolist()
|
201 |
metric_names = leaderboard.columns.tolist()
|
@@ -266,7 +266,7 @@ with block:
|
|
266 |
Select options to update the visualization.
|
267 |
"""
|
268 |
)
|
269 |
-
# Plotting section remains available as before
|
270 |
benchmark_type_selector_plot = gr.Dropdown(
|
271 |
choices=list(benchmark_specific_metrics.keys()),
|
272 |
label="Select Benchmark Type for Plotting",
|
@@ -346,15 +346,6 @@ with block:
|
|
346 |
label="Save results for leaderboard and visualization",
|
347 |
value=True
|
348 |
)
|
349 |
-
# New independent checkboxes for output return options:
|
350 |
-
return_leaderboard = gr.Checkbox(
|
351 |
-
label="Return Leaderboard CSV",
|
352 |
-
value=False
|
353 |
-
)
|
354 |
-
return_plots = gr.Checkbox(
|
355 |
-
label="Return Plot Results",
|
356 |
-
value=False
|
357 |
-
)
|
358 |
with gr.Row():
|
359 |
human_file = gr.components.File(
|
360 |
label="The representation file (csv) for Human dataset",
|
@@ -366,11 +357,16 @@ with block:
|
|
366 |
file_count="single",
|
367 |
type='filepath'
|
368 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
submit_button = gr.Button("Submit Eval")
|
370 |
submission_result_msg = gr.Markdown()
|
371 |
-
|
372 |
-
submission_csv_file = gr.File(label="Leaderboard CSV", visible=True)
|
373 |
-
submission_plots_file = gr.File(label="Plot Results ZIP", visible=True)
|
374 |
submit_button.click(
|
375 |
submission_callback,
|
376 |
inputs=[
|
@@ -384,10 +380,9 @@ with block:
|
|
384 |
function_dataset,
|
385 |
family_prediction_dataset,
|
386 |
save_checkbox,
|
387 |
-
|
388 |
-
return_plots,
|
389 |
],
|
390 |
-
outputs=[submission_result_msg,
|
391 |
)
|
392 |
|
393 |
with gr.Row():
|
|
|
60 |
gr.Warning("Your submission has not been processed. Please check your representation files!")
|
61 |
return -1
|
62 |
|
63 |
+
# Even if save is False, we store the submission (e.g., temporarily) so that the leaderboard includes it.
|
64 |
if save:
|
65 |
save_results(representation_name, benchmark_types, results)
|
66 |
else:
|
|
|
100 |
for btype in benchmark_types:
|
101 |
# For each benchmark type, choose plotting parameters based on additional selections.
|
102 |
if btype == "similarity":
|
103 |
+
# Use the user-selected similarity tasks (if provided) to determine the metrics.
|
104 |
x_metric = similarity_tasks[0] if similarity_tasks and len(similarity_tasks) > 0 else None
|
105 |
y_metric = similarity_tasks[1] if similarity_tasks and len(similarity_tasks) > 1 else None
|
106 |
elif btype == "function":
|
107 |
x_metric = function_prediction_aspect if function_prediction_aspect else None
|
108 |
y_metric = function_prediction_dataset if function_prediction_dataset else None
|
109 |
elif btype == "family":
|
110 |
+
# For family, assume that family_prediction_dataset is a list of datasets.
|
111 |
x_metric = family_prediction_dataset[0] if family_prediction_dataset and len(family_prediction_dataset) > 0 else None
|
112 |
y_metric = family_prediction_dataset[1] if family_prediction_dataset and len(family_prediction_dataset) > 1 else None
|
113 |
elif btype == "affinity":
|
114 |
+
# For affinity, you may use default plotting parameters.
|
115 |
+
x_metric, y_metric = None, None
|
116 |
else:
|
117 |
x_metric, y_metric = None, None
|
118 |
|
119 |
# Generate the plot using your benchmark_plot function.
|
120 |
+
# Here, aspect, dataset, and single_metric are passed as None, but you could extend this logic.
|
121 |
plot_img = benchmark_plot(btype, method_names, x_metric, y_metric, None, None, None)
|
122 |
plot_file = os.path.join(tmp_dir, f"{btype}.png")
|
123 |
if isinstance(plot_img, plt.Figure):
|
124 |
plot_img.savefig(plot_file)
|
125 |
plt.close(plot_img)
|
126 |
else:
|
127 |
+
# If benchmark_plot already returns a file path, use it directly.
|
128 |
plot_file = plot_img
|
129 |
plot_files.append(plot_file)
|
130 |
|
|
|
147 |
function_prediction_dataset,
|
148 |
family_prediction_dataset,
|
149 |
save_checkbox,
|
150 |
+
return_option, # New radio selection: "Leaderboard CSV" or "Plot Results"
|
|
|
151 |
):
|
152 |
"""
|
153 |
+
Runs the evaluation and then returns either a downloadable CSV of the leaderboard
|
154 |
+
(which includes the new submission) or a ZIP file of plots generated based on the submission's selections.
|
155 |
"""
|
156 |
eval_status = add_new_eval(
|
157 |
human_file,
|
|
|
167 |
)
|
168 |
|
169 |
if eval_status == -1:
|
170 |
+
return "Submission failed. Please check your files and selections.", None
|
|
|
|
|
|
|
|
|
171 |
|
172 |
+
if return_option == "Leaderboard CSV":
|
173 |
+
csv_path = download_leaderboard_csv()
|
174 |
+
return "Your leaderboard CSV (including your submission) is ready for download.", csv_path
|
175 |
+
elif return_option == "Plot Results":
|
176 |
+
zip_path = generate_plots_based_on_submission(
|
177 |
benchmark_types,
|
178 |
similarity_tasks,
|
179 |
function_prediction_aspect,
|
180 |
function_prediction_dataset,
|
181 |
family_prediction_dataset,
|
182 |
)
|
183 |
+
return "Your plots are ready for download.", zip_path
|
184 |
+
else:
|
185 |
+
return "Submission processed, but no output option was selected.", None
|
186 |
|
187 |
|
188 |
# --------------------------
|
|
|
195 |
|
196 |
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
197 |
with gr.TabItem("🏅 PROBE Leaderboard", elem_id="probe-benchmark-tab-table", id=1):
|
198 |
+
# Leaderboard tab (unchanged from before)
|
199 |
leaderboard = get_baseline_df(None, None)
|
200 |
method_names = leaderboard['Method'].unique().tolist()
|
201 |
metric_names = leaderboard.columns.tolist()
|
|
|
266 |
Select options to update the visualization.
|
267 |
"""
|
268 |
)
|
269 |
+
# (Plotting section remains available as before; not the focus of the submission callback)
|
270 |
benchmark_type_selector_plot = gr.Dropdown(
|
271 |
choices=list(benchmark_specific_metrics.keys()),
|
272 |
label="Select Benchmark Type for Plotting",
|
|
|
346 |
label="Save results for leaderboard and visualization",
|
347 |
value=True
|
348 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
with gr.Row():
|
350 |
human_file = gr.components.File(
|
351 |
label="The representation file (csv) for Human dataset",
|
|
|
357 |
file_count="single",
|
358 |
type='filepath'
|
359 |
)
|
360 |
+
# New radio button for output selection.
|
361 |
+
return_option = gr.Radio(
|
362 |
+
choices=["Leaderboard CSV", "Plot Results"],
|
363 |
+
label="Return Output",
|
364 |
+
value="Leaderboard CSV",
|
365 |
+
interactive=True,
|
366 |
+
)
|
367 |
submit_button = gr.Button("Submit Eval")
|
368 |
submission_result_msg = gr.Markdown()
|
369 |
+
submission_result_file = gr.File()
|
|
|
|
|
370 |
submit_button.click(
|
371 |
submission_callback,
|
372 |
inputs=[
|
|
|
380 |
function_dataset,
|
381 |
family_prediction_dataset,
|
382 |
save_checkbox,
|
383 |
+
return_option,
|
|
|
384 |
],
|
385 |
+
outputs=[submission_result_msg, submission_result_file]
|
386 |
)
|
387 |
|
388 |
with gr.Row():
|