File size: 68,903 Bytes
24a5f16
 
f6b51b3
24a5f16
 
 
 
 
 
 
f6b51b3
 
 
 
24a5f16
dfa1e52
24a5f16
 
 
f6b51b3
 
dfa1e52
 
24a5f16
 
 
ed120b4
24a5f16
f6b51b3
 
 
 
 
24a5f16
f6b51b3
dfa1e52
f6b51b3
24a5f16
f6b51b3
24a5f16
f6b51b3
 
 
24a5f16
dfa1e52
 
 
 
 
24a5f16
 
 
f6b51b3
24a5f16
 
dfa1e52
24a5f16
ed120b4
f6b51b3
 
 
dfa1e52
ed120b4
f6b51b3
ed120b4
7206088
dbbe798
dfa1e52
 
 
 
ed120b4
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
7206088
 
 
 
 
 
f6b51b3
24a5f16
 
f6b51b3
24a5f16
f6b51b3
 
 
 
 
 
 
 
24a5f16
 
f6b51b3
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
 
 
dfa1e52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
dfa1e52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
 
dfa1e52
f6b51b3
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
 
f6b51b3
 
24a5f16
dfa1e52
 
24a5f16
 
f6b51b3
24a5f16
 
 
 
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
24a5f16
f6b51b3
24a5f16
dfa1e52
f6b51b3
 
 
 
 
dfa1e52
 
 
f6b51b3
dfa1e52
 
 
f6b51b3
dfa1e52
f6b51b3
dfa1e52
 
f6b51b3
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
 
 
f6b51b3
dfa1e52
 
f6b51b3
dfa1e52
f6b51b3
dfa1e52
 
 
 
 
 
 
 
 
 
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
 
f6b51b3
 
dfa1e52
f6b51b3
 
 
dfa1e52
f6b51b3
 
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
f6b51b3
 
 
dfa1e52
f6b51b3
 
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
f6b51b3
 
 
 
 
 
 
 
dfa1e52
f6b51b3
 
dfa1e52
 
f6b51b3
dfa1e52
 
f6b51b3
dfa1e52
 
 
 
 
 
 
 
 
f6b51b3
dfa1e52
 
f6b51b3
 
 
 
 
dfa1e52
 
 
 
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
 
f6b51b3
dfa1e52
f6b51b3
 
dfa1e52
f6b51b3
 
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
f6b51b3
 
dfa1e52
f6b51b3
 
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
f6b51b3
 
 
 
 
 
 
 
 
 
dfa1e52
 
f6b51b3
 
 
 
dfa1e52
f6b51b3
 
dfa1e52
f6b51b3
 
dfa1e52
 
 
 
 
 
 
 
 
 
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
 
 
 
 
 
 
 
 
 
 
 
 
f6b51b3
dfa1e52
 
 
f6b51b3
dfa1e52
 
f6b51b3
 
 
dfa1e52
f6b51b3
 
 
dfa1e52
f6b51b3
dfa1e52
 
 
 
 
 
 
 
 
 
f6b51b3
 
 
dfa1e52
 
 
f6b51b3
dfa1e52
 
f6b51b3
 
 
dfa1e52
 
 
24a5f16
f6b51b3
 
 
dfa1e52
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
f6b51b3
 
 
 
 
dfa1e52
f6b51b3
 
 
 
dfa1e52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f6b51b3
dfa1e52
 
 
 
 
269e9b8
 
f6b51b3
dfa1e52
f6b51b3
24a5f16
 
dfa1e52
24a5f16
dfa1e52
f6b51b3
dfa1e52
 
f6b51b3
 
 
 
0963663
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
f6b51b3
dfa1e52
f6b51b3
 
 
 
 
 
 
 
dfa1e52
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24a5f16
dfa1e52
 
fb92134
dfa1e52
fb92134
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
24a5f16
dfa1e52
 
24a5f16
 
dfa1e52
f6b51b3
 
 
 
24a5f16
 
dfa1e52
24a5f16
f6b51b3
24a5f16
 
dfa1e52
f6b51b3
24a5f16
 
dfa1e52
 
f6b51b3
24a5f16
dfa1e52
 
 
f6b51b3
 
 
 
 
 
dfa1e52
24a5f16
 
 
 
dfa1e52
f6b51b3
 
 
 
 
 
 
dfa1e52
f6b51b3
24a5f16
dfa1e52
 
f6b51b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfa1e52
 
f6b51b3
 
 
 
 
dfa1e52
 
f6b51b3
 
 
 
 
dfa1e52
 
 
 
24a5f16
 
 
 
 
dfa1e52
24a5f16
f6b51b3
24a5f16
dfa1e52
 
 
 
24a5f16
 
 
 
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
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
import os
import json
import math
import numpy as np
import pandas as pd
import gradio as gr
from huggingface_hub import HfApi, hf_hub_download


OWNER = "inceptionai"

ARAGEN_REQUESTS_REPO_ID = f"{OWNER}/aragen-requests-dataset"
HINDIGEN_REQUESTS_REPO_ID = f"{OWNER}/hindigen-requests-dataset"
IFEVAL_REQUESTS_REPO_ID = f"{OWNER}/arabicifeval-requests-dataset"


HEADER = """
<center>
<br></br>
<h1>Multilingual Leaderboards ๐ŸŒ</h1>
<h2>Generative Evaluation for Global South</h2>
<br></br>
</center>
"""

ABOUT_SECTION = """
## About

In our `12-24` release, we introduced the **AraGen Benchmark**, along with the **3C3H** evaluation measure (aka the 3C3H Score). You can find more details about AraGen and 3C3H [here](https://huggingface.co/blog/leaderboard-3c3h-aragen). The first versions of the benchmark, **AraGen-12-24** and **AraGen-03-25 (v2)**, are publicly available in the [`inceptionai/AraGen`](https://huggingface.co/datasets/inceptionai/AraGen) dataset. The current AraGen leaderboard in this Space is powered by **AraGen-v3**.

Building on that foundation, we extend our evaluation beyond Arabic, introducing **HindiGen**, a generative benchmark for Hindi that will follow the same release philosophy as AraGen. The current **HindiGen-v1** powers the HindiGen leaderboards here; a future **HindiGen-v2** release will be publicly shared along with the v1 dataset.

In this release, we present three main leaderboards:

**AraGen-v3:**

- The AraGen Benchmark is designed to evaluate and compare the performance of Chat/Instruct Arabic Large Language Models on a suite of generative tasks that are culturally relevant to the Arab region, history, politics, cuisine, and more. By leveraging **3C3H** as an evaluation metricโ€”which assesses a model's output across six dimensions: Correctness, Completeness, Conciseness, Helpfulness, Honesty, and Harmlessnessโ€”the leaderboard offers a comprehensive and holistic evaluation of a modelโ€™s chat capabilities and its ability to generate human-like and ethically responsible content.

**HindiGen-v1:**

- The HindiGen Benchmark evaluates Chat/Instruct LLMs on Hindi generative tasks such as question answering, grammar, and safety. It follows the same 3C3H evaluation methodology and bootstrapped confidence intervals, enabling statistically grounded comparisons between models on culturally and linguistically rich Hindi content.

**Instruction Following (IFEval โ€“ Arabic & English):**

- We have established a robust leaderboard that benchmarks models on Arabic and English instruction following, offering an open and comparative performance landscape for the research community. Concurrently, we released the first publicly available Arabic [dataset](https://huggingface.co/datasets/inceptionai/Arabic_IFEval) aimed at evaluating LLMs' ability to follow instructions. The Arabic IFEval samples are meticulously curated to capture the languageโ€™s unique nuancesโ€”such as diacritization and distinctive phonetic featuresโ€”often overlooked in generic datasets. Our dedicated linguistic team generated original samples and adapted selections from the IFEval English dataset, ensuring that the material resonates with Arabic cultural contexts and meets the highest standards of authenticity and quality.

### Why Focus on Chat Models?

Our evaluations are conducted in a generative mode, meaning that we expect models to produce complete, context-rich responses rather than simply predicting the next token as base models do. This approach not only yields results that are more explainable and nuanced compared to logit-based measurements, but it also captures elements like creativity, coherence, and ethical considerationsโ€”providing deeper insights into overall model performance.

### Contact

For inquiries or assistance, please join the conversation on our [Discussions Tab](https://huggingface.co/spaces/inceptionai/Leaderboards/discussions) or reach out via [email](mailto:[email protected]).
"""

BOTTOM_LOGO = """<img src="https://huggingface.co/spaces/inceptionai/Arabic-Leaderboards/resolve/main/assets/pictures/03-25/arabic-leaderboards-colab-march-preview-free-3.png" style="width:50%;display:block;margin-left:auto;margin-right:auto;border-radius:15px;">"""

CITATION_BUTTON_TEXT = """
@misc{leaderboards,
  author = {El Filali, Ali and Albarri, Sarah and Kamboj, Samta and Sengupta, Neha and Nakov, Preslav and Abouelseoud, Arwa},
  title = {Multilingual Leaderboards: Generative Evaluation for Global South},
  year = {2025},
  publisher = {Inception},
  howpublished = "url{https://huggingface.co/spaces/inceptionai/Leaderboards}"
}
"""

CITATION_BUTTON_LABEL = """
Copy the following snippet to cite the results from all Arabic Leaderboards in this Space.
"""


def extract_score_value(entry):
    """
    Helper to extract (value, lower, upper) from both old v2 format (float)
    and new v3/v1 formats (dict with "value"/"lower"/"upper").
    All values are returned in [0, 1] space; caller can convert to percentages.

    We use the "value" field as the point estimate.
    """
    if entry is None:
        return (math.nan, math.nan, math.nan)

    # Old format: just a float
    if isinstance(entry, (int, float)):
        v = float(entry)
        return (v, math.nan, math.nan)

    # New format: dict with "value", "lower", "upper"
    if isinstance(entry, dict):
        v = float(entry.get("value", math.nan))
        lower = entry.get("lower", math.nan)
        upper = entry.get("upper", math.nan)
        lower = float(lower) if isinstance(lower, (int, float)) else math.nan
        upper = float(upper) if isinstance(upper, (int, float)) else math.nan
        return (v, lower, upper)

    return (math.nan, math.nan, math.nan)


def compute_leaderboard_3c3h(df_3c3h_base: pd.DataFrame) -> pd.DataFrame:
    """
    Build the 3C3H leaderboard with:
      - Rank (by 3C3H Score)
      - Rank Spread (based on 3C3H Score CI)
      - 95% CI (ยฑ) for 3C3H Score (only)
      - Model Size Filter

    All scores are in percentage space.
    """
    df = df_3c3h_base.copy()

    # Model size filter helper
    max_model_size_value = 1000
    df["Model Size Filter"] = df["Model Size"].replace(np.inf, max_model_size_value)

    # Sort & rank by 3C3H Score (point estimate)
    if "3C3H Score" in df.columns:
        df = df.sort_values(by="3C3H Score", ascending=False)
    df = df.reset_index(drop=True)
    df.insert(0, "Rank", range(1, len(df) + 1))

    # Rank Spread based on 3C3H Score CI
    main_col = "3C3H Score"
    lower_col = "3C3H Score Lower"
    upper_col = "3C3H Score Upper"

    # Effective lower/upper: if not present, fall back to point estimate
    if lower_col in df.columns:
        lower_eff = df[lower_col].copy()
    else:
        lower_eff = df[main_col].copy()

    if upper_col in df.columns:
        upper_eff = df[upper_col].copy()
    else:
        upper_eff = df[main_col].copy()

    # order of base scenario: all models at their point estimates (value-based)
    sort_desc = df.sort_values(by=main_col, ascending=False)
    score_order = sort_desc[main_col].values  # descending

    def rank_position(x, order):
        """
        Given a value x and a descending array 'order',
        return the rank index where x would land
        if all others stayed as in 'order'.

        Rank = 1 + number of scores strictly greater than x.
        """
        if np.isnan(x):
            return math.nan

        # Ignore NaNs in the score order
        valid = order[~np.isnan(order)]
        if valid.size == 0:
            return math.nan

        # 'valid' is descending; count how many scores are strictly greater than x
        num_greater = np.sum(valid > x)
        rank = num_greater + 1

        # Clamp rank to [1, len(valid)] for numerical safety
        if rank < 1:
            rank = 1
        elif rank > len(valid):
            rank = len(valid)

        return int(rank)

    best_ranks = []
    worst_ranks = []
    for low, high in zip(lower_eff.values, upper_eff.values):
        best = rank_position(high, score_order)   # optimistic: use upper bound
        worst = rank_position(low, score_order)   # pessimistic: use lower bound
        best_ranks.append(best)
        worst_ranks.append(worst)

    spread = []
    for b, w in zip(best_ranks, worst_ranks):
        if math.isnan(b) or math.isnan(w):
            spread.append("-")
        else:
            spread.append(f"{int(b)} <--> {int(w)}")
    df.insert(1, "Rank Spread", spread)

    # 95% CI (ยฑ) for 3C3H Score only (in percentage space)
    if lower_col in df.columns and upper_col in df.columns:
        ci = (df[upper_col] - df[lower_col]) / 2.0
        df["95% CI (ยฑ)"] = ci.round(4)
    else:
        df["95% CI (ยฑ)"] = np.nan

    # Round score columns
    score_columns_3c3h = [
        "3C3H Score",
        "Correctness",
        "Completeness",
        "Conciseness",
        "Helpfulness",
        "Honesty",
        "Harmlessness",
    ]
    for col in score_columns_3c3h:
        if col in df.columns:
            df[col] = df[col].round(4)

    df["95% CI (ยฑ)"] = df["95% CI (ยฑ)"].round(4)

    return df


def load_results(benchmark="aragen"):
    """
    Loads results for the given benchmark.

    benchmark:
      - "aragen"   -> uses aragen_v3_results.json (or v2 fallback)
      - "hindigen" -> uses hindigen_v1_results.json

    Supports:
      - old v2 format (simple floats)
      - new v3/v1 format (dict with value/lower/upper)

    Returns:
      df_3c3h     : 3C3H leaderboard dataframe (with Rank, Rank Spread, 95% CI (ยฑ))
      df_tasks    : tasks leaderboard dataframe
      task_columns: list of task score columns
    """
    current_dir = os.path.dirname(os.path.abspath(__file__))

    if benchmark == "hindigen":
        results_file = os.path.join(current_dir, "assets", "results", "hindigen_v1_results.json")
    else:
        v3_file = os.path.join(current_dir, "assets", "results", "aragen_v3_results.json")
        v2_file = os.path.join(current_dir, "assets", "results", "aragen_v2_results.json")
        if os.path.exists(v3_file):
            results_file = v3_file
        else:
            results_file = v2_file

    with open(results_file, "r", encoding="utf-8") as f:
        data = json.load(f)

    # Filter out entries that only contain "_last_sync_timestamp"
    filtered_data = []
    for entry in data:
        if len(entry.keys()) == 1 and "_last_sync_timestamp" in entry:
            continue
        filtered_data.append(entry)
    data = filtered_data

    data_3c3h = []
    data_tasks = []

    for model_data in data:
        meta = model_data.get("Meta", {})
        model_name = meta.get("Model Name", "UNK")
        revision = meta.get("Revision", "UNK")
        precision = meta.get("Precision", "UNK")
        license_ = meta.get("License", "UNK")
        params = meta.get("Params", "UNK")

        # Parse model size
        try:
            model_size_numeric = float(params)
        except Exception:
            model_size_numeric = np.inf

        # Find the key that holds the scores (e.g. "claude-3-7-sonnet-20250219 Scores", "claude-3.5-sonnet Scores")
        scores_key = None
        for k in model_data.keys():
            if k.endswith("Scores"):
                scores_key = k
                break

        scores_data = model_data.get(scores_key, {}) if scores_key else {}
        scores_3c3h = scores_data.get("3C3H Scores", {})
        scores_tasks = scores_data.get("Tasks Scores", {})

        # --- 3C3H entry ---
        entry3 = {
            "Model Name": model_name,
            "Revision": revision,
            "License": license_,
            "Precision": precision,
            "Model Size": model_size_numeric,
        }

        for metric_name, metric_entry in scores_3c3h.items():
            v, lower, upper = extract_score_value(metric_entry)
            # Point estimate (percentage)
            entry3[metric_name] = v * 100 if not math.isnan(v) else np.nan

            # Only keep lower/upper for 3C3H Score (for CI & Rank Spread)
            if metric_name == "3C3H Score":
                entry3["3C3H Score Lower"] = (
                    lower * 100 if not math.isnan(lower) else np.nan
                )
                entry3["3C3H Score Upper"] = (
                    upper * 100 if not math.isnan(upper) else np.nan
                )

        data_3c3h.append(entry3)

        # --- Tasks entry ---
        entryt = {
            "Model Name": model_name,
            "Revision": revision,
            "License": license_,
            "Precision": precision,
            "Model Size": model_size_numeric,
        }

        for task_name, task_entry in scores_tasks.items():
            v, _, _ = extract_score_value(task_entry)
            entryt[task_name] = v * 100 if not math.isnan(v) else np.nan

        data_tasks.append(entryt)

    df_3c3h_base = pd.DataFrame(data_3c3h)
    df_tasks_base = pd.DataFrame(data_tasks)

    # Build 3C3H leaderboard (rank, rank spread, CI, size filter)
    df_3c3h = compute_leaderboard_3c3h(df_3c3h_base)

    # Build tasks leaderboard (no weighted average, no rank spread, no CI)
    if df_tasks_base.empty:
        df_tasks = df_tasks_base.copy()
        task_columns = []
    else:
        meta_cols_tasks = [
            "Model Name",
            "Revision",
            "License",
            "Precision",
            "Model Size",
        ]
        task_columns = [
            col
            for col in df_tasks_base.columns
            if col not in meta_cols_tasks
        ]

        df_tasks = df_tasks_base.copy()

        # Round task scores
        if task_columns:
            df_tasks[task_columns] = df_tasks[task_columns].round(4)

        # Model size filter
        max_model_size_value = 1000
        df_tasks["Model Size Filter"] = df_tasks["Model Size"].replace(
            np.inf, max_model_size_value
        )

        # Sort & rank: based on the first task (typically Question Answering (QA))
        if task_columns:
            first_task = task_columns[0]
            df_tasks = df_tasks.sort_values(by=first_task, ascending=False)
        else:
            df_tasks = df_tasks.sort_values(by="Model Name", ascending=True)

        df_tasks = df_tasks.reset_index(drop=True)
        df_tasks.insert(0, "Rank", range(1, len(df_tasks) + 1))

    return df_3c3h, df_tasks, task_columns


def load_if_data():
    """
    Loads the instruction-following data from ifeval_results.jsonl 
    and returns a dataframe with relevant columns, 
    converting decimal values to percentage format.
    """
    current_dir = os.path.dirname(os.path.abspath(__file__))
    results_file = os.path.join(current_dir, "assets", "results", "ifeval_results.jsonl")
    
    data = []
    with open(results_file, "r", encoding="utf-8") as f:
        for line in f:
            line = line.strip()
            if not line:
                continue
            data.append(json.loads(line))
    
    df = pd.DataFrame(data)
    
    # Convert numeric columns
    numeric_cols = ["En Prompt-lvl", "En Instruction-lvl", "Ar Prompt-lvl", "Ar Instruction-lvl"]
    for col in numeric_cols:
        df[col] = pd.to_numeric(df[col], errors="coerce")

    # Compute average accuracy for En and Ar
    df["Average Accuracy (En)"] = (df["En Prompt-lvl"] + df["En Instruction-lvl"]) / 2
    df["Average Accuracy (Ar)"] = (df["Ar Prompt-lvl"] + df["Ar Instruction-lvl"]) / 2
    
    # Convert them to percentage format (e.g., 0.871 -> 87.1)
    for col in numeric_cols:
        df[col] = (df[col] * 100).round(1)
    df["Average Accuracy (En)"] = (df["Average Accuracy (En)"] * 100).round(1)
    df["Average Accuracy (Ar)"] = (df["Average Accuracy (Ar)"] * 100).round(1)
    
    # Handle size as numeric
    def parse_size(x):
        try:
            return float(x)
        except:
            return np.inf
    
    df["Model Size"] = df["Size (B)"].apply(parse_size)
    
    # Add a filter column for size
    max_model_size_value = 1000
    df["Model Size Filter"] = df["Model Size"].replace(np.inf, max_model_size_value)
    
    # Sort by "Average Accuracy (Ar)" as an example
    df = df.sort_values(by="Average Accuracy (Ar)", ascending=False)
    df = df.reset_index(drop=True)
    df.insert(0, "Rank", range(1, len(df) + 1))
    
    return df


def submit_model(model_name, revision, precision, params, license, modality, leaderboards_selected):
    """
    Submits a model to one or more leaderboards:
      - AraGen   -> inceptionai/aragen-requests-dataset
      - HindiGen -> inceptionai/hindigen-requests-dataset
      - IFEval   -> inceptionai/arabicifeval-requests-dataset

    User must choose at least one leaderboard.
    """
    if not leaderboards_selected:
        return "**Error:** You must choose at least one leaderboard (AraGen, HindiGen, and/or IFEval)."

    # Normalize precision
    if precision == "Missing":
        precision_norm = None
    else:
        precision_norm = precision.strip().lower() if precision else None

    repo_map = {
        "AraGen": ARAGEN_REQUESTS_REPO_ID,
        "HindiGen": HINDIGEN_REQUESTS_REPO_ID,
        "IFEval": IFEVAL_REQUESTS_REPO_ID,
    }

    # Map leaderboards that use the 3C3H JSON result files (for dedup vs results)
    results_benchmark_map = {
        "AraGen": "aragen",
        "HindiGen": "hindigen",
    }

    api = HfApi()

    # Validate model exists on HuggingFace Hub once
    try:
        _ = api.model_info(model_name)
    except Exception:
        return f"**Error: Could not find model '{model_name}' on HuggingFace Hub. Please ensure the model name is correct and the model is public.**"

    org_model = model_name.split("/")
    if len(org_model) != 2:
        return "**Please enter the full model name including the organization or username, e.g., 'inceptionai/jais-family-30b-8k'**"
    org, model_id = org_model

    hf_api_token = os.environ.get("HF_API_TOKEN", None)

    # Dedup & upload per leaderboard
    success_targets = []
    skipped_targets = []
    errors = []

    for leaderboard in leaderboards_selected:
        repo_id = repo_map.get(leaderboard)
        if repo_id is None:
            errors.append(f"- Unknown leaderboard: {leaderboard}")
            continue

        # Deduplicate against existing results (only for AraGen/HindiGen)
        already_evaluated = False
        if leaderboard in results_benchmark_map:
            df_3c3h_lb, _, _ = load_results(results_benchmark_map[leaderboard])
            if not df_3c3h_lb.empty:
                existing_models_results = df_3c3h_lb[["Model Name", "Revision", "Precision"]]
                model_exists_in_results = (
                    (existing_models_results["Model Name"] == model_name)
                    & (existing_models_results["Revision"] == revision)
                    & (existing_models_results["Precision"] == (precision_norm if precision_norm is not None else existing_models_results["Precision"]))
                ).any()
                if model_exists_in_results:
                    skipped_targets.append(
                        f"- **{leaderboard}**: Model already appears in the leaderboard results."
                    )
                    already_evaluated = True

        # Deduplicate against pending/finished requests in this repo
        def load_req(status_folder):
            return load_requests(repo_id, status_folder)

        df_pending = load_req("pending")
        df_finished = load_req("finished")

        if not already_evaluated:
            if not df_pending.empty:
                existing_models_pending = df_pending[["model_name", "revision", "precision"]]
                model_exists_in_pending = (
                    (existing_models_pending["model_name"] == model_name)
                    & (existing_models_pending["revision"] == revision)
                    & (existing_models_pending["precision"] == precision_norm)
                ).any()
                if model_exists_in_pending:
                    skipped_targets.append(
                        f"- **{leaderboard}**: Model is already in pending evaluations."
                    )
                    already_evaluated = True

        if not already_evaluated:
            if not df_finished.empty:
                existing_models_finished = df_finished[["model_name", "revision", "precision"]]
                model_exists_in_finished = (
                    (existing_models_finished["model_name"] == model_name)
                    & (existing_models_finished["revision"] == revision)
                    & (existing_models_finished["precision"] == precision_norm)
                ).any()
                if model_exists_in_finished:
                    skipped_targets.append(
                        f"- **{leaderboard}**: Model has already been evaluated (finished)."
                    )
                    already_evaluated = True

        if already_evaluated:
            continue

        # Prepare submission JSON
        status = "PENDING"
        submission = {
            "model_name": model_name,
            "license": license,
            "revision": revision,
            "precision": precision_norm,
            "params": params,
            "status": status,
            "modality": modality,
            "leaderboard": leaderboard,
        }
        submission_json = json.dumps(submission, indent=2)

        precision_str = precision_norm if precision_norm else "Missing"
        file_path_in_repo = f"pending/{org}/{model_id}_eval_request_{revision}_{precision_str}.json"

        try:
            api.upload_file(
                path_or_fileobj=submission_json.encode("utf-8"),
                path_in_repo=file_path_in_repo,
                repo_id=repo_id,
                repo_type="dataset",
                token=hf_api_token,
            )
            success_targets.append(leaderboard)
        except Exception as e:
            errors.append(f"- **{leaderboard}**: Error while submitting โ€“ {str(e)}")

    # Build user-facing message
    messages = []
    if success_targets:
        messages.append(
            f"โœ… Model **'{model_name}'** has been submitted for evaluation to: "
            + ", ".join(f"**{lb}**" for lb in success_targets)
            + "."
        )
    if skipped_targets:
        messages.append("โš ๏ธ Skipped submissions:\n" + "\n".join(skipped_targets))
    if errors:
        messages.append("โŒ Errors:\n" + "\n".join(errors))

    if not messages:
        return "**No submissions were made.** Please check if the model is already pending or evaluated."

    return "\n\n".join(messages)


def load_requests(repo_id, status_folder):
    """
    Loads request JSON files from a given dataset repo and status folder:
      status_folder in {"pending", "finished", "failed"}
    """
    api = HfApi()
    requests_data = []

    hf_api_token = os.environ.get("HF_API_TOKEN", None)

    try:
        files_info = api.list_repo_files(
            repo_id=repo_id,
            repo_type="dataset",
            token=hf_api_token,
        )
    except Exception as e:
        print(f"Error accessing dataset repository {repo_id}: {e}")
        return pd.DataFrame()

    files_in_folder = [
        f for f in files_info if f.startswith(f"{status_folder}/") and f.endswith(".json")
    ]

    for file_path in files_in_folder:
        try:
            local_file_path = hf_hub_download(
                repo_id=repo_id,
                filename=file_path,
                repo_type="dataset",
                token=hf_api_token,
            )
            with open(local_file_path, "r") as f:
                request = json.load(f)
            requests_data.append(request)
        except Exception as e:
            print(f"Error loading file {file_path}: {e}")
            continue

    df = pd.DataFrame(requests_data)
    return df


# ---------- FILTER HELPERS (AraGen) ----------

def filter_df_3c3h(
    search_query,
    selected_cols,
    precision_filters,
    license_filters,
    min_size,
    max_size,
):
    # AraGen 3C3H
    df_3c3h, _, _ = load_results("aragen")
    df_ = df_3c3h.copy()

    # Sanity check on size range
    if min_size > max_size:
        min_size, max_size = max_size, min_size

    # Text search
    if search_query:
        df_ = df_[df_["Model Name"].str.contains(search_query, case=False, na=False)]

    # Precision filtering
    if precision_filters:
        include_missing = "Missing" in precision_filters
        selected_precisions = [p for p in precision_filters if p != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["Precision"].isin(selected_precisions))
                | (df_["Precision"] == "UNK")
                | (df_["Precision"].isna())
            ]
        else:
            df_ = df_[df_["Precision"].isin(selected_precisions)]

    # License filtering
    if license_filters:
        include_missing = "Missing" in license_filters
        selected_licenses = [l for l in license_filters if l != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["License"].isin(selected_licenses))
                | (df_["License"] == "UNK")
                | (df_["License"].isna())
            ]
        else:
            df_ = df_[df_["License"].isin(selected_licenses)]

    # Model size filter
    df_ = df_[
        (df_["Model Size Filter"] >= min_size) & (df_["Model Size Filter"] <= max_size)
    ]

    # Keep global Rank / Rank Spread; just reset the index
    df_ = df_.reset_index(drop=True)

    # Column ordering
    fixed_column_order = [
        "Rank",
        "Rank Spread",
        "Model Name",
        "3C3H Score",
        "95% CI (ยฑ)",
        "Correctness",
        "Completeness",
        "Conciseness",
        "Helpfulness",
        "Honesty",
        "Harmlessness",
        "Revision",
        "License",
        "Precision",
        "Model Size",
    ]

    selected_cols = [
        col
        for col in fixed_column_order
        if col in selected_cols and col in df_.columns
    ]

    return df_[selected_cols]


def filter_df_tasks(
    search_query,
    selected_cols,
    precision_filters,
    license_filters,
    min_size,
    max_size,
    task_columns,
):
    # AraGen tasks
    _, df_tasks, _ = load_results("aragen")
    df_ = df_tasks.copy()

    if min_size > max_size:
        min_size, max_size = max_size, min_size

    if search_query:
        df_ = df_[df_["Model Name"].str.contains(search_query, case=False, na=False)]

    if precision_filters:
        include_missing = "Missing" in precision_filters
        selected_precisions = [p for p in precision_filters if p != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["Precision"].isin(selected_precisions))
                | (df_["Precision"] == "UNK")
                | (df_["Precision"].isna())
            ]
        else:
            df_ = df_[df_["Precision"].isin(selected_precisions)]

    if license_filters:
        include_missing = "Missing" in license_filters
        selected_licenses = [l for l in license_filters if l != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["License"].isin(selected_licenses))
                | (df_["License"] == "UNK")
                | (df_["License"].isna())
            ]
        else:
            df_ = df_[df_["License"].isin(selected_licenses)]

    df_ = df_[
        (df_["Model Size Filter"] >= min_size) & (df_["Model Size Filter"] <= max_size)
    ]

    # Re-rank within filtered subset using first task as sort key
    if "Rank" in df_.columns:
        df_ = df_.drop(columns=["Rank"])

    if task_columns:
        first_task = task_columns[0]
        if first_task in df_.columns:
            df_ = df_.sort_values(by=first_task, ascending=False)
        else:
            df_ = df_.sort_values(by="Model Name", ascending=True)
    else:
        df_ = df_.sort_values(by="Model Name", ascending=True)

    df_ = df_.reset_index(drop=True)
    df_.insert(0, "Rank", range(1, len(df_) + 1))

    fixed_column_order = [
        "Rank",
        "Model Name",
        "Question Answering (QA)",
        "Orthographic and Grammatical Analysis",
        "Safety",
        "Reasoning",
        "Revision",
        "License",
        "Precision",
        "Model Size",
    ]

    selected_cols = [
        col for col in fixed_column_order if col in selected_cols and col in df_.columns
    ]
    return df_[selected_cols]


# ---------- FILTER HELPERS (HindiGen) ----------

def filter_df_3c3h_hindigen(
    search_query,
    selected_cols,
    precision_filters,
    license_filters,
    min_size,
    max_size,
):
    df_3c3h_hi, _, _ = load_results("hindigen")
    df_ = df_3c3h_hi.copy()

    if min_size > max_size:
        min_size, max_size = max_size, min_size

    if search_query:
        df_ = df_[df_["Model Name"].str.contains(search_query, case=False, na=False)]

    if precision_filters:
        include_missing = "Missing" in precision_filters
        selected_precisions = [p for p in precision_filters if p != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["Precision"].isin(selected_precisions))
                | (df_["Precision"] == "UNK")
                | (df_["Precision"].isna())
            ]
        else:
            df_ = df_[df_["Precision"].isin(selected_precisions)]

    if license_filters:
        include_missing = "Missing" in license_filters
        selected_licenses = [l for l in license_filters if l != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["License"].isin(selected_licenses))
                | (df_["License"] == "UNK")
                | (df_["License"].isna())
            ]
        else:
            df_ = df_[df_["License"].isin(selected_licenses)]

    df_ = df_[
        (df_["Model Size Filter"] >= min_size) & (df_["Model Size Filter"] <= max_size)
    ]

    df_ = df_.reset_index(drop=True)

    fixed_column_order = [
        "Rank",
        "Rank Spread",
        "Model Name",
        "3C3H Score",
        "95% CI (ยฑ)",
        "Correctness",
        "Completeness",
        "Conciseness",
        "Helpfulness",
        "Honesty",
        "Harmlessness",
        "Revision",
        "License",
        "Precision",
        "Model Size",
    ]

    selected_cols = [
        col
        for col in fixed_column_order
        if col in selected_cols and col in df_.columns
    ]

    return df_[selected_cols]


def filter_df_tasks_hindigen(
    search_query,
    selected_cols,
    precision_filters,
    license_filters,
    min_size,
    max_size,
    task_columns,
):
    _, df_tasks_hi, _ = load_results("hindigen")
    df_ = df_tasks_hi.copy()

    if min_size > max_size:
        min_size, max_size = max_size, min_size

    if search_query:
        df_ = df_[df_["Model Name"].str.contains(search_query, case=False, na=False)]

    if precision_filters:
        include_missing = "Missing" in precision_filters
        selected_precisions = [p for p in precision_filters if p != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["Precision"].isin(selected_precisions))
                | (df_["Precision"] == "UNK")
                | (df_["Precision"].isna())
            ]
        else:
            df_ = df_[df_["Precision"].isin(selected_precisions)]

    if license_filters:
        include_missing = "Missing" in license_filters
        selected_licenses = [l for l in license_filters if l != "Missing"]
        if include_missing:
            df_ = df_[
                (df_["License"].isin(selected_licenses))
                | (df_["License"] == "UNK")
                | (df_["License"].isna())
            ]
        else:
            df_ = df_[df_["License"].isin(selected_licenses)]

    df_ = df_[
        (df_["Model Size Filter"] >= min_size) & (df_["Model Size Filter"] <= max_size)
    ]

    if "Rank" in df_.columns:
        df_ = df_.drop(columns=["Rank"])

    if task_columns:
        first_task = task_columns[0]
        if first_task in df_.columns:
            df_ = df_.sort_values(by=first_task, ascending=False)
        else:
            df_ = df_.sort_values(by="Model Name", ascending=True)
    else:
        df_ = df_.sort_values(by="Model Name", ascending=True)

    df_ = df_.reset_index(drop=True)
    df_.insert(0, "Rank", range(1, len(df_) + 1))

    fixed_column_order = [
        "Rank",
        "Model Name",
        "Question Answering (QA)",
        "Grammar",
        "Safety",
        "Revision",
        "License",
        "Precision",
        "Model Size",
    ]

    selected_cols = [
        col for col in fixed_column_order if col in selected_cols and col in df_.columns
    ]
    return df_[selected_cols]


def filter_if_df(search_query, selected_cols, family_filters, min_size, max_size):
    """
    Filters the instruction-following dataframe based on various criteria.
    We have removed 'Filter by Type' and 'Filter by Creator'.
    """
    df_ = load_if_data().copy()
    if min_size > max_size:
        min_size, max_size = max_size, min_size
    
    # Search by model name
    if search_query:
        df_ = df_[df_["Model Name"].str.contains(search_query, case=False, na=False)]
    
    # Filter by Family only (Creator and Type filters removed)
    if family_filters:
        df_ = df_[df_["Family"].isin(family_filters)]
    
    # Filter by Model Size
    df_ = df_[
        (df_["Model Size Filter"] >= min_size) & (df_["Model Size Filter"] <= max_size)
    ]
    
    # Re-rank within the filtered subset
    if "Rank" in df_.columns:
        df_ = df_.drop(columns=["Rank"])
    df_ = df_.reset_index(drop=True)
    df_.insert(0, "Rank", range(1, len(df_) + 1))
    
    fixed_column_order = [
        "Rank",
        "Model Name",
        "Average Accuracy (Ar)",
        "Ar Prompt-lvl",
        "Ar Instruction-lvl",
        "Average Accuracy (En)",
        "En Prompt-lvl",
        "En Instruction-lvl",
        "Type",
        "Creator",
        "Family",
        "Size (B)",
        "Base Model",
        "Context Window",
        "Lang.",
    ]
    
    selected_cols = [
        col for col in fixed_column_order if col in selected_cols and col in df_.columns
    ]
    return df_[selected_cols]


def main():
    # Load AraGen, HindiGen, and IFEval data
    df_3c3h_ar, df_tasks_ar, task_columns_ar = load_results("aragen")
    df_3c3h_hi, df_tasks_hi, task_columns_hi = load_results("hindigen")
    df_if = load_if_data()  # Instruction Following DF

    # ---------- AraGen options ----------
    precision_options_3c3h = sorted(df_3c3h_ar["Precision"].dropna().unique().tolist())
    precision_options_3c3h = [p for p in precision_options_3c3h if p != "UNK"]
    precision_options_3c3h.append("Missing")

    license_options_3c3h = sorted(df_3c3h_ar["License"].dropna().unique().tolist())
    license_options_3c3h = [l for l in license_options_3c3h if l != "UNK"]
    license_options_3c3h.append("Missing")

    precision_options_tasks = sorted(df_tasks_ar["Precision"].dropna().unique().tolist())
    precision_options_tasks = [p for p in precision_options_tasks if p != "UNK"]
    precision_options_tasks.append("Missing")

    license_options_tasks = sorted(df_tasks_ar["License"].dropna().unique().tolist())
    license_options_tasks = [l for l in license_options_tasks if l != "UNK"]
    license_options_tasks.append("Missing")

    min_model_size_3c3h = int(df_3c3h_ar["Model Size Filter"].min())
    max_model_size_3c3h = int(df_3c3h_ar["Model Size Filter"].max())

    min_model_size_tasks = int(df_tasks_ar["Model Size Filter"].min())
    max_model_size_tasks = int(df_tasks_ar["Model Size Filter"].max())

    column_choices_3c3h = [
        col
        for col in df_3c3h_ar.columns.tolist()
        if col
        not in [
            "Model Size Filter",
            "3C3H Score Lower",
            "3C3H Score Upper",
        ]
    ]

    column_choices_tasks = [
        col
        for col in df_tasks_ar.columns.tolist()
        if col != "Model Size Filter"
    ]

    # ---------- HindiGen options ----------
    precision_options_3c3h_hi = sorted(df_3c3h_hi["Precision"].dropna().unique().tolist())
    precision_options_3c3h_hi = [p for p in precision_options_3c3h_hi if p != "UNK"]
    precision_options_3c3h_hi.append("Missing")

    license_options_3c3h_hi = sorted(df_3c3h_hi["License"].dropna().unique().tolist())
    license_options_3c3h_hi = [l for l in license_options_3c3h_hi if l != "UNK"]
    license_options_3c3h_hi.append("Missing")

    precision_options_tasks_hi = sorted(df_tasks_hi["Precision"].dropna().unique().tolist())
    precision_options_tasks_hi = [p for p in precision_options_tasks_hi if p != "UNK"]
    precision_options_tasks_hi.append("Missing")

    license_options_tasks_hi = sorted(df_tasks_hi["License"].dropna().unique().tolist())
    license_options_tasks_hi = [l for l in license_options_tasks_hi if l != "UNK"]
    license_options_tasks_hi.append("Missing")

    min_model_size_3c3h_hi = int(df_3c3h_hi["Model Size Filter"].min())
    max_model_size_3c3h_hi = int(df_3c3h_hi["Model Size Filter"].max())

    min_model_size_tasks_hi = int(df_tasks_hi["Model Size Filter"].min())
    max_model_size_tasks_hi = int(df_tasks_hi["Model Size Filter"].max())

    column_choices_3c3h_hi = [
        col
        for col in df_3c3h_hi.columns.tolist()
        if col
        not in [
            "Model Size Filter",
            "3C3H Score Lower",
            "3C3H Score Upper",
        ]
    ]

    column_choices_tasks_hi = [
        col
        for col in df_tasks_hi.columns.tolist()
        if col != "Model Size Filter"
    ]

    # ---------- IFEval options ----------
    family_options_if = sorted(df_if["Family"].dropna().unique().tolist())
    min_model_size_if = int(df_if["Model Size Filter"].min())
    max_model_size_if = int(df_if["Model Size Filter"].max())

    all_if_columns = [
        "Rank",
        "Model Name",
        "Average Accuracy (Ar)",
        "Ar Prompt-lvl",
        "Ar Instruction-lvl",
        "Average Accuracy (En)",
        "En Prompt-lvl",
        "En Instruction-lvl",
        "Type",
        "Creator",
        "Family",
        "Size (B)",
        "Base Model",
        "Context Window",
        "Lang.",
    ]
    default_if_columns = [
        "Rank",
        "Model Name",
        "Average Accuracy (Ar)",
        "Ar Prompt-lvl",
        "Ar Instruction-lvl",
        "Average Accuracy (En)",
    ]

    with gr.Blocks() as demo:
        gr.HTML(HEADER)

        with gr.Tabs():
            #
            # AL Leaderboards Tab (AraGen + IFEval)
            #
            with gr.Tab("AL Leaderboards ๐Ÿ…"):
                with gr.Tabs():
                    # -------------------------
                    # Sub-Tab: AraGen Leaderboards
                    # -------------------------
                    with gr.Tab("๐Ÿช AraGen Leaderboards (v3)"):
                        with gr.Tabs():
                            # 3C3H Scores
                            with gr.Tab("3C3H Scores"):
                                with gr.Accordion("โš™๏ธ Filters", open=False):
                                    with gr.Row():
                                        search_box_3c3h = gr.Textbox(
                                            placeholder="Search for models...", 
                                            label="Search", 
                                            interactive=True,
                                        )
                                    with gr.Row():
                                        column_selector_3c3h = gr.CheckboxGroup(
                                            choices=column_choices_3c3h,
                                            value=[
                                                "Rank",
                                                "Rank Spread",
                                                "Model Name",
                                                "3C3H Score",
                                                "95% CI (ยฑ)",
                                                "Correctness",
                                                "Completeness",
                                                "Conciseness",
                                                "Helpfulness",
                                                "Honesty",
                                                "Harmlessness",
                                            ],
                                            label="Select columns to display",
                                        )
                                    with gr.Row():
                                        license_filter_3c3h = gr.CheckboxGroup(
                                            choices=license_options_3c3h,
                                            value=license_options_3c3h.copy(),
                                            label="Filter by License",
                                        )
                                        precision_filter_3c3h = gr.CheckboxGroup(
                                            choices=precision_options_3c3h,
                                            value=precision_options_3c3h.copy(),
                                            label="Filter by Precision",
                                        )
                                    with gr.Row():
                                        model_size_min_filter_3c3h = gr.Slider(
                                            minimum=min_model_size_3c3h,
                                            maximum=max_model_size_3c3h,
                                            value=min_model_size_3c3h,
                                            step=1,
                                            label="Minimum Model Size",
                                            interactive=True,
                                        )
                                        model_size_max_filter_3c3h = gr.Slider(
                                            minimum=min_model_size_3c3h,
                                            maximum=max_model_size_3c3h,
                                            value=max_model_size_3c3h,
                                            step=1,
                                            label="Maximum Model Size",
                                            interactive=True,
                                        )
                                leaderboard_3c3h = gr.Dataframe(
                                    df_3c3h_ar[
                                        [
                                            "Rank",
                                            "Rank Spread",
                                            "Model Name",
                                            "3C3H Score",
                                            "95% CI (ยฑ)",
                                            "Correctness",
                                            "Completeness",
                                            "Conciseness",
                                            "Helpfulness",
                                            "Honesty",
                                            "Harmlessness",
                                        ]
                                    ],
                                    interactive=False,
                                )
                                filter_inputs_3c3h = [
                                    search_box_3c3h,
                                    column_selector_3c3h,
                                    precision_filter_3c3h,
                                    license_filter_3c3h,
                                    model_size_min_filter_3c3h,
                                    model_size_max_filter_3c3h,
                                ]
                                search_box_3c3h.submit(
                                    filter_df_3c3h,
                                    inputs=filter_inputs_3c3h,
                                    outputs=leaderboard_3c3h,
                                )
                                for component in filter_inputs_3c3h:
                                    component.change(
                                        filter_df_3c3h,
                                        inputs=filter_inputs_3c3h,
                                        outputs=leaderboard_3c3h,
                                    )

                            # Tasks Scores
                            with gr.Tab("Tasks Scores"):
                                gr.Markdown(
                                    "This table is sorted based on the **first task** "
                                    "(e.g., Question Answering (QA))."
                                )
                                with gr.Accordion("โš™๏ธ Filters", open=False):
                                    with gr.Row():
                                        search_box_tasks = gr.Textbox(
                                            placeholder="Search for models...", 
                                            label="Search", 
                                            interactive=True,
                                        )
                                    with gr.Row():
                                        column_selector_tasks = gr.CheckboxGroup(
                                            choices=column_choices_tasks,
                                            value=["Rank", "Model Name"] + task_columns_ar,
                                            label="Select columns to display",
                                        )
                                    with gr.Row():
                                        license_filter_tasks = gr.CheckboxGroup(
                                            choices=license_options_tasks,
                                            value=license_options_tasks.copy(),
                                            label="Filter by License",
                                        )
                                        precision_filter_tasks = gr.CheckboxGroup(
                                            choices=precision_options_tasks,
                                            value=precision_options_tasks.copy(),
                                            label="Filter by Precision",
                                        )
                                    with gr.Row():
                                        model_size_min_filter_tasks = gr.Slider(
                                            minimum=min_model_size_tasks,
                                            maximum=max_model_size_tasks,
                                            value=min_model_size_tasks,
                                            step=1,
                                            label="Minimum Model Size",
                                            interactive=True,
                                        )
                                        model_size_max_filter_tasks = gr.Slider(
                                            minimum=min_model_size_tasks,
                                            maximum=max_model_size_tasks,
                                            value=max_model_size_tasks,
                                            step=1,
                                            label="Maximum Model Size",
                                            interactive=True,
                                        )
                                leaderboard_tasks = gr.Dataframe(
                                    df_tasks_ar[["Rank", "Model Name"] + task_columns_ar],
                                    interactive=False,
                                )
                                filter_inputs_tasks = [
                                    search_box_tasks,
                                    column_selector_tasks,
                                    precision_filter_tasks,
                                    license_filter_tasks,
                                    model_size_min_filter_tasks,
                                    model_size_max_filter_tasks,
                                ]
                                search_box_tasks.submit(
                                    lambda sq, cols, pf, lf, min_val, max_val: filter_df_tasks(
                                        sq, cols, pf, lf, min_val, max_val, task_columns_ar
                                    ),
                                    inputs=filter_inputs_tasks,
                                    outputs=leaderboard_tasks,
                                )
                                for component in filter_inputs_tasks:
                                    component.change(
                                        lambda sq, cols, pf, lf, min_val, max_val: filter_df_tasks(
                                            sq, cols, pf, lf, min_val, max_val, task_columns_ar
                                        ),
                                        inputs=filter_inputs_tasks,
                                        outputs=leaderboard_tasks,
                                    )

                    # -------------------------
                    # Sub-Tab: Instruction Following Leaderboard
                    # -------------------------
                    with gr.Tab("๐Ÿ—ก๏ธ Instruction Following Leaderboard"):
                        with gr.Accordion("โš™๏ธ Filters", open=False):
                            with gr.Row():
                                search_box_if = gr.Textbox(
                                    placeholder="Search for models...", 
                                    label="Search", 
                                    interactive=True,
                                )
                            with gr.Row():
                                column_selector_if = gr.CheckboxGroup(
                                    choices=all_if_columns,
                                    value=default_if_columns,
                                    label="Select columns to display",
                                )
                            with gr.Row():
                                family_filter_if = gr.CheckboxGroup(
                                    choices=family_options_if,
                                    value=family_options_if.copy(),
                                    label="Filter by Family",
                                )
                            with gr.Row():
                                model_size_min_filter_if = gr.Slider(
                                    minimum=min_model_size_if,
                                    maximum=max_model_size_if,
                                    value=min_model_size_if,
                                    step=1,
                                    label="Minimum Model Size",
                                    interactive=True,
                                )
                                model_size_max_filter_if = gr.Slider(
                                    minimum=min_model_size_if,
                                    maximum=max_model_size_if,
                                    value=max_model_size_if,
                                    step=1,
                                    label="Maximum Model Size",
                                    interactive=True,
                                )
                        leaderboard_if = gr.Dataframe(
                            df_if[default_if_columns],
                            interactive=False,
                        )
                        filter_inputs_if = [
                            search_box_if,
                            column_selector_if,
                            family_filter_if,
                            model_size_min_filter_if,
                            model_size_max_filter_if,
                        ]
                        search_box_if.submit(
                            filter_if_df, inputs=filter_inputs_if, outputs=leaderboard_if
                        )
                        for component in filter_inputs_if:
                            component.change(
                                filter_if_df, inputs=filter_inputs_if, outputs=leaderboard_if
                            )

            #
            # HindiGen Leaderboards Tab
            #
            with gr.Tab("HindiGen Leaderboards ๐Ÿ‡ฎ๐Ÿ‡ณ"):
                with gr.Tabs():
                    # 3C3H Scores
                    with gr.Tab("3C3H Scores"):
                        with gr.Accordion("โš™๏ธ Filters", open=False):
                            with gr.Row():
                                search_box_3c3h_hi = gr.Textbox(
                                    placeholder="Search for models...", 
                                    label="Search", 
                                    interactive=True,
                                )
                            with gr.Row():
                                column_selector_3c3h_hi = gr.CheckboxGroup(
                                    choices=column_choices_3c3h_hi,
                                    value=[
                                        "Rank",
                                        "Rank Spread",
                                        "Model Name",
                                        "3C3H Score",
                                        "95% CI (ยฑ)",
                                        "Correctness",
                                        "Completeness",
                                        "Conciseness",
                                        "Helpfulness",
                                        "Honesty",
                                        "Harmlessness",
                                    ],
                                    label="Select columns to display",
                                )
                            with gr.Row():
                                license_filter_3c3h_hi = gr.CheckboxGroup(
                                    choices=license_options_3c3h_hi,
                                    value=license_options_3c3h_hi.copy(),
                                    label="Filter by License",
                                )
                                precision_filter_3c3h_hi = gr.CheckboxGroup(
                                    choices=precision_options_3c3h_hi,
                                    value=precision_options_3c3h_hi.copy(),
                                    label="Filter by Precision",
                                )
                            with gr.Row():
                                model_size_min_filter_3c3h_hi = gr.Slider(
                                    minimum=min_model_size_3c3h_hi,
                                    maximum=max_model_size_3c3h_hi,
                                    value=min_model_size_3c3h_hi,
                                    step=1,
                                    label="Minimum Model Size",
                                    interactive=True,
                                )
                                model_size_max_filter_3c3h_hi = gr.Slider(
                                    minimum=min_model_size_3c3h_hi,
                                    maximum=max_model_size_3c3h_hi,
                                    value=max_model_size_3c3h_hi,
                                    step=1,
                                    label="Maximum Model Size",
                                    interactive=True,
                                )
                        leaderboard_3c3h_hi = gr.Dataframe(
                            df_3c3h_hi[
                                [
                                    "Rank",
                                    "Rank Spread",
                                    "Model Name",
                                    "3C3H Score",
                                    "95% CI (ยฑ)",
                                    "Correctness",
                                    "Completeness",
                                    "Conciseness",
                                    "Helpfulness",
                                    "Honesty",
                                    "Harmlessness",
                                ]
                            ],
                            interactive=False,
                        )
                        filter_inputs_3c3h_hi = [
                            search_box_3c3h_hi,
                            column_selector_3c3h_hi,
                            precision_filter_3c3h_hi,
                            license_filter_3c3h_hi,
                            model_size_min_filter_3c3h_hi,
                            model_size_max_filter_3c3h_hi,
                        ]
                        search_box_3c3h_hi.submit(
                            filter_df_3c3h_hindigen,
                            inputs=filter_inputs_3c3h_hi,
                            outputs=leaderboard_3c3h_hi,
                        )
                        for component in filter_inputs_3c3h_hi:
                            component.change(
                                filter_df_3c3h_hindigen,
                                inputs=filter_inputs_3c3h_hi,
                                outputs=leaderboard_3c3h_hi,
                            )

                    # Tasks Scores
                    with gr.Tab("Tasks Scores"):
                        gr.Markdown(
                            "This table is sorted based on the **first task** "
                            "(e.g., Question Answering (QA))."
                        )
                        with gr.Accordion("โš™๏ธ Filters", open=False):
                            with gr.Row():
                                search_box_tasks_hi = gr.Textbox(
                                    placeholder="Search for models...", 
                                    label="Search", 
                                    interactive=True,
                                )
                            with gr.Row():
                                column_selector_tasks_hi = gr.CheckboxGroup(
                                    choices=column_choices_tasks_hi,
                                    value=["Rank", "Model Name"] + task_columns_hi,
                                    label="Select columns to display",
                                )
                            with gr.Row():
                                license_filter_tasks_hi = gr.CheckboxGroup(
                                    choices=license_options_tasks_hi,
                                    value=license_options_tasks_hi.copy(),
                                    label="Filter by License",
                                )
                                precision_filter_tasks_hi = gr.CheckboxGroup(
                                    choices=precision_options_tasks_hi,
                                    value=precision_options_tasks_hi.copy(),
                                    label="Filter by Precision",
                                )
                            with gr.Row():
                                model_size_min_filter_tasks_hi = gr.Slider(
                                    minimum=min_model_size_tasks_hi,
                                    maximum=max_model_size_tasks_hi,
                                    value=min_model_size_tasks_hi,
                                    step=1,
                                    label="Minimum Model Size",
                                    interactive=True,
                                )
                                model_size_max_filter_tasks_hi = gr.Slider(
                                    minimum=min_model_size_tasks_hi,
                                    maximum=max_model_size_tasks_hi,
                                    value=max_model_size_tasks_hi,
                                    step=1,
                                    label="Maximum Model Size",
                                    interactive=True,
                                )
                        leaderboard_tasks_hi = gr.Dataframe(
                            df_tasks_hi[["Rank", "Model Name"] + task_columns_hi],
                            interactive=False,
                        )
                        filter_inputs_tasks_hi = [
                            search_box_tasks_hi,
                            column_selector_tasks_hi,
                            precision_filter_tasks_hi,
                            license_filter_tasks_hi,
                            model_size_min_filter_tasks_hi,
                            model_size_max_filter_tasks_hi,
                        ]
                        search_box_tasks_hi.submit(
                            lambda sq, cols, pf, lf, min_val, max_val: filter_df_tasks_hindigen(
                                sq, cols, pf, lf, min_val, max_val, task_columns_hi
                            ),
                            inputs=filter_inputs_tasks_hi,
                            outputs=leaderboard_tasks_hi,
                        )
                        for component in filter_inputs_tasks_hi:
                            component.change(
                                lambda sq, cols, pf, lf, min_val, max_val: filter_df_tasks_hindigen(
                                    sq, cols, pf, lf, min_val, max_val, task_columns_hi
                                ),
                                inputs=filter_inputs_tasks_hi,
                                outputs=leaderboard_tasks_hi,
                            )

            #
            # About & Submit Tab
            #
            with gr.Tab("About & Submit Page ๐Ÿ“"):
                # Load request tables for all three request datasets
                df_pending_ar = load_requests(ARAGEN_REQUESTS_REPO_ID, "pending")
                df_finished_ar = load_requests(ARAGEN_REQUESTS_REPO_ID, "finished")
                df_failed_ar = load_requests(ARAGEN_REQUESTS_REPO_ID, "failed")

                df_pending_hi = load_requests(HINDIGEN_REQUESTS_REPO_ID, "pending")
                df_finished_hi = load_requests(HINDIGEN_REQUESTS_REPO_ID, "finished")
                df_failed_hi = load_requests(HINDIGEN_REQUESTS_REPO_ID, "failed")

                df_pending_if = load_requests(IFEVAL_REQUESTS_REPO_ID, "pending")
                df_finished_if = load_requests(IFEVAL_REQUESTS_REPO_ID, "finished")
                df_failed_if = load_requests(IFEVAL_REQUESTS_REPO_ID, "failed")
                
                gr.Markdown(ABOUT_SECTION)
                
                gr.Markdown("## Submit Your Model for Evaluation")
                with gr.Column():
                    model_name_input = gr.Textbox(
                        label="Model Name",
                        placeholder="Enter the full model name from HuggingFace Hub (e.g., inceptionai/jais-family-30b-8k)",
                    )
                    revision_input = gr.Textbox(
                        label="Revision", placeholder="main", value="main"
                    )
                    precision_input = gr.Dropdown(
                        choices=["float16", "float32", "bfloat16", "8bit", "4bit"],
                        label="Precision",
                        value="float16",
                    )
                    params_input = gr.Textbox(
                        label="Params",
                        placeholder="Enter the approximate number of parameters as Integer (e.g., 7, 13, 30, 70 ...)",
                    )
                    license_input = gr.Textbox(
                        label="License",
                        placeholder="Enter the license type (Generic one is 'Open' in case no License is provided)",
                        value="Open",
                    )
                    modality_input = gr.Radio(
                        choices=["Text"],
                        label="Modality",
                        value="Text",
                    )
                    leaderboard_targets = gr.CheckboxGroup(
                        choices=["AraGen", "HindiGen", "IFEval"],
                        label="Choose which leaderboard(s) to submit to",
                        info="You must choose at least one.",
                    )
                    submit_button = gr.Button("Submit Model")
                    submission_result = gr.Markdown()
                    submit_button.click(
                        submit_model,
                        inputs=[
                            model_name_input,
                            revision_input,
                            precision_input,
                            params_input,
                            license_input,
                            modality_input,
                            leaderboard_targets,
                        ],
                        outputs=submission_result,
                    )

                gr.Markdown("## Evaluation Status")

                gr.Markdown("### AraGen Requests")
                with gr.Accordion(
                    f"AraGen โ€“ Pending Evaluations ({len(df_pending_ar)})", open=False
                ):
                    if not df_pending_ar.empty:
                        gr.Dataframe(df_pending_ar)
                    else:
                        gr.Markdown("No pending evaluations.")
                with gr.Accordion(
                    f"AraGen โ€“ Finished Evaluations ({len(df_finished_ar)})", open=False
                ):
                    if not df_finished_ar.empty:
                        gr.Dataframe(df_finished_ar)
                    else:
                        gr.Markdown("No finished evaluations.")
                with gr.Accordion(
                    f"AraGen โ€“ Failed Evaluations ({len(df_failed_ar)})", open=False
                ):
                    if not df_failed_ar.empty:
                        gr.Dataframe(df_failed_ar)
                    else:
                        gr.Markdown("No failed evaluations.")

                gr.Markdown("### HindiGen Requests")
                with gr.Accordion(
                    f"HindiGen โ€“ Pending Evaluations ({len(df_pending_hi)})", open=False
                ):
                    if not df_pending_hi.empty:
                        gr.Dataframe(df_pending_hi)
                    else:
                        gr.Markdown("No pending evaluations.")
                with gr.Accordion(
                    f"HindiGen โ€“ Finished Evaluations ({len(df_finished_hi)})", open=False
                ):
                    if not df_finished_hi.empty:
                        gr.Dataframe(df_finished_hi)
                    else:
                        gr.Markdown("No finished evaluations.")
                with gr.Accordion(
                    f"HindiGen โ€“ Failed Evaluations ({len(df_failed_hi)})", open=False
                ):
                    if not df_failed_hi.empty:
                        gr.Dataframe(df_failed_hi)
                    else:
                        gr.Markdown("No failed evaluations.")

                gr.Markdown("### IFEval Requests")
                with gr.Accordion(
                    f"IFEval โ€“ Pending Evaluations ({len(df_pending_if)})", open=False
                ):
                    if not df_pending_if.empty:
                        gr.Dataframe(df_pending_if)
                    else:
                        gr.Markdown("No pending evaluations.")
                with gr.Accordion(
                    f"IFEval โ€“ Finished Evaluations ({len(df_finished_if)})", open=False
                ):
                    if not df_finished_if.empty:
                        gr.Dataframe(df_finished_if)
                    else:
                        gr.Markdown("No finished evaluations.")
                with gr.Accordion(
                    f"IFEval โ€“ Failed Evaluations ({len(df_failed_if)})", open=False
                ):
                    if not df_failed_if.empty:
                        gr.Dataframe(df_failed_if)
                    else:
                        gr.Markdown("No failed evaluations.")

            # Citation Section
            with gr.Row():
                with gr.Accordion("๐Ÿ“™ Citation", open=False):
                    citation_button = gr.Textbox(
                        value=CITATION_BUTTON_TEXT,
                        label=CITATION_BUTTON_LABEL,
                        lines=8,
                        elem_id="citation-button",
                        show_copy_button=True,
                    )
        
        gr.HTML(BOTTOM_LOGO)
        
        demo.launch()


if __name__ == "__main__":
    main()