still trying to make the leaderboard
Browse files- app.py +3 -40
- requirements.txt +2 -1
- submit.py +2 -0
- utils.py +54 -0
- visualize.py +3 -0
app.py
CHANGED
@@ -15,39 +15,7 @@ import os
|
|
15 |
|
16 |
from submit import submit_boundary
|
17 |
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
|
18 |
-
|
19 |
-
def read_boundary(filename):
|
20 |
-
local_path = hf_hub_download(
|
21 |
-
repo_id=submissions_repo,
|
22 |
-
repo_type="dataset",
|
23 |
-
filename=filename,
|
24 |
-
)
|
25 |
-
return local_path
|
26 |
-
|
27 |
-
def write_results(record, result):
|
28 |
-
record.update(result)
|
29 |
-
record['result_filename'] = record['submission_filename'].strip('.json') + '_results.json'
|
30 |
-
record['evaluated'] = True
|
31 |
-
if 'objectives' in record.keys():
|
32 |
-
record['objective'] = record.pop('objectives')
|
33 |
-
record['minimize_objective'] = True
|
34 |
-
|
35 |
-
|
36 |
-
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
|
37 |
-
json.dump(record, tmp, indent=2)
|
38 |
-
tmp.flush()
|
39 |
-
tmp_name = tmp.name
|
40 |
-
|
41 |
-
API.upload_file(
|
42 |
-
path_or_fileobj=tmp_name,
|
43 |
-
path_in_repo=record['result_filename'],
|
44 |
-
repo_id=results_repo,
|
45 |
-
repo_type="dataset",
|
46 |
-
commit_message=f"Add result data for {record['result_filename']}"
|
47 |
-
)
|
48 |
-
|
49 |
-
pathlib.Path(tmp_name).unlink()
|
50 |
-
return
|
51 |
|
52 |
def evaluate_boundary(filename):
|
53 |
local_path = read_boundary(filename)
|
@@ -58,11 +26,6 @@ def evaluate_boundary(filename):
|
|
58 |
write_results(data_dict, result)
|
59 |
return
|
60 |
|
61 |
-
def get_user(profile: gr.OAuthProfile | None) -> str:
|
62 |
-
if profile is None:
|
63 |
-
return "Please login to submit a boundary for evaluation."
|
64 |
-
return profile.username
|
65 |
-
|
66 |
def get_leaderboard():
|
67 |
ds = load_dataset(results_repo, split='train')
|
68 |
df = pd.DataFrame(ds)
|
@@ -73,7 +36,7 @@ def get_leaderboard():
|
|
73 |
return df
|
74 |
|
75 |
def show_output_box(message):
|
76 |
-
return gr.
|
77 |
|
78 |
def gradio_interface() -> gr.Blocks:
|
79 |
with gr.Blocks() as demo:
|
@@ -115,7 +78,7 @@ def gradio_interface() -> gr.Blocks:
|
|
115 |
boundary_file = gr.File(label="Boundary JSON File (.json)")
|
116 |
|
117 |
boundary_file
|
118 |
-
message = gr.Textbox(label="
|
119 |
submit_btn = gr.Button("Evaluate")
|
120 |
submit_btn.click(
|
121 |
submit_boundary,
|
|
|
15 |
|
16 |
from submit import submit_boundary
|
17 |
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
|
18 |
+
from utils import read_boundary, write_results, get_user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def evaluate_boundary(filename):
|
21 |
local_path = read_boundary(filename)
|
|
|
26 |
write_results(data_dict, result)
|
27 |
return
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
def get_leaderboard():
|
30 |
ds = load_dataset(results_repo, split='train')
|
31 |
df = pd.DataFrame(ds)
|
|
|
36 |
return df
|
37 |
|
38 |
def show_output_box(message):
|
39 |
+
return gr.update(value=message, visible=True)
|
40 |
|
41 |
def gradio_interface() -> gr.Blocks:
|
42 |
with gr.Blocks() as demo:
|
|
|
78 |
boundary_file = gr.File(label="Boundary JSON File (.json)")
|
79 |
|
80 |
boundary_file
|
81 |
+
message = gr.Textbox(label="Submission Status", lines=3, visible=False)
|
82 |
submit_btn = gr.Button("Evaluate")
|
83 |
submit_btn.click(
|
84 |
submit_boundary,
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ constellaration==0.2.1
|
|
2 |
gradio
|
3 |
datasets
|
4 |
huggingface_hub
|
5 |
-
gradio-leaderboard
|
|
|
|
2 |
gradio
|
3 |
datasets
|
4 |
huggingface_hub
|
5 |
+
gradio-leaderboard
|
6 |
+
plotly
|
submit.py
CHANGED
@@ -14,6 +14,8 @@ from datetime import datetime
|
|
14 |
import os
|
15 |
from huggingface_hub import HfApi
|
16 |
|
|
|
|
|
17 |
def submit_boundary(
|
18 |
problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
|
19 |
boundary_file: BinaryIO,
|
|
|
14 |
import os
|
15 |
from huggingface_hub import HfApi
|
16 |
|
17 |
+
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
|
18 |
+
|
19 |
def submit_boundary(
|
20 |
problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
|
21 |
boundary_file: BinaryIO,
|
utils.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pathlib
|
2 |
+
from pathlib import Path
|
3 |
+
import tempfile
|
4 |
+
from typing import BinaryIO, Literal
|
5 |
+
import json
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
from datasets import load_dataset, Dataset
|
10 |
+
from huggingface_hub import upload_file, hf_hub_download
|
11 |
+
from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
|
12 |
+
from evaluation import evaluate_problem
|
13 |
+
from datetime import datetime
|
14 |
+
import os
|
15 |
+
|
16 |
+
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
|
17 |
+
|
18 |
+
def read_boundary(filename):
|
19 |
+
local_path = hf_hub_download(
|
20 |
+
repo_id=submissions_repo,
|
21 |
+
repo_type="dataset",
|
22 |
+
filename=filename,
|
23 |
+
)
|
24 |
+
return local_path
|
25 |
+
|
26 |
+
def write_results(record, result):
|
27 |
+
record.update(result)
|
28 |
+
record['result_filename'] = record['submission_filename'].strip('.json') + '_results.json'
|
29 |
+
record['evaluated'] = True
|
30 |
+
if 'objectives' in record.keys():
|
31 |
+
record['objective'] = record.pop('objectives')
|
32 |
+
record['minimize_objective'] = True
|
33 |
+
|
34 |
+
|
35 |
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
|
36 |
+
json.dump(record, tmp, indent=2)
|
37 |
+
tmp.flush()
|
38 |
+
tmp_name = tmp.name
|
39 |
+
|
40 |
+
API.upload_file(
|
41 |
+
path_or_fileobj=tmp_name,
|
42 |
+
path_in_repo=record['result_filename'],
|
43 |
+
repo_id=results_repo,
|
44 |
+
repo_type="dataset",
|
45 |
+
commit_message=f"Add result data for {record['result_filename']}"
|
46 |
+
)
|
47 |
+
|
48 |
+
pathlib.Path(tmp_name).unlink()
|
49 |
+
return
|
50 |
+
|
51 |
+
def get_user(profile: gr.OAuthProfile | None) -> str:
|
52 |
+
if profile is None:
|
53 |
+
return "Please login to submit a boundary for evaluation."
|
54 |
+
return profile.username
|
visualize.py
CHANGED
@@ -3,4 +3,7 @@ from constellaration.utils import (
|
|
3 |
visualization,
|
4 |
visualization_utils,
|
5 |
)
|
|
|
6 |
|
|
|
|
|
|
3 |
visualization,
|
4 |
visualization_utils,
|
5 |
)
|
6 |
+
import plotly.express as px
|
7 |
|
8 |
+
def make_visual(boundary):
|
9 |
+
visualization.plot_surface(boundary)
|