Spaces:
Running
Running
first front end push
Browse files
about.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
|
| 4 |
+
PROBLEM_TYPES = ["unconditional", "conditional"]
|
| 5 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
| 6 |
+
CACHE_PATH=os.getenv("HF_HOME", ".")
|
| 7 |
+
API = HfApi(token=TOKEN)
|
| 8 |
+
organization="cgeorgiaw"
|
| 9 |
+
submissions_repo = f'{organization}/lemat-bench-submissions'
|
| 10 |
+
results_repo = f'{organization}/lemat-bench-results'
|
app.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from datasets import load_dataset
|
| 7 |
+
from gradio_leaderboard import Leaderboard
|
| 8 |
+
from evaluation import evaluate_problem
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from submit import submit_boundary
|
| 13 |
+
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
|
| 14 |
+
from utils import read_submission_from_hub, read_result_from_hub, write_results, get_user, make_user_clickable, make_boundary_clickable
|
| 15 |
+
from visualize import make_visual
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def get_leaderboard():
|
| 19 |
+
ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
|
| 20 |
+
full_df = pd.DataFrame(ds)
|
| 21 |
+
full_df['full results'] = full_df['result_filename'].apply(lambda x: make_boundary_clickable(x)).astype(str)
|
| 22 |
+
|
| 23 |
+
full_df.rename(columns={'submission_time': 'submission time', 'problem_type': 'problem type'}, inplace=True)
|
| 24 |
+
to_show = full_df.copy(deep=True)
|
| 25 |
+
to_show = to_show[to_show['user'] != 'test']
|
| 26 |
+
to_show = to_show[['submission time', 'problem type', 'user', 'score', 'full results']]
|
| 27 |
+
to_show['user'] = to_show['user'].apply(lambda x: make_user_clickable(x)).astype(str)
|
| 28 |
+
|
| 29 |
+
return to_show
|
| 30 |
+
|
| 31 |
+
def show_output_box(message):
|
| 32 |
+
return gr.update(value=message, visible=True)
|
| 33 |
+
|
| 34 |
+
def gradio_interface() -> gr.Blocks:
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown("## Welcome to the ConStellaration Boundary Leaderboard!")
|
| 37 |
+
with gr.Tabs(elem_classes="tab-buttons"):
|
| 38 |
+
with gr.TabItem("🚀 Leaderboard", elem_id="boundary-benchmark-tab-table"):
|
| 39 |
+
gr.Markdown("# Boundary Design Leaderboard")
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
Leaderboard(
|
| 43 |
+
value=get_leaderboard(),
|
| 44 |
+
datatype=['date', 'str', 'html', 'number', 'html'],
|
| 45 |
+
select_columns=["submission time", "problem type", "user", "score", "full results"],
|
| 46 |
+
search_columns=["submission time", "score", "user"],
|
| 47 |
+
# hide_columns=["result_filename", "submission_filename", "objective", "minimize_objective", "boundary_json", "evaluated"],
|
| 48 |
+
filter_columns=["problem type"],
|
| 49 |
+
every=60,
|
| 50 |
+
render=True
|
| 51 |
+
)
|
| 52 |
+
except:
|
| 53 |
+
gr.Markdown("Leaderboard is empty.")
|
| 54 |
+
|
| 55 |
+
gr.Markdown("For the `geometrical` and `simple_to_build`, the scores are bounded between 0.0 and 1.0, where 1.0 is the best possible score. For the `mhd_stable` multi-objective problem, the score is unbounded with a undefined maximum score.")
|
| 56 |
+
|
| 57 |
+
with gr.TabItem("❔About", elem_id="boundary-benchmark-tab-table"):
|
| 58 |
+
gr.Markdown(
|
| 59 |
+
"""
|
| 60 |
+
## About LeMat-Bench
|
| 61 |
+
|
| 62 |
+
**Welcome to the LeMat-Bench Leaderboard**, There are unconditional generation and conditional generation components of this leaderboard.
|
| 63 |
+
|
| 64 |
+
""")
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
with gr.TabItem("✉️ Submit", elem_id="boundary-benchmark-tab-table"):
|
| 68 |
+
gr.Markdown(
|
| 69 |
+
"""
|
| 70 |
+
# Plasma Boundary Evaluation Submission
|
| 71 |
+
Upload your plasma boundary JSON and select the problem type to get your score.
|
| 72 |
+
"""
|
| 73 |
+
)
|
| 74 |
+
filename = gr.State(value=None)
|
| 75 |
+
eval_state = gr.State(value=None)
|
| 76 |
+
user_state = gr.State(value=None)
|
| 77 |
+
|
| 78 |
+
# gr.LoginButton()
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
with gr.Column():
|
| 82 |
+
problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
|
| 83 |
+
username_input = gr.Textbox(
|
| 84 |
+
label="Username",
|
| 85 |
+
placeholder="Enter your Hugging Face username",
|
| 86 |
+
info="This will be displayed on the leaderboard."
|
| 87 |
+
)
|
| 88 |
+
with gr.Column():
|
| 89 |
+
boundary_file = gr.File(label="Upload a ZIP of your CIF files.")
|
| 90 |
+
|
| 91 |
+
username_input.change(
|
| 92 |
+
fn=lambda x: x if x.strip() else None,
|
| 93 |
+
inputs=username_input,
|
| 94 |
+
outputs=user_state
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
submit_btn = gr.Button("Submission")
|
| 98 |
+
message = gr.Textbox(label="Status", lines=1, visible=False)
|
| 99 |
+
# help message
|
| 100 |
+
gr.Markdown("If you have issues with submission or using the leaderboard, please start a discussion in the Community tab of this Space.")
|
| 101 |
+
|
| 102 |
+
submit_btn.click(
|
| 103 |
+
submit_boundary,
|
| 104 |
+
inputs=[problem_type, boundary_file, user_state],
|
| 105 |
+
outputs=[message, filename],
|
| 106 |
+
).then(
|
| 107 |
+
fn=show_output_box,
|
| 108 |
+
inputs=[message],
|
| 109 |
+
outputs=[message],
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
return demo
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
gradio_interface().launch()
|
utils.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 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/{results_repo}/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_result_from_hub(filename):
|
| 25 |
+
local_path = hf_hub_download(
|
| 26 |
+
repo_id=results_repo,
|
| 27 |
+
repo_type="dataset",
|
| 28 |
+
filename=filename,
|
| 29 |
+
)
|
| 30 |
+
return local_path
|
| 31 |
+
|
| 32 |
+
def get_user(profile: gr.OAuthProfile | None) -> str:
|
| 33 |
+
if profile is None:
|
| 34 |
+
return "Please login to make a submission to the leaderboard."
|
| 35 |
+
return profile.username
|