taagarwa commited on
Commit
abb343c
Β·
1 Parent(s): f647606

πŸ› Add patch to gradio_leaderboard before import

Browse files
Files changed (1) hide show
  1. app.py +46 -4
app.py CHANGED
@@ -1,5 +1,49 @@
1
  import os
2
  import re
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  import gradio as gr
5
  from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
@@ -131,12 +175,10 @@ with demo:
131
 
132
  with gr.Tabs():
133
  with gr.Tab("πŸ† Leaderboard"):
134
- # leaderboard = init_leaderboard(LEADERBOARD_DF)
135
- leaderboard = gr.DataFrame(LEADERBOARD_DF)
136
 
137
  with gr.Tab("πŸƒ Benchmark Runs"):
138
- # benchmark_runs = init_benchmark_runs(BENCHMARK_RUN_DF)
139
- benchmark_runs = gr.DataFrame(BENCHMARK_RUN_DF)
140
  gr.Markdown("\* `internal` refers to internal benchmarks performed by the model provider where the harness/environment were not made public")
141
 
142
  with gr.Tab("πŸ“ About"):
 
1
  import os
2
  import re
3
+ from pathlib import Path
4
+
5
+
6
+ def patch_gradio_leaderboard():
7
+ """Patch gradio_leaderboard JS to fix crash on tab switch with Gradio 5.x.
8
+
9
+ See PR.md for details.
10
+ """
11
+ import gradio_leaderboard
12
+ pkg_dir = Path(gradio_leaderboard.__file__).parent
13
+ js_file = pkg_dir / "templates" / "component" / "Index-CzS_eGV6.js"
14
+ if not js_file.exists():
15
+ return
16
+
17
+ src = js_file.read_text()
18
+
19
+ patches = [
20
+ # Fix 1 & 2: Guard r[39]/a[39] filter callback (undefined during Svelte outro)
21
+ (
22
+ 'r[0].filter(\n /*func*/\n r[39]\n ).map(qd)',
23
+ '(r[39] ? r[0].filter(r[39]) : r[0]).map(qd)',
24
+ ),
25
+ (
26
+ 'a[0].filter(\n /*func*/\n a[39]\n ).map(qd))',
27
+ '(a[39] ? a[0].filter(a[39]) : a[0]).map(qd))',
28
+ ),
29
+ # Fix 3: Lx (Boolean) extracted from Rx (globals) which is undefined in Gradio 5
30
+ (
31
+ '{ Boolean: Lx } = Rx,',
32
+ 'Lx = (Rx && Rx.Boolean) || Boolean,',
33
+ ),
34
+ ]
35
+
36
+ patched = False
37
+ for old, new in patches:
38
+ if old in src:
39
+ src = src.replace(old, new)
40
+ patched = True
41
+
42
+ if patched:
43
+ js_file.write_text(src)
44
+
45
+
46
+ patch_gradio_leaderboard()
47
 
48
  import gradio as gr
49
  from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
 
175
 
176
  with gr.Tabs():
177
  with gr.Tab("πŸ† Leaderboard"):
178
+ leaderboard = init_leaderboard(LEADERBOARD_DF)
 
179
 
180
  with gr.Tab("πŸƒ Benchmark Runs"):
181
+ benchmark_runs = init_benchmark_runs(BENCHMARK_RUN_DF)
 
182
  gr.Markdown("\* `internal` refers to internal benchmarks performed by the model provider where the harness/environment were not made public")
183
 
184
  with gr.Tab("πŸ“ About"):