elmadany commited on
Commit
e6924cd
·
verified ·
1 Parent(s): 0607385

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +213 -51
app.py CHANGED
@@ -1,7 +1,8 @@
1
-
2
  import gradio as gr
3
 
4
  from src.helper import *
 
 
5
  # Custom CSS to replicate the Google-style card design from the image
6
  custom_head_html = """
7
  <link rel="stylesheet" href="https://africa.dlnlp.ai/sahara/font-awesome/css/font-awesome.min.css">
@@ -25,7 +26,40 @@ new_header_html = """
25
  """
26
 
27
  google_style_css = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
 
 
 
 
 
 
29
  .flat-navy-button {
30
  background-color: #117b75 !important; /* Navy Blue */
31
  color: #fff !important;
@@ -38,7 +72,7 @@ google_style_css = """
38
  background-color: #117b75 !important; /* Lighter navy for hover */
39
  color: #e8850e !important;
40
  }
41
- div.gradio-container-5-37-0{
42
  background:#FFFBF5 !important;
43
  }
44
 
@@ -67,12 +101,12 @@ div.svelte-1nguped {
67
  }
68
  .content-card h2 {
69
  font-family: "Rubik", sans-serif;
70
- font-size: 30px;
71
- font-weight: 600;
72
- line-height: 1.25;
73
- letter-spacing: -1px;
74
- color: #2f3b7d;
75
- text-transform:none;
76
 
77
  /* font-size: 30px;
78
  font-weight: bold;
@@ -80,6 +114,13 @@ div.svelte-1nguped {
80
  margin-top: 0;
81
  margin-bottom: 20px; */
82
  }
 
 
 
 
 
 
 
83
  .content-card p {
84
  /* font-size: 18px; */
85
  /* line-height: 1.7; */
@@ -131,17 +172,17 @@ button.svelte-1tcem6n.svelte-1tcem6n {
131
  background-color: #7d3561 !important;
132
  }
133
 
134
- .gradio-container-5-37-0 .prose table,
135
- .gradio-container-5-37-0 .prose tr,
136
- .gradio-container-5-37-0 .prose td,
137
- .gradio-container-5-37-0 .prose th {
138
  border: 0 !important;
139
  border-top: 2px solid #dca02a;
140
  border-bottom: 2px solid #dca02a;
141
  }
142
 
143
 
144
- .gradio-container-5-37-0 .prose table {
145
  border-top: 2px solid #dca02a !important;
146
  border-bottom: 2px solid #dca02a !important;
147
  margin-bottom:20px;
@@ -151,10 +192,20 @@ button.svelte-1tcem6n.svelte-1tcem6n {
151
  border-collapse: collapse;
152
  table-layout: fixed;
153
  }
154
- .gradio-container-5-37-0 .prose thead tr {
155
  border-bottom: 2px solid #dca02a !important;
156
  }
157
- .gradio-container-5-37-0 .prose th {
 
 
 
 
 
 
 
 
 
 
158
  color: #7d3561;
159
  font-weight: bold;
160
  /* font-size: 20px; */
@@ -162,24 +213,25 @@ button.svelte-1tcem6n.svelte-1tcem6n {
162
  vertical-align: middle;
163
  border: 0 !important;
164
  }
165
- .gradio-container-5-37-0 .prose td {
166
  /* font-size: 18px; */
167
  padding: 8px 5px;
168
  border: 0 !important;
169
  vertical-align: middle;
170
  }
171
- .gradio-container-5-37-0 .prose th:first-child,
172
- .gradio-container-5-37-0 .prose td:first-child {
 
173
  min-width: 400px !important;
174
- max-width: 400px !important;
175
  width:400px !important;
176
  text-align: left !important;
177
  }
178
- .gradio-container-5-37-0 .prose th:not(:first-child),
179
- .gradio-container-5-37-0 .prose td:not(:first-child) {
180
  min-width: 90px;
181
- max-width: 140px;
182
- width: auto;
183
  text-align: center;
184
  }
185
  """
@@ -189,64 +241,174 @@ introduction_text = """
189
  """
190
  # with gr.Blocks(title="Sahara Leaderboard", css=custom_css) as demo:
191
  # with gr.Blocks(title="Sahara Leaderboard") as demo:
192
- with gr.Blocks(css=google_style_css) as demo:
193
  # Use elem_classes to apply our custom CSS to this group
194
  gr.HTML(new_header_html)
195
  # === UPDATED BUTTONS START ===
196
  with gr.Row():
197
  gr.Button("Official Website", link="https://africa.dlnlp.ai/sahara", elem_classes=['flat-navy-button'])
198
- gr.Button("ACL 2025 Paper", link="https://arxiv.org/abs/2502.19582", elem_classes=['flat-navy-button'])
199
  gr.Button("Tasks", link="https://africa.dlnlp.ai/sahara/tasks", elem_classes=['flat-navy-button'])
200
- gr.Button("Submission Instructions", link="https://africa.dlnlp.ai/sahara/instructions", elem_classes=['flat-navy-button'])
201
- gr.Button("New Submission", link="https://africa.dlnlp.ai/sahara/submit", elem_classes=['flat-navy-button'])
202
- gr.Button("GitHub Repo", link="https://github.com/UBC-NLP/sahara", elem_classes=['flat-navy-button'])
 
 
 
 
 
 
 
 
 
 
 
 
203
  # === UPDATED BUTTONS END ===
204
- # gr.Markdown(introduction_text)
205
- # with gr.Group(elem_classes="content-card"):
206
- # gr.Markdown(introduction_text)
207
- # gr.Markdown(
208
- # "HI # 🏆 Model Evaluation Leaderboard (Clustered, Private HF Dataset)\n"
209
- # "- Language dropdown uses names, not ISO codes; e.g. Swahili = (swa+swh results).\n"
210
- # "- Tabs by cluster; each cluster tab shows only its tasks, with fixed column width via CSS HTML tables."
211
- # )
212
  with gr.Group(elem_classes="content-card"):
213
  gr.Markdown("<br>")
214
- with gr.Tabs():
 
 
 
 
 
 
215
  # Main leaderboard
216
- with gr.Tab("Main Leaderboard"):
217
  gr.HTML("<br><br><center><h2>Main Leaderboard</h2></center><br>")
218
  gr.HTML(df_to_html(main_overall_tab))
219
  # Task Clusters leaderboards
220
- with gr.Tab("Task-Clusters Leaderboards"):
221
- gr.HTML("<br><br><center><h2>Task-Clusters Leaderboards</h2></center><br>")
222
  CLUSTERS_NAME=[cname for cname, cdf in cluster_tabs.items()]
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
- clusters_dropdown = gr.Dropdown(choices=CLUSTERS_NAME, label="Select Task-CLuster", interactive=True)
225
  def get_claster_table(cluster_name):
226
  for cname, cdf in cluster_tabs.items():
227
  if cname== cluster_name:
228
  return cdf
 
 
229
  cluster_table_component = gr.HTML(df_to_html(get_claster_table(CLUSTERS_NAME[0])) if CLUSTERS_NAME else "<b>No cluser found</b>")
 
230
  def update_cluster_table(cluster_name):
231
  df = get_claster_table(cluster_name)
232
- return df_to_html(df)
233
- clusters_dropdown.change(update_cluster_table, clusters_dropdown, cluster_table_component)
234
 
 
235
 
236
- # for cname, cdf in cluster_tabs.items():
237
- # with gr.Tab(f"{cname}"):
238
- # gr.HTML(df_to_html(cdf))
239
  # Languages Leaderboards
240
- with gr.Tab("Language-Specific Leaderboards"):
241
- gr.HTML("<br><br><center><h2>Language-Specific Leaderboards</h2></center><br>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  lang_dropdown = gr.Dropdown(choices=LANG_NAME_LIST, label="Select Language", interactive=True)
243
  lang_table_component = gr.HTML(df_to_html(get_lang_table(LANG_NAME_LIST[0])) if LANG_NAME_LIST else "<b>No languages found</b>")
244
  def update_lang_table(lang_name):
245
  df = get_lang_table(lang_name)
246
- return df_to_html(df)
247
- lang_dropdown.change(update_lang_table, lang_dropdown, lang_table_component)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  gr.HTML("<center><img src='https://africa.dlnlp.ai/sahara//img/sahara_web_sponsers.jpg' width='25%'> </center>")
249
-
250
 
 
251
  if __name__ == "__main__":
252
  demo.launch(share=True)
 
 
1
  import gradio as gr
2
 
3
  from src.helper import *
4
+
5
+
6
  # Custom CSS to replicate the Google-style card design from the image
7
  custom_head_html = """
8
  <link rel="stylesheet" href="https://africa.dlnlp.ai/sahara/font-awesome/css/font-awesome.min.css">
 
26
  """
27
 
28
  google_style_css = """
29
+ /* Citation Block */
30
+ .citation-block {
31
+ position: relative;
32
+ background-color: #FDF6E3; /* Light cream background */
33
+ border-radius: 8px;
34
+ padding: 25px;
35
+ }
36
+ .citation-block pre {
37
+ background-color: transparent;
38
+ border: none;
39
+ padding: 0;
40
+ /* font-size: 14px; */
41
+ white-space: pre-wrap;
42
+ word-break: break-all;
43
+ }
44
+ .citation-block .btn-copy {
45
+ position: absolute;
46
+ top: 15px;
47
+ right: 15px;
48
+ background-color: #D97706;
49
+ border-color: #c56a05;
50
+ color: white;
51
+ }
52
+ .citation-block .btn-copy:hover, .citation-block .btn-copy:focus {
53
+ background-color: #c56a05;
54
+ color: white;
55
+ }
56
 
57
+
58
+ .fillable.svelte-15jxnnn.svelte-15jxnnn:not(.fill_width) {
59
+ /* min-width: 400px !important; */
60
+ max-width: 1580px !important;
61
+ }
62
+
63
  .flat-navy-button {
64
  background-color: #117b75 !important; /* Navy Blue */
65
  color: #fff !important;
 
72
  background-color: #117b75 !important; /* Lighter navy for hover */
73
  color: #e8850e !important;
74
  }
75
+ div[class*="gradio-container"] {
76
  background:#FFFBF5 !important;
77
  }
78
 
 
101
  }
102
  .content-card h2 {
103
  font-family: "Rubik", sans-serif;
104
+ font-size: 30px;
105
+ font-weight: 600;
106
+ line-height: 1.25;
107
+ letter-spacing: -1px;
108
+ color: #2f3b7d;
109
+ text-transform:none;
110
 
111
  /* font-size: 30px;
112
  font-weight: bold;
 
114
  margin-top: 0;
115
  margin-bottom: 20px; */
116
  }
117
+ .content-card h3 {
118
+ font-size: 20px;
119
+ color: #2f3b7d;
120
+ }
121
+ .content-card h3 .title {
122
+ color: #7d3561;
123
+ }
124
  .content-card p {
125
  /* font-size: 18px; */
126
  /* line-height: 1.7; */
 
172
  background-color: #7d3561 !important;
173
  }
174
 
175
+ div[class*="gradio-container"] .prose table,
176
+ div[class*="gradio-container"] .prose tr,
177
+ div[class*="gradio-container"] .prose td,
178
+ div[class*="gradio-container"] .prose th {
179
  border: 0 !important;
180
  border-top: 2px solid #dca02a;
181
  border-bottom: 2px solid #dca02a;
182
  }
183
 
184
 
185
+ div[class*="gradio-container"] .prose table {
186
  border-top: 2px solid #dca02a !important;
187
  border-bottom: 2px solid #dca02a !important;
188
  margin-bottom:20px;
 
192
  border-collapse: collapse;
193
  table-layout: fixed;
194
  }
195
+ div[class*="gradio-container"] .prose thead tr {
196
  border-bottom: 2px solid #dca02a !important;
197
  }
198
+ div[class*="gradio-container"] .prose th .rotate_div {
199
+ transform: rotate(-45deg) !important;
200
+ color: #7d3561;
201
+ padding-top: 10px !important;
202
+ padding-bottom: 5px !important;
203
+ font-weight: None !important;
204
+ font-size: 12px !important;
205
+ /*height: 30px !important; Give the cell enough height for the rotated text */
206
+ }
207
+ div[class*="gradio-container"] .prose th {
208
+ /* transform: rotate(-90deg) !important; */
209
  color: #7d3561;
210
  font-weight: bold;
211
  /* font-size: 20px; */
 
213
  vertical-align: middle;
214
  border: 0 !important;
215
  }
216
+ div[class*="gradio-container"] .prose td {
217
  /* font-size: 18px; */
218
  padding: 8px 5px;
219
  border: 0 !important;
220
  vertical-align: middle;
221
  }
222
+ div[class*="gradio-container"] .prose th:first-child,
223
+ div[class*="gradio-container"] .prose td:first-child {
224
+ transform: rotate(0deg) !important;
225
  min-width: 400px !important;
226
+ /* max-width: 400px !important; */
227
  width:400px !important;
228
  text-align: left !important;
229
  }
230
+ div[class*="gradio-container"] .prose th:not(:first-child),
231
+ div[class*="gradio-container"] .prose td:not(:first-child) {
232
  min-width: 90px;
233
+ /* max-width: 140px; */
234
+ width:auto !important;
235
  text-align: center;
236
  }
237
  """
 
241
  """
242
  # with gr.Blocks(title="Sahara Leaderboard", css=custom_css) as demo:
243
  # with gr.Blocks(title="Sahara Leaderboard") as demo:
244
+ with gr.Blocks(title="Sahara Benchmark Leaderboards", css=google_style_css) as demo:
245
  # Use elem_classes to apply our custom CSS to this group
246
  gr.HTML(new_header_html)
247
  # === UPDATED BUTTONS START ===
248
  with gr.Row():
249
  gr.Button("Official Website", link="https://africa.dlnlp.ai/sahara", elem_classes=['flat-navy-button'])
250
+ gr.Button("ACL 2025 Paper", link="https://aclanthology.org/2025.acl-long.1572", elem_classes=['flat-navy-button'])
251
  gr.Button("Tasks", link="https://africa.dlnlp.ai/sahara/tasks", elem_classes=['flat-navy-button'])
252
+ # gr.Button("Submission Instructions", link="https://africa.dlnlp.ai/sahara/instructions", elem_classes=['flat-navy-button'])
253
+ # gr.Button("New Submission", link="https://africa.dlnlp.ai/sahara/submit", elem_classes=['flat-navy-button'])
254
+ # gr.Button("GitHub Repo", link="https://github.com/UBC-NLP/sahara", elem_classes=['flat-navy-button'])
255
+ # These buttons will now show an alert message
256
+ # submission_btn = gr.Button("Submission Instructions", elem_classes=['flat-navy-button'])
257
+ # new_submission_btn = gr.Button("New Submission", elem_classes=['flat-navy-button'])
258
+ # github_btn = gr.Button("GitHub Repo", elem_classes=['flat-navy-button'])
259
+ # # Function to display the alert
260
+ # def show_coming_soon_alert():
261
+ # gr.Info("Stay tuned! It will be ready soon.")
262
+
263
+ # # Link the click event of each button to the alert function
264
+ # submission_btn.click(fn=show_coming_soon_alert)
265
+ # new_submission_btn.click(fn=show_coming_soon_alert)
266
+ # github_btn.click(fn=show_coming_soon_alert)
267
  # === UPDATED BUTTONS END ===
268
+
 
 
 
 
 
 
 
269
  with gr.Group(elem_classes="content-card"):
270
  gr.Markdown("<br>")
271
+ # Hidden component to trigger JavaScript on load
272
+ # url_trigger = gr.Textbox(visible=False)
273
+
274
+ # State to hold URL parameters
275
+ # url_params_state = gr.State({})
276
+
277
+ with gr.Tabs() as tabs:
278
  # Main leaderboard
279
+ with gr.Tab("Main Leaderboard", id="main"):
280
  gr.HTML("<br><br><center><h2>Main Leaderboard</h2></center><br>")
281
  gr.HTML(df_to_html(main_overall_tab))
282
  # Task Clusters leaderboards
283
+ with gr.Tab("Task-Cluster Leaderboard", id="clusters"):
284
+ gr.HTML("<br><br><center><h2>Task-Cluster Leaderboard</h2></center><br>")
285
  CLUSTERS_NAME=[cname for cname, cdf in cluster_tabs.items()]
286
+ cname = CLUSTERS_NAME[0]
287
+ initial_cluster_title_html = f"<h3><span class='title'>Task-Cluster name:</span> {cname}</span></h3>"
288
+
289
+ # 2. Create a variable for the title component so it can be updated.
290
+ cluster_title_component = gr.HTML(initial_cluster_title_html)
291
+
292
+ clusters_dropdown = gr.Dropdown(
293
+ choices=CLUSTERS_NAME,
294
+ label="Select Task-CLuster",
295
+ interactive=True,
296
+ elem_id="cluster_dropdown",
297
+ value=CLUSTERS_NAME[0] # Set default value
298
+ )
299
 
 
300
  def get_claster_table(cluster_name):
301
  for cname, cdf in cluster_tabs.items():
302
  if cname== cluster_name:
303
  return cdf
304
+ return None
305
+
306
  cluster_table_component = gr.HTML(df_to_html(get_claster_table(CLUSTERS_NAME[0])) if CLUSTERS_NAME else "<b>No cluser found</b>")
307
+
308
  def update_cluster_table(cluster_name):
309
  df = get_claster_table(cluster_name)
310
+ cluster_title_html = f"<h3><span class='title'>Task-Cluster name:</span> {cluster_name}</span></h3>"
311
+ return cluster_title_html, df_to_html(df) if df is not None else "<b>No data found</b>"
312
 
313
+ clusters_dropdown.change(update_cluster_table, clusters_dropdown, outputs=[cluster_title_component, cluster_table_component])
314
 
 
 
 
315
  # Languages Leaderboards
316
+ # Task-Specific Leaderboards
317
+ with gr.Tab("Task-Specific Leaderboard", id="tasks"):
318
+ # --- MODIFIED ---
319
+ # 1. Define the initial title based on the first task in the list.
320
+ gr.HTML("<br><br><center><h2>Task-Specific Leaderboard (per langauge)</h2></center><br>")
321
+ initial_task_name = TASK_NAME_LIST[0]
322
+ tname=initial_task_name.split(' (')[0]
323
+ tid=initial_task_name.split(' (')[-1].split(')')[0]
324
+ initial_title_html = f"<h3><span class='title'>Task name:</span> {tname}<br> <span class='title'>Task identifier:</span> {tid}</h3>"
325
+
326
+ # 2. Create a variable for the title component so it can be updated.
327
+ task_title_component = gr.HTML(initial_title_html)
328
+
329
+ # Dropdown for selecting the task (remains the same)
330
+ task_dropdown = gr.Dropdown(choices=TASK_NAME_LIST, label="Select Task", interactive=True, value=initial_task_name)
331
+
332
+ # --- MODIFIED ---
333
+ # 3. Modify the update function to return TWO values: the new title and the new table.
334
+ def update_task_table(task_name_with_id):
335
+ # Create the new dynamic title HTML
336
+ tname=task_name_with_id.split(' (')[0]
337
+ tid=task_name_with_id.split(' (')[-1].split(')')[0]
338
+ new_title = f"<h3><span class='title'>Task name:</span> {tname}<br> <span class='title'>Task identifier:</span> {tid}</h3>"
339
+ # new_title = f"<br><br><center><h2>{task_name_with_id} Leaderboard</h2></center><br>"
340
+
341
+ # Parse the task key to get the data
342
+ task_key = task_name_with_id.split('(')[-1].strip(')')
343
+ df = get_task_leaderboard(task_key)
344
+
345
+ # Return both the new title and the HTML for the table
346
+ return new_title, df_to_html(df)
347
+
348
+ # Initial table display (remains the same)
349
+ initial_task_key = initial_task_name.split('(')[-1].strip(')')
350
+ task_table_component = gr.HTML(df_to_html(get_task_leaderboard(initial_task_key)))
351
+
352
+ # --- MODIFIED ---
353
+ # 4. Update the .change() event to send outputs to BOTH the title and table components.
354
+ task_dropdown.change(
355
+ fn=update_task_table,
356
+ inputs=task_dropdown,
357
+ outputs=[task_title_component, task_table_component]
358
+ )
359
+
360
+ with gr.Tab("Language-Specific Leaderboard", id="langs"):
361
+ gr.HTML("<br><br><center><h2>Language-Specific Leaderboard (per task)</h2></center><br>")
362
+ lang_name=LANG_NAME_LIST[0]
363
+ initial_lang_title_html = f"<h3><span class='title'>Language name:</span> {lang_name} <br> <span class='title'>Language ISO-3:</span> {next(iter(LANGNAME2ISOS.get(lang_name)))} </h3>"
364
+
365
+ # 2. Create a variable for the title component so it can be updated.
366
+ lang_title_component = gr.HTML(initial_lang_title_html)
367
  lang_dropdown = gr.Dropdown(choices=LANG_NAME_LIST, label="Select Language", interactive=True)
368
  lang_table_component = gr.HTML(df_to_html(get_lang_table(LANG_NAME_LIST[0])) if LANG_NAME_LIST else "<b>No languages found</b>")
369
  def update_lang_table(lang_name):
370
  df = get_lang_table(lang_name)
371
+ new_title = f"<h3><span class='title'>Language name:</span> {lang_name} <br> <span class='title'>Language ISO-3:</span> {next(iter(LANGNAME2ISOS.get(lang_name)))}</h3>"
372
+ return new_title, df_to_html(df)
373
+ lang_dropdown.change(update_lang_table, lang_dropdown, outputs=[lang_title_component, lang_table_component])
374
+ # --- NEW TAB FOR MODEL-SPECIFIC LEADERBOARD ---
375
+ with gr.Tab("Model-Specific Leaderboard", id="models"):
376
+ gr.HTML("<br><br><center><h2>Model-Specific Leaderboard (per task)</h2></center><br>")
377
+
378
+ initial_model_name = MODEL_NAME_LIST[0]
379
+ initial_model_title_html = f"<h3><span class='title'>Model name:</span> {initial_model_name}</h3>"
380
+
381
+ # Component to display the dynamic title
382
+ model_title_component = gr.HTML(initial_model_title_html)
383
+
384
+ # Dropdown for selecting the model
385
+ model_dropdown = gr.Dropdown(
386
+ choices=MODEL_NAME_LIST,
387
+ label="Select Model",
388
+ interactive=True,
389
+ value=initial_model_name
390
+ )
391
+
392
+ # Component to display the model's performance table
393
+ model_table_component = gr.HTML(df_to_html(get_model_table(initial_model_name)))
394
+
395
+ # Function to update the title and table based on dropdown selection
396
+ def update_model_table(model_name):
397
+ df = get_model_table(model_name)
398
+ new_title = f"<h3><span class='title'>Model name:</span> {model_name}</h3>"
399
+ return new_title, df_to_html(df)
400
+
401
+ # Link the dropdown's change event to the update function
402
+ model_dropdown.change(
403
+ fn=update_model_table,
404
+ inputs=model_dropdown,
405
+ outputs=[model_title_component, model_table_component]
406
+ )
407
+ with gr.Group(elem_classes="content-card"):
408
+ gr.Markdown("<br>")
409
+ gr.HTML("<h2>Citation</h2>If you use the Sahara benchmark for your scientific publication, or if you find the resources in this website useful, please cite our <a href='https://africa.dlnlp.ai/sahara/'>ACL2025 paper </a>as well as the papers of the <a href='https://africa.dlnlp.ai/sahara/tasks'>original authors</a>.")
410
  gr.HTML("<center><img src='https://africa.dlnlp.ai/sahara//img/sahara_web_sponsers.jpg' width='25%'> </center>")
 
411
 
412
+
413
  if __name__ == "__main__":
414
  demo.launch(share=True)