trying to write results
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import pathlib
|
|
2 |
import tempfile
|
3 |
from typing import BinaryIO, Literal
|
4 |
import json
|
|
|
5 |
|
6 |
import gradio as gr
|
7 |
from datasets import load_dataset, Dataset
|
@@ -86,6 +87,8 @@ def read_boundary(filename):
|
|
86 |
def write_results(record, result):
|
87 |
record.update(result)
|
88 |
record['result_filename'] = record['submission_filename'].strip('.json') + '_results.json'
|
|
|
|
|
89 |
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
|
90 |
json.dump(record, tmp, indent=2)
|
91 |
tmp.flush()
|
@@ -103,6 +106,21 @@ def write_results(record, result):
|
|
103 |
return
|
104 |
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
def gradio_interface() -> gr.Blocks:
|
107 |
with gr.Blocks() as demo:
|
108 |
gr.Markdown(
|
@@ -125,6 +143,18 @@ def gradio_interface() -> gr.Blocks:
|
|
125 |
inputs=[problem_type, boundary_file],
|
126 |
outputs=output,
|
127 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
return demo
|
129 |
|
130 |
|
|
|
2 |
import tempfile
|
3 |
from typing import BinaryIO, Literal
|
4 |
import json
|
5 |
+
import pandas as pd
|
6 |
|
7 |
import gradio as gr
|
8 |
from datasets import load_dataset, Dataset
|
|
|
87 |
def write_results(record, result):
|
88 |
record.update(result)
|
89 |
record['result_filename'] = record['submission_filename'].strip('.json') + '_results.json'
|
90 |
+
record['evaluated'] = True
|
91 |
+
|
92 |
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
|
93 |
json.dump(record, tmp, indent=2)
|
94 |
tmp.flush()
|
|
|
106 |
return
|
107 |
|
108 |
|
109 |
+
def get_leaderboard(problem_type: str):
|
110 |
+
ds = load_dataset(results_repo, split=problem_type)
|
111 |
+
|
112 |
+
filtered = ds.filter(lambda x: x["evaluated"])
|
113 |
+
|
114 |
+
if len(filtered) == 0:
|
115 |
+
return pd.DataFrame(columns=["submission_time", "problem_type", "score"])
|
116 |
+
|
117 |
+
df = pd.DataFrame(filtered)
|
118 |
+
score_field = "score" if "score" in df.columns else "objective" # fallback
|
119 |
+
|
120 |
+
df = df.sort_values(by=score_field, ascending=True)
|
121 |
+
leaderboard = df[["submission_time", "problem_type", score_field]].reset_index(drop=True)
|
122 |
+
return leaderboard
|
123 |
+
|
124 |
def gradio_interface() -> gr.Blocks:
|
125 |
with gr.Blocks() as demo:
|
126 |
gr.Markdown(
|
|
|
143 |
inputs=[problem_type, boundary_file],
|
144 |
outputs=output,
|
145 |
)
|
146 |
+
|
147 |
+
with gr.Row():
|
148 |
+
leaderboard_type = gr.Dropdown(PROBLEM_TYPES, label="Leaderboard Problem Type", value="geometrical")
|
149 |
+
leaderboard_btn = gr.Button("Load Leaderboard")
|
150 |
+
|
151 |
+
leaderboard_df = gr.Dataframe(label="Leaderboard")
|
152 |
+
|
153 |
+
leaderboard_btn.click(
|
154 |
+
lambda pt: get_leaderboard(pt).to_dict(orient="records"),
|
155 |
+
inputs=[leaderboard_type],
|
156 |
+
outputs=[leaderboard_df]
|
157 |
+
)
|
158 |
return demo
|
159 |
|
160 |
|