idolezal commited on
Commit
8c3991f
1 Parent(s): 305114d

Added table with tournament results for selected model

Browse files
Files changed (2) hide show
  1. app.py +56 -1
  2. server.py +44 -0
app.py CHANGED
@@ -143,11 +143,23 @@ def fetch_model_detail(submission_id):
143
  gr.update(value=metadata['link_to_model'], visible=True)
144
  )
145
 
 
 
 
 
 
 
146
  def change_leaderboard_category(category):
147
  if category == leaderboard_server.TASKS_CATEGORY_OVERALL:
148
  task_abbreviation_legend = gr.update(
149
  visible=False,
150
  )
 
 
 
 
 
 
151
  else:
152
  task_abbreviation_legend_body = []
153
 
@@ -159,6 +171,12 @@ def change_leaderboard_category(category):
159
  value=task_abbreviation_legend_body,
160
  visible=True,
161
  )
 
 
 
 
 
 
162
 
163
  return (
164
  gr.update(
@@ -167,6 +185,8 @@ def change_leaderboard_category(category):
167
  datatype="markdown",
168
  ),
169
  task_abbreviation_legend,
 
 
170
  )
171
 
172
  def show_modal():
@@ -292,10 +312,45 @@ with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css) as main:
292
  elem_classes="leaderboard-table-legend",
293
  )
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  category_of_tasks.change(
296
  fn=change_leaderboard_category,
297
  inputs=category_of_tasks,
298
- outputs=[results_table, results_table_legend],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  )
300
 
301
  with gr.TabItem('Model details'):
 
143
  gr.update(value=metadata['link_to_model'], visible=True)
144
  )
145
 
146
+ def fetch_model_tournament_results_table(submission_id, category):
147
+ return gr.update(
148
+ value=leaderboard_server.get_model_tournament_table(submission_id, category),
149
+ visible=True,
150
+ )
151
+
152
  def change_leaderboard_category(category):
153
  if category == leaderboard_server.TASKS_CATEGORY_OVERALL:
154
  task_abbreviation_legend = gr.update(
155
  visible=False,
156
  )
157
+ tournament_results_dropdown = gr.update(
158
+ visible=False,
159
+ )
160
+ model_tournament_results_table = gr.update(
161
+ visible=False,
162
+ )
163
  else:
164
  task_abbreviation_legend_body = []
165
 
 
171
  value=task_abbreviation_legend_body,
172
  visible=True,
173
  )
174
+
175
+ tournament_results_dropdown = gr.update(
176
+ visible=True,
177
+ )
178
+
179
+ model_tournament_results_table = gr.update()
180
 
181
  return (
182
  gr.update(
 
185
  datatype="markdown",
186
  ),
187
  task_abbreviation_legend,
188
+ tournament_results_dropdown,
189
+ model_tournament_results_table,
190
  )
191
 
192
  def show_modal():
 
312
  elem_classes="leaderboard-table-legend",
313
  )
314
 
315
+ with gr.Row():
316
+ gr.Markdown("## Tournament results for selected model")
317
+
318
+ with leaderboard_server.var_lock.ro:
319
+ tournament_results_dropdown = gr.Dropdown(
320
+ value=None,
321
+ choices=leaderboard_server.submission_ids, # TODO: team_name/model_name
322
+ label="Select model",
323
+ visible=False,
324
+ interactive=True,
325
+ )
326
+
327
+ model_tournament_results_table = gr.DataFrame(
328
+ value=None,
329
+ datatype="markdown",
330
+ label="The model won against…",
331
+ visible=False,
332
+ interactive=False,
333
+ elem_classes="leaderboard-table-model-details",
334
+ )
335
+
336
  category_of_tasks.change(
337
  fn=change_leaderboard_category,
338
  inputs=category_of_tasks,
339
+ outputs=[
340
+ results_table,
341
+ results_table_legend,
342
+ tournament_results_dropdown,
343
+ model_tournament_results_table,
344
+ ],
345
+ )
346
+
347
+ tournament_results_dropdown.change(
348
+ fn=fetch_model_tournament_results_table,
349
+ inputs=[
350
+ tournament_results_dropdown,
351
+ category_of_tasks,
352
+ ],
353
+ outputs=model_tournament_results_table,
354
  )
355
 
356
  with gr.TabItem('Model details'):
server.py CHANGED
@@ -214,6 +214,50 @@ class LeaderboardServer:
214
  self.submission_ids.add(submission_id)
215
  self.submission_id_to_file[submission_id] = submission_file
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  def get_leaderboard(self, pre_submit=None, category=None):
218
  with self.var_lock.ro:
219
  tournament_results = pre_submit.tournament_results if pre_submit else self.tournament_results
 
214
  self.submission_ids.add(submission_id)
215
  self.submission_id_to_file[submission_id] = submission_file
216
 
217
+ def get_model_tournament_table(self, submission_id, category):
218
+ if category == self.TASKS_CATEGORY_OVERALL:
219
+ return None
220
+
221
+ model_tournament_table = []
222
+ match_results = {}
223
+
224
+ with self.var_lock.ro:
225
+ for competitor_id in self.tournament_results[submission_id].keys() - {submission_id}: # without self
226
+ match_results["competitor_id"] = competitor_id
227
+ for task in self.tournament_results[submission_id][competitor_id]:
228
+ task_category = self.TASKS_METADATA[task]["category"]
229
+ if task_category == category:
230
+ match_results[task] = bool(self.tournament_results[submission_id][competitor_id][task])
231
+
232
+ model_tournament_table.append(match_results)
233
+
234
+ dataframe = pd.DataFrame.from_records(model_tournament_table)
235
+
236
+ extra_attributes_map_word_to_header = {
237
+ "competitor_id": "Competitor",
238
+ }
239
+ first_attributes = [
240
+ "competitor_id",
241
+ ]
242
+ df_order = [
243
+ key
244
+ for key in dict.fromkeys(
245
+ first_attributes
246
+ + sorted(
247
+ list(self.TASKS_METADATA.keys())
248
+ + list(dataframe.columns)
249
+ )
250
+ ).keys()
251
+ if key in dataframe.columns
252
+ ]
253
+ dataframe = dataframe[df_order]
254
+ attributes_map_word_to_header = {key: value["abbreviation"] for key, value in self.TASKS_METADATA.items()}
255
+ attributes_map_word_to_header.update(extra_attributes_map_word_to_header)
256
+ dataframe = dataframe.rename(
257
+ columns=attributes_map_word_to_header
258
+ )
259
+ return dataframe
260
+
261
  def get_leaderboard(self, pre_submit=None, category=None):
262
  with self.var_lock.ro:
263
  tournament_results = pre_submit.tournament_results if pre_submit else self.tournament_results