bgamazay commited on
Commit
29889b7
·
verified ·
1 Parent(s): f8f6371

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -39,10 +39,10 @@ def make_link(mname):
39
  display_name = parts[1] if len(parts) > 1 else mname
40
  return f'[{display_name}](https://huggingface.co/{mname})'
41
 
42
- # --- Leaderboard Table Functions (Removed redundant drop) ---
43
 
44
  def create_minimal_bar_html(energy_value_wh, energy_score, max_energy_value):
45
- """Generates HTML for the minimal bar chart with dynamic max energy."""
46
  if max_energy_value <= 0: # Avoid division by zero if max energy is 0 or negative
47
  bar_percentage = 0
48
  else:
@@ -69,12 +69,11 @@ def get_model_names(task):
69
  max_energy_for_task = df['total_gpu_energy'].max() # Calculate max energy for this task
70
 
71
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_for_task
72
- df['GPU Energy (Wh)'] = df.apply(lambda row: create_minimal_bar_html(row['total_gpu_energy'], row['energy_score'], max_energy_for_task), axis=1)
73
 
74
  df['Model'] = df['model'].apply(make_link)
75
  df['Score'] = df['energy_score'].apply(format_stars)
76
  df = df[['Model', 'GPU Energy (Wh)', 'Score']] # Keep only these columns
77
- # df = df.drop('total_gpu_energy', axis=1) # REMOVED redundant drop
78
  return df
79
 
80
  def get_all_model_names():
@@ -92,11 +91,10 @@ def get_all_model_names():
92
  max_energy_overall = all_df['total_gpu_energy'].max() # Calculate overall max AFTER sorting
93
 
94
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_overall
95
- all_df['GPU Energy (Wh)'] = all_df.apply(lambda row: create_minimal_bar_html(row['total_gpu_energy'], row['energy_score'], max_energy_overall), axis=1)
96
  all_df['Model'] = all_df['model'].apply(make_link)
97
  all_df['Score'] = all_df['energy_score'].apply(format_stars)
98
  all_df = all_df[['Model', 'GPU Energy (Wh)', 'Score']]
99
- # all_df = all_df.drop('total_gpu_energy', axis=1) # REMOVED redundant drop
100
  return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
101
 
102
 
@@ -113,19 +111,18 @@ def get_text_generation_model_names(model_class):
113
  max_energy_for_class = df['total_gpu_energy'].max() # Calculate max energy for this class
114
 
115
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_for_class
116
- df['GPU Energy (Wh)'] = df.apply(lambda row: create_minimal_bar_html(row['total_gpu_energy'], row['energy_score'], max_energy_for_class), axis=1)
117
 
118
  df['Model'] = df['model'].apply(make_link)
119
  df['Score'] = df['energy_score'].apply(format_stars)
120
  df = df[['Model', 'GPU Energy (Wh)', 'Score']] # Keep only these columns
121
- # df = df.drop('total_gpu_energy', axis=1) # REMOVED redundant drop
122
  return df
123
 
124
  def update_text_generation(model_class):
125
  table = get_text_generation_model_names(model_class)
126
  return table
127
 
128
- # --- Build the Gradio Interface (Plots Removed, Tables with Dynamic Bars) ---
129
 
130
  demo = gr.Blocks(css="""
131
  .gr-dataframe table {
@@ -165,41 +162,41 @@ Select different tasks to see scored models. Submit open models for testing and
165
  model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
166
  label="Select Model Class",
167
  value="A")
168
- tg_table = gr.Dataframe(get_text_generation_model_names("A"), datatype="markdown") # No plot anymore
169
  # Update table when the dropdown value changes
170
  model_class_dropdown.change(fn=update_text_generation,
171
  inputs=model_class_dropdown,
172
  outputs=[tg_table])
173
 
174
  with gr.TabItem("Image Generation 📷"):
175
- table = gr.Dataframe(get_model_names('image_generation.csv'), datatype="markdown")
176
 
177
  with gr.TabItem("Text Classification 🎭"):
178
- table = gr.Dataframe(get_model_names('text_classification.csv'), datatype="markdown")
179
 
180
  with gr.TabItem("Image Classification 🖼️"):
181
- table = gr.Dataframe(get_model_names('image_classification.csv'), datatype="markdown")
182
 
183
  with gr.TabItem("Image Captioning 📝"):
184
- table = gr.Dataframe(get_model_names('image_captioning.csv'), datatype="markdown")
185
 
186
  with gr.TabItem("Summarization 📃"):
187
- table = gr.Dataframe(get_model_names('summarization.csv'), datatype="markdown")
188
 
189
  with gr.TabItem("Automatic Speech Recognition 💬"):
190
- table = gr.Dataframe(get_model_names('asr.csv'), datatype="markdown")
191
 
192
  with gr.TabItem("Object Detection 🚘"):
193
- table = gr.Dataframe(get_model_names('object_detection.csv'), datatype="markdown")
194
 
195
  with gr.TabItem("Sentence Similarity 📚"):
196
- table = gr.Dataframe(get_model_names('sentence_similarity.csv'), datatype="markdown")
197
 
198
  with gr.TabItem("Extractive QA ❔"):
199
- table = gr.Dataframe(get_model_names('question_answering.csv'), datatype="markdown")
200
 
201
  with gr.TabItem("All Tasks 💡"):
202
- table = gr.Dataframe(get_all_model_names(), datatype="markdown")
203
 
204
  with gr.Accordion("📙 Citation", open=False):
205
  citation_button = gr.Textbox(
 
39
  display_name = parts[1] if len(parts) > 1 else mname
40
  return f'[{display_name}](https://huggingface.co/{mname})'
41
 
42
+ # --- Leaderboard Table Functions (Using gr.HTML Component) ---
43
 
44
  def create_minimal_bar_html(energy_value_wh, energy_score, max_energy_value):
45
+ """Generates HTML for the minimal bar chart."""
46
  if max_energy_value <= 0: # Avoid division by zero if max energy is 0 or negative
47
  bar_percentage = 0
48
  else:
 
69
  max_energy_for_task = df['total_gpu_energy'].max() # Calculate max energy for this task
70
 
71
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_for_task
72
+ df['GPU Energy (Wh)'] = df.apply(lambda row: gr.HTML(create_minimal_bar_html(row['total_gpu_energy'], row['energy_score'], max_energy_for_task)), axis=1)
73
 
74
  df['Model'] = df['model'].apply(make_link)
75
  df['Score'] = df['energy_score'].apply(format_stars)
76
  df = df[['Model', 'GPU Energy (Wh)', 'Score']] # Keep only these columns
 
77
  return df
78
 
79
  def get_all_model_names():
 
91
  max_energy_overall = all_df['total_gpu_energy'].max() # Calculate overall max AFTER sorting
92
 
93
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_overall
94
+ all_df['GPU Energy (Wh)'] = all_df.apply(lambda row: gr.HTML(create_minimal_bar_html(row['total_gpu_energy'], row['energy_score'], max_energy_overall)), axis=1)
95
  all_df['Model'] = all_df['model'].apply(make_link)
96
  all_df['Score'] = all_df['energy_score'].apply(format_stars)
97
  all_df = all_df[['Model', 'GPU Energy (Wh)', 'Score']]
 
98
  return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
99
 
100
 
 
111
  max_energy_for_class = df['total_gpu_energy'].max() # Calculate max energy for this class
112
 
113
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_for_class
114
+ df['GPU Energy (Wh)'] = df.apply(lambda row: gr.HTML(create_minimal_bar_html(row['total_gpu_energy'], row['energy_score'], max_energy_for_class)), axis=1)
115
 
116
  df['Model'] = df['model'].apply(make_link)
117
  df['Score'] = df['energy_score'].apply(format_stars)
118
  df = df[['Model', 'GPU Energy (Wh)', 'Score']] # Keep only these columns
 
119
  return df
120
 
121
  def update_text_generation(model_class):
122
  table = get_text_generation_model_names(model_class)
123
  return table
124
 
125
+ # --- Build the Gradio Interface (Plots Removed, Tables with Dynamic Bars using gr.HTML) ---
126
 
127
  demo = gr.Blocks(css="""
128
  .gr-dataframe table {
 
162
  model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
163
  label="Select Model Class",
164
  value="A")
165
+ tg_table = gr.Dataframe(get_text_generation_model_names("A")) # No datatype="markdown" here
166
  # Update table when the dropdown value changes
167
  model_class_dropdown.change(fn=update_text_generation,
168
  inputs=model_class_dropdown,
169
  outputs=[tg_table])
170
 
171
  with gr.TabItem("Image Generation 📷"):
172
+ table = gr.Dataframe(get_model_names('image_generation.csv')) # No datatype="markdown" here
173
 
174
  with gr.TabItem("Text Classification 🎭"):
175
+ table = gr.Dataframe(get_model_names('text_classification.csv')) # No datatype="markdown" here
176
 
177
  with gr.TabItem("Image Classification 🖼️"):
178
+ table = gr.Dataframe(get_model_names('image_classification.csv')) # No datatype="markdown" here
179
 
180
  with gr.TabItem("Image Captioning 📝"):
181
+ table = gr.Dataframe(get_model_names('image_captioning.csv')) # No datatype="markdown" here
182
 
183
  with gr.TabItem("Summarization 📃"):
184
+ table = gr.Dataframe(get_model_names('summarization.csv')) # No datatype="markdown" here
185
 
186
  with gr.TabItem("Automatic Speech Recognition 💬"):
187
+ table = gr.Dataframe(get_model_names('asr.csv')) # No datatype="markdown" here
188
 
189
  with gr.TabItem("Object Detection 🚘"):
190
+ table = gr.Dataframe(get_model_names('object_detection.csv')) # No datatype="markdown" here
191
 
192
  with gr.TabItem("Sentence Similarity 📚"):
193
+ table = gr.Dataframe(get_model_names('sentence_similarity.csv')) # No datatype="markdown" here
194
 
195
  with gr.TabItem("Extractive QA ❔"):
196
+ table = gr.Dataframe(get_model_names('question_answering.csv')) # No datatype="markdown" here
197
 
198
  with gr.TabItem("All Tasks 💡"):
199
+ table = gr.Dataframe(get_all_model_names()) # No datatype="markdown" here
200
 
201
  with gr.Accordion("📙 Citation", open=False):
202
  citation_button = gr.Textbox(