Spaces:
Running
Running
File size: 63,694 Bytes
695087d 603247d 695087d 603247d bce84cc 603247d f589e51 603247d 695087d 603247d 9568660 695087d 5a80058 0e935df 5a80058 603247d 6d4c755 603247d 3856741 6d4c755 3856741 603247d bce84cc 3856741 603247d 7bc8d30 3856741 f589e51 603247d bce84cc 3856741 603247d 7bc8d30 3856741 f589e51 603247d 6d4c755 603247d 6d4c755 603247d 6d4c755 603247d 342518d e430913 342518d 5a80058 6d4c755 5a80058 bce84cc 5a80058 bce84cc 6d4c755 bce84cc 6d4c755 5a80058 c998efb 6d4c755 c998efb 6d4c755 c998efb 5a80058 c998efb 6d4c755 c998efb 6d4c755 c998efb fe89fc2 c998efb 6369a6a c998efb 5a80058 bce84cc ef8c739 bce84cc f589e51 3856741 58717d6 3856741 603247d 3856741 603247d bce84cc 3856741 603247d 7bc8d30 3856741 f589e51 603247d ef8c739 bce84cc 3856741 ef8c739 7bc8d30 3856741 f589e51 ef8c739 f589e51 ef8c739 603247d bce84cc 3856741 603247d 7bc8d30 3856741 f589e51 603247d ef8c739 6d4c755 bce84cc 3856741 6d4c755 ef8c739 6d4c755 ef8c739 6d4c755 7bc8d30 6d4c755 3856741 6d4c755 f589e51 6d4c755 bce84cc ef8c739 5a80058 ef8c739 bce84cc ef8c739 6d4c755 5a80058 6d4c755 bce84cc 603247d bce84cc 3856741 ef8c739 7bc8d30 3856741 f589e51 603247d bce84cc 603247d bce84cc f589e51 603247d 3856741 bce84cc ef8c739 bce84cc f589e51 603247d 3856741 603247d bce84cc 3856741 603247d 7bc8d30 3856741 f589e51 603247d bce84cc 3856741 603247d 7bc8d30 3856741 f589e51 603247d 58717d6 603247d 3856741 603247d 3856741 603247d 7bc8d30 3856741 f589e51 603247d 6d4c755 5a80058 6d4c755 603247d bce84cc ef8c739 3856741 f589e51 603247d 09f88c7 c998efb b3f1539 09f88c7 c998efb 09f88c7 c998efb 8e60916 c998efb 09f88c7 c998efb 09f88c7 c998efb 09f88c7 c998efb 09f88c7 c998efb 09f88c7 5a80058 09f88c7 8dcd7a7 09f88c7 603247d 09f88c7 603247d 09f88c7 8dcd7a7 09f88c7 8dcd7a7 09f88c7 8dcd7a7 09f88c7 8dcd7a7 09f88c7 8dcd7a7 09f88c7 6369a6a 8dcd7a7 09f88c7 8dcd7a7 6369a6a 09f88c7 8dcd7a7 09f88c7 8dcd7a7 09f88c7 8dcd7a7 5a80058 c998efb 6d4c755 c998efb 5a80058 ad50a71 5a80058 c998efb ad50a71 c998efb ad50a71 5a80058 ad50a71 5a80058 ad50a71 5a80058 ad50a71 5a80058 09f88c7 c998efb 8dcd7a7 09f88c7 8dcd7a7 6d4c755 ee8aeec 6d4c755 ee8aeec 6d4c755 ee8aeec 6d4c755 09f88c7 bce84cc 8dcd7a7 09f88c7 8e60916 09f88c7 3856741 09f88c7 3856741 09f88c7 3856741 09f88c7 7bc8d30 09f88c7 8dcd7a7 09f88c7 8dcd7a7 09f88c7 603247d 0d20259 6d4c755 0d20259 6d4c755 0d20259 695087d 603247d 9568660 ef8c739 0d20259 ef8c739 6d4c755 0d20259 6d4c755 0d20259 ef8c739 0d20259 5a80058 0d20259 5a80058 8e60916 0d20259 bce84cc 0d20259 bce84cc 8e60916 9578973 0d20259 9578973 5a80058 603247d 6d4c755 603247d 0d20259 6d4c755 0d20259 603247d 0d20259 603247d 0d20259 603247d 7bc8d30 0d20259 603247d 3856741 0d20259 f589e51 0d20259 9568660 603247d 0d20259 603247d 0d20259 9568660 603247d 6d4c755 0d20259 68f8427 0d20259 3856741 5a80058 7bc8d30 3856741 f589e51 0d20259 5a80058 0d20259 5a80058 0d20259 6d4c755 0d20259 6d4c755 c998efb 0d20259 6d4c755 0d20259 c998efb ab0bf39 5a80058 603247d 0d20259 5a80058 0d20259 5a80058 fe89fc2 0d20259 c998efb 0d20259 695087d 9568660 342518d 0d20259 342518d 0d20259 9568660 0d20259 ef8c739 bce84cc 3856741 bce84cc ef8c739 9568660 0d20259 9568660 0d20259 603247d 0d20259 695087d 9568660 0d20259 9568660 0d20259 9568660 0d20259 9568660 0d20259 9568660 0d20259 9568660 0d20259 9568660 0d20259 9568660 0d20259 603247d 9568660 0d20259 603247d 9568660 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 6d4c755 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 9578973 0d20259 9578973 3856741 0d20259 3856741 6d4c755 3856741 0d20259 6d4c755 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 6d4c755 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 0d20259 3856741 603247d 9568660 603247d c998efb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 |
import gradio as gr
import os
import pandas as pd
import json
from PIL import Image, ImageSequence
import io
from functools import reduce
import numpy as np
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
from leaderboard_utils import (
get_organization,
get_mario_planning_leaderboard,
get_sokoban_leaderboard,
get_2048_leaderboard,
get_candy_leaderboard,
get_tetris_planning_leaderboard,
get_ace_attorney_leaderboard,
get_combined_leaderboard,
GAME_ORDER
)
from data_visualization import (
get_combined_leaderboard_with_group_bar,
create_horizontal_bar_chart,
get_combined_leaderboard_with_single_radar
)
from gallery_tab import create_video_gallery
HAS_ENHANCED_LEADERBOARD = True
# Define time points and their corresponding data files
TIME_POINTS = {
"03/25/2025": "rank_data_03_25_2025.json",
# Add more time points here as they become available
}
# Load the initial JSON file with rank data
with open(TIME_POINTS["03/25/2025"], "r", encoding='utf-8') as f:
rank_data = json.load(f)
# Load the model leaderboard data
with open("rank_single_model_03_25_2025.json", "r", encoding='utf-8') as f:
model_rank_data = json.load(f)
# Add leaderboard state at the top level
leaderboard_state = {
"current_game": None,
"previous_overall": {
# "Super Mario Bros": True, # Commented out
"Super Mario Bros": True,
"Sokoban": True,
"2048": True,
"Candy Crush": True,
# "Tetris(complete)", # Commented out
"Tetris": True,
"Ace Attorney": True
},
"previous_details": {
# "Super Mario Bros": False, # Commented out
"Super Mario Bros": False,
"Sokoban": False,
"2048": False,
"Candy Crush": False,
# "Tetris(complete)": False, # Commented out
"Tetris": False,
"Ace Attorney": False
}
}
# Load video links and news data
with open('assets/game_video_link.json', 'r', encoding='utf-8') as f:
VIDEO_LINKS = json.load(f)
with open('assets/news.json', 'r', encoding='utf-8') as f:
NEWS_DATA = json.load(f)
def load_rank_data(time_point):
"""Load rank data for a specific time point"""
if time_point in TIME_POINTS:
try:
with open(TIME_POINTS[time_point], "r", encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
return None
return None
# Add a note about score values
def add_score_note():
return gr.Markdown("*Note: 'n/a' in the table indicates no data point for that model.*", elem_classes="score-note")
# Function to prepare DataFrame for display
def prepare_dataframe_for_display(df, for_game=None):
"""Format DataFrame for better display in the UI"""
# Clone the DataFrame to avoid modifying the original
display_df = df.copy()
# Filter out normalized score columns
norm_columns = [col for col in display_df.columns if col.startswith('norm_')]
if norm_columns:
display_df = display_df.drop(columns=norm_columns)
# Replace '_' with '-' for better display
for col in display_df.columns:
if col.endswith(' Score') and col != 'Avg Normalized Score':
display_df[col] = display_df[col].apply(lambda x: '-' if x == '_' else x)
# If we're in detailed view, sort by score
if for_game:
# Sort by relevant score column
score_col = f"{for_game} Score"
if score_col in display_df.columns:
# Convert to numeric for sorting, treating '-' as NaN
display_df[score_col] = pd.to_numeric(display_df[score_col], errors='coerce')
# Sort by score in descending order
display_df = display_df.sort_values(by=score_col, ascending=False)
# Filter out models that didn't participate
display_df = display_df[~display_df[score_col].isna()]
else:
# For overall view, sort by average normalized score if available, otherwise fallback to average scores
if 'Avg Normalized Score' in display_df.columns:
# Sort by average normalized score (already calculated in leaderboard_utils)
display_df = display_df.sort_values(by='Avg Normalized Score', ascending=False)
else:
# Calculate an internal sorting key based on average scores, but don't add it to the display_df
score_cols = [col for col in display_df.columns if col.endswith(' Score')]
if score_cols:
temp_sort_df = display_df.copy()
for col in score_cols:
temp_sort_df[col] = pd.to_numeric(temp_sort_df[col], errors='coerce')
# Create a temporary column for sorting
temp_sort_df['temp_avg_score_for_sort'] = temp_sort_df[score_cols].mean(axis=1)
# Sort by this temporary average score (higher is better for scores)
# and then by Player name as a tie-breaker
display_df = display_df.loc[temp_sort_df.sort_values(by=['temp_avg_score_for_sort', 'Player'], ascending=[False, True]).index]
# Add medal emojis for top 3 performers
if len(display_df) > 0 and 'Player' in display_df.columns:
# Reset index to get proper ranking after sorting
display_df = display_df.reset_index(drop=True)
# Add medal emojis to Player names for top 3
medal_emojis = ['๐ฅ', '๐ฅ', '๐ฅ']
for i in range(min(3, len(display_df))):
original_name = display_df.loc[i, 'Player']
display_df.loc[i, 'Player'] = f"{medal_emojis[i]} {original_name}"
# Add line breaks to column headers
new_columns = {}
for col in display_df.columns:
if col.endswith(' Score') and col != 'Avg Normalized Score':
# Replace 'Game Name Score' with 'Game Name\nScore'
game_name = col.replace(' Score', '')
new_col = f"{game_name}\nScore"
new_columns[col] = new_col
elif col == 'Avg Normalized Score':
# Add line break to Avg Normalized Score column
new_columns[col] = "Avg Normalized\nScore"
# Rename columns with new line breaks
if new_columns:
display_df = display_df.rename(columns=new_columns)
return display_df
# Helper function to ensure leaderboard updates maintain consistent height
def update_df_with_height(df):
"""Update DataFrame with consistent height parameter."""
# Create column widths array
col_widths = ["40px"] # Row number column width
col_widths.append("230px") # Player column - reduced by 20px
col_widths.append("120px") # Organization column
# Check if there's an Avg Normalized Score column
if any('Avg Normalized' in col for col in df.columns):
col_widths.append("140px") # Avg Normalized Score column - slightly wider
# Add game score columns
remaining_cols = len(df.columns) - len(col_widths) + 1 # +1 because we subtracted row number column
for _ in range(remaining_cols):
col_widths.append("120px")
return gr.update(value=df,
show_row_numbers=True,
show_fullscreen_button=True,
line_breaks=True,
show_search="search",
# max_height=None, # Remove height limitation - COMMENTED OUT
column_widths=col_widths)
def update_leaderboard(# mario_overall, mario_details, # Commented out
mario_plan_overall, mario_plan_details, # Added
sokoban_overall, sokoban_details,
_2048_overall, _2048_details,
candy_overall, candy_details,
# tetris_overall, tetris_details, # Commented out
tetris_plan_overall, tetris_plan_details,
ace_attorney_overall, ace_attorney_details,
top_n=5,
data_source=None):
global leaderboard_state
# Use provided data source or default to rank_data
data = data_source if data_source is not None else rank_data
# Convert current checkbox states to dictionary for easier comparison
current_overall = {
# "Super Mario Bros": mario_overall, # Commented out
"Super Mario Bros": mario_plan_overall,
"Sokoban": sokoban_overall,
"2048": _2048_overall,
"Candy Crush": candy_overall,
# "Tetris(complete)": tetris_overall, # Commented out
"Tetris": tetris_plan_overall,
"Ace Attorney": ace_attorney_overall
}
current_details = {
# "Super Mario Bros": mario_details, # Commented out
"Super Mario Bros": mario_plan_details,
"Sokoban": sokoban_details,
"2048": _2048_details,
"Candy Crush": candy_details,
# "Tetris(complete)": tetris_details, # Commented out
"Tetris": tetris_plan_details,
"Ace Attorney": ace_attorney_details
}
# Find which game's state changed
changed_game = None
for game in current_overall.keys():
if (current_overall[game] != leaderboard_state["previous_overall"][game] or
current_details[game] != leaderboard_state["previous_details"][game]):
changed_game = game
break
if changed_game:
# If a game's details checkbox was checked
if current_details[changed_game] and not leaderboard_state["previous_details"][changed_game]:
# Reset all other games' states
for game in current_overall.keys():
if game != changed_game:
current_overall[game] = False
current_details[game] = False
leaderboard_state["previous_overall"][game] = False
leaderboard_state["previous_details"][game] = False
# Update state for the selected game
leaderboard_state["current_game"] = changed_game
leaderboard_state["previous_overall"][changed_game] = True
leaderboard_state["previous_details"][changed_game] = True
current_overall[changed_game] = True
# If a game's overall checkbox was checked
elif current_overall[changed_game] and not leaderboard_state["previous_overall"][changed_game]:
# If we were in details view for another game, switch to overall view
if leaderboard_state["current_game"] and leaderboard_state["previous_details"][leaderboard_state["current_game"]]:
# Reset previous game's details
leaderboard_state["previous_details"][leaderboard_state["current_game"]] = False
current_details[leaderboard_state["current_game"]] = False
leaderboard_state["current_game"] = None
# Update state
leaderboard_state["previous_overall"][changed_game] = True
leaderboard_state["previous_details"][changed_game] = False
# If a game's overall checkbox was unchecked
elif not current_overall[changed_game] and leaderboard_state["previous_overall"][changed_game]:
# If we're in details view, don't allow unchecking the overall checkbox
if leaderboard_state["current_game"] == changed_game:
current_overall[changed_game] = True
else:
leaderboard_state["previous_overall"][changed_game] = False
if leaderboard_state["current_game"] == changed_game:
leaderboard_state["current_game"] = None
# If a game's details checkbox was unchecked
elif not current_details[changed_game] and leaderboard_state["previous_details"][changed_game]:
leaderboard_state["previous_details"][changed_game] = False
if leaderboard_state["current_game"] == changed_game:
leaderboard_state["current_game"] = None
# When exiting details view, only reset the current game's state
current_overall[changed_game] = True
current_details[changed_game] = False
leaderboard_state["previous_overall"][changed_game] = True
leaderboard_state["previous_details"][changed_game] = False
# Special case: If all games are selected and we're trying to view details
all_games_selected = all(current_overall.values()) and not any(current_details.values())
if all_games_selected and changed_game and current_details[changed_game]:
# Reset all other games' states
for game in current_overall.keys():
if game != changed_game:
current_overall[game] = False
current_details[game] = False
leaderboard_state["previous_overall"][game] = False
leaderboard_state["previous_details"][game] = False
# Update state for the selected game
leaderboard_state["current_game"] = changed_game
leaderboard_state["previous_overall"][changed_game] = True
leaderboard_state["previous_details"][changed_game] = True
current_overall[changed_game] = True
# Build dictionary for selected games
selected_games = {
# "Super Mario Bros": current_overall["Super Mario Bros"], # Commented out
"Super Mario Bros": current_overall["Super Mario Bros"],
"Sokoban": current_overall["Sokoban"],
"2048": current_overall["2048"],
"Candy Crush": current_overall["Candy Crush"],
# "Tetris(complete)": current_overall["Tetris(complete)"], # Commented out
"Tetris": current_overall["Tetris"],
"Ace Attorney": current_overall["Ace Attorney"]
}
# Get the appropriate DataFrame and charts based on current state
if leaderboard_state["current_game"]:
# For detailed view - use slider value for both leaderboards
limit = top_n
# if leaderboard_state["current_game"] == "Super Mario Bros": # Commented out
# df = get_mario_leaderboard(data)
if leaderboard_state["current_game"] == "Super Mario Bros":
df = get_mario_planning_leaderboard(data, limit)
elif leaderboard_state["current_game"] == "Sokoban":
df = get_sokoban_leaderboard(data, limit)
elif leaderboard_state["current_game"] == "2048":
df = get_2048_leaderboard(data, limit)
elif leaderboard_state["current_game"] == "Candy Crush":
df = get_candy_leaderboard(data, limit)
elif leaderboard_state["current_game"] == "Tetris":
df = get_tetris_planning_leaderboard(data, limit)
elif leaderboard_state["current_game"] == "Ace Attorney":
df = get_ace_attorney_leaderboard(data, limit)
else: # Should not happen if current_game is one of the known games
df = pd.DataFrame() # Empty df
display_df = prepare_dataframe_for_display(df, leaderboard_state["current_game"])
chart = create_horizontal_bar_chart(df, leaderboard_state["current_game"])
radar_chart = chart # In detailed view, radar and group bar can be the same as the main chart
group_bar_chart = chart
else:
# For overall view - use slider value for both leaderboards
limit = top_n
df, group_bar_chart = get_combined_leaderboard_with_group_bar(data, selected_games, top_n, limit)
display_df = prepare_dataframe_for_display(df)
# Pass appropriate title and top_n based on data source
_, radar_chart = get_combined_leaderboard_with_single_radar(data, selected_games, limit_to_top_n=limit, top_n=top_n)
chart = radar_chart # In overall view, the 'detailed' chart can be the radar chart
# Return values, including all four plot placeholders
return (update_df_with_height(display_df), chart, radar_chart, group_bar_chart,
current_overall["Super Mario Bros"], current_details["Super Mario Bros"],
current_overall["Sokoban"], current_details["Sokoban"],
current_overall["2048"], current_details["2048"],
current_overall["Candy Crush"], current_details["Candy Crush"],
current_overall["Tetris"], current_details["Tetris"],
current_overall["Ace Attorney"], current_details["Ace Attorney"])
def update_leaderboard_with_time(time_point, # mario_overall, mario_details, # Commented out
mario_plan_overall, mario_plan_details, # Added
sokoban_overall, sokoban_details,
_2048_overall, _2048_details,
candy_overall, candy_details,
# tetris_overall, tetris_details, # Commented out
tetris_plan_overall, tetris_plan_details,
ace_attorney_overall, ace_attorney_details):
# Load rank data for the selected time point
global rank_data
new_rank_data = load_rank_data(time_point)
if new_rank_data is not None:
rank_data = new_rank_data
# Use the existing update_leaderboard function, including Super Mario
return update_leaderboard(# mario_overall, mario_details, # Commented out
mario_plan_overall, mario_plan_details, # Added
sokoban_overall, sokoban_details,
_2048_overall, _2048_details,
candy_overall, candy_details,
# tetris_overall, tetris_details, # Commented out
tetris_plan_overall, tetris_plan_details,
ace_attorney_overall, ace_attorney_details)
def get_total_model_count(data_source):
"""Get the total number of unique models in the data"""
selected_games = {
"Super Mario Bros": True,
"Sokoban": True,
"2048": True,
"Candy Crush": True,
"Tetris": True,
"Ace Attorney": True
}
df = get_combined_leaderboard(data_source, selected_games)
return len(df["Player"].unique())
def get_initial_state():
"""Get the initial state for the leaderboard"""
return {
"current_game": None,
"previous_overall": {
# "Super Mario Bros": True, # Commented out
"Super Mario Bros": True,
"Sokoban": True,
"2048": True,
"Candy Crush": True,
# "Tetris(complete)", # Commented out
"Tetris": True,
"Ace Attorney": True
},
"previous_details": {
# "Super Mario Bros": False, # Commented out
"Super Mario Bros": False,
"Sokoban": False,
"2048": False,
"Candy Crush": False,
# "Tetris(complete)": False, # Commented out
"Tetris": False,
"Ace Attorney": False
}
}
def clear_filters(top_n=5, data_source=None):
global leaderboard_state
# Use provided data source or default to rank_data
data = data_source if data_source is not None else rank_data
selected_games = {
"Super Mario Bros": True,
"Sokoban": True,
"2048": True,
"Candy Crush": True,
"Tetris": True,
"Ace Attorney": True
}
# Use slider value for both leaderboards
limit = top_n
df, group_bar_chart = get_combined_leaderboard_with_group_bar(data, selected_games, top_n, limit)
display_df = prepare_dataframe_for_display(df)
# Pass top_n parameter for consistent titles
_, radar_chart = get_combined_leaderboard_with_single_radar(data, selected_games, limit_to_top_n=limit, top_n=top_n)
leaderboard_state = get_initial_state()
# Return values, including all four plot placeholders
return (update_df_with_height(display_df), radar_chart, radar_chart, group_bar_chart,
True, False, # mario_plan
True, False, # sokoban
True, False, # 2048
True, False, # candy
True, False, # Tetrisplan
True, False) # ace attorney
def create_timeline_slider():
"""Create a custom timeline slider component"""
timeline_html = """
<div class="timeline-container">
<style>
.timeline-container {
width: 85%; /* Increased from 70% to 85% */
padding: 8px;
font-family: Arial, sans-serif;
height: 40px;
display: flex;
align-items: center;
}
.timeline-track {
position: relative;
height: 6px;
background: #e0e0e0;
border-radius: 3px;
margin: 0;
width: 100%;
}
.timeline-progress {
position: absolute;
height: 100%;
background: #2196F3;
border-radius: 3px;
width: 100%;
}
.timeline-handle {
position: absolute;
right: 0;
top: 50%;
transform: translate(50%, -50%);
width: 20px;
height: 20px;
background: #2196F3;
border: 3px solid white;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.timeline-date {
position: absolute;
top: -25px;
transform: translateX(-50%);
background: #2196F3; /* Changed to match slider blue color */
color: #ffffff !important;
padding: 3px 8px;
border-radius: 4px;
font-size: 12px;
white-space: nowrap;
font-weight: 600;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
letter-spacing: 0.5px;
text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
</style>
<div class="timeline-track">
<div class="timeline-progress"></div>
<div class="timeline-handle">
<div class="timeline-date">03/25/2025</div>
</div>
</div>
</div>
<script>
(function() {
const container = document.querySelector('.timeline-container');
const track = container.querySelector('.timeline-track');
const handle = container.querySelector('.timeline-handle');
let isDragging = false;
// For now, we only have one time point
const timePoints = {
"03/25/2025": 1.0
};
function updatePosition(e) {
if (!isDragging) return;
const rect = track.getBoundingClientRect();
let x = (e.clientX - rect.left) / rect.width;
x = Math.max(0, Math.min(1, x));
// For now, snap to the only available time point
x = 1.0;
handle.style.right = `${(1 - x) * 100}%`;
}
handle.addEventListener('mousedown', (e) => {
isDragging = true;
e.preventDefault();
});
document.addEventListener('mousemove', updatePosition);
document.addEventListener('mouseup', () => {
isDragging = false;
});
// Prevent text selection while dragging
container.addEventListener('selectstart', (e) => {
if (isDragging) e.preventDefault();
});
})();
</script>
"""
return gr.HTML(timeline_html)
def build_app():
with gr.Blocks(css="""
/* Fix for scrolling issues */
html, body {
overflow-y: hidden !important;
overflow-x: hidden !important;
width: 100% !important;
height: 100% !important;
max-height: none !important;
position: relative !important;
}
.radar-tip {
font-size: 14px;
color: #555;
margin-top: 5px;
margin-bottom: 20px;
font-style: italic;
}
/* Force scrolling to work on the main container */
.gradio-container, #root, #app {
width: 100% !important;
max-width: 1200px !important;
margin-left: auto !important;
margin-right: auto !important;
min-height: auto !important;
height: auto !important;
overflow: visible !important;
position: relative !important;
}
/* Remove ALL inner scrollbars - very important! */
.gradio-container * {
scrollbar-width: none !important; /* Firefox */
}
/* Hide scrollbars for Chrome, Safari and Opera */
.gradio-container *::-webkit-scrollbar {
display: none !important;
}
/* Only allow scrollbar on body */
body::-webkit-scrollbar {
display: block !important;
width: 10px !important;
}
body::-webkit-scrollbar-track {
background: #f1f1f1 !important;
}
body::-webkit-scrollbar-thumb {
background: #888 !important;
border-radius: 5px !important;
}
body::-webkit-scrollbar-thumb:hover {
background: #555 !important;
}
/* Clean up table styling */
.table-container {
width: 100% !important;
overflow: hidden !important;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
/* Remove duplicate scrollbars */
.gradio-dataframe [data-testid="table"],
[data-testid="dataframe"] [data-testid="table"],
.gradio-dataframe tbody,
[data-testid="dataframe"] tbody,
.table-container > div,
.table-container > div > div {
overflow: hidden !important;
/* max-height: none !important; */ /* REMOVED */
}
/* Ensure table contents are visible without scrollbars */
.gradio-dataframe,
[data-testid="dataframe"] {
overflow: visible !important;
/* max-height: none !important; */ /* REMOVED */
border: none !important;
}
/* Visualization styling */
.visualization-container .js-plotly-plot {
margin-left: auto !important;
margin-right: auto !important;
display: block !important;
max-width: 1000px;
}
/* Section styling */
.section-title {
font-size: 1.5em;
font-weight: bold;
color: #2c3e50;
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #e9ecef;
text-align: center;
}
/* Fix table styling */
.table-container table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
table-layout: fixed !important;
}
/* Column width customization - adjust for row numbers being first column */
.table-container th:nth-child(2),
.table-container td:nth-child(2) {
width: 230px !important;
min-width: 200px !important;
max-width: 280px !important;
padding-left: 8px !important;
padding-right: 8px !important;
}
.table-container th:nth-child(3),
.table-container td:nth-child(3) {
width: 120px !important;
min-width: 100px !important;
max-width: 140px !important;
}
/* Avg Normalized Score column (4th column) */
.table-container th:nth-child(4),
.table-container td:nth-child(4) {
width: 140px !important;
min-width: 120px !important;
max-width: 160px !important;
text-align: center !important;
}
/* Game score columns (5th column onwards) */
.table-container th:nth-child(n+5),
.table-container td:nth-child(n+5) {
width: 120px !important;
min-width: 100px !important;
max-width: 140px !important;
text-align: center !important;
}
/* Make headers sticky */
.table-container th {
position: sticky !important;
top: 0 !important;
background-color: var(--header-bg, #f8f9fa) !important;
z-index: 10 !important;
font-weight: bold;
padding: 16px 10px !important;
border-bottom: 2px solid var(--border-color, #e9ecef);
white-space: pre-wrap !important;
word-wrap: break-word !important;
line-height: 1.2 !important;
height: auto !important;
min-height: 60px !important;
vertical-align: middle !important;
color: var(--header-text, #2c3e50) !important;
}
/* Dark mode specific styles */
.dark .table-container th {
--header-bg: #2d3748;
--header-text: #e2e8f0;
--border-color: #4a5568;
}
/* Light mode specific styles */
.light .table-container th {
--header-bg: #f8f9fa;
--header-text: #2c3e50;
--border-color: #e9ecef;
}
/* Simple cell styling */
.table-container td {
padding: 8px 8px;
border-bottom: 1px solid var(--border-color, #e9ecef);
}
/* Row number column styling */
.gradio-dataframe thead tr th[id="0"],
.gradio-dataframe tbody tr td:nth-child(1),
[data-testid="dataframe"] thead tr th[id="0"],
[data-testid="dataframe"] tbody tr td:nth-child(1),
.svelte-1gfkn6j thead tr th:first-child,
.svelte-1gfkn6j tbody tr td:first-child {
width: 40px !important;
min-width: 40px !important;
max-width: 40px !important;
padding: 4px !important;
text-align: center !important;
font-size: 0.85em !important;
}
/* Fix for Gradio footer causing scroll issues */
footer {
position: relative !important;
width: 100% !important;
margin-top: 40px !important;
}
.welcome-message {
background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
color: #333;
padding: 20px;
border-radius: 10px;
margin: 20px 0;
text-align: center;
box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}
/* Dark mode support for welcome message */
.dark .welcome-message {
background: linear-gradient(135deg, #1a4a4f 0%, #4a1f3a 100%);
color: #e0e0e0;
box-shadow: 0 4px 15px rgba(255,255,255,0.05);
}
.welcome-message h3 {
margin: 0 0 10px 0;
font-size: 1.3em;
color: inherit;
}
.welcome-message p {
margin: 0;
font-size: 1.1em;
line-height: 1.5;
color: inherit;
}
""") as demo:
gr.Markdown("# ๐ฎ Lmgame Bench: Leaderboard ๐ฒ")
# Add custom JavaScript for table header line breaks
gr.HTML("""
<script>
// Function to add line breaks to table headers
function formatTableHeaders() {
// Find all table headers in the document
const headers = document.querySelectorAll('th');
headers.forEach(header => {
let text = header.textContent || '';
// Skip if already processed
if (header.getAttribute('data-processed') === 'true') {
return;
}
// Store original content for reference
if (!header.getAttribute('data-original')) {
header.setAttribute('data-original', header.innerHTML);
}
let newContent = header.innerHTML;
// Format Super Mario Brosheader
if (text.includes('Super Mario Bros')) {
newContent = newContent.replace(/Super\s+Mario\s+Bros/g, 'Super<br>Mario Bros');
}
// Format Tetrisheaders
if (text.includes('Tetris(complete)')) {
newContent = newContent.replace(/Tetris\s+\(complete\)/g, 'Tetris<br>(complete)');
}
if (text.includes('Tetris')) {
newContent = newContent.replace(/Tetris\s+\(planning\s+only\)/g, 'Tetris');
}
// Format Candy Crush header
if (text.includes('Candy Crush')) {
newContent = newContent.replace(/Candy\s+Crash/g, 'Candy<br>Crash');
}
// Make Organization header wider and fix its name
if (text.includes('Organization') || text.includes('Organi-zation')) {
header.style.minWidth = '150px';
header.style.width = '150px';
// Fix the Organization header name if it has a line break
if (text.includes('Organi-') || text.includes('zation')) {
newContent = newContent.replace(/Organi-<br>zation|Organi-zation/, 'Organization');
}
}
// Update content if changed
if (newContent !== header.innerHTML) {
header.innerHTML = newContent;
header.setAttribute('data-processed', 'true');
// Also ensure headers have proper styling
header.style.whiteSpace = 'normal';
header.style.lineHeight = '1.2';
header.style.verticalAlign = 'middle';
header.style.minHeight = '70px';
header.style.fontSize = '0.9em';
}
});
}
// Function to fix player name cells to prevent line breaking
function fixPlayerCells() {
// Find all table cells in the document
const tables = document.querySelectorAll('table');
tables.forEach(table => {
// Process rows starting from index 1 (skip header)
const rows = table.querySelectorAll('tr');
rows.forEach((row, index) => {
// Skip header row
if (index === 0) return;
// Get the player cell (typically 2nd cell)
const playerCell = row.querySelector('td:nth-child(2)');
const orgCell = row.querySelector('td:nth-child(3)');
if (playerCell) {
playerCell.style.whiteSpace = 'nowrap';
playerCell.style.overflow = 'hidden';
playerCell.style.textOverflow = 'ellipsis';
playerCell.style.maxWidth = '230px';
playerCell.style.textAlign = 'left';
}
if (orgCell) {
orgCell.style.whiteSpace = 'nowrap';
orgCell.style.overflow = 'hidden';
orgCell.style.textOverflow = 'ellipsis';
orgCell.style.minWidth = '150px';
orgCell.style.width = '150px';
}
});
});
}
// Function to run all formatting
function formatTable() {
formatTableHeaders();
fixPlayerCells();
}
// Run on load and then periodically to catch any new tables
setInterval(formatTable, 500);
// Also run when the DOM content is loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', formatTable);
} else {
formatTable();
}
// Run when the page is fully loaded with resources
window.addEventListener('load', formatTable);
</script>
""")
with gr.Tabs():
with gr.Tab("๐ค Model Leaderboard"):
with gr.Row():
gr.Markdown("""
**๐ฎ Welcome to LMGame Bench!**
We invite developers to implement their own gaming agents by replacing our `baseAgent` in `customer_runner.py` and evaluate them on our comprehensive benchmark. Visit our repository at https://github.com/lmgame-org/GamingAgent to get started and join the competition to see how your agent performs!
""", elem_classes="welcome-message")
# Visualization section
with gr.Row():
gr.Markdown("### ๐ Data Visualization")
# Detailed view visualization (single chart)
model_detailed_visualization = gr.Plot(
label="Performance Visualization",
visible=False,
elem_classes="visualization-container"
)
with gr.Row():
# Calculate dynamic maximum based on total models
model_max_models = get_total_model_count(model_rank_data)
model_top_n_slider = gr.Slider(
minimum=1,
maximum=model_max_models,
step=1,
value=model_max_models,
label=f"Number of Top Models to Display in All Views (max: {model_max_models})",
elem_classes="top-n-slider"
)
with gr.Column(visible=True) as model_overall_visualizations:
with gr.Tabs():
with gr.Tab("๐ Radar Chart"):
model_radar_visualization = gr.Plot(
label="Comparative Analysis (Radar Chart)",
elem_classes="visualization-container"
)
gr.Markdown(
"*๐ก Click a legend entry to isolate that model. Double-click additional ones to add them for comparison.*",
elem_classes="radar-tip"
)
with gr.Tab("๐ Group Bar Chart"):
model_group_bar_visualization = gr.Plot(
label="Comparative Analysis (Group Bar Chart)",
elem_classes="visualization-container"
)
gr.Markdown(
"*๐ก Click a legend entry to isolate that model. Double-click additional ones to add them for comparison.*",
elem_classes="radar-tip"
)
# Game selection section
with gr.Row():
gr.Markdown("### ๐น๏ธ Game Selection")
with gr.Row():
with gr.Column():
gr.Markdown("**๐ Super Mario Bros**")
model_mario_plan_overall = gr.Checkbox(label="Super Mario Bros Score", value=True)
model_mario_plan_details = gr.Checkbox(label="Super Mario Bros Details", value=False)
with gr.Column():
gr.Markdown("**๐ฆ Sokoban**")
model_sokoban_overall = gr.Checkbox(label="Sokoban Score", value=True)
model_sokoban_details = gr.Checkbox(label="Sokoban Details", value=False)
with gr.Column():
gr.Markdown("**๐ข 2048**")
model_2048_overall = gr.Checkbox(label="2048 Score", value=True)
model_2048_details = gr.Checkbox(label="2048 Details", value=False)
with gr.Column():
gr.Markdown("**๐ฌ Candy Crush**")
model_candy_overall = gr.Checkbox(label="Candy Crush Score", value=True)
model_candy_details = gr.Checkbox(label="Candy Crush Details", value=False)
with gr.Column():
gr.Markdown("**๐ฏ Tetris**")
model_tetris_plan_overall = gr.Checkbox(label="Tetris Score", value=True)
model_tetris_plan_details = gr.Checkbox(label="Tetris Details", value=False)
with gr.Column():
gr.Markdown("**โ๏ธ Ace Attorney**")
model_ace_attorney_overall = gr.Checkbox(label="Ace Attorney Score", value=True)
model_ace_attorney_details = gr.Checkbox(label="Ace Attorney Details", value=False)
# Controls
with gr.Row():
with gr.Column(scale=2):
gr.Markdown("**โฐ Time Tracker**")
model_timeline = create_timeline_slider()
with gr.Column(scale=1):
gr.Markdown("**๐ Controls**")
model_clear_btn = gr.Button("Reset Filters", variant="secondary")
# Leaderboard table
with gr.Row():
gr.Markdown("### ๐ Detailed Results")
with gr.Row():
gr.Markdown("*๐ก The slider above controls how many top models are shown in the radar chart, bar chart, and data table.*", elem_classes="radar-tip")
# Get initial leaderboard dataframe (limited by default slider value for model leaderboard)
model_initial_df = get_combined_leaderboard(model_rank_data, {
"Super Mario Bros": True,
"Sokoban": True,
"2048": True,
"Candy Crush": True,
"Tetris": True,
"Ace Attorney": True
}, limit_to_top_n=None)
# Format the DataFrame for display
model_initial_display_df = prepare_dataframe_for_display(model_initial_df)
# Custom column widths including row numbers for model leaderboard
model_col_widths = ["40px"] # Row number column width
model_col_widths.append("230px") # Player column - reduced by 20px
model_col_widths.append("120px") # Organization column
# Check if there's an Avg Normalized Score column
if any('Avg Normalized' in col for col in model_initial_display_df.columns):
model_col_widths.append("140px") # Avg Normalized Score column - slightly wider
# Add game score columns
remaining_cols = len(model_initial_display_df.columns) - len(model_col_widths) + 1 # +1 because we subtracted row number column
for _ in range(remaining_cols):
model_col_widths.append("120px")
# Add reference to Jupyter notebook
with gr.Row():
gr.Markdown("*All data analysis can be replicated by checking [this Jupyter notebook](https://colab.research.google.com/drive/1CYFiJGm3EoBXXI8vICPVR82J9qrmmRvc#scrollTo=qft1Oald-21J)*")
# Create a standard DataFrame component with enhanced styling
with gr.Row():
model_leaderboard_df = gr.DataFrame(
value=model_initial_display_df,
interactive=True,
elem_id="model-leaderboard-table",
elem_classes="table-container",
wrap=True,
show_row_numbers=True,
show_fullscreen_button=True,
line_breaks=True,
max_height=1000,
show_search="search",
column_widths=model_col_widths
)
# Add the score note below the table
with gr.Row():
model_score_note = add_score_note()
# List of all checkboxes for model leaderboard
model_checkbox_list = [
model_mario_plan_overall, model_mario_plan_details,
model_sokoban_overall, model_sokoban_details,
model_2048_overall, model_2048_details,
model_candy_overall, model_candy_details,
model_tetris_plan_overall, model_tetris_plan_details,
model_ace_attorney_overall, model_ace_attorney_details
]
# Update visualizations when checkboxes change
def update_model_visualizations(*checkbox_states):
# Check if any details checkbox is selected
is_details_view = any([
checkbox_states[1], # Mario Plan details
checkbox_states[3], # Sokoban details
checkbox_states[5], # 2048 details
checkbox_states[7], # Candy Crush details
checkbox_states[9], # Tetris details
checkbox_states[11] # Ace Attorney details
])
# Update visibility of visualization blocks
return {
model_detailed_visualization: gr.update(visible=is_details_view),
model_overall_visualizations: gr.update(visible=not is_details_view)
}
# Add change event to all checkboxes
for checkbox in model_checkbox_list:
checkbox.change(
update_model_visualizations,
inputs=model_checkbox_list,
outputs=[model_detailed_visualization, model_overall_visualizations]
)
# Update leaderboard and visualizations when checkboxes change
for checkbox in model_checkbox_list:
checkbox.change(
lambda *args: update_leaderboard(*args, data_source=model_rank_data),
inputs=model_checkbox_list + [model_top_n_slider],
outputs=[
model_leaderboard_df,
model_detailed_visualization,
model_radar_visualization,
model_group_bar_visualization
] + model_checkbox_list
)
# Update when model top_n_slider changes
model_top_n_slider.change(
lambda *args: update_leaderboard(*args, data_source=model_rank_data),
inputs=model_checkbox_list + [model_top_n_slider],
outputs=[
model_leaderboard_df,
model_detailed_visualization,
model_radar_visualization,
model_group_bar_visualization
] + model_checkbox_list
)
# Update when clear button is clicked
model_clear_btn.click(
lambda *args: clear_filters(*args, data_source=model_rank_data),
inputs=[model_top_n_slider],
outputs=[
model_leaderboard_df,
model_detailed_visualization,
model_radar_visualization,
model_group_bar_visualization
] + model_checkbox_list
)
# Initialize the model leaderboard (with all models shown by default)
demo.load(
lambda: clear_filters(top_n=get_total_model_count(model_rank_data), data_source=model_rank_data),
inputs=[],
outputs=[
model_leaderboard_df,
model_detailed_visualization,
model_radar_visualization,
model_group_bar_visualization
] + model_checkbox_list
)
with gr.Tab("๐ Agent Leaderboard"):
# Visualization section
with gr.Row():
# Calculate dynamic maximum based on total models
agent_max_models = get_total_model_count(rank_data)
agent_top_n_slider = gr.Slider(
minimum=1,
maximum=agent_max_models,
step=1,
value=5,
label=f"Number of Top Models to Display in All Views (max: {agent_max_models})",
elem_classes="top-n-slider"
)
with gr.Row():
gr.Markdown("### ๐ Data Visualization")
# Detailed view visualization (single chart)
detailed_visualization = gr.Plot(
label="Performance Visualization",
visible=False,
elem_classes="visualization-container"
)
# with gr.Row():
# # Calculate dynamic maximum based on total models
# agent_max_models = get_total_model_count(rank_data)
# top_n_slider = gr.Slider(
# minimum=1,
# maximum=agent_max_models,
# step=1,
# value=min(3, agent_max_models),
# label=f"Number of Top Models to Display in All Views (max: {agent_max_models})",
# elem_classes="top-n-slider"
# )
with gr.Column(visible=True) as overall_visualizations:
with gr.Tabs():
with gr.Tab("๐ Radar Chart"):
radar_visualization = gr.Plot(
label="Comparative Analysis (Radar Chart)",
elem_classes="visualization-container"
)
gr.Markdown(
"*๐ก Click a legend entry to isolate that model. Double-click additional ones to add them for comparison.*\n\n*๐ฎ Model Name (GamingAgent) - Our specialized gaming agents*",
elem_classes="radar-tip"
)
with gr.Tab("๐ Group Bar Chart"):
group_bar_visualization = gr.Plot(
label="Comparative Analysis (Group Bar Chart)",
elem_classes="visualization-container"
)
gr.Markdown(
"*๐ก Click a legend entry to isolate that model. Double-click additional ones to add them for comparison.*\n\n*๐ฎ Model Name (GamingAgent) - Our specialized gaming agents*",
elem_classes="radar-tip"
)
# Hidden placeholder for group bar visualization (to maintain code references)
# group_bar_visualization = gr.Plot(visible=False)
# Game selection section
with gr.Row():
gr.Markdown("### ๐น๏ธ Game Selection")
with gr.Row():
# with gr.Column(): # Commented out Super Mario BrosUI
# gr.Markdown("**๐ฎ Super Mario Bros**")
# mario_overall = gr.Checkbox(label="Super Mario BrosScore", value=True)
# mario_details = gr.Checkbox(label="Super Mario BrosDetails", value=False)
with gr.Column(): # Added Super Mario BrosUI
gr.Markdown("**๐ Super Mario Bros**")
mario_plan_overall = gr.Checkbox(label="Super Mario Bros Score", value=True)
mario_plan_details = gr.Checkbox(label="Super Mario Bros Details", value=False)
with gr.Column(): # Sokoban is now after mario_plan
gr.Markdown("**๐ฆ Sokoban**")
sokoban_overall = gr.Checkbox(label="Sokoban Score", value=True)
sokoban_details = gr.Checkbox(label="Sokoban Details", value=False)
with gr.Column():
gr.Markdown("**๐ข 2048**")
_2048_overall = gr.Checkbox(label="2048 Score", value=True)
_2048_details = gr.Checkbox(label="2048 Details", value=False)
with gr.Column():
gr.Markdown("**๐ฌ Candy Crush**")
candy_overall = gr.Checkbox(label="Candy Crush Score", value=True)
candy_details = gr.Checkbox(label="Candy Crush Details", value=False)
# with gr.Column(): # Commented out Tetris(complete) UI
# gr.Markdown("**๐ฏ Tetris(complete)**")
# tetris_overall = gr.Checkbox(label="Tetris(complete) Score", value=True)
# tetris_details = gr.Checkbox(label="Tetris(complete) Details", value=False)
with gr.Column():
gr.Markdown("**๐ฏ Tetris**")
tetris_plan_overall = gr.Checkbox(label="Tetris Score", value=True)
tetris_plan_details = gr.Checkbox(label="Tetris Details", value=False)
with gr.Column():
gr.Markdown("**โ๏ธ Ace Attorney**")
ace_attorney_overall = gr.Checkbox(label="Ace Attorney Score", value=True)
ace_attorney_details = gr.Checkbox(label="Ace Attorney Details", value=False)
# Controls
with gr.Row():
with gr.Column(scale=2):
gr.Markdown("**โฐ Time Tracker**")
timeline = create_timeline_slider()
with gr.Column(scale=1):
gr.Markdown("**๐ Controls**")
clear_btn = gr.Button("Reset Filters", variant="secondary")
# Leaderboard table
with gr.Row():
gr.Markdown("### ๐ Detailed Results")
with gr.Row():
gr.Markdown("*๐ฎ Model Name (GamingAgent) - Our specialized gaming agents*", elem_classes="radar-tip")
# Welcome message for custom gaming agents
# Get initial leaderboard dataframe (limited by default slider value for agent leaderboard)
initial_df = get_combined_leaderboard(rank_data, {
# "Super Mario Bros": True, # Commented out
"Super Mario Bros": True,
"Sokoban": True,
"2048": True,
"Candy Crush": True,
# "Tetris(complete)": True, # Commented out
"Tetris": True,
"Ace Attorney": True
}, limit_to_top_n=5)
# Format the DataFrame for display
initial_display_df = prepare_dataframe_for_display(initial_df)
# Custom column widths including row numbers
col_widths = ["40px"] # Row number column width
col_widths.append("230px") # Player column - reduced by 20px
col_widths.append("120px") # Organization column
# Check if there's an Avg Normalized Score column
if any('Avg Normalized' in col for col in initial_display_df.columns):
col_widths.append("140px") # Avg Normalized Score column - slightly wider
# Add game score columns
remaining_cols = len(initial_display_df.columns) - len(col_widths) + 1 # +1 because we subtracted row number column
for _ in range(remaining_cols):
col_widths.append("120px")
# Create a standard DataFrame component with enhanced styling
with gr.Row():
leaderboard_df = gr.DataFrame(
value=initial_display_df,
interactive=True,
elem_id="leaderboard-table",
elem_classes="table-container",
wrap=True,
show_row_numbers=True,
show_fullscreen_button=True,
line_breaks=True,
max_height=1000, # Set a larger fixed height
show_search="search",
column_widths=col_widths
)
# Add the score note below the table
with gr.Row():
score_note = add_score_note()
# List of all checkboxes, including Super Mario Bros
checkbox_list = [
# mario_overall, mario_details, # Commented out
mario_plan_overall, mario_plan_details,
sokoban_overall, sokoban_details,
_2048_overall, _2048_details,
candy_overall, candy_details,
# tetris_overall, tetris_details, # Commented out
tetris_plan_overall, tetris_plan_details,
ace_attorney_overall, ace_attorney_details
]
# Update visualizations when checkboxes change
def update_visualizations(*checkbox_states):
# Check if any details checkbox is selected
# Adjusted indices due to addition of Super Mario
is_details_view = any([
checkbox_states[1], # Mario Plan details
checkbox_states[3], # Sokoban details
checkbox_states[5], # 2048 details
checkbox_states[7], # Candy Crush details
checkbox_states[9], # Tetris details
checkbox_states[11] # Ace Attorney details
])
# Update visibility of visualization blocks
return {
detailed_visualization: gr.update(visible=is_details_view),
overall_visualizations: gr.update(visible=not is_details_view)
}
# Add change event to all checkboxes
for checkbox in checkbox_list:
checkbox.change(
update_visualizations,
inputs=checkbox_list,
outputs=[detailed_visualization, overall_visualizations]
)
# Update leaderboard and visualizations when checkboxes change
for checkbox in checkbox_list:
checkbox.change(
lambda *args: update_leaderboard(*args, data_source=rank_data),
inputs=checkbox_list + [agent_top_n_slider],
outputs=[
leaderboard_df,
detailed_visualization,
radar_visualization,
group_bar_visualization
] + checkbox_list
)
# Update when agent top_n_slider changes
agent_top_n_slider.change(
lambda *args: update_leaderboard(*args, data_source=rank_data),
inputs=checkbox_list + [agent_top_n_slider],
outputs=[
leaderboard_df,
detailed_visualization,
radar_visualization,
group_bar_visualization
] + checkbox_list
)
# Update when clear button is clicked
clear_btn.click(
lambda *args: clear_filters(*args, data_source=rank_data),
inputs=[agent_top_n_slider],
outputs=[
leaderboard_df,
detailed_visualization,
radar_visualization,
group_bar_visualization
] + checkbox_list
)
# Initialize the agent leaderboard (with top 5 limit)
demo.load(
lambda: clear_filters(top_n=5, data_source=rank_data),
inputs=[],
outputs=[
leaderboard_df,
detailed_visualization,
radar_visualization,
group_bar_visualization
] + checkbox_list
)
with gr.Tab("๐ฅ Gallery"):
video_gallery = create_video_gallery()
return demo
if __name__ == "__main__":
demo_app = build_app()
# Add file serving configuration
demo_app.launch(
debug=True,
show_error=True,
share=True,
height="100%",
width="100%"
) |