Fhrozen commited on
Commit
fc68877
·
1 Parent(s): fc07249

update tabs

Browse files
app.py CHANGED
@@ -9,7 +9,10 @@ from typing import Dict, List, Tuple, Optional
9
  import math
10
 
11
  from espnet_leaderboard.display.css_html_js import CUSTOM_CSS
12
- from espnet_leaderboard.display.task_tab import create_leaderboard_tab
 
 
 
13
  from espnet_leaderboard.leaderboard.data import LeaderboardData
14
 
15
 
@@ -56,7 +59,7 @@ def create_app():
56
  with gr.Tab("Speaker Recognition"):
57
  create_leaderboard_tab("Speaker Recognition", leaderboard_data, rows_per_page=20)
58
 
59
- with gr.Tab("Request a model here!"):
60
  create_submit_tab()
61
 
62
  with gr.Tab("About"):
@@ -69,7 +72,7 @@ def create_app():
69
 
70
  To submit your model results:
71
  1. Prepare your results in the required format
72
- 2. Submit via the `Request a model` tab
73
  3. Results will be automatically updated on the leaderboard
74
 
75
  ### Data Sources
 
9
  import math
10
 
11
  from espnet_leaderboard.display.css_html_js import CUSTOM_CSS
12
+ from espnet_leaderboard.display.tabs import (
13
+ create_leaderboard_tab,
14
+ create_submit_tab
15
+ )
16
  from espnet_leaderboard.leaderboard.data import LeaderboardData
17
 
18
 
 
59
  with gr.Tab("Speaker Recognition"):
60
  create_leaderboard_tab("Speaker Recognition", leaderboard_data, rows_per_page=20)
61
 
62
+ with gr.Tab("Request a model"):
63
  create_submit_tab()
64
 
65
  with gr.Tab("About"):
 
72
 
73
  To submit your model results:
74
  1. Prepare your results in the required format
75
+ 2. Submit via the **Request a model** tab
76
  3. Results will be automatically updated on the leaderboard
77
 
78
  ### Data Sources
espnet_leaderboard/display/tabs.py CHANGED
@@ -1,5 +1,8 @@
1
  import gradio as gr
2
  import math
 
 
 
3
 
4
  from espnet_leaderboard.leaderboard.data import LeaderboardData
5
 
@@ -109,17 +112,82 @@ def create_leaderboard_tab(
109
 
110
  def create_submit_tab():
111
  gr.Markdown("## Request a model here!")
112
- def submit_model(model_text):
113
  if (model_text is None) or len(model_text) < 1:
114
- raise gr.Error("Please enter a model name.")
115
  splits = model_text.split("/")
116
  if len(splits) != 2:
117
- raise gr.Error("Incorrect request format. Expected format: 'user_name/model_name'")
118
- if len(splits[0]) < 1 or len(splits[1]) < 1:
119
- raise gr.Error("Incorrect request format. Both user name and model name are required.")
120
- gr.Info(f"Submitted {model_text}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  return ""
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  with gr.Tabs():
124
  with gr.Tab("From Huggingface Hub"):
125
  with gr.Row():
@@ -135,20 +203,45 @@ def create_submit_tab():
135
 
136
  with gr.Row():
137
  with gr.Column(scale=1):
138
- next_btn = gr.Button("Submit ✉️")
139
  with gr.Column(scale=2):
140
  pass
141
 
142
  with gr.Tab("From Custom results"):
143
  gr.Markdown("Submit your results in JSON format here: ")
144
  gr.Markdown("The file needs to have the fields detailed [here](https://github.com/espnet/espnet).")
145
- custom_model_box = gr.UploadButton(
146
- label="Search Models",
147
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
- next_btn.click(
150
- fn=submit_model,
151
  inputs=[model_box],
152
  outputs=[model_box]
153
  )
 
 
 
 
 
 
 
 
 
 
 
154
  return
 
1
  import gradio as gr
2
  import math
3
+ import re
4
+
5
+ import json
6
 
7
  from espnet_leaderboard.leaderboard.data import LeaderboardData
8
 
 
112
 
113
  def create_submit_tab():
114
  gr.Markdown("## Request a model here!")
115
+ def _submit_model(model_text):
116
  if (model_text is None) or len(model_text) < 1:
117
+ return model_text
118
  splits = model_text.split("/")
119
  if len(splits) != 2:
120
+ gr.Warning("Incorrect request format.")
121
+ return model_text
122
+ for split in splits:
123
+ if len(split) == 0:
124
+ gr.Warning("Incorrect request format.")
125
+ return model_text
126
+ # Check if split contains only valid GitHub repository characters
127
+ # Valid characters: alphanumeric, hyphens, underscores, dots
128
+ if not re.match(r'^[a-zA-Z0-9._-]+$', split):
129
+ gr.Warning(
130
+ "Invalid characters in repository name. "
131
+ "Only alphanumeric characters, hyphens, "
132
+ "underscores, and dots are allowed."
133
+ )
134
+ return model_text
135
+
136
+ gr.Info(
137
+ f"Model id <b>{model_text}</b> submitted.<br/>"
138
+ "Thank you for your submission."
139
+ )
140
  return ""
141
 
142
+ def _check_custom_file(json_file):
143
+ # Check if file is None or empty
144
+ if json_file is None:
145
+ return
146
+
147
+ # Get the file path
148
+ file_path = json_file.name if hasattr(json_file, 'name') else str(json_file)
149
+
150
+ # Check if the file has .json extension
151
+ if not file_path.lower().endswith('.json'):
152
+ gr.Warning(
153
+ "Invalid file format. Please upload a JSON file with .json extension."
154
+ )
155
+ return
156
+
157
+ # Try to validate JSON content
158
+ try:
159
+ with open(file_path, 'r') as f:
160
+ json_content = json.load(f)
161
+ gr.Info(
162
+ f"JSON file <b>{file_path.split('/')[-1]}</b> uploaded successfully.<br/>"
163
+ "File is being validated."
164
+ )
165
+ # Return None to clear the file component after successful upload
166
+ return json_file
167
+ except json.JSONDecodeError as e:
168
+ gr.Warning(
169
+ f"Invalid JSON format: {str(e)}"
170
+ )
171
+ return
172
+ except Exception as e:
173
+ gr.Warning(
174
+ f"Error reading file: {str(e)}"
175
+ )
176
+ return
177
+
178
+ def _submit_custom(json_file):
179
+ if json_file is None:
180
+ return json_file
181
+
182
+ with open(json_file, "r", encoding="utf-8") as reader:
183
+ # Here the content is loaded as string to be saved in the database.
184
+ content = reader.read()
185
+ gr.Info(
186
+ f"Custom results <b>{json_file}</b> submitted.<br/>"
187
+ "Thank you for your submission."
188
+ )
189
+ return
190
+
191
  with gr.Tabs():
192
  with gr.Tab("From Huggingface Hub"):
193
  with gr.Row():
 
203
 
204
  with gr.Row():
205
  with gr.Column(scale=1):
206
+ submit_model_btn = gr.Button("Submit ✉️")
207
  with gr.Column(scale=2):
208
  pass
209
 
210
  with gr.Tab("From Custom results"):
211
  gr.Markdown("Submit your results in JSON format here: ")
212
  gr.Markdown("The file needs to have the fields detailed [here](https://github.com/espnet/espnet).")
213
+ with gr.Row():
214
+ with gr.Column(scale=2):
215
+ custom_file = gr.File(file_types=[".json"])
216
+ with gr.Row():
217
+ with gr.Column():
218
+ upload_button = gr.UploadButton(
219
+ label="Upload JSON File",
220
+ file_types=[".json"],
221
+ file_count="single",
222
+ )
223
+ with gr.Column():
224
+ submit_custom_button = gr.Button(
225
+ "Submit ✉️"
226
+ )
227
+ with gr.Column(scale=1):
228
+ pass
229
+
230
 
231
+ submit_model_btn.click(
232
+ fn=_submit_model,
233
  inputs=[model_box],
234
  outputs=[model_box]
235
  )
236
+ submit_custom_button.click(
237
+ fn=_submit_custom,
238
+ inputs=[custom_file],
239
+ outputs=[custom_file]
240
+ )
241
+ upload_button.upload(
242
+ fn=_check_custom_file,
243
+ inputs=[upload_button],
244
+ outputs=[custom_file]
245
+ )
246
+
247
  return
espnet_leaderboard/submission/__init__.py ADDED
File without changes