Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,60 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
import os
|
4 |
import random
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return []
|
22 |
-
return []
|
23 |
-
|
24 |
-
# Funci贸n para convertir el json del leaderboard en tabla
|
25 |
-
def update_table():
|
26 |
-
data = load_data()
|
27 |
table_data = []
|
28 |
for item in data:
|
29 |
table_data.append([item.get("team_name", ""), item.get("run_id", ""),
|
30 |
item.get("lenient_f1", ""), item.get("strict_f1", ""), item.get("average_f1", "")])
|
31 |
return table_data
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Funci贸n para evaluar los resultados
|
34 |
def evaluate_results(file_path):
|
35 |
-
lenient_f1=random.random()
|
36 |
-
strict_f1=random.random()
|
37 |
-
average_f1=(lenient_f1+strict_f1)/2
|
38 |
return lenient_f1, strict_f1, average_f1
|
39 |
|
|
|
40 |
# Funci贸n para procesar el archivo de resultados
|
41 |
def process_file(file_path, team_input, run_id, description, email):
|
42 |
-
warn=False
|
43 |
if not file_path:
|
44 |
gr.Warning("File cannot be blank")
|
45 |
warn=True
|
@@ -58,7 +73,7 @@ def process_file(file_path, team_input, run_id, description, email):
|
|
58 |
if not email:
|
59 |
gr.Warning("Email cannot be blank")
|
60 |
warn=True
|
61 |
-
|
62 |
if warn:
|
63 |
return gr.Button(visible=True), gr.Button(visible=False), None, None, None
|
64 |
|
@@ -67,25 +82,10 @@ def process_file(file_path, team_input, run_id, description, email):
|
|
67 |
return gr.Button(visible=False), gr.Button(visible=True), lenient_f1, strict_f1, average_f1
|
68 |
|
69 |
|
70 |
-
# Funci贸n para subir los resultados al leaderboard
|
71 |
-
def update_leaderboard(email, team_input, run_id, description, lenient_f1, strict_f1, average_f1):
|
72 |
-
data = load_data()
|
73 |
-
data.append({
|
74 |
-
"email": email,
|
75 |
-
"team_name": team_input,
|
76 |
-
"run_id": run_id,
|
77 |
-
"description": description,
|
78 |
-
"lenient_f1": lenient_f1,
|
79 |
-
"strict_f1": strict_f1,
|
80 |
-
"average_f1": average_f1
|
81 |
-
})
|
82 |
-
save_data(data)
|
83 |
-
return update_table(), gr.Tabs(selected=0), gr.Button(visible=True), gr.Button(visible=False), "", "", "", "", None, None, None, None # Clear inputs
|
84 |
-
|
85 |
# Main
|
86 |
-
|
87 |
with gr.Blocks() as leaderboard:
|
88 |
-
|
89 |
gr.Markdown(
|
90 |
"""
|
91 |
# Dipromats 2024 Task 2 Leaderboard
|
@@ -99,13 +99,13 @@ with gr.Blocks() as leaderboard:
|
|
99 |
with gr.TabItem("Leaderboard", id=0):
|
100 |
gr.Markdown(
|
101 |
"""
|
102 |
-
#
|
103 |
# Leaderboard
|
104 |
""")
|
105 |
leaderboard_table = gr.Dataframe(headers=["Team", "Run ID", "Lenient F1", "Strict F1", "Average F1"],
|
106 |
-
value=
|
107 |
interactive=False)
|
108 |
-
|
109 |
# Tab Evaluate
|
110 |
with gr.TabItem("Evaluate your results", id=1):
|
111 |
gr.Markdown(
|
@@ -114,7 +114,7 @@ with gr.Blocks() as leaderboard:
|
|
114 |
Then you can decide to submit your results to the leaderboard or not.
|
115 |
Make sure that you upload a file with the json format described in...
|
116 |
""")
|
117 |
-
|
118 |
# Submission Form
|
119 |
with gr.Row():
|
120 |
with gr.Column():
|
@@ -128,17 +128,17 @@ with gr.Blocks() as leaderboard:
|
|
128 |
|
129 |
# System results table
|
130 |
with gr.Row(visible=True):
|
131 |
-
lenient_f1 = gr.Number(label="Lenient F1", interactive=False)
|
132 |
strict_f1 = gr.Number(label="Strict F1", interactive=False)
|
133 |
average_f1 = gr.Number(label="Average F1", interactive=False)
|
134 |
|
135 |
# Submit to leaderboard
|
136 |
submit_button = gr.Button("Submit to leaderboard", visible=False)
|
137 |
|
138 |
-
evaluate_button.click(process_file,
|
139 |
-
inputs=[file_input, team_input, run_id, description_input, email_input],
|
140 |
outputs=[evaluate_button,submit_button,lenient_f1, strict_f1, average_f1])
|
141 |
-
submit_button.click(update_leaderboard,
|
142 |
-
inputs=[email_input, team_input, run_id, description_input, lenient_f1, strict_f1, average_f1],
|
143 |
outputs=[leaderboard_table, tabs, evaluate_button, submit_button, team_input, run_id, description_input, email_input, file_input,lenient_f1, strict_f1, average_f1])
|
144 |
leaderboard.launch()
|
|
|
1 |
+
# prompt: instead of using JSON_FILE in local drive, use the HuggingFace dataset "NLP-UNED/dipromats2024-t2_leaderboard-data"
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
import os
|
5 |
import random
|
6 |
+
import datasets #load_dataset, save_to_disk, load_from_disk
|
7 |
|
8 |
+
# Use the Hugging Face dataset
|
9 |
+
DATASET_NAME = "NLP-UNED/dipromats2024-t2_leaderboard-data"
|
10 |
+
|
11 |
+
try:
|
12 |
+
#dataset = datasets.load_dataset(DATASET_NAME)
|
13 |
+
#data = dataset['train']
|
14 |
+
data = datasets.load_from_disk(DATASET_NAME)
|
15 |
+
|
16 |
+
except Exception as e:
|
17 |
+
print(f"Error loading dataset: {e}")
|
18 |
+
data = []
|
19 |
+
|
20 |
+
# Funci贸n para convertir el dataset en tabla
|
21 |
+
def data_to_table():
|
22 |
+
global data
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
table_data = []
|
24 |
for item in data:
|
25 |
table_data.append([item.get("team_name", ""), item.get("run_id", ""),
|
26 |
item.get("lenient_f1", ""), item.get("strict_f1", ""), item.get("average_f1", "")])
|
27 |
return table_data
|
28 |
|
29 |
+
|
30 |
+
# Funci贸n para subir los resultados al leaderboard
|
31 |
+
def update_leaderboard(email, team_input, run_id, description, lenient_f1, strict_f1, average_f1):
|
32 |
+
global data
|
33 |
+
data.add_item({
|
34 |
+
"email": email,
|
35 |
+
"team_name": team_input,
|
36 |
+
"run_id": run_id,
|
37 |
+
"description": description,
|
38 |
+
"lenient_f1": lenient_f1,
|
39 |
+
"strict_f1": strict_f1,
|
40 |
+
"average_f1": average_f1
|
41 |
+
})
|
42 |
+
#data.save_to_disk(DATASET_NAME)
|
43 |
+
data.save_to_disk(DATASET_NAME+"/prueba")
|
44 |
+
return data_to_table(), gr.Tabs(selected=0), gr.Button(visible=True), gr.Button(visible=False), "", "", "", "", None, None, None, None
|
45 |
+
|
46 |
+
|
47 |
# Funci贸n para evaluar los resultados
|
48 |
def evaluate_results(file_path):
|
49 |
+
lenient_f1 = random.random()
|
50 |
+
strict_f1 = random.random()
|
51 |
+
average_f1 = (lenient_f1 + strict_f1) / 2
|
52 |
return lenient_f1, strict_f1, average_f1
|
53 |
|
54 |
+
|
55 |
# Funci贸n para procesar el archivo de resultados
|
56 |
def process_file(file_path, team_input, run_id, description, email):
|
57 |
+
warn = False
|
58 |
if not file_path:
|
59 |
gr.Warning("File cannot be blank")
|
60 |
warn=True
|
|
|
73 |
if not email:
|
74 |
gr.Warning("Email cannot be blank")
|
75 |
warn=True
|
76 |
+
|
77 |
if warn:
|
78 |
return gr.Button(visible=True), gr.Button(visible=False), None, None, None
|
79 |
|
|
|
82 |
return gr.Button(visible=False), gr.Button(visible=True), lenient_f1, strict_f1, average_f1
|
83 |
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
# Main
|
86 |
+
|
87 |
with gr.Blocks() as leaderboard:
|
88 |
+
|
89 |
gr.Markdown(
|
90 |
"""
|
91 |
# Dipromats 2024 Task 2 Leaderboard
|
|
|
99 |
with gr.TabItem("Leaderboard", id=0):
|
100 |
gr.Markdown(
|
101 |
"""
|
102 |
+
#
|
103 |
# Leaderboard
|
104 |
""")
|
105 |
leaderboard_table = gr.Dataframe(headers=["Team", "Run ID", "Lenient F1", "Strict F1", "Average F1"],
|
106 |
+
value=data_to_table(),
|
107 |
interactive=False)
|
108 |
+
|
109 |
# Tab Evaluate
|
110 |
with gr.TabItem("Evaluate your results", id=1):
|
111 |
gr.Markdown(
|
|
|
114 |
Then you can decide to submit your results to the leaderboard or not.
|
115 |
Make sure that you upload a file with the json format described in...
|
116 |
""")
|
117 |
+
|
118 |
# Submission Form
|
119 |
with gr.Row():
|
120 |
with gr.Column():
|
|
|
128 |
|
129 |
# System results table
|
130 |
with gr.Row(visible=True):
|
131 |
+
lenient_f1 = gr.Number(label="Lenient F1", interactive=False)
|
132 |
strict_f1 = gr.Number(label="Strict F1", interactive=False)
|
133 |
average_f1 = gr.Number(label="Average F1", interactive=False)
|
134 |
|
135 |
# Submit to leaderboard
|
136 |
submit_button = gr.Button("Submit to leaderboard", visible=False)
|
137 |
|
138 |
+
evaluate_button.click(process_file,
|
139 |
+
inputs=[file_input, team_input, run_id, description_input, email_input],
|
140 |
outputs=[evaluate_button,submit_button,lenient_f1, strict_f1, average_f1])
|
141 |
+
submit_button.click(update_leaderboard,
|
142 |
+
inputs=[email_input, team_input, run_id, description_input, lenient_f1, strict_f1, average_f1],
|
143 |
outputs=[leaderboard_table, tabs, evaluate_button, submit_button, team_input, run_id, description_input, email_input, file_input,lenient_f1, strict_f1, average_f1])
|
144 |
leaderboard.launch()
|