bgamazay commited on
Commit
be5dffd
·
verified ·
1 Parent(s): d4f7fe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -33
app.py CHANGED
@@ -109,16 +109,17 @@ def compute_efficiency_ratio(df):
109
  ratio = max_val / min_val if min_val > 0 else 1
110
  return ratio
111
 
112
- def generate_callout(ratio, scope_text):
113
  """
114
- Returns a right-aligned callout where the inner box is shrink-wrapped to its text.
115
- The ratio is formatted with a comma for thousands.
 
116
  """
117
  return (
118
  f'<div style="text-align: right;">'
119
- f' <div style="display: inline-block; background-color: #f2f2f2; padding: 10px; '
120
- f' border-radius: 5px; margin-bottom:10px;">'
121
- f' Energy efficiency difference of <strong>{ratio:,.1f}x</strong> for {scope_text}.'
122
  f' </div>'
123
  f'</div>'
124
  )
@@ -132,7 +133,7 @@ def get_global_callout():
132
  df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
133
  all_df = pd.concat([all_df, df], ignore_index=True)
134
  ratio = compute_efficiency_ratio(all_df)
135
- return generate_callout(ratio, "all models in leaderboard")
136
 
137
  ### ZIP DOWNLOAD FUNCTIONS ###
138
 
@@ -174,70 +175,70 @@ def update_text_generation(selected_display, sort_order):
174
  return df
175
  df = process_df('text_generation.csv', sort_order, filter_fn)
176
  ratio = compute_efficiency_ratio(df)
177
- callout = generate_callout(ratio, "all models in task")
178
  table_html = generate_html_table_from_df(df)
179
  return callout, table_html
180
 
181
  def update_image_generation(sort_order):
182
  df = process_df('image_generation.csv', sort_order)
183
  ratio = compute_efficiency_ratio(df)
184
- callout = generate_callout(ratio, "all models in task")
185
  table_html = generate_html_table_from_df(df)
186
  return callout, table_html
187
 
188
  def update_text_classification(sort_order):
189
  df = process_df('text_classification.csv', sort_order)
190
  ratio = compute_efficiency_ratio(df)
191
- callout = generate_callout(ratio, "all models in task")
192
  table_html = generate_html_table_from_df(df)
193
  return callout, table_html
194
 
195
  def update_image_classification(sort_order):
196
  df = process_df('image_classification.csv', sort_order)
197
  ratio = compute_efficiency_ratio(df)
198
- callout = generate_callout(ratio, "all models in task")
199
  table_html = generate_html_table_from_df(df)
200
  return callout, table_html
201
 
202
  def update_image_captioning(sort_order):
203
  df = process_df('image_captioning.csv', sort_order)
204
  ratio = compute_efficiency_ratio(df)
205
- callout = generate_callout(ratio, "all models in task")
206
  table_html = generate_html_table_from_df(df)
207
  return callout, table_html
208
 
209
  def update_summarization(sort_order):
210
  df = process_df('summarization.csv', sort_order)
211
  ratio = compute_efficiency_ratio(df)
212
- callout = generate_callout(ratio, "all models in task")
213
  table_html = generate_html_table_from_df(df)
214
  return callout, table_html
215
 
216
  def update_asr(sort_order):
217
  df = process_df('asr.csv', sort_order)
218
  ratio = compute_efficiency_ratio(df)
219
- callout = generate_callout(ratio, "all models in task")
220
  table_html = generate_html_table_from_df(df)
221
  return callout, table_html
222
 
223
  def update_object_detection(sort_order):
224
  df = process_df('object_detection.csv', sort_order)
225
  ratio = compute_efficiency_ratio(df)
226
- callout = generate_callout(ratio, "all models in task")
227
  table_html = generate_html_table_from_df(df)
228
  return callout, table_html
229
 
230
  def update_sentence_similarity(sort_order):
231
  df = process_df('sentence_similarity.csv', sort_order)
232
  ratio = compute_efficiency_ratio(df)
233
- callout = generate_callout(ratio, "all models in task")
234
  table_html = generate_html_table_from_df(df)
235
  return callout, table_html
236
 
237
  def update_extractive_qa(sort_order):
238
  df = process_df('question_answering.csv', sort_order)
239
  ratio = compute_efficiency_ratio(df)
240
- callout = generate_callout(ratio, "all models in task")
241
  table_html = generate_html_table_from_df(df)
242
  return callout, table_html
243
 
@@ -257,7 +258,7 @@ def update_all_tasks(sort_order):
257
  ascending = True if sort_order == "Low to High" else False
258
  all_df = all_df.sort_values(by='gpu_energy_numeric', ascending=ascending)
259
  ratio = compute_efficiency_ratio(all_df)
260
- callout = generate_callout(ratio, "all models in leaderboard")
261
  table_html = generate_html_table_from_df(all_df)
262
  return callout, table_html
263
 
@@ -294,28 +295,25 @@ with demo:
294
  </div>
295
  ''')
296
 
297
- # --- Centered Logo ---
298
- gr.HTML('''
299
- <div style="text-align: center; margin-top: 0px;">
300
- <img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
301
- alt="Logo"
302
- style="display: inline-block; max-width: 300px; height: auto;">
303
- </div>
304
- ''')
305
-
306
- # --- Global Welcome & Callout Row ---
307
  with gr.Row():
308
- with gr.Column(scale=8):
309
- gr.Markdown("<div style='text-align: left; font-size: 1.2em; margin-top: 10px;'>Select different tasks to see scored models.</div>")
310
- with gr.Column(scale=4):
 
 
 
 
 
 
311
  global_callout = gr.HTML(get_global_callout())
312
 
313
  # --- Tabs for the different tasks ---
314
  with gr.Tabs():
315
- # --- Text Generation Tab ---
316
  with gr.TabItem("Text Generation 💬"):
317
  with gr.Row():
318
- with gr.Column(scale=8):
319
  model_class_options = [
320
  "A (Single Consumer GPU) <20B parameters",
321
  "B (Single Cloud GPU) 20-66B parameters",
@@ -326,6 +324,7 @@ with demo:
326
  label="Select Model Class",
327
  value=model_class_options[0]
328
  )
 
329
  sort_dropdown_tg = gr.Dropdown(
330
  choices=["Low to High", "High to Low"],
331
  label="Sort",
 
109
  ratio = max_val / min_val if min_val > 0 else 1
110
  return ratio
111
 
112
+ def generate_info_callout(ratio, scope_text):
113
  """
114
+ Returns an inline, right-aligned "did you know" callout using a lightbulb emoji.
115
+ The callout uses a light green background, a small font, and states:
116
+ "💡 did you know: XXXx energy use difference between most and least efficient model in [scope_text]."
117
  """
118
  return (
119
  f'<div style="text-align: right;">'
120
+ f' <div style="display: inline-block; background-color: #e6ffe6; padding: 8px; '
121
+ f' border-radius: 5px; font-size: 0.8em;">'
122
+ f' 💡 did you know: <strong>{ratio:,.1f}x</strong> energy use difference between most and least efficient model in {scope_text}.'
123
  f' </div>'
124
  f'</div>'
125
  )
 
133
  df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
134
  all_df = pd.concat([all_df, df], ignore_index=True)
135
  ratio = compute_efficiency_ratio(all_df)
136
+ return generate_info_callout(ratio, "this leaderboard")
137
 
138
  ### ZIP DOWNLOAD FUNCTIONS ###
139
 
 
175
  return df
176
  df = process_df('text_generation.csv', sort_order, filter_fn)
177
  ratio = compute_efficiency_ratio(df)
178
+ callout = generate_info_callout(ratio, "this task")
179
  table_html = generate_html_table_from_df(df)
180
  return callout, table_html
181
 
182
  def update_image_generation(sort_order):
183
  df = process_df('image_generation.csv', sort_order)
184
  ratio = compute_efficiency_ratio(df)
185
+ callout = generate_info_callout(ratio, "this task")
186
  table_html = generate_html_table_from_df(df)
187
  return callout, table_html
188
 
189
  def update_text_classification(sort_order):
190
  df = process_df('text_classification.csv', sort_order)
191
  ratio = compute_efficiency_ratio(df)
192
+ callout = generate_info_callout(ratio, "this task")
193
  table_html = generate_html_table_from_df(df)
194
  return callout, table_html
195
 
196
  def update_image_classification(sort_order):
197
  df = process_df('image_classification.csv', sort_order)
198
  ratio = compute_efficiency_ratio(df)
199
+ callout = generate_info_callout(ratio, "this task")
200
  table_html = generate_html_table_from_df(df)
201
  return callout, table_html
202
 
203
  def update_image_captioning(sort_order):
204
  df = process_df('image_captioning.csv', sort_order)
205
  ratio = compute_efficiency_ratio(df)
206
+ callout = generate_info_callout(ratio, "this task")
207
  table_html = generate_html_table_from_df(df)
208
  return callout, table_html
209
 
210
  def update_summarization(sort_order):
211
  df = process_df('summarization.csv', sort_order)
212
  ratio = compute_efficiency_ratio(df)
213
+ callout = generate_info_callout(ratio, "this task")
214
  table_html = generate_html_table_from_df(df)
215
  return callout, table_html
216
 
217
  def update_asr(sort_order):
218
  df = process_df('asr.csv', sort_order)
219
  ratio = compute_efficiency_ratio(df)
220
+ callout = generate_info_callout(ratio, "this task")
221
  table_html = generate_html_table_from_df(df)
222
  return callout, table_html
223
 
224
  def update_object_detection(sort_order):
225
  df = process_df('object_detection.csv', sort_order)
226
  ratio = compute_efficiency_ratio(df)
227
+ callout = generate_info_callout(ratio, "this task")
228
  table_html = generate_html_table_from_df(df)
229
  return callout, table_html
230
 
231
  def update_sentence_similarity(sort_order):
232
  df = process_df('sentence_similarity.csv', sort_order)
233
  ratio = compute_efficiency_ratio(df)
234
+ callout = generate_info_callout(ratio, "this task")
235
  table_html = generate_html_table_from_df(df)
236
  return callout, table_html
237
 
238
  def update_extractive_qa(sort_order):
239
  df = process_df('question_answering.csv', sort_order)
240
  ratio = compute_efficiency_ratio(df)
241
+ callout = generate_info_callout(ratio, "this task")
242
  table_html = generate_html_table_from_df(df)
243
  return callout, table_html
244
 
 
258
  ascending = True if sort_order == "Low to High" else False
259
  all_df = all_df.sort_values(by='gpu_energy_numeric', ascending=ascending)
260
  ratio = compute_efficiency_ratio(all_df)
261
+ callout = generate_info_callout(ratio, "this leaderboard")
262
  table_html = generate_html_table_from_df(all_df)
263
  return callout, table_html
264
 
 
295
  </div>
296
  ''')
297
 
298
+ # --- Logo & Global Callout Row ---
 
 
 
 
 
 
 
 
 
299
  with gr.Row():
300
+ with gr.Column(scale=6):
301
+ gr.HTML('''
302
+ <div style="text-align: left; margin-top: 0px;">
303
+ <img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
304
+ alt="Logo"
305
+ style="display: inline-block; max-width: 300px; height: auto;">
306
+ </div>
307
+ ''')
308
+ with gr.Column(scale=6):
309
  global_callout = gr.HTML(get_global_callout())
310
 
311
  # --- Tabs for the different tasks ---
312
  with gr.Tabs():
313
+ # --- Text Generation Tab (two dropdowns side by side with task callout to the right) ---
314
  with gr.TabItem("Text Generation 💬"):
315
  with gr.Row():
316
+ with gr.Column(scale=4):
317
  model_class_options = [
318
  "A (Single Consumer GPU) <20B parameters",
319
  "B (Single Cloud GPU) 20-66B parameters",
 
324
  label="Select Model Class",
325
  value=model_class_options[0]
326
  )
327
+ with gr.Column(scale=4):
328
  sort_dropdown_tg = gr.Dropdown(
329
  choices=["Low to High", "High to Low"],
330
  label="Sort",