File size: 2,856 Bytes
b78ff28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
85
86
87
88
89
90
91
"""Gradio app for the PLUG challenge.

Four tabs β€” About, Submit, Leaderboard, FAQ β€” whose content is gated on
``config.CURRENT_PHASE``. All challenge-specific copy comes from ``config`` and
all benchmark facts from ``plug_challenge.benchmarks``; this module only decides
the layout.
"""

import gradio as gr
from gradio.themes.utils import sizes
from loguru import logger

from config import (
    ABOUT_MD,
    CHALLENGE_ANNOUNCEMENT_LINK,
    CURRENT_PHASE,
    DATASET_DOWNLOAD_LINK,
    FAQ_MD,
    HEADER_MARKDOWN,
    PAGE_TITLE,
)
from leaderboards import render_leaderboards
from submission import render_submission_tab

_TABLE_CSS = """
<style>
#welcome-md table, #faq-md table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}
#welcome-md th, #welcome-md td, #faq-md th, #faq-md td {
    padding: 10px;
    border: 1px solid rgba(0,0,0,0.1);
}
#welcome-md thead th, #faq-md thead th {
    background: var(--panel-background-fill, #f5f5f7);
}
</style>
"""


def _link_button(url: str, label: str, colour: str) -> str:
    """Render one prominent call-to-action link."""
    return f"""
        <div style="margin: 12px 0 20px 0; text-align: center;">
            <a href="{url}" target="_blank"
               style="display: inline-block; padding: 12px 28px; background: {colour};
                      color: #fff; font-size: 1.05rem; font-weight: 600; border-radius: 8px;
                      text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,0.18);">
                {label}
            </a>
        </div>
    """


with gr.Blocks(
    title=PAGE_TITLE,
    fill_height=False,
    theme=gr.themes.Ocean(text_size=sizes.text_lg),
) as demo:
    gr.Markdown(HEADER_MARKDOWN)
    gr.HTML(_TABLE_CSS)

    with gr.Row():
        with gr.Column(scale=1):
            if CHALLENGE_ANNOUNCEMENT_LINK:
                gr.HTML(_link_button(CHALLENGE_ANNOUNCEMENT_LINK, "πŸ“„ About PLUG β†’", "#2563eb"))
        with gr.Column(scale=1):
            # Hidden before the challenge opens: the data is released when submissions do.
            if DATASET_DOWNLOAD_LINK and CURRENT_PHASE >= 1:
                gr.HTML(_link_button(DATASET_DOWNLOAD_LINK, "πŸ—„οΈ Challenge data β†’", "#059669"))

    with gr.Tabs(elem_classes="tab-buttons"):
        with gr.TabItem("πŸ“– About"):
            gr.Markdown(ABOUT_MD, elem_id="welcome-md")

        with gr.TabItem("βœ‰οΈ Submit"):
            render_submission_tab(phase=CURRENT_PHASE)

        with gr.TabItem("🏁 Leaderboard" if CURRENT_PHASE >= 2 else "🏎️ Leaderboard"):
            render_leaderboards(phase=CURRENT_PHASE, demo=demo)

        with gr.TabItem("πŸ› οΈ FAQ"):
            gr.Markdown(FAQ_MD, elem_id="faq-md")


if __name__ == "__main__":
    logger.info("Starting the PLUG challenge Gradio app (phase {})...", CURRENT_PHASE)
    demo.launch()