"""Submission tab – lets registered teams upload results.""" import gradio as gr from utils import add_submission, load_registrations def _submit(team_name: str, method: str, score_str: str, file): team_name = team_name.strip() method = method.strip() if not team_name or not method or score_str == "": return gr.update(value="⚠️ All fields are required.", visible=True) # Check the team is registered df = load_registrations() if df.empty or not (df["team_name"] == team_name).any(): return gr.update( value="⚠️ Team not found. Please register first.", visible=True ) try: score = float(score_str) file_name = file.name if file else "" add_submission(team_name, method, score, file_name) return gr.update( value=f"✅ Submission recorded for **{team_name}** (score: {score:.4f}).", visible=True, ) except ValueError: return gr.update(value="⚠️ Score must be a number.", visible=True) except Exception as exc: return gr.update(value=f"❌ Submission failed: {exc}", visible=True) def build_submission_tab() -> None: gr.Markdown("## Submit your results") gr.Markdown( "Your team must be registered before submitting. " "Enter the **exact** team name used during registration." ) with gr.Row(): with gr.Column(): team_name = gr.Textbox(label="Team name", placeholder="Team Awesome") method = gr.Textbox(label="Method name", placeholder="BERT + SVM") score = gr.Textbox(label="Score", placeholder="0.9142") file = gr.File(label="Result file (optional)") submit = gr.Button("Submit", variant="primary") status = gr.Markdown(visible=False) submit.click( fn=_submit, inputs=[team_name, method, score, file], outputs=status, )