idolezal commited on
Commit
834359f
2 Parent(s): 78879a4 4123571

Merge branch 'results_dataset_integrity_check' into 'more_match_details'

Browse files
Files changed (4) hide show
  1. README.md +2 -2
  2. app.py +2 -43
  3. content.py +1 -1
  4. server.py +94 -35
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: LLM Benchmark
3
  emoji: 📊
4
  colorFrom: gray
5
  colorTo: blue
@@ -9,4 +9,4 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: 🇨🇿 BenCzechMark [Beta Preview]
3
  emoji: 📊
4
  colorFrom: gray
5
  colorTo: blue
 
9
  pinned: false
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -255,60 +255,19 @@ tr.row_odd {
255
  background-color: var(--table-odd-background-fill);
256
  }
257
 
258
- .leaderboard-table th:first-child, .leaderboard-table td:first-child {
259
- position: sticky;
260
- left: 0;
261
- z-index: 1;
262
- background-color: inherit;
263
- }
264
-
265
  .leaderboard-table td:first-child p, .leaderboard-table-model-details td:first-child p {
266
  margin: 0px;
267
  }
268
 
269
- .leaderboard-table th:nth-child(2), .leaderboard-table td:nth-child(2) {
270
- position: sticky;
271
- left: var(--cell-width-0);
272
- z-index: 1;
273
- background-color: inherit;
274
- }
275
-
276
- .leaderboard-table th:nth-child(3), .leaderboard-table td:nth-child(3) {
277
- position: sticky;
278
- left: calc(var(--cell-width-0) + var(--cell-width-1));
279
- z-index: 1;
280
- background-color: inherit;
281
- }
282
-
283
- .leaderboard-table th:nth-child(4), .leaderboard-table td:nth-child(4) {
284
- position: sticky;
285
- left: calc(var(--cell-width-0) + var(--cell-width-1) + var(--cell-width-2));
286
- z-index: 1;
287
- background-color: inherit;
288
- }
289
-
290
  .leaderboard-table th:nth-child(5), .leaderboard-table td:nth-child(5) {
291
- position: sticky;
292
- left: calc(var(--cell-width-0) + var(--cell-width-1) + var(--cell-width-2) + var(--cell-width-3));
293
- z-index: 1;
294
- background-color: inherit;
295
  }
296
 
297
  .leaderboard-table td:nth-child(5) p {
298
  font-weight: bolder;
299
  }
300
 
301
- .leaderboard-table th:nth-child(5)::after, .leaderboard-table td:nth-child(5)::after {
302
- box-shadow: inset 5px 0px 4px -4px var(--border-color-primary);
303
- position: absolute;
304
- top: 0;
305
- right: 0;
306
- bottom: 0;
307
- content: "";
308
- width: 30px;
309
- transform: translateX(100%);
310
- }
311
-
312
  """
313
 
314
  with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css) as main:
 
255
  background-color: var(--table-odd-background-fill);
256
  }
257
 
 
 
 
 
 
 
 
258
  .leaderboard-table td:first-child p, .leaderboard-table-model-details td:first-child p {
259
  margin: 0px;
260
  }
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  .leaderboard-table th:nth-child(5), .leaderboard-table td:nth-child(5) {
263
+ border-right-width: 2px;
264
+ border-right-color: var(--border-color-primary);
 
 
265
  }
266
 
267
  .leaderboard-table td:nth-child(5) p {
268
  font-weight: bolder;
269
  }
270
 
 
 
 
 
 
 
 
 
 
 
 
271
  """
272
 
273
  with gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css=custom_css) as main:
content.py CHANGED
@@ -2,7 +2,7 @@
2
  This file contains the text content for the leaderboard client.
3
  """
4
  HEADER_MARKDOWN = """
5
- # ![Czech Republic Flag](https://raw.githubusercontent.com/yammadev/flag-icons/bd4bcf4f4829002cd10416029e05ba89a7554af4/png/CZ.png) BenCzechMark [Beta Preview]
6
 
7
  Welcome to the leaderboard! Here you can submit your model and compare it with the existing models.
8
  """
 
2
  This file contains the text content for the leaderboard client.
3
  """
4
  HEADER_MARKDOWN = """
5
+ # 🇨🇿 BenCzechMark [Beta Preview]
6
 
7
  Welcome to the leaderboard! Here you can submit your model and compare it with the existing models.
8
  """
server.py CHANGED
@@ -161,11 +161,14 @@ class LeaderboardServer:
161
  self.submission_ids = set()
162
  self.submission_id_to_file = {} # Map submission ids to file paths
163
  self.submission_id_to_model_title = {}
 
164
  self.fetch_existing_models()
165
  self.tournament_results = self.load_tournament_results()
166
 
167
  self.pre_submit_lock = pre_submit_lock
168
  self.pre_submit = None
 
 
169
 
170
  def update_leaderboard(self):
171
  self.local_leaderboard = snapshot_download(
@@ -215,6 +218,64 @@ class LeaderboardServer:
215
  self.submission_ids.add(submission_id)
216
  self.submission_id_to_file[submission_id] = submission_file
217
  self.submission_id_to_model_title[submission_id] = metadata["team_name"] + "/" + metadata["model_name"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  @staticmethod
220
  def _model_tournament_table_highlight_true_and_false(x):
@@ -237,11 +298,7 @@ class LeaderboardServer:
237
 
238
  with self.var_lock.ro:
239
  for competitor_id in self.tournament_results[submission_id].keys() - {submission_id}: # without self
240
- path = self.submission_id_to_file.get(competitor_id)
241
- if path:
242
- data = json.load(open(path))
243
- else:
244
- raise gr.Error(f"Submission [{competitor_id}] not found")
245
 
246
  match_results = {}
247
  for task in self.tournament_results[submission_id][competitor_id]:
@@ -300,16 +357,13 @@ class LeaderboardServer:
300
  else:
301
  processed_results = []
302
  for submission_id in tournament_results.keys():
303
- path = self.submission_id_to_file.get(submission_id)
304
- if path is None:
305
  if pre_submit and submission_id == pre_submit.submission_id:
306
  data = json.load(open(pre_submit.file))
307
  else:
308
  raise gr.Error(f"Internal error: Submission [{submission_id}] not found")
309
- elif path:
310
- data = json.load(open(path))
311
  else:
312
- raise gr.Error(f"Submission [{submission_id}] not found")
313
 
314
  if submission_id != data["metadata"]["submission_id"]:
315
  raise gr.Error(f"Proper submission [{submission_id}] not found")
@@ -532,33 +586,38 @@ class LeaderboardServer:
532
  if self.pre_submit:
533
  tournament_results, submission_id, file = self.pre_submit
534
 
535
- api.upload_file(
536
- path_or_fileobj=file,
537
- path_in_repo=f"data/{submission_id}.json",
538
- repo_id=self.server_address,
539
- repo_type=self.repo_type,
540
- token=HF_TOKEN,
541
- )
542
-
543
- # Temporary save tournament results
544
- tournament_results_path = os.path.join(self.local_leaderboard, "tournament.json")
545
- with open(tournament_results_path, "w") as f:
546
- json.dump(tournament_results, f, sort_keys=True, indent=2) # readable JSON
547
-
548
- api.upload_file(
549
- path_or_fileobj=tournament_results_path,
550
- path_in_repo="tournament.json",
551
- repo_id=self.server_address,
552
- repo_type=self.repo_type,
553
- token=HF_TOKEN,
554
- )
555
 
556
  self.pre_submit = None
557
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  def get_model_detail(self, submission_id):
559
- with self.var_lock.ro:
560
- path = self.submission_id_to_file.get(submission_id)
561
- if path is None:
562
  raise gr.Error(f"Submission [{submission_id}] not found")
563
- data = json.load(open(path))
564
- return data["metadata"]
 
 
 
161
  self.submission_ids = set()
162
  self.submission_id_to_file = {} # Map submission ids to file paths
163
  self.submission_id_to_model_title = {}
164
+ self.submission_id_to_data = {} # Only data (results and metadata) using by leaderboard
165
  self.fetch_existing_models()
166
  self.tournament_results = self.load_tournament_results()
167
 
168
  self.pre_submit_lock = pre_submit_lock
169
  self.pre_submit = None
170
+
171
+ self.results_dataset_integrity_check() # Check integrity of the results dataset after (re)start Hugging Face Space
172
 
173
  def update_leaderboard(self):
174
  self.local_leaderboard = snapshot_download(
 
218
  self.submission_ids.add(submission_id)
219
  self.submission_id_to_file[submission_id] = submission_file
220
  self.submission_id_to_model_title[submission_id] = metadata["team_name"] + "/" + metadata["model_name"]
221
+ self.submission_id_to_data[submission_id] = {"results": data["results"], "metadata": metadata}
222
+
223
+ def results_dataset_integrity_check(self):
224
+ """
225
+ Zkontroluje, že:
226
+ - všechny modely byly v duelu se všemi
227
+ -- pokud ne, znemožní potvrzení nových submitů a udělá zbývající zápasy
228
+ -- kontroluje soubory v adresáři "/data" a soubor "tournament.json"
229
+ - v souboru "tournament.json" není `submission_id`, které by nemělo soubor v adresáři "/data"
230
+ """
231
+
232
+ while True:
233
+ with self.pre_submit_lock:
234
+ if self.pre_submit == None:
235
+ gr.Info('Checking integrity...', duration=15)
236
+ self.update_leaderboard()
237
+
238
+ with self.var_lock.ro:
239
+ # Is every `submission_id` in results known?
240
+ if self.tournament_results.keys() - self.submission_ids != set():
241
+ pass
242
+ # Was every `submission_id` in some match?
243
+ elif self.submission_ids - self.tournament_results.keys() != set():
244
+ pass
245
+ # Are all competitors known?
246
+ elif any(
247
+ self.tournament_results[submission_id].keys() - self.submission_ids != set()
248
+ for submission_id in self.submission_ids
249
+ ):
250
+ pass
251
+ # Has had every `submission_id` match with all competitors?
252
+ elif any(
253
+ self.submission_ids - self.tournament_results[submission_id].keys() != set()
254
+ for submission_id in self.submission_ids
255
+ ):
256
+ pass
257
+ else:
258
+ break
259
+
260
+ gr.Info('Running tournament...', duration=15)
261
+ with self.var_lock.rw:
262
+ self.tournament_results = {}
263
+ for submission_id in self.submission_ids:
264
+ with self.var_lock.ro:
265
+ file = self.submission_id_to_file[submission_id]
266
+ tournament_results = self.start_tournament(submission_id, file)
267
+ with self.var_lock.rw:
268
+ self.tournament_results = tournament_results
269
+
270
+ gr.Info('Uploading tournament results...', duration=5)
271
+ if self.tournament_results:
272
+ self._upload_tournament_results(self.tournament_results)
273
+
274
+ break
275
+ gr.Info("Waiting in queue...", duration=5)
276
+ time.sleep(10)
277
+
278
+ gr.Info('Integrity of the results dataset is checked', duration=5)
279
 
280
  @staticmethod
281
  def _model_tournament_table_highlight_true_and_false(x):
 
298
 
299
  with self.var_lock.ro:
300
  for competitor_id in self.tournament_results[submission_id].keys() - {submission_id}: # without self
301
+ data = self.submission_id_to_data[competitor_id]
 
 
 
 
302
 
303
  match_results = {}
304
  for task in self.tournament_results[submission_id][competitor_id]:
 
357
  else:
358
  processed_results = []
359
  for submission_id in tournament_results.keys():
360
+ if submission_id not in self.submission_id_to_data:
 
361
  if pre_submit and submission_id == pre_submit.submission_id:
362
  data = json.load(open(pre_submit.file))
363
  else:
364
  raise gr.Error(f"Internal error: Submission [{submission_id}] not found")
 
 
365
  else:
366
+ data = self.submission_id_to_data[submission_id]
367
 
368
  if submission_id != data["metadata"]["submission_id"]:
369
  raise gr.Error(f"Proper submission [{submission_id}] not found")
 
586
  if self.pre_submit:
587
  tournament_results, submission_id, file = self.pre_submit
588
 
589
+ self._upload_submission(submission_id, file)
590
+ self._upload_tournament_results(tournament_results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
 
592
  self.pre_submit = None
593
 
594
+ def _upload_submission(self, submission_id, file):
595
+ api.upload_file(
596
+ path_or_fileobj=file,
597
+ path_in_repo=f"data/{submission_id}.json",
598
+ repo_id=self.server_address,
599
+ repo_type=self.repo_type,
600
+ token=HF_TOKEN,
601
+ )
602
+
603
+ def _upload_tournament_results(self, tournament_results):
604
+ # Temporary save tournament results
605
+ tournament_results_path = os.path.join(self.local_leaderboard, "tournament.json")
606
+ with open(tournament_results_path, "w") as f:
607
+ json.dump(tournament_results, f, sort_keys=True, indent=2) # readable JSON
608
+
609
+ api.upload_file(
610
+ path_or_fileobj=tournament_results_path,
611
+ path_in_repo="tournament.json",
612
+ repo_id=self.server_address,
613
+ repo_type=self.repo_type,
614
+ token=HF_TOKEN,
615
+ )
616
+
617
  def get_model_detail(self, submission_id):
618
+ if submission_id not in self.submission_id_to_data:
 
 
619
  raise gr.Error(f"Submission [{submission_id}] not found")
620
+ else:
621
+ with self.var_lock.ro:
622
+ data = self.submission_id_to_data[submission_id]
623
+ return data["metadata"]