still trying to make the leaderboard
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import pathlib
|
|
|
2 |
import tempfile
|
3 |
from typing import BinaryIO, Literal
|
4 |
import json
|
@@ -70,19 +71,18 @@ def submit_boundary(
|
|
70 |
)
|
71 |
pathlib.Path(tmp_name).unlink()
|
72 |
|
73 |
-
# then do eval
|
74 |
local_path = read_boundary(filename)
|
75 |
|
76 |
try:
|
77 |
result = evaluate_problem(problem_type, local_path)
|
78 |
write_results(record, result)
|
79 |
-
output = str(result)
|
80 |
except Exception as e:
|
81 |
-
raise gr.Error(f"Error during
|
82 |
-
finally:
|
83 |
-
|
84 |
|
85 |
-
return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly."
|
86 |
|
87 |
def read_boundary(filename):
|
88 |
local_path = hf_hub_download(
|
@@ -113,6 +113,15 @@ def write_results(record, result):
|
|
113 |
pathlib.Path(tmp_name).unlink()
|
114 |
return
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
117 |
if profile is None:
|
118 |
return "Please login to submit a boundary for evaluation."
|
@@ -159,6 +168,8 @@ def gradio_interface() -> gr.Blocks:
|
|
159 |
"""
|
160 |
)
|
161 |
user_state = gr.State(value=None)
|
|
|
|
|
162 |
|
163 |
gr.LoginButton()
|
164 |
|
@@ -169,18 +180,23 @@ def gradio_interface() -> gr.Blocks:
|
|
169 |
boundary_file = gr.File(label="Boundary JSON File (.json)")
|
170 |
|
171 |
boundary_file
|
172 |
-
|
173 |
submit_btn = gr.Button("Evaluate")
|
174 |
submit_btn.click(
|
175 |
submit_boundary,
|
176 |
inputs=[problem_type, boundary_file, user_state],
|
177 |
-
outputs=
|
178 |
).then(
|
179 |
fn=show_output_box,
|
180 |
-
inputs=[
|
181 |
-
outputs=[
|
182 |
)
|
183 |
'''.then(
|
|
|
|
|
|
|
|
|
|
|
184 |
fn=update_leaderboard,
|
185 |
inputs=[problem_type],
|
186 |
outputs=[leaderboard_df]
|
|
|
1 |
import pathlib
|
2 |
+
from pathlib import Path
|
3 |
import tempfile
|
4 |
from typing import BinaryIO, Literal
|
5 |
import json
|
|
|
71 |
)
|
72 |
pathlib.Path(tmp_name).unlink()
|
73 |
|
74 |
+
'''# then do eval
|
75 |
local_path = read_boundary(filename)
|
76 |
|
77 |
try:
|
78 |
result = evaluate_problem(problem_type, local_path)
|
79 |
write_results(record, result)
|
|
|
80 |
except Exception as e:
|
81 |
+
raise gr.Error(f"Error during file write:\n{e}")
|
82 |
+
finally:'''
|
83 |
+
tmp_boundary_path.unlink()
|
84 |
|
85 |
+
return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly.", filename
|
86 |
|
87 |
def read_boundary(filename):
|
88 |
local_path = hf_hub_download(
|
|
|
113 |
pathlib.Path(tmp_name).unlink()
|
114 |
return
|
115 |
|
116 |
+
def evaluate_boundary(filename):
|
117 |
+
local_path = read_boundary(filename)
|
118 |
+
with Path(local_path).open("r") as f:
|
119 |
+
raw = f.read()
|
120 |
+
data_dict = json.loads(raw)
|
121 |
+
result = evaluate_problem(data_dict['problem_type'], local_path)
|
122 |
+
write_results(data_dict, result)
|
123 |
+
return
|
124 |
+
|
125 |
def get_user(profile: gr.OAuthProfile | None) -> str:
|
126 |
if profile is None:
|
127 |
return "Please login to submit a boundary for evaluation."
|
|
|
168 |
"""
|
169 |
)
|
170 |
user_state = gr.State(value=None)
|
171 |
+
filename = gr.State(value=None)
|
172 |
+
eval_state = gr.State(value=None)
|
173 |
|
174 |
gr.LoginButton()
|
175 |
|
|
|
180 |
boundary_file = gr.File(label="Boundary JSON File (.json)")
|
181 |
|
182 |
boundary_file
|
183 |
+
message = gr.Textbox(label="Evaluation Result", lines=10, visible=False)
|
184 |
submit_btn = gr.Button("Evaluate")
|
185 |
submit_btn.click(
|
186 |
submit_boundary,
|
187 |
inputs=[problem_type, boundary_file, user_state],
|
188 |
+
outputs=[message, filename],
|
189 |
).then(
|
190 |
fn=show_output_box,
|
191 |
+
inputs=[message],
|
192 |
+
outputs=[message],
|
193 |
)
|
194 |
'''.then(
|
195 |
+
fn=evaluate_boundary,
|
196 |
+
inputs=[filename],
|
197 |
+
outputs=[eval_state]
|
198 |
+
)
|
199 |
+
.then(
|
200 |
fn=update_leaderboard,
|
201 |
inputs=[problem_type],
|
202 |
outputs=[leaderboard_df]
|