bgamazay commited on
Commit
e60e5e0
Β·
verified Β·
1 Parent(s): 20d2b71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -21
app.py CHANGED
@@ -69,7 +69,6 @@ def generate_html_table_from_df(df):
69
  html += '<tbody>'
70
  for _, row in df.iterrows():
71
  energy_numeric = row['gpu_energy_numeric']
72
- # Format energy with commas and 2 decimal places.
73
  energy_str = f"{energy_numeric:,.2f}"
74
  bar_width = (energy_numeric / max_energy) * 100
75
  score_val = row['energy_score']
@@ -111,11 +110,13 @@ def generate_info_callout(ratio, scope_text):
111
  """
112
  Returns a "did you know" callout with a lightbulb emoji.
113
  The callout uses a light green background, a small font, and is limited to a max-width of 250px.
 
114
  """
115
  return (
116
- f'<div style="max-width:250px; font-size:0.8em; background-color:#e6ffe6; padding:8px; border-radius:5px;">'
117
- f'πŸ’‘ did you know: <strong>{ratio:,.1f}x</strong> energy use difference between most and least efficient model in {scope_text}.'
118
- f'</div>'
 
119
  )
120
 
121
  def get_global_callout():
@@ -258,13 +259,14 @@ def update_all_tasks(sort_order):
258
 
259
  ### BUILD THE GRADIO INTERFACE ###
260
 
261
- # Compute the global header HTML using the global callout.
 
262
  global_header_html = f"""
263
  <div style="position: relative; width: 100%; text-align: center; margin-bottom: 20px;">
264
  <img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
265
  alt="Logo"
266
- style="width:300px; max-width:300px; height:auto; display: inline-block;">
267
- <div style="position: absolute; top: 50%; left: calc(50% + 160px); transform: translateY(-50%);">
268
  {get_global_callout()}
269
  </div>
270
  </div>
@@ -289,7 +291,7 @@ demo = gr.Blocks(css="""
289
  """)
290
 
291
  with demo:
292
- # Header Links
293
  gr.HTML(f"""
294
  <div style="display: flex; justify-content: space-evenly; align-items: center; margin-bottom: 20px;">
295
  <a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">Submission Portal</a>
@@ -301,12 +303,12 @@ with demo:
301
  </div>
302
  """)
303
 
304
- # Global Header: Centered Logo with Global Callout
305
  gr.HTML(global_header_html)
306
 
307
- # Tabs for different tasks
308
  with gr.Tabs():
309
- # Text Generation Tab
310
  with gr.TabItem("Text Generation πŸ’¬"):
311
  with gr.Row():
312
  with gr.Column(scale=4):
@@ -327,7 +329,7 @@ with demo:
327
  model_class_dropdown.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=[tg_callout, tg_table])
328
  sort_dropdown_tg.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=[tg_callout, tg_table])
329
 
330
- # Image Generation Tab
331
  with gr.TabItem("Image Generation πŸ“·"):
332
  with gr.Row():
333
  with gr.Column(scale=8):
@@ -340,7 +342,7 @@ with demo:
340
  img_table.value = init_table
341
  sort_dropdown_img.change(fn=update_image_generation, inputs=sort_dropdown_img, outputs=[img_callout, img_table])
342
 
343
- # Text Classification Tab
344
  with gr.TabItem("Text Classification 🎭"):
345
  with gr.Row():
346
  with gr.Column(scale=8):
@@ -353,7 +355,7 @@ with demo:
353
  tc_table.value = init_table
354
  sort_dropdown_tc.change(fn=update_text_classification, inputs=sort_dropdown_tc, outputs=[tc_callout, tc_table])
355
 
356
- # Image Classification Tab
357
  with gr.TabItem("Image Classification πŸ–ΌοΈ"):
358
  with gr.Row():
359
  with gr.Column(scale=8):
@@ -366,7 +368,7 @@ with demo:
366
  ic_table.value = init_table
367
  sort_dropdown_ic.change(fn=update_image_classification, inputs=sort_dropdown_ic, outputs=[ic_callout, ic_table])
368
 
369
- # Image Captioning Tab
370
  with gr.TabItem("Image Captioning πŸ“"):
371
  with gr.Row():
372
  with gr.Column(scale=8):
@@ -379,7 +381,7 @@ with demo:
379
  icap_table.value = init_table
380
  sort_dropdown_icap.change(fn=update_image_captioning, inputs=sort_dropdown_icap, outputs=[icap_callout, icap_table])
381
 
382
- # Summarization Tab
383
  with gr.TabItem("Summarization πŸ“ƒ"):
384
  with gr.Row():
385
  with gr.Column(scale=8):
@@ -392,7 +394,7 @@ with demo:
392
  sum_table.value = init_table
393
  sort_dropdown_sum.change(fn=update_summarization, inputs=sort_dropdown_sum, outputs=[sum_callout, sum_table])
394
 
395
- # Automatic Speech Recognition Tab
396
  with gr.TabItem("Automatic Speech Recognition πŸ’¬"):
397
  with gr.Row():
398
  with gr.Column(scale=8):
@@ -405,7 +407,7 @@ with demo:
405
  asr_table.value = init_table
406
  sort_dropdown_asr.change(fn=update_asr, inputs=sort_dropdown_asr, outputs=[asr_callout, asr_table])
407
 
408
- # Object Detection Tab
409
  with gr.TabItem("Object Detection 🚘"):
410
  with gr.Row():
411
  with gr.Column(scale=8):
@@ -418,7 +420,7 @@ with demo:
418
  od_table.value = init_table
419
  sort_dropdown_od.change(fn=update_object_detection, inputs=sort_dropdown_od, outputs=[od_callout, od_table])
420
 
421
- # Sentence Similarity Tab
422
  with gr.TabItem("Sentence Similarity πŸ“š"):
423
  with gr.Row():
424
  with gr.Column(scale=8):
@@ -431,7 +433,7 @@ with demo:
431
  ss_table.value = init_table
432
  sort_dropdown_ss.change(fn=update_sentence_similarity, inputs=sort_dropdown_ss, outputs=[ss_callout, ss_table])
433
 
434
- # Extractive QA Tab
435
  with gr.TabItem("Extractive QA ❔"):
436
  with gr.Row():
437
  with gr.Column(scale=8):
@@ -444,7 +446,7 @@ with demo:
444
  qa_table.value = init_table
445
  sort_dropdown_qa.change(fn=update_extractive_qa, inputs=sort_dropdown_qa, outputs=[qa_callout, qa_table])
446
 
447
- # All Tasks Tab
448
  with gr.TabItem("All Tasks πŸ’‘"):
449
  with gr.Row():
450
  with gr.Column(scale=8):
 
69
  html += '<tbody>'
70
  for _, row in df.iterrows():
71
  energy_numeric = row['gpu_energy_numeric']
 
72
  energy_str = f"{energy_numeric:,.2f}"
73
  bar_width = (energy_numeric / max_energy) * 100
74
  score_val = row['energy_score']
 
110
  """
111
  Returns a "did you know" callout with a lightbulb emoji.
112
  The callout uses a light green background, a small font, and is limited to a max-width of 250px.
113
+ It is wrapped in a container that aligns it to the right.
114
  """
115
  return (
116
+ f'<div style="text-align: right;">'
117
+ f'<div style="display:inline-block; max-width:250px; font-size:0.8em; background-color:#e6ffe6; padding:8px; border-radius:5px;">'
118
+ f'πŸ’‘ There\'s a <strong>{ratio:,.1f}x</strong> energy use difference between the most and least efficient model in {scope_text}.'
119
+ f'</div></div>'
120
  )
121
 
122
  def get_global_callout():
 
259
 
260
  ### BUILD THE GRADIO INTERFACE ###
261
 
262
+ # Build the global header HTML. The logo is centered across the full width,
263
+ # and the global callout is positioned at the right edge (20px from the right).
264
  global_header_html = f"""
265
  <div style="position: relative; width: 100%; text-align: center; margin-bottom: 20px;">
266
  <img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
267
  alt="Logo"
268
+ style="width:300px; max-width:300px; height:auto; display:inline-block;">
269
+ <div style="position: absolute; top: 50%; right: 20px; transform: translateY(-50%);">
270
  {get_global_callout()}
271
  </div>
272
  </div>
 
291
  """)
292
 
293
  with demo:
294
+ # --- Header Links ---
295
  gr.HTML(f"""
296
  <div style="display: flex; justify-content: space-evenly; align-items: center; margin-bottom: 20px;">
297
  <a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">Submission Portal</a>
 
303
  </div>
304
  """)
305
 
306
+ # --- Global Header: Centered Logo with Global Callout at Right Edge ---
307
  gr.HTML(global_header_html)
308
 
309
+ # --- Tabs for the different tasks ---
310
  with gr.Tabs():
311
+ # --- Text Generation Tab (dropdowns side by side with task callout to the right) ---
312
  with gr.TabItem("Text Generation πŸ’¬"):
313
  with gr.Row():
314
  with gr.Column(scale=4):
 
329
  model_class_dropdown.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=[tg_callout, tg_table])
330
  sort_dropdown_tg.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=[tg_callout, tg_table])
331
 
332
+ # --- Image Generation Tab ---
333
  with gr.TabItem("Image Generation πŸ“·"):
334
  with gr.Row():
335
  with gr.Column(scale=8):
 
342
  img_table.value = init_table
343
  sort_dropdown_img.change(fn=update_image_generation, inputs=sort_dropdown_img, outputs=[img_callout, img_table])
344
 
345
+ # --- Text Classification Tab ---
346
  with gr.TabItem("Text Classification 🎭"):
347
  with gr.Row():
348
  with gr.Column(scale=8):
 
355
  tc_table.value = init_table
356
  sort_dropdown_tc.change(fn=update_text_classification, inputs=sort_dropdown_tc, outputs=[tc_callout, tc_table])
357
 
358
+ # --- Image Classification Tab ---
359
  with gr.TabItem("Image Classification πŸ–ΌοΈ"):
360
  with gr.Row():
361
  with gr.Column(scale=8):
 
368
  ic_table.value = init_table
369
  sort_dropdown_ic.change(fn=update_image_classification, inputs=sort_dropdown_ic, outputs=[ic_callout, ic_table])
370
 
371
+ # --- Image Captioning Tab ---
372
  with gr.TabItem("Image Captioning πŸ“"):
373
  with gr.Row():
374
  with gr.Column(scale=8):
 
381
  icap_table.value = init_table
382
  sort_dropdown_icap.change(fn=update_image_captioning, inputs=sort_dropdown_icap, outputs=[icap_callout, icap_table])
383
 
384
+ # --- Summarization Tab ---
385
  with gr.TabItem("Summarization πŸ“ƒ"):
386
  with gr.Row():
387
  with gr.Column(scale=8):
 
394
  sum_table.value = init_table
395
  sort_dropdown_sum.change(fn=update_summarization, inputs=sort_dropdown_sum, outputs=[sum_callout, sum_table])
396
 
397
+ # --- Automatic Speech Recognition Tab ---
398
  with gr.TabItem("Automatic Speech Recognition πŸ’¬"):
399
  with gr.Row():
400
  with gr.Column(scale=8):
 
407
  asr_table.value = init_table
408
  sort_dropdown_asr.change(fn=update_asr, inputs=sort_dropdown_asr, outputs=[asr_callout, asr_table])
409
 
410
+ # --- Object Detection Tab ---
411
  with gr.TabItem("Object Detection 🚘"):
412
  with gr.Row():
413
  with gr.Column(scale=8):
 
420
  od_table.value = init_table
421
  sort_dropdown_od.change(fn=update_object_detection, inputs=sort_dropdown_od, outputs=[od_callout, od_table])
422
 
423
+ # --- Sentence Similarity Tab ---
424
  with gr.TabItem("Sentence Similarity πŸ“š"):
425
  with gr.Row():
426
  with gr.Column(scale=8):
 
433
  ss_table.value = init_table
434
  sort_dropdown_ss.change(fn=update_sentence_similarity, inputs=sort_dropdown_ss, outputs=[ss_callout, ss_table])
435
 
436
+ # --- Extractive QA Tab ---
437
  with gr.TabItem("Extractive QA ❔"):
438
  with gr.Row():
439
  with gr.Column(scale=8):
 
446
  qa_table.value = init_table
447
  sort_dropdown_qa.change(fn=update_extractive_qa, inputs=sort_dropdown_qa, outputs=[qa_callout, qa_table])
448
 
449
+ # --- All Tasks Tab ---
450
  with gr.TabItem("All Tasks πŸ’‘"):
451
  with gr.Row():
452
  with gr.Column(scale=8):