File size: 24,343 Bytes
d64ffef
 
 
 
 
 
46dbc41
d64ffef
 
 
 
 
 
46dbc41
d64ffef
 
 
 
7901bf8
d64ffef
 
7901bf8
 
 
d64ffef
 
7901bf8
 
d64ffef
 
 
7901bf8
 
 
d64ffef
 
 
7901bf8
 
 
d64ffef
 
 
 
7901bf8
 
 
43752dc
d64ffef
 
ff61dce
0877d91
 
 
 
 
d684081
0877d91
 
 
 
 
 
d684081
 
0877d91
d684081
0877d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d684081
 
0877d91
d684081
0877d91
 
 
d684081
 
0877d91
ff61dce
 
 
0877d91
 
 
 
ff61dce
 
0877d91
 
 
 
ff61dce
0877d91
ff61dce
0877d91
 
 
 
 
 
 
 
 
 
 
ff61dce
 
0877d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff61dce
0877d91
 
 
 
 
 
ff61dce
 
0877d91
 
 
 
 
 
 
43752dc
0877d91
 
 
 
 
 
 
 
 
43752dc
ff61dce
0877d91
ff61dce
0877d91
 
 
 
 
 
 
ff61dce
 
0877d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff61dce
0877d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff61dce
43752dc
 
d64ffef
d684081
43752dc
 
 
 
 
 
d64ffef
2b5f545
 
 
46dbc41
 
 
 
 
2b5f545
 
 
 
 
 
 
 
46dbc41
2b5f545
46dbc41
2b5f545
 
 
46dbc41
2b5f545
 
 
 
 
 
 
46dbc41
 
 
 
 
 
 
 
43752dc
 
 
 
 
 
 
d64ffef
 
43752dc
d64ffef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43752dc
 
 
 
 
 
 
 
 
 
 
 
7901bf8
 
 
 
 
43752dc
 
 
 
 
 
 
 
7901bf8
43752dc
 
 
 
7901bf8
43752dc
 
7901bf8
43752dc
 
 
d64ffef
d684081
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
import gradio as gr
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd

from data import load_data
from leaderboard import compute_leaderboard
from rank_through_time import (
    plot_rank_for_subdataset,
    plot_value_for_subdataset,
)

df = load_data()

ALL_METRICS = sorted(df["metric"].unique().tolist())
ALL_SUBDATASETS = sorted(df["subdataset"].unique().tolist())
ALL_MODELS = sorted(df["model"].unique().tolist())
ALL_FREQUENCIES = sorted(df["frequency"].unique().tolist())


def build_table(metric, subdataset, frequency, models):
    data = load_data()
    sub = data[data["metric"] == metric]
    if subdataset != "All":
        sub = sub[sub["subdataset"] == subdataset]
    if frequency != "All":
        sub = sub[sub["frequency"] == frequency]
    if models:
        sub = sub[sub["model"].isin(models)]
    pivot = sub.pivot_table(
        index=["subdataset", "frequency", "cutoff"],
        columns="model",
        values="value",
    )
    pivot = pivot.sort_index()
    pivot = pivot.reset_index()
    # Format numeric columns to 3 decimal places
    num_cols = pivot.select_dtypes(include="number").columns
    pivot[num_cols] = pivot[num_cols].round(3)
    return pivot


def build_plots(metric, subdataset):
    data = load_data()
    fig_rank = plot_rank_for_subdataset(data, metric, subdataset)
    fig_value = plot_value_for_subdataset(data, metric, subdataset)
    return fig_rank, fig_value


CUSTOM_CSS = """\
/* ═══════════════════════════════════════════════════════════
   LIGHT MODE β€” Ethereal Glass
   ═══════════════════════════════════════════════════════════ */

/* ── Page background with floating aurora ─────────────────── */
.gradio-container {
    background:
        radial-gradient(ellipse at 20% 0%, rgba(124, 58, 237, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(59, 130, 246, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(6, 182, 212, 0.08) 0%, transparent 60%),
        linear-gradient(160deg, #f5f3ff 0%, #eef2ff 40%, #f0fdfa 100%) !important;
    color: #1e1b4b !important;
}

/* ── Title banner β€” gradient with glow ────────────────────── */
.title-banner {
    background: linear-gradient(120deg, #7c3aed, #3b82f6, #06b6d4) !important;
    padding: 20px 28px !important;
    border-radius: 20px;
    margin-bottom: 14px !important;
    box-shadow:
        0 8px 32px rgba(124, 58, 237, 0.3),
        0 0 60px rgba(59, 130, 246, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}
.title-banner::after {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 40%,
        rgba(255, 255, 255, 0.08) 50%,
        transparent 60%
    );
    animation: shimmer 6s ease-in-out infinite;
}
@keyframes shimmer {
    0%, 100% { transform: translateX(-30%) translateY(-30%) rotate(0deg); }
    50% { transform: translateX(30%) translateY(30%) rotate(5deg); }
}
.title-banner h1 {
    color: #ffffff !important;
    margin: 0 !important;
    position: relative;
    z-index: 1;
    letter-spacing: -0.02em;
}

/* ── Accent top bar β€” animated gradient ───────────────────── */
.gradio-container::before {
    content: "";
    display: block;
    height: 3px;
    background: linear-gradient(90deg, #7c3aed, #3b82f6, #06b6d4, #7c3aed);
    background-size: 200% 100%;
    animation: gradientSlide 4s linear infinite;
    margin: -16px -16px 16px -16px;
}
@keyframes gradientSlide {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

/* ── Header card β€” frosted glass ──────────────────────────── */
.gradio-container > .main > .wrap > div:first-child {
    background: rgba(255, 255, 255, 0.55) !important;
    border: 1px solid rgba(124, 58, 237, 0.1);
    border-radius: 16px;
    padding: 24px 28px;
    margin-bottom: 14px;
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    box-shadow:
        0 4px 24px rgba(124, 58, 237, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
    color: #1e1b4b !important;
}

/* ── Tab buttons β€” pill glass ─────────────────────────────── */
button.tab-nav-button {
    color: #4c1d95 !important;
    background: rgba(255, 255, 255, 0.5) !important;
    border-radius: 999px !important;
    border: 1px solid rgba(124, 58, 237, 0.12) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.3s ease !important;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.06);
}
button.tab-nav-button:hover {
    background: rgba(124, 58, 237, 0.08) !important;
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.12);
    transform: translateY(-1px);
}
button.tab-nav-button.selected {
    color: #ffffff !important;
    border-color: transparent !important;
    background-image: linear-gradient(120deg, #7c3aed, #3b82f6) !important;
    box-shadow:
        0 6px 24px rgba(124, 58, 237, 0.35),
        0 0 40px rgba(59, 130, 246, 0.1);
}

/* ── Table β€” glass with depth ─────────────────────────────── */
.table-wrap {
    border-radius: 16px !important;
    overflow: hidden;
    border: 1px solid rgba(124, 58, 237, 0.1) !important;
    box-shadow: 0 4px 24px rgba(124, 58, 237, 0.08);
}
.table-wrap thead th {
    background: linear-gradient(120deg, #4c1d95, #1e40af) !important;
    color: #ffffff !important;
    letter-spacing: 0.03em;
}
.table-wrap tbody tr {
    transition: all 0.2s ease;
}
.table-wrap tbody tr:hover {
    background: rgba(124, 58, 237, 0.06) !important;
}

/* ── Dropdowns & form elements ────────────────────────────── */
.gr-dropdown, .multiselect-dropdown {
    border-radius: 12px !important;
    border: 1px solid rgba(124, 58, 237, 0.18) !important;
    background: rgba(245, 243, 255, 0.6) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #1e1b4b !important;
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.06);
}

/* ── Light mode: inputs ───────────────────────────────────── */
.gradio-container input,
.gradio-container textarea,
.gradio-container select {
    background: rgba(245, 243, 255, 0.5) !important;
    border: 1px solid rgba(124, 58, 237, 0.15) !important;
    border-radius: 10px !important;
    color: #1e1b4b !important;
}

/* ── Light mode: all panels/blocks transparent ────────────── */
.gr-group,
.gr-box,
.gr-panel,
.gr-form,
.gr-block,
.block,
.form,
.panel,
.tabitem,
.tabitem > div,
.tab-content,
.gap,
.gr-padded,
.wrap,
.dropdown-container,
.secondary-wrap,
.input-container {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* ── Light mode: tags / chips ─────────────────────────────── */
.token,
.token-remove,
.tag,
span.tag,
.multiselect-token,
.pill {
    background: rgba(124, 58, 237, 0.1) !important;
    border: 1px solid rgba(124, 58, 237, 0.25) !important;
    border-radius: 999px !important;
    color: #4c1d95 !important;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.token:hover,
.tag:hover,
.multiselect-token:hover,
.pill:hover {
    background: rgba(124, 58, 237, 0.18) !important;
    border-color: rgba(124, 58, 237, 0.4) !important;
}

/* ── Light mode: dropdown lists when open ─────────────────── */
.dropdown-content,
ul[role="listbox"],
.options {
    background: rgba(255, 255, 255, 0.85) !important;
    border: 1px solid rgba(124, 58, 237, 0.15) !important;
    border-radius: 12px !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 8px 32px rgba(124, 58, 237, 0.1);
}
.dropdown-content li:hover,
ul[role="listbox"] li:hover,
.options li:hover {
    background: rgba(124, 58, 237, 0.08) !important;
}

/* ── Light mode: labels ───────────────────────────────────── */
label,
.gr-block label,
.label-text,
.block-label {
    color: #4c1d95 !important;
}

/* ── Tab content spacing ──────────────────────────────────── */
.tabitem {
    padding-top: 14px;
}

/* ═══════════════════════════════════════════════════════════
   DARK MODE β€” Aurora Noir
   ═══════════════════════════════════════════════════════════ */

.dark .gradio-container {
    background:
        radial-gradient(ellipse at 25% 15%, rgba(124, 58, 237, 0.18) 0%, transparent 50%),
        radial-gradient(ellipse at 75% 70%, rgba(59, 130, 246, 0.14) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 40%, rgba(6, 182, 212, 0.06) 0%, transparent 55%),
        linear-gradient(180deg, #110d24 0%, #0d0b1a 50%, #080614 100%) !important;
    color: #f1f5f9 !important;
    position: relative;
}

/* ── Body glare effect ────────────────────────────────────── */
.dark .gradio-container::after {
    content: "";
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        35deg,
        transparent 0%,
        transparent 42%,
        rgba(124, 58, 237, 0.04) 45%,
        rgba(255, 255, 255, 0.03) 50%,
        rgba(59, 130, 246, 0.04) 55%,
        transparent 58%,
        transparent 100%
    );
    animation: bodyGlare 10s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}
@keyframes bodyGlare {
    0%, 100% { transform: translateX(-20%) translateY(-10%) rotate(-5deg); }
    50% { transform: translateX(20%) translateY(10%) rotate(5deg); }
}

/* ── Force all text readable ──────────────────────────────── */
.dark .gradio-container,
.dark .gradio-container *:not(.title-banner *):not(button.tab-nav-button) {
    color: #f1f5f9 !important;
}
.dark .gradio-container .prose,
.dark .gradio-container .prose * {
    color: #e2e8f0 !important;
}
.dark .gradio-container .markdown-text,
.dark .gradio-container .markdown-text * {
    color: #e2e8f0 !important;
}
.dark .gradio-container strong,
.dark .gradio-container b {
    color: #ffffff !important;
}
.dark .gradio-container h2,
.dark .gradio-container h3,
.dark .gradio-container h4 {
    color: #ffffff !important;
    text-shadow: 0 0 30px rgba(124, 58, 237, 0.3);
}
.dark .gradio-container a {
    color: #93c5fd !important;
}

/* ── All inputs β€” normal + focus + active ─────────────────── */
.dark .gradio-container input,
.dark .gradio-container textarea,
.dark .gradio-container select,
.dark .gradio-container input[type="text"],
.dark .gradio-container input[type="search"],
.dark .gradio-container input[type="number"],
.dark .gradio-container input:focus,
.dark .gradio-container input:active,
.dark .gradio-container textarea:focus,
.dark .gradio-container textarea:active,
.dark .gradio-container select:focus,
.dark .gradio-container select:active {
    color: #f1f5f9 !important;
    background: rgba(10, 6, 32, 0.8) !important;
    border: 1px solid rgba(124, 58, 237, 0.25) !important;
    border-radius: 10px !important;
    outline: none !important;
    caret-color: #a78bfa !important;
}

/* ── Title banner β€” frosted glass ─────────────────────────── */
.dark .title-banner {
    background: linear-gradient(120deg, rgba(124, 58, 237, 0), rgba(59, 130, 246, 0), rgba(34, 211, 238, 0)) !important;
    padding: 20px 28px !important;
    border-radius: 20px;
    margin-bottom: 14px !important;
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(20px);
    position: relative;
    z-index: 1;
}
.dark .title-banner h1 {
    color: #ffffff !important;
}

/* ── Kill all block/panel backgrounds β€” seamless look ─────── */
.dark .gr-group,
.dark .gr-box,
.dark .gr-panel,
.dark .gr-form,
.dark .gr-block,
.dark .block,
.dark .form,
.dark .panel,
.dark .gradio-container > .main,
.dark .gradio-container > .main > .wrap,
.dark .gradio-container > .main > .wrap > div,
.dark .tabitem,
.dark .tabitem > div,
.dark .tabitem > .gr-group,
.dark .tabitem > .gr-box,
.dark .tab-content,
.dark .gap,
.dark .gr-padded {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* ── Header card β€” keep its glass style ───────────────────── */
.dark .gradio-container > .main > .wrap > div:first-child {
    background: rgba(10, 6, 32, 0.6) !important;
    border: 1px solid rgba(124, 58, 237, 0.15) !important;
    border-radius: 16px !important;
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(124, 58, 237, 0.1);
    position: relative;
    z-index: 1;
}

/* ── Dropdowns β€” glass ────────────────────────────────────── */
.dark .gr-dropdown,
.dark .multiselect-dropdown {
    background: rgba(10, 6, 32, 0.5) !important;
    border: 1px solid rgba(124, 58, 237, 0.2) !important;
    border-radius: 12px !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* ── Dropdown containers + select wrappers ────────────────── */
.dark .wrap,
.dark .dropdown-container,
.dark .secondary-wrap,
.dark .input-container {
    background: transparent !important;
    border-color: rgba(124, 58, 237, 0.15) !important;
}

/* ── Dropdown/listbox popups (scoped β€” no markdown lists) ── */
.dark .gradio-container [role="listbox"],
.dark .gradio-container [role="listbox"] [role="option"],
.dark .gradio-container .dropdown-content,
.dark .gradio-container .dropdown-content li {
    background: rgba(10, 6, 32, 0.95) !important;
    color: #f1f5f9 !important;
}
.dark .gradio-container [role="listbox"],
.dark .gradio-container .dropdown-content {
    border: 1px solid rgba(124, 58, 237, 0.25) !important;
    border-radius: 12px !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ── Dropdown items: hover + selected ─────────────────────── */
.dark .gradio-container [role="option"]:hover,
.dark .gradio-container .dropdown-content li:hover {
    background: rgba(124, 58, 237, 0.2) !important;
    color: #ffffff !important;
}
.dark .gradio-container [role="option"][aria-selected="true"],
.dark .gradio-container .dropdown-content li.selected {
    background: rgba(124, 58, 237, 0.35) !important;
    color: #ffffff !important;
}

/* ── Checkmarks and icons inside dropdowns ────────────────── */
.dark .gradio-container [role="option"] svg,
.dark .gradio-container .dropdown-content li svg {
    color: #a78bfa !important;
    fill: #a78bfa !important;
}

/* ── Tags / chips (model selectors) ───────────────────────── */
.dark .token,
.dark .token-remove,
.dark .tag,
.dark span.tag,
.dark .multiselect-token,
.dark .pill {
    background: rgba(124, 58, 237, 0.2) !important;
    border: 1px solid rgba(124, 58, 237, 0.3) !important;
    border-radius: 999px !important;
    color: #e2e8f0 !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.dark .token:hover,
.dark .tag:hover,
.dark .multiselect-token:hover,
.dark .pill:hover {
    background: rgba(124, 58, 237, 0.3) !important;
    border-color: rgba(124, 58, 237, 0.5) !important;
}
.dark .token-remove:hover,
.dark .remove-btn:hover {
    color: #f87171 !important;
}

/* ── Label text above inputs ──────────────────────────────── */
.dark label,
.dark .gr-block label,
.dark .label-text,
.dark .block-label {
    color: #cbd5e1 !important;
}

/* ── Tab buttons β€” glass pills ────────────────────────────── */
.dark button.tab-nav-button {
    color: #cbd5e1 !important;
    background: rgba(10, 6, 32, 0.5) !important;
    border-radius: 999px !important;
    border: 1px solid rgba(124, 58, 237, 0.15) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: all 0.3s ease !important;
    position: relative;
    z-index: 1;
}
.dark button.tab-nav-button:hover {
    background: rgba(124, 58, 237, 0.12) !important;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.15);
    border-color: rgba(124, 58, 237, 0.3) !important;
}
.dark button.tab-nav-button.selected {
    color: #ffffff !important;
    border-color: transparent !important;
    background-image: linear-gradient(120deg, rgba(124, 58, 237, 1), rgba(59, 130, 246, 1)) !important;
    box-shadow:
        0 10px 30px rgba(37, 99, 235, 0.5),
        0 0 50px rgba(124, 58, 237, 0.15);
}

/* ── Table β€” aurora glass ─────────────────────────────────── */
.dark .table-wrap {
    border-radius: 16px !important;
    overflow: hidden;
    border: 1px solid rgba(124, 58, 237, 0.2) !important;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.5),
        0 0 60px rgba(124, 58, 237, 0.08);
    position: relative;
    z-index: 1;
}
.dark .table-wrap thead th {
    background: linear-gradient(120deg, rgba(46, 16, 101, 0.9), rgba(30, 58, 138, 0.9)) !important;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(124, 58, 237, 0.3) !important;
    letter-spacing: 0.03em;
    text-shadow: 0 0 10px rgba(124, 58, 237, 0.4);
    backdrop-filter: blur(12px);
}
.dark .table-wrap tbody tr {
    background: rgba(0, 0, 0, 0.35) !important;
    color: #f1f5f9 !important;
    transition: all 0.25s ease;
}
.dark .table-wrap tbody tr:nth-child(even) {
    background: rgba(10, 6, 32, 0.4) !important;
}
.dark .table-wrap tbody tr:hover {
    background: linear-gradient(120deg, rgba(124, 58, 237, 0.12), rgba(59, 130, 246, 0.12)) !important;
    box-shadow: inset 0 0 30px rgba(124, 58, 237, 0.06);
}
.dark .table-wrap tbody td {
    color: #f1f5f9 !important;
    border-bottom: 1px solid rgba(124, 58, 237, 0.06) !important;
}
"""

with gr.Blocks(title="Impermanent Leaderboard") as app:
    gr.Markdown("# Impermanent Leaderboard", elem_classes=["title-banner"])
    gr.Markdown(
        "A **live** time-series forecasting benchmark designed to avoid data contamination. "
        "Automated pipelines continuously fetch fresh data from GitHub β€” including the number of "
        "open issues, opened PRs, pushes, and stars β€” ensuring that models are always evaluated "
        "on data they could not have seen during training."
    )

    cutoff_dates = sorted(df["cutoff"].unique())
    n_dates = len(cutoff_dates)
    date_min, date_max = cutoff_dates[0], cutoff_dates[-1]
    frequencies = sorted(df["frequency"].unique())
    subdatasets = sorted(df["subdataset"].unique())
    n_total = len(df)
    n_missing = int(df["value"].isna().sum())
    pct_complete = (n_total - n_missing) / n_total * 100 if n_total else 0

    gr.Markdown(f"""\
## Datasets

GitHub repositories are selected across several **buckets based on their number of stars**,
yielding a mix of both intermittent (low-activity) and high-volume time series.
For each bucket, an automated pipeline fetches four signals:

{chr(10).join(f"- **{s}**" for s in subdatasets)}

Each signal is collected at {", ".join(f"**{f}**" for f in frequencies)} granularity.

## Models

The benchmark evaluates **{len(ALL_MODELS)} models**: {", ".join(f"`{m}`" for m in ALL_MODELS)}.

## Evaluation dates

Forecast methods are evaluated **every week** using rolling forecast evaluations.
Currently **{n_dates} evaluations** are available, from **{date_min}** to **{date_max}**.
""")

    if n_missing > 0:
        gr.Markdown(
            f"> **Note:** {n_missing} out of {n_total} results "
            f"({pct_complete:.0f}% complete) are still pending. "
            "New evaluations are computed on a rolling basis and will "
            "appear automatically."
        )

    with gr.Tab("Leaderboard πŸ†"):
        lb = compute_leaderboard(df)
        gr.Dataframe(
            value=lb,
            #label="Leaderboard",
            interactive=False,
            headers=[f"**{c}**" for c in lb.columns],
        )

    with gr.Tab("Results over time πŸ“ˆ"):
        with gr.Row():
            time_metric_dd = gr.Dropdown(
                choices=ALL_METRICS,
                value=ALL_METRICS[0],
                label="Metric",
            )
            time_subdataset_dd = gr.Dropdown(
                choices=ALL_SUBDATASETS,
                value=ALL_SUBDATASETS[0],
                label="Subdataset",
            )

        rank_plot = gr.Plot(label="Rank over time")
        value_plot = gr.Plot(label="Metric value over time")

        def update_plots(metric, subdataset):
            fig_rank, fig_value = build_plots(metric, subdataset)
            return fig_rank, fig_value

        app.load(
            fn=update_plots,
            inputs=[time_metric_dd, time_subdataset_dd],
            outputs=[rank_plot, value_plot],
        )

        for control in [time_metric_dd, time_subdataset_dd]:
            control.change(
                fn=update_plots,
                inputs=[time_metric_dd, time_subdataset_dd],
                outputs=[rank_plot, value_plot],
            )

    with gr.Tab("All results πŸ“‹"):
        with gr.Row():
            metric_dd = gr.Dropdown(
                choices=ALL_METRICS,
                value=ALL_METRICS[0],
                label="Metric",
            )
            subdataset_dd = gr.Dropdown(
                choices=["All"] + ALL_SUBDATASETS,
                value="All",
                label="Subdataset",
            )
            frequency_dd = gr.Dropdown(
                choices=["All"] + ALL_FREQUENCIES,
                value="All",
                label="Frequency",
            )
            models_dd = gr.Dropdown(
                choices=ALL_MODELS,
                value=ALL_MODELS,
                multiselect=True,
                label="Models",
            )

        results_table = gr.Dataframe(
            value=build_table(ALL_METRICS[0], "All", "All", ALL_MODELS),
            label="Results",
            interactive=False,
        )

        for control in [metric_dd, subdataset_dd, frequency_dd, models_dd]:
            control.change(
                fn=build_table,
                inputs=[metric_dd, subdataset_dd, frequency_dd, models_dd],
                outputs=results_table,
            )

if __name__ == "__main__":
    app.launch(css=CUSTOM_CSS, ssr_mode=False)