cgeorgiaw HF Staff commited on
Commit
63bdadc
·
1 Parent(s): b41b751

still trying to make the leaderboard

Browse files
Files changed (4) hide show
  1. about.py +9 -0
  2. app.py +6 -75
  3. submit.py +69 -0
  4. visualize.py +6 -0
about.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import HfApi
3
+
4
+ PROBLEM_TYPES = ["geometrical", "simple_to_build", "mhd_stable"]
5
+ TOKEN = os.environ.get("HF_TOKEN")
6
+ CACHE_PATH=os.getenv("HF_HOME", ".")
7
+ API = HfApi(token=TOKEN)
8
+ submissions_repo = "cgeorgiaw/constellaration-submissions"
9
+ results_repo = "cgeorgiaw/constellaration-results"
app.py CHANGED
@@ -12,77 +12,9 @@ from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
12
  from evaluation import evaluate_problem
13
  from datetime import datetime
14
  import os
15
- from huggingface_hub import HfApi
16
-
17
- PROBLEM_TYPES = ["geometrical", "simple_to_build", "mhd_stable"]
18
- TOKEN = os.environ.get("HF_TOKEN")
19
- CACHE_PATH=os.getenv("HF_HOME", ".")
20
- API = HfApi(token=TOKEN)
21
- submissions_repo = "cgeorgiaw/constellaration-submissions"
22
- results_repo = "cgeorgiaw/constellaration-results"
23
-
24
- def submit_boundary(
25
- problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
26
- boundary_file: BinaryIO,
27
- user_state,
28
- ) -> str:
29
-
30
- # error handling
31
- if user_state is None:
32
- raise gr.Error("You must be logged in to submit a file.")
33
-
34
- file_path = boundary_file.name
35
-
36
- if not file_path:
37
- raise gr.Error("Uploaded file object does not have a valid file path.")
38
-
39
- path_obj = pathlib.Path(file_path)
40
- timestamp = datetime.utcnow().isoformat()
41
-
42
- with (
43
- path_obj.open("rb") as f_in,
44
- tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp_boundary,
45
- ):
46
- file_content = f_in.read()
47
- tmp_boundary.write(file_content)
48
- tmp_boundary_path = pathlib.Path(tmp_boundary.name)
49
-
50
- # write to dataset
51
- filename = f"{problem_type}/{timestamp.replace(':', '-')}_{problem_type}.json"
52
- record = {
53
- "submission_filename": filename,
54
- "submission_time": timestamp,
55
- "problem_type": problem_type,
56
- "boundary_json": file_content.decode("utf-8"),
57
- "evaluated": False,
58
- "user": user_state,
59
- }
60
- with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
61
- json.dump(record, tmp, indent=2)
62
- tmp.flush()
63
- tmp_name = tmp.name
64
-
65
- API.upload_file(
66
- path_or_fileobj=tmp_name,
67
- path_in_repo=filename,
68
- repo_id=submissions_repo,
69
- repo_type="dataset",
70
- commit_message=f"Add submission for {problem_type} at {timestamp}"
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(
@@ -131,7 +63,7 @@ def get_user(profile: gr.OAuthProfile | None) -> str:
131
  return "Please login to submit a boundary for evaluation."
132
  return profile.username
133
 
134
- def get_leaderboard(problem_type: str):
135
  ds = load_dataset(results_repo, split='train')
136
  df = pd.DataFrame(ds)
137
 
@@ -148,15 +80,14 @@ def gradio_interface() -> gr.Blocks:
148
  with gr.Tabs(elem_classes="tab-buttons"):
149
  with gr.TabItem("Leaderboard", elem_id="boundary-benchmark-tab-table"):
150
  gr.Markdown("# Boundary Design Leaderboard")
151
- leaderboard_type = gr.Dropdown(PROBLEM_TYPES, value="simple_to_build", label="Problem Type")
152
- leaderboard_df = get_leaderboard(leaderboard_type)
153
 
154
  Leaderboard(
155
  value=leaderboard_df,
156
  select_columns=["submission_time", "feasibility", "score", "objective", "user"],
157
- search_columns=["submission_time", "score"],
158
  hide_columns=["result_filename", "submission_filename", "minimize_objective", "boundary_json", "evaluated"],
159
- # filter_columns=["T", "Precision", "Model Size"],
160
  )
161
 
162
  # def update_leaderboard(problem_type):
 
12
  from evaluation import evaluate_problem
13
  from datetime import datetime
14
  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(
 
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)
69
 
 
80
  with gr.Tabs(elem_classes="tab-buttons"):
81
  with gr.TabItem("Leaderboard", elem_id="boundary-benchmark-tab-table"):
82
  gr.Markdown("# Boundary Design Leaderboard")
83
+ leaderboard_df = get_leaderboard()
 
84
 
85
  Leaderboard(
86
  value=leaderboard_df,
87
  select_columns=["submission_time", "feasibility", "score", "objective", "user"],
88
+ search_columns=["submission_time", "score", "user"],
89
  hide_columns=["result_filename", "submission_filename", "minimize_objective", "boundary_json", "evaluated"],
90
+ filter_columns=["problem_type", "submission_time"],
91
  )
92
 
93
  # def update_leaderboard(problem_type):
submit.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from huggingface_hub import HfApi
16
+
17
+ def submit_boundary(
18
+ problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
19
+ boundary_file: BinaryIO,
20
+ user_state,
21
+ ) -> str:
22
+
23
+ # error handling
24
+ if user_state is None:
25
+ raise gr.Error("You must be logged in to submit a file.")
26
+
27
+ file_path = boundary_file.name
28
+
29
+ if not file_path:
30
+ raise gr.Error("Uploaded file object does not have a valid file path.")
31
+
32
+ path_obj = pathlib.Path(file_path)
33
+ timestamp = datetime.utcnow().isoformat()
34
+
35
+ with (
36
+ path_obj.open("rb") as f_in,
37
+ tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp_boundary,
38
+ ):
39
+ file_content = f_in.read()
40
+ tmp_boundary.write(file_content)
41
+ tmp_boundary_path = pathlib.Path(tmp_boundary.name)
42
+
43
+ # write to dataset
44
+ filename = f"{problem_type}/{timestamp.replace(':', '-')}_{problem_type}.json"
45
+ record = {
46
+ "submission_filename": filename,
47
+ "submission_time": timestamp,
48
+ "problem_type": problem_type,
49
+ "boundary_json": file_content.decode("utf-8"),
50
+ "evaluated": False,
51
+ "user": user_state,
52
+ }
53
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
54
+ json.dump(record, tmp, indent=2)
55
+ tmp.flush()
56
+ tmp_name = tmp.name
57
+
58
+ API.upload_file(
59
+ path_or_fileobj=tmp_name,
60
+ path_in_repo=filename,
61
+ repo_id=submissions_repo,
62
+ repo_type="dataset",
63
+ commit_message=f"Add submission for {problem_type} at {timestamp}"
64
+ )
65
+ pathlib.Path(tmp_name).unlink()
66
+
67
+ tmp_boundary_path.unlink()
68
+
69
+ return "✅ Your submission has been received! Sit tight and your scores will appear on the leaderboard shortly.", filename
visualize.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from constellaration.utils import (
2
+ file_exporter,
3
+ visualization,
4
+ visualization_utils,
5
+ )
6
+