|
import gradio as gr |
|
import json |
|
import os |
|
import random |
|
|
|
|
|
JSON_FILE = "dipromats2024-t2_leaderboard-data.json" |
|
|
|
|
|
def save_data(data): |
|
with open(JSON_FILE, "w") as f: |
|
json.dump(data, f, indent=4) |
|
|
|
|
|
def load_data(): |
|
if os.path.exists(JSON_FILE): |
|
with open(JSON_FILE, "r") as f: |
|
try: |
|
return json.load(f) |
|
except json.JSONDecodeError: |
|
return [] |
|
return [] |
|
|
|
|
|
def update_table(): |
|
data = load_data() |
|
table_data = [] |
|
for item in data: |
|
table_data.append([item.get("team_name", ""), item.get("run_id", ""), |
|
item.get("lenient_f1", ""), item.get("strict_f1", ""), item.get("average_f1", "")]) |
|
return table_data |
|
|
|
|
|
def evaluate_results(file_path): |
|
lenient_f1=random.random() |
|
strict_f1=random.random() |
|
average_f1=(lenient_f1+strict_f1)/2 |
|
return lenient_f1, strict_f1, average_f1 |
|
|
|
|
|
def process_file(file_path, team_input, run_id, description, email): |
|
warn=False |
|
if not file_path: |
|
gr.Warning("File cannot be blank") |
|
warn=True |
|
if not team_input: |
|
gr.Warning("Team name cannot be blank") |
|
warn=True |
|
if not run_id: |
|
gr.Warning("Run ID cannot be blank") |
|
warn=True |
|
if not file_path: |
|
gr.Warning("File cannot be blank") |
|
warn=True |
|
if not description: |
|
gr.Warning("Description cannot be blank") |
|
warn=True |
|
if not email: |
|
gr.Warning("Email cannot be blank") |
|
warn=True |
|
|
|
if warn: |
|
return gr.Button(visible=True), gr.Button(visible=False), None, None, None |
|
|
|
lenient_f1, strict_f1, average_f1 = evaluate_results(file_path) |
|
|
|
return gr.Button(visible=False), gr.Button(visible=True), lenient_f1, strict_f1, average_f1 |
|
|
|
|
|
|
|
def update_leaderboard(email, team_input, run_id, description, lenient_f1, strict_f1, average_f1): |
|
data = load_data() |
|
data.append({ |
|
"email": email, |
|
"team_name": team_input, |
|
"run_id": run_id, |
|
"description": description, |
|
"lenient_f1": lenient_f1, |
|
"strict_f1": strict_f1, |
|
"average_f1": average_f1 |
|
}) |
|
save_data(data) |
|
return update_table(), gr.Tabs(selected=0), gr.Button(visible=True), gr.Button(visible=False), "", "", "", "", None, None, None, None |
|
|
|
|
|
|
|
with gr.Blocks() as leaderboard: |
|
gr.Markdown( |
|
""" |
|
# Dipromats 2024 Task 2 Leaderboard |
|
# Automatic Detection of Narratives from Diplomats of Major Powers |
|
This is... |
|
You can... |
|
""") |
|
with gr.Tabs() as tabs: |
|
|
|
|
|
with gr.TabItem("Leaderboard", id=0): |
|
gr.Markdown( |
|
""" |
|
# |
|
# Leaderboard |
|
""") |
|
leaderboard_table = gr.Dataframe(headers=["Team", "Run ID", "Lenient F1", "Strict F1", "Average F1"], |
|
value=update_table(), |
|
interactive=False) |
|
|
|
|
|
with gr.TabItem("Evaluate your results", id=1): |
|
gr.Markdown( |
|
""" |
|
# Upload your results and get evaluated |
|
Then you can decide to submit your results to the leaderboard or not. |
|
Make sure that you upload a file with the json format described in... |
|
""") |
|
|
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
with gr.Row(): |
|
team_input = gr.Textbox(label="Team Name") |
|
run_id = gr.Textbox(label="Run ID") |
|
email_input = gr.Textbox(label="Email (only for submission verification, it won't be shown)") |
|
description_input = gr.Textbox(label="System description", lines=6) |
|
file_input = gr.File(label="Upload a JSON file", file_types=[".json"], type="filepath", file_count="single") |
|
evaluate_button = gr.Button("Evaluate") |
|
|
|
|
|
with gr.Row(visible=True): |
|
lenient_f1 = gr.Number(label="Lenient F1", interactive=False) |
|
strict_f1 = gr.Number(label="Strict F1", interactive=False) |
|
average_f1 = gr.Number(label="Average F1", interactive=False) |
|
|
|
|
|
submit_button = gr.Button("Submit to leaderboard", visible=False) |
|
|
|
evaluate_button.click(process_file, |
|
inputs=[file_input, team_input, run_id, description_input, email_input], |
|
outputs=[evaluate_button,submit_button,lenient_f1, strict_f1, average_f1]) |
|
submit_button.click(update_leaderboard, |
|
inputs=[email_input, team_input, run_id, description_input, lenient_f1, strict_f1, average_f1], |
|
outputs=[leaderboard_table, tabs, evaluate_button, submit_button, team_input, run_id, description_input, email_input, file_input,lenient_f1, strict_f1, average_f1]) |
|
leaderboard.launch() |