cgeorgiaw HF Staff commited on
Commit
3c0df4a
·
1 Parent(s): 2d4a889
Files changed (2) hide show
  1. app.py +14 -15
  2. utils.py +9 -3
app.py CHANGED
@@ -14,7 +14,7 @@ import os
14
 
15
  from submit import submit_boundary
16
  from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
17
- from utils import read_boundary, write_results, get_user
18
  from visualize import make_visual
19
 
20
  def evaluate_boundary(filename):
@@ -23,25 +23,25 @@ def evaluate_boundary(filename):
23
  with Path(local_path).open("r") as f:
24
  raw = f.read()
25
  data_dict = json.loads(raw)
26
- result = evaluate_problem(data_dict['problem_type'], local_path)
 
 
 
 
27
 
28
  write_results(data_dict, result)
29
  return
30
 
31
- def make_clickable(name):
32
- link =f'https://huggingface.co/{name}'
33
- return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{name}</a>'
34
-
35
  def get_leaderboard():
36
  ds = load_dataset(results_repo, split='train')
37
- df = pd.DataFrame(ds)
 
38
 
39
- df.rename(columns={'submission_time': 'submission time', 'problem_type': 'problem type'}, inplace=True)
40
- # df['user'] = df['user'].apply(lambda x: make_clickable(x)).astype(str)
41
- score_field = "score" if "score" in df.columns else "objective" # fallback
42
 
43
- df = df.sort_values(by=score_field, ascending=True)
44
- return df
45
 
46
  def show_output_box(message):
47
  return gr.update(value=message, visible=True)
@@ -55,10 +55,10 @@ def gradio_interface() -> gr.Blocks:
55
 
56
  Leaderboard(
57
  value=get_leaderboard(),
58
- datatype=['str', 'date', 'str', 'str', 'bool', 'markdown', 'number', 'bool', 'number', 'number', 'str'],
59
  select_columns=["submission time", "feasibility", "score", "problem type", "user"],
60
  search_columns=["submission time", "score", "user"],
61
- hide_columns=["result_filename", "submission_filename", "objective", "minimize_objective", "boundary_json", "evaluated"],
62
  filter_columns=["problem type"],
63
  every=60,
64
  render=True
@@ -119,7 +119,6 @@ def gradio_interface() -> gr.Blocks:
119
  problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
120
  boundary_file = gr.File(label="Boundary JSON File (.json)")
121
 
122
- boundary_file
123
  submit_btn = gr.Button("Evaluate")
124
  message = gr.Textbox(label="Status", lines=1, visible=False)
125
  submit_btn.click(
 
14
 
15
  from submit import submit_boundary
16
  from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
17
+ from utils import read_boundary, write_results, get_user, make_user_clickable, make_boundary_clickable
18
  from visualize import make_visual
19
 
20
  def evaluate_boundary(filename):
 
23
  with Path(local_path).open("r") as f:
24
  raw = f.read()
25
  data_dict = json.loads(raw)
26
+
27
+ try:
28
+ result = evaluate_problem(data_dict['problem_type'], local_path)
29
+ except Exception as e:
30
+ raise gr.Error(f'Evaluation failed: {e}. No results written to results dataset.')
31
 
32
  write_results(data_dict, result)
33
  return
34
 
 
 
 
 
35
  def get_leaderboard():
36
  ds = load_dataset(results_repo, split='train')
37
+ full_df = pd.DataFrame(ds)
38
+ full_df['full results'] = full_df['result_filename'].apply(lambda x: make_boundary_clickable(x)).astype(str)
39
 
40
+ full_df.rename(columns={'submission_time': 'submission time', 'problem_type': 'problem type'}, inplace=True)
41
+ to_show = full_df[['submission time', 'problem type', 'user', 'score', 'full results']]
42
+ to_show['user'] = to_show['user'].apply(lambda x: make_user_clickable(x)).astype(str)
43
 
44
+ return to_show
 
45
 
46
  def show_output_box(message):
47
  return gr.update(value=message, visible=True)
 
55
 
56
  Leaderboard(
57
  value=get_leaderboard(),
58
+ datatype=['date', 'str', 'html', 'number', 'html'],
59
  select_columns=["submission time", "feasibility", "score", "problem type", "user"],
60
  search_columns=["submission time", "score", "user"],
61
+ # hide_columns=["result_filename", "submission_filename", "objective", "minimize_objective", "boundary_json", "evaluated"],
62
  filter_columns=["problem type"],
63
  every=60,
64
  render=True
 
119
  problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
120
  boundary_file = gr.File(label="Boundary JSON File (.json)")
121
 
 
122
  submit_btn = gr.Button("Evaluate")
123
  message = gr.Textbox(label="Status", lines=1, visible=False)
124
  submit_btn.click(
utils.py CHANGED
@@ -6,15 +6,21 @@ 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,
@@ -35,7 +41,7 @@ def write_results(record, result):
35
  if 'objective' not in record.keys():
36
  record['objective'] = 0.0
37
  record['minimize_objective'] = True
38
- record['feasibility'] = 0.0 # sum(record['feasibilities'])/len(record['feasibilities'])
39
 
40
  with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
41
  json.dump(record, tmp, indent=2)
 
6
  import pandas as pd
7
 
8
  import gradio as gr
 
9
  from huggingface_hub import upload_file, hf_hub_download
 
10
  from evaluation import evaluate_problem
11
  from datetime import datetime
12
  import os
13
 
14
  from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
15
 
16
+ def make_user_clickable(name):
17
+ link =f'https://huggingface.co/{name}'
18
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{name}</a>'
19
+
20
+ def make_boundary_clickable(filename):
21
+ link =f'https://huggingface.co/datasets/proxima-fusion/constellaration-bench-results/blob/main/{filename}'
22
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">link</a>'
23
+
24
  def read_boundary(filename):
25
  local_path = hf_hub_download(
26
  repo_id=submissions_repo,
 
41
  if 'objective' not in record.keys():
42
  record['objective'] = 0.0
43
  record['minimize_objective'] = True
44
+ record['feasibility'] = sum(record['feasibility'])/len(record['feasibility'])
45
 
46
  with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
47
  json.dump(record, tmp, indent=2)