PLUG-challenge / app.py
alanclayrichard's picture
initial commit with test setup
b78ff28
Raw History Blame Contribute Delete
2.86 kB
"""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()