idolezal commited on
Commit
bc7f740
1 Parent(s): 375e927

Table with tasks abbreviations and names

Browse files
Files changed (2) hide show
  1. app.py +38 -6
  2. server.py +16 -0
app.py CHANGED
@@ -15,7 +15,7 @@ from content import (
15
  RANKING_AFTER_SUBMISSION_MARKDOWN,
16
  MORE_DETAILS_MARKDOWN,
17
  )
18
- from server import LeaderboardServer
19
 
20
  leaderboard_server = LeaderboardServer()
21
 
@@ -144,10 +144,39 @@ def fetch_model_detail(submission_id):
144
  )
145
 
146
  def change_leaderboard_category(category):
147
- return gr.update(
148
- value=leaderboard_server.get_leaderboard(category=category),
149
- visible=True,
150
- datatype="markdown",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  )
152
 
153
  def show_modal():
@@ -258,10 +287,13 @@ with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css) as main:
258
  elem_classes="leaderboard-table",
259
  )
260
 
 
 
 
261
  category_of_tasks.change(
262
  fn=change_leaderboard_category,
263
  inputs=category_of_tasks,
264
- outputs=results_table,
265
  )
266
 
267
  with gr.TabItem('Model details'):
 
15
  RANKING_AFTER_SUBMISSION_MARKDOWN,
16
  MORE_DETAILS_MARKDOWN,
17
  )
18
+ from server import LeaderboardServer, xmlEscape, MARKDOWN_SPECIAL_CHARACTERS
19
 
20
  leaderboard_server = LeaderboardServer()
21
 
 
144
  )
145
 
146
  def change_leaderboard_category(category):
147
+ if category == leaderboard_server.TASKS_CATEGORY_OVERALL:
148
+ task_abbreviation_legend = ""
149
+ else:
150
+ task_abbreviation_legend_head = [
151
+ "| task abbreviation | task name |",
152
+ "| --- | --- |",
153
+ ]
154
+ task_abbreviation_legend_body = []
155
+ task_abbreviation_legend_tail = [
156
+ "",
157
+ ]
158
+ abbreviation2name = leaderboard_server.CATEGORY_TO_TASK_ABBREVIATION_TO_NAME[category]
159
+ for abbr, name in abbreviation2name.items():
160
+ abbr_escaped = xmlEscape(abbr, MARKDOWN_SPECIAL_CHARACTERS)
161
+ name_escaped = xmlEscape(abbr, MARKDOWN_SPECIAL_CHARACTERS)
162
+ task_abbreviation_legend_body.append(f"| {abbr_escaped} | {name_escaped} |")
163
+
164
+ task_abbreviation_legend = (
165
+ task_abbreviation_legend_head
166
+ + task_abbreviation_legend_body
167
+ + task_abbreviation_legend_tail
168
+ )
169
+ task_abbreviation_legend = "\n".join(task_abbreviation_legend)
170
+
171
+ return (
172
+ gr.update(
173
+ value=leaderboard_server.get_leaderboard(category=category),
174
+ visible=True,
175
+ datatype="markdown",
176
+ ),
177
+ gr.update(
178
+ value=task_abbreviation_legend,
179
+ ),
180
  )
181
 
182
  def show_modal():
 
287
  elem_classes="leaderboard-table",
288
  )
289
 
290
+ with gr.Row():
291
+ results_table_legend = gr.Markdown()
292
+
293
  category_of_tasks.change(
294
  fn=change_leaderboard_category,
295
  inputs=category_of_tasks,
296
+ outputs=[results_table, results_table_legend],
297
  )
298
 
299
  with gr.TabItem('Model details'):
server.py CHANGED
@@ -155,6 +155,7 @@ class LeaderboardServer:
155
  self.TASKS_METADATA = json.load(open(TASKS_METADATA_PATH))
156
  self.TASKS_CATEGORIES = {self.TASKS_METADATA[task]["category"] for task in self.TASKS_METADATA}
157
  self.TASKS_CATEGORY_OVERALL = "Overall"
 
158
 
159
  self.var_lock = ReadWriteLock()
160
  self.submission_ids = set()
@@ -185,6 +186,21 @@ class LeaderboardServer:
185
  results = json.load(ranks_file)
186
  return results
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  def fetch_existing_models(self):
189
  # Models data
190
  for submission_file in glob.glob(os.path.join(self.local_leaderboard, "data") + "/*.json"):
 
155
  self.TASKS_METADATA = json.load(open(TASKS_METADATA_PATH))
156
  self.TASKS_CATEGORIES = {self.TASKS_METADATA[task]["category"] for task in self.TASKS_METADATA}
157
  self.TASKS_CATEGORY_OVERALL = "Overall"
158
+ self.CATEGORY_TO_TASK_ABBREVIATION_TO_NAME = self._prepare_category_to_task_abbr_to_name()
159
 
160
  self.var_lock = ReadWriteLock()
161
  self.submission_ids = set()
 
186
  results = json.load(ranks_file)
187
  return results
188
 
189
+ def _prepare_category_to_task_abbr_to_name(self):
190
+ tasks_per_category = {}
191
+ for task in self.TASKS_METADATA:
192
+ task_category = self.TASKS_METADATA[task]["category"]
193
+ tasks_per_category.setdefault(task_category, list()).append(task)
194
+
195
+ category2abbreviation2name = {}
196
+ for category, tasks in tasks_per_category.items():
197
+ abbreviation2name = {self.TASKS_METADATA[t]["abbreviation"]: self.TASKS_METADATA[t]["name"] for t in tasks}
198
+ sorted_abbreviation2name = dict.fromkeys(sorted(abbreviation2name.keys()))
199
+ sorted_abbreviation2name.update(sorted_abbreviation2name)
200
+ category2abbreviation2name[category] = sorted_abbreviation2name
201
+
202
+ return category2abbreviation2name
203
+
204
  def fetch_existing_models(self):
205
  # Models data
206
  for submission_file in glob.glob(os.path.join(self.local_leaderboard, "data") + "/*.json"):