Spaces:
Running
Running
| 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 about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo | |
| def get_leaderboard(): | |
| ds = load_dataset(results_repo, split='train', download_mode="force_redownload") | |
| full_df = pd.DataFrame(ds) | |
| if len(full_df) == 0: | |
| return pd.DataFrame({'date':[], 'model':[], 'score':[], 'verified':[]}) | |
| return full_df | |
| def show_output_box(message): | |
| return gr.update(value=message, visible=True) | |
| def submit_cif_files(problem_type, cif_files, profile: gr.OAuthProfile | None): | |
| return | |
| def gradio_interface() -> gr.Blocks: | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Welcome to the LeMaterial Generative Benchmark Leaderboard!") | |
| with gr.Tabs(elem_classes="tab-buttons"): | |
| with gr.TabItem("🚀 Leaderboard", elem_id="boundary-benchmark-tab-table"): | |
| gr.Markdown("# LeMat-Gen-Bench") | |
| try: | |
| Leaderboard( | |
| value=get_leaderboard(), | |
| datatype=['date', 'model', 'score', 'verified'], | |
| select_columns=["model"], | |
| search_columns=["model"], | |
| filter_columns=["verified"], | |
| every=60, | |
| render=True | |
| ) | |
| except: | |
| gr.Markdown("Leaderboard is empty.") | |
| gr.Markdown("Verified submissions mean the results came from a model submission rather than a CIF submission.") | |
| with gr.TabItem("❔About", elem_id="boundary-benchmark-tab-table"): | |
| gr.Markdown( | |
| """ | |
| ## About LeMat-Gen-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) | |
| gr.LoginButton() | |
| with gr.Row(): | |
| with gr.Column(): | |
| problem_type = gr.Dropdown(PROBLEM_TYPES, label="Problem Type") | |
| with gr.Column(): | |
| cif_file = gr.File(label="Upload a CSV, a pkl, or a ZIP of CIF files.") | |
| 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_cif_files, | |
| inputs=[problem_type, cif_file], | |
| outputs=[message, filename], | |
| ).then( | |
| fn=show_output_box, | |
| inputs=[message], | |
| outputs=[message], | |
| ) | |
| return demo | |
| if __name__ == "__main__": | |
| gradio_interface().launch() | |