bgamazay commited on
Commit
f8f25eb
·
verified ·
1 Parent(s): d05cc50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -27
app.py CHANGED
@@ -39,7 +39,7 @@ 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 (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."""
@@ -49,12 +49,10 @@ def create_minimal_bar_html(energy_value_wh, energy_score, max_energy_value):
49
  bar_percentage = min(100, (energy_value_wh / max_energy_value) * 100) # Cap at 100%
50
  bar_color = color_map.get(str(energy_score), "gray") # Default color if score is unexpected
51
 
52
- html = f"""
53
- <div style="display: flex; align-items: center; gap: 5px;">
54
- <div style="width: {bar_percentage}%; height: 10px; background-color: {bar_color}; border-radius: 2px;"></div>
55
- <span>{energy_value_wh:.4f} Wh</span>
56
- </div>
57
- """
58
  return html
59
 
60
 
@@ -69,7 +67,7 @@ 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: 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)
@@ -91,7 +89,7 @@ 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']]
@@ -111,7 +109,7 @@ def get_text_generation_model_names(model_class):
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)
@@ -122,7 +120,7 @@ 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 {
@@ -135,17 +133,25 @@ demo = gr.Blocks(css="""
135
  overflow: hidden;
136
  text-overflow: ellipsis;
137
  }
138
- /* CSS for minimal bar chart inside table cell */
139
- .minimal-bar-container {
140
  display: flex;
141
  align-items: center;
142
- gap: 5px; /* space between bar and text */
 
 
 
143
  }
144
- .minimal-bar {
145
  height: 10px;
146
  background-color: blue; /* default, will be overridden by dynamic color */
147
  border-radius: 2px;
148
  }
 
 
 
 
 
149
  """)
150
 
151
  with demo:
@@ -162,41 +168,41 @@ Select different tasks to see scored models. Submit open models for testing and
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(
@@ -210,4 +216,4 @@ Select different tasks to see scored models. Submit open models for testing and
210
  """Last updated: February 2025"""
211
  )
212
 
213
- demo.launch(share=True) # Added share=True here
 
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 (Back to datatype="markdown" approach) ---
43
 
44
  def create_minimal_bar_html(energy_value_wh, energy_score, max_energy_value):
45
  """Generates HTML for the minimal bar chart."""
 
49
  bar_percentage = min(100, (energy_value_wh / max_energy_value) * 100) # Cap at 100%
50
  bar_color = color_map.get(str(energy_score), "gray") # Default color if score is unexpected
51
 
52
+ html = f"""<div class='minimal-bar-container'>
53
+ <div class='minimal-bar' style='width: {bar_percentage}%; background-color: {bar_color};'></div>
54
+ <span style='margin-left: 5px;'>{energy_value_wh:.4f} Wh</span>
55
+ </div>""" # Added classes and inline styles for better control
 
 
56
  return html
57
 
58
 
 
67
  max_energy_for_task = df['total_gpu_energy'].max() # Calculate max energy for this task
68
 
69
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_for_task
70
+ 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)
71
 
72
  df['Model'] = df['model'].apply(make_link)
73
  df['Score'] = df['energy_score'].apply(format_stars)
 
89
  max_energy_overall = all_df['total_gpu_energy'].max() # Calculate overall max AFTER sorting
90
 
91
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_overall
92
+ 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)
93
  all_df['Model'] = all_df['model'].apply(make_link)
94
  all_df['Score'] = all_df['energy_score'].apply(format_stars)
95
  all_df = all_df[['Model', 'GPU Energy (Wh)', 'Score']]
 
109
  max_energy_for_class = df['total_gpu_energy'].max() # Calculate max energy for this class
110
 
111
  # Create HTML bar chart for GPU Energy column, passing dynamic max_energy_for_class
112
+ 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)
113
 
114
  df['Model'] = df['model'].apply(make_link)
115
  df['Score'] = df['energy_score'].apply(format_stars)
 
120
  table = get_text_generation_model_names(model_class)
121
  return table
122
 
123
+ # --- Build the Gradio Interface (Plots Removed, Tables with Dynamic Bars using datatype="markdown") ---
124
 
125
  demo = gr.Blocks(css="""
126
  .gr-dataframe table {
 
133
  overflow: hidden;
134
  text-overflow: ellipsis;
135
  }
136
+ /* CSS for minimal bar chart inside table cell - more specific CSS */
137
+ .gr-dataframe td > .minimal-bar-container { /* Target minimal-bar-container WITHIN dataframe cells */
138
  display: flex;
139
  align-items: center;
140
+ gap: 5px;
141
+ margin: 0; /* Reset margins */
142
+ padding: 0; /* Reset paddings */
143
+ line-height: normal; /* Reset line-height */
144
  }
145
+ .gr-dataframe td > .minimal-bar-container > .minimal-bar { /* Target minimal-bar WITHIN container in dataframe cells */
146
  height: 10px;
147
  background-color: blue; /* default, will be overridden by dynamic color */
148
  border-radius: 2px;
149
  }
150
+ .gr-dataframe td > .minimal-bar-container > span { /* Target span for text value in dataframe cells */
151
+ font-size: 0.9em; /* Adjust text size if needed */
152
+ color: #333; /* Adjust text color if needed */
153
+ }
154
+
155
  """)
156
 
157
  with demo:
 
168
  model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
169
  label="Select Model Class",
170
  value="A")
171
+ tg_table = gr.Dataframe(get_text_generation_model_names("A"), datatype="markdown") # IMPORTANT: datatype="markdown"
172
  # Update table when the dropdown value changes
173
  model_class_dropdown.change(fn=update_text_generation,
174
  inputs=model_class_dropdown,
175
  outputs=[tg_table])
176
 
177
  with gr.TabItem("Image Generation 📷"):
178
+ table = gr.Dataframe(get_model_names('image_generation.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
179
 
180
  with gr.TabItem("Text Classification 🎭"):
181
+ table = gr.Dataframe(get_model_names('text_classification.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
182
 
183
  with gr.TabItem("Image Classification 🖼️"):
184
+ table = gr.Dataframe(get_model_names('image_classification.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
185
 
186
  with gr.TabItem("Image Captioning 📝"):
187
+ table = gr.Dataframe(get_model_names('image_captioning.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
188
 
189
  with gr.TabItem("Summarization 📃"):
190
+ table = gr.Dataframe(get_model_names('summarization.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
191
 
192
  with gr.TabItem("Automatic Speech Recognition 💬"):
193
+ table = gr.Dataframe(get_model_names('asr.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
194
 
195
  with gr.TabItem("Object Detection 🚘"):
196
+ table = gr.Dataframe(get_model_names('object_detection.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
197
 
198
  with gr.TabItem("Sentence Similarity 📚"):
199
+ table = gr.Dataframe(get_model_names('sentence_similarity.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
200
 
201
  with gr.TabItem("Extractive QA ❔"):
202
+ table = gr.Dataframe(get_model_names('question_answering.csv'), datatype="markdown") # IMPORTANT: datatype="markdown"
203
 
204
  with gr.TabItem("All Tasks 💡"):
205
+ table = gr.Dataframe(get_all_model_names(), datatype="markdown") # IMPORTANT: datatype="markdown"
206
 
207
  with gr.Accordion("📙 Citation", open=False):
208
  citation_button = gr.Textbox(
 
216
  """Last updated: February 2025"""
217
  )
218
 
219
+ demo.launch(share=True)