File size: 5,609 Bytes
554d184
23bce77
 
 
80c3833
554d184
d9c89bb
 
8b63d2d
29974fb
80c3833
 
29974fb
80c3833
 
cfed2a3
80c3833
 
 
29974fb
 
80c3833
 
 
29974fb
23bce77
29974fb
23bce77
 
 
92944d2
80c3833
 
 
29974fb
 
80c3833
 
 
 
 
 
 
 
29974fb
cfed2a3
80c3833
 
 
23bce77
 
80c3833
 
 
23bce77
92944d2
80c3833
23bce77
 
80c3833
23bce77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80c3833
23bce77
 
92944d2
23bce77
92944d2
23bce77
554d184
 
23bce77
80c3833
23bce77
80c3833
23bce77
 
 
 
 
 
 
 
 
 
 
 
 
80c3833
23bce77
 
 
80c3833
23bce77
80c3833
23bce77
 
 
 
 
 
 
 
80c3833
23bce77
 
 
 
 
 
 
 
 
 
 
 
 
80c3833
23bce77
 
 
 
 
 
80c3833
 
23bce77
80c3833
 
23bce77
29974fb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import gradio as gr
import json
import os
import random
import datasets #load_dataset, save_to_disk, load_from_disk

# Primero crea el token en los Settings de tu Usuario
# Despu茅s c贸pialo a Secrets en los Settings del Space
HF_TOKEN = os.environ['HF_DIPROMATS2024_T2_LEADERBOARD_TOKEN']

# Use the Hugging Face dataset
DATASET_NAME = "NLP-UNED/dipromats2024-t2_leaderboard-data"
SPLIT = 'results'

try:
    dataset = datasets.load_dataset(DATASET_NAME, token=HF_TOKEN)

except Exception as e:
    print(f"Error loading dataset: {e}")
    dataset = datasets.Dataset.from_dict({"email": [], "team_name": [], "run_id": [], "description": [], "lenient_f1": [], "strict_f1": [], "average_f1": []})
    dataset = datasets.DatasetDict({SPLIT: dataset})

# Funci贸n para convertir el dataset en tabla
def data_to_table():
    global dataset
    table_data = []
    for item in dataset[SPLIT]:
        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


# Funci贸n para subir los resultados al leaderboard
def update_leaderboard(email, team_input, run_id, description, lenient_f1, strict_f1, average_f1):
    global datataset
    new_data = dataset[SPLIT].add_item({
        "email": email,
        "team_name": team_input,
        "run_id": run_id,
        "description": description,
        "lenient_f1": lenient_f1,
        "strict_f1": strict_f1,
        "average_f1": average_f1
    })
    dataset[SPLIT] = new_data
    new_data.push_to_hub(DATASET_NAME, split=SPLIT, token=HF_TOKEN)
    return data_to_table(), gr.Tabs(selected=0), gr.Button(visible=True), gr.Button(visible=False), "", "", "", "", None, None, None, None


# Funci贸n para evaluar los resultados
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


# Funci贸n para procesar el archivo de resultados
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


# Main

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:

        # Tab Leaderboard
        with gr.TabItem("Leaderboard", id=0):
            gr.Markdown(
                """
                #
                # Leaderboard
                """)
            leaderboard_table = gr.Dataframe(headers=["Team", "Run ID", "Lenient F1", "Strict F1", "Average F1"],
                        value=data_to_table(),
                        interactive=False)

        # Tab Evaluate
        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...
                """)

            # Submission Form
            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")

            # System results table
            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 to leaderboard
            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()