anselp commited on
Commit
29974fb
verified
1 Parent(s): 6d2771a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -1,27 +1,30 @@
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
- HF_TOKEN = os.getenv('HF_TOKEN_UNEDNLP_WRITE')
11
 
12
  try:
13
  dataset = datasets.load_dataset(DATASET_NAME)
14
- data = dataset['train']
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
@@ -29,8 +32,8 @@ def data_to_table():
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,
@@ -39,7 +42,8 @@ def update_leaderboard(email, team_input, run_id, description, lenient_f1, stric
39
  "strict_f1": strict_f1,
40
  "average_f1": average_f1
41
  })
42
- data.push_to_hub(DATASET_NAME, token=HF_TOKEN)
 
43
  return data_to_table(), gr.Tabs(selected=0), gr.Button(visible=True), gr.Button(visible=False), "", "", "", "", None, None, None, None
44
 
45
 
@@ -140,4 +144,4 @@ with gr.Blocks() as leaderboard:
140
  submit_button.click(update_leaderboard,
141
  inputs=[email_input, team_input, run_id, description_input, lenient_f1, strict_f1, average_f1],
142
  outputs=[leaderboard_table, tabs, evaluate_button, submit_button, team_input, run_id, description_input, email_input, file_input,lenient_f1, strict_f1, average_f1])
143
- leaderboard.launch(debug=True)
 
 
1
  import gradio as gr
2
  import json
3
  import os
4
  import random
5
  import datasets #load_dataset, save_to_disk, load_from_disk
6
 
7
+ from google.colab import userdata
8
+
9
+ HF_TOKEN = userdata.get('HF-DIPROMATS2024-T2-LEADERBOARD-TOKEN')
10
+
11
  # Use the Hugging Face dataset
12
  DATASET_NAME = "NLP-UNED/dipromats2024-t2_leaderboard-data"
13
+ SPLIT = 'results'
14
 
15
  try:
16
  dataset = datasets.load_dataset(DATASET_NAME)
 
17
 
18
  except Exception as e:
19
  print(f"Error loading dataset: {e}")
20
+ dataset = datasets.Dataset.from_dict({"email": [], "team_name": [], "run_id": [], "description": [], "lenient_f1": [], "strict_f1": [], "average_f1": []})
21
+ dataset = datasets.DatasetDict({SPLIT: dataset})
22
 
23
  # Funci贸n para convertir el dataset en tabla
24
  def data_to_table():
25
+ global dataset
26
  table_data = []
27
+ for item in dataset[SPLIT]:
28
  table_data.append([item.get("team_name", ""), item.get("run_id", ""),
29
  item.get("lenient_f1", ""), item.get("strict_f1", ""), item.get("average_f1", "")])
30
  return table_data
 
32
 
33
  # Funci贸n para subir los resultados al leaderboard
34
  def update_leaderboard(email, team_input, run_id, description, lenient_f1, strict_f1, average_f1):
35
+ global datataset
36
+ new_data = dataset[SPLIT].add_item({
37
  "email": email,
38
  "team_name": team_input,
39
  "run_id": run_id,
 
42
  "strict_f1": strict_f1,
43
  "average_f1": average_f1
44
  })
45
+ dataset[SPLIT] = new_data
46
+ new_data.push_to_hub(DATASET_NAME, split=SPLIT, token=HF_TOKEN)
47
  return data_to_table(), gr.Tabs(selected=0), gr.Button(visible=True), gr.Button(visible=False), "", "", "", "", None, None, None, None
48
 
49
 
 
144
  submit_button.click(update_leaderboard,
145
  inputs=[email_input, team_input, run_id, description_input, lenient_f1, strict_f1, average_f1],
146
  outputs=[leaderboard_table, tabs, evaluate_button, submit_button, team_input, run_id, description_input, email_input, file_input,lenient_f1, strict_f1, average_f1])
147
+ leaderboard.launch()