File size: 2,176 Bytes
7f4459e
8fe2dca
7f4459e
 
 
 
 
8fe2dca
 
 
 
 
 
 
 
 
 
 
 
 
 
7f4459e
8fe2dca
 
 
 
 
 
 
 
 
 
 
 
 
 
7f4459e
 
 
 
 
 
 
8fe2dca
7f4459e
8fe2dca
 
7f4459e
 
8fe2dca
7f4459e
 
c7e2071
 
8fe2dca
 
c7e2071
7f4459e
 
 
c7e2071
 
 
 
 
7f4459e
 
c7e2071
8fe2dca
c7e2071
 
8fe2dca
c7e2071
7f4459e
 
 
 
c7e2071
 
8fe2dca
 
c7e2071
 
8fe2dca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import gradio as gr
import pandas as pd

from about import ABOUT_TEXT, INTRO_TEXT, SUBMISSION_TEXT, TITLE
from utils import load_results_dataframe, submit_zip


EMPTY_COLUMNS = [
    "rank",
    "model_name",
    "team_name",
    "avg_vrmse",
    "density_vrmse",
    "pressure_vrmse",
    "velocity_x_vrmse",
    "velocity_y_vrmse",
    "submitted_at",
    "status",
]


def refresh_leaderboard():
    try:
        df = load_results_dataframe()
        if df is None or not isinstance(df, pd.DataFrame):
            df = pd.DataFrame(columns=EMPTY_COLUMNS)
        return df, "Leaderboard loaded."
    except Exception as exc:
        return pd.DataFrame(columns=EMPTY_COLUMNS), f"Error loading leaderboard: {exc}"


def handle_submit(zip_file):
    try:
        return submit_zip(zip_file)
    except Exception as exc:
        return f"Submission failed: {exc}"


with gr.Blocks(title="The Well Leaderboard MVP") as demo:
    gr.Markdown(TITLE)
    gr.Markdown(INTRO_TEXT)

    with gr.Tab("Leaderboard"):
        leaderboard_status = gr.Markdown("Loading leaderboard...")
        leaderboard = gr.Dataframe(
            headers=EMPTY_COLUMNS,
            value=pd.DataFrame(columns=EMPTY_COLUMNS),
            label="Ranked results",
            wrap=True,
            interactive=False,
        )
        refresh_button = gr.Button("Refresh leaderboard")
        refresh_button.click(
            fn=refresh_leaderboard,
            outputs=[leaderboard, leaderboard_status],
            api_name=False,
        )

    with gr.Tab("Submit"):
        gr.Markdown(SUBMISSION_TEXT)
        zip_file = gr.File(
            label="Submission zip",
            file_count="single",
            file_types=[".zip"],
        )
        submit_button = gr.Button("Submit")
        submission_status = gr.Markdown()
        submit_button.click(
            fn=handle_submit,
            inputs=zip_file,
            outputs=submission_status,
            api_name=False,
        )

    with gr.Tab("About"):
        gr.Markdown(ABOUT_TEXT)

    demo.load(
        fn=refresh_leaderboard,
        outputs=[leaderboard, leaderboard_status],
        api_name=False,
    )

demo.launch()