LeMat-GenBench / app.py
cgeorgiaw's picture
cgeorgiaw HF Staff
cleaning up some old imports
03f4e0c
raw
history blame
4.9 kB
from pathlib import Path
import json
import pandas as pd
import gradio as gr
from datasets import load_dataset
from gradio_leaderboard import Leaderboard
from datetime import datetime
import os
from submit import submit_boundary
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
from utils import make_user_clickable, make_boundary_clickable
def get_leaderboard():
ds = load_dataset(results_repo, split='train', download_mode="force_redownload")
full_df = pd.DataFrame(ds)
full_df['full results'] = full_df['result_filename'].apply(lambda x: make_boundary_clickable(x)).astype(str)
full_df.rename(columns={'submission_time': 'submission time', 'problem_type': 'problem type'}, inplace=True)
to_show = full_df.copy(deep=True)
to_show = to_show[to_show['user'] != 'test']
to_show = to_show[['submission time', 'problem type', 'user', 'score', 'full results']]
to_show['user'] = to_show['user'].apply(lambda x: make_user_clickable(x)).astype(str)
return to_show
def show_output_box(message):
return gr.update(value=message, visible=True)
def gradio_interface() -> gr.Blocks:
with gr.Blocks() as demo:
gr.Markdown("## Welcome to the ConStellaration Boundary Leaderboard!")
with gr.Tabs(elem_classes="tab-buttons"):
with gr.TabItem("🚀 Leaderboard", elem_id="boundary-benchmark-tab-table"):
gr.Markdown("# Boundary Design Leaderboard")
try:
Leaderboard(
value=get_leaderboard(),
datatype=['date', 'str', 'html', 'number', 'html'],
select_columns=["submission time", "problem type", "user", "score", "full results"],
search_columns=["submission time", "score", "user"],
# hide_columns=["result_filename", "submission_filename", "objective", "minimize_objective", "boundary_json", "evaluated"],
filter_columns=["problem type"],
every=60,
render=True
)
except:
gr.Markdown("Leaderboard is empty.")
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.")
with gr.TabItem("❔About", elem_id="boundary-benchmark-tab-table"):
gr.Markdown(
"""
## About LeMat-Bench
**Welcome to the LeMat-Bench Leaderboard**, There are unconditional generation and conditional generation components of this leaderboard.
""")
with gr.TabItem("✉️ Submit", elem_id="boundary-benchmark-tab-table"):
gr.Markdown(
"""
# Materials Submission
Upload a CSV, pkl, or a ZIP of CIFs with your structures.
"""
)
filename = gr.State(value=None)
eval_state = gr.State(value=None)
user_state = gr.State(value=None)
# gr.LoginButton()
with gr.Row():
with gr.Column():
problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type")
username_input = gr.Textbox(
label="Username",
placeholder="Enter your Hugging Face username",
info="This will be displayed on the leaderboard."
)
with gr.Column():
boundary_file = gr.File(label="Upload a CSV, a pkl, or a ZIP of CIF files.")
username_input.change(
fn=lambda x: x if x.strip() else None,
inputs=username_input,
outputs=user_state
)
submit_btn = gr.Button("Submission")
message = gr.Textbox(label="Status", lines=1, visible=False)
# help message
gr.Markdown("If you have issues with submission or using the leaderboard, please start a discussion in the Community tab of this Space.")
submit_btn.click(
submit_boundary,
inputs=[problem_type, boundary_file, user_state],
outputs=[message, filename],
).then(
fn=show_output_box,
inputs=[message],
outputs=[message],
)
return demo
if __name__ == "__main__":
gradio_interface().launch()