bgamazay commited on
Commit
88fbc65
·
verified ·
1 Parent(s): c3f4f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -22
app.py CHANGED
@@ -39,13 +39,9 @@ def make_link(mname):
39
 
40
  def generate_html_table_from_df(df):
41
  """
42
- Given a dataframe that already includes:
43
- - 'gpu_energy_numeric': numeric energy (in Wh)
44
- - 'Model': the model link HTML,
45
- - 'Score': the HTML stars,
46
- - and 'energy_score' as an integer,
47
- generate an HTML table that shows the energy value plus a horizontal bar whose width is computed
48
- relative to the maximum energy.
49
  """
50
  max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
51
  color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
@@ -59,7 +55,7 @@ def generate_html_table_from_df(df):
59
  for _, row in df.iterrows():
60
  energy_numeric = row['gpu_energy_numeric']
61
  energy_str = f"{energy_numeric:.4f}"
62
- # Compute the relative width (as a percentage) for the horizontal bar
63
  bar_width = (energy_numeric / max_energy) * 100
64
  score_val = row['energy_score']
65
  bar_color = color_map.get(str(score_val), "gray")
@@ -83,7 +79,8 @@ def get_model_names_html(task):
83
  df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
84
  df['Model'] = df['model'].apply(make_link)
85
  df['Score'] = df['energy_score'].apply(format_stars)
86
- df = df.sort_values(by='gpu_energy_numeric')
 
87
  return generate_html_table_from_df(df)
88
 
89
  def get_all_model_names_html():
@@ -98,23 +95,33 @@ def get_all_model_names_html():
98
  df['Score'] = df['energy_score'].apply(format_stars)
99
  all_df = pd.concat([all_df, df], ignore_index=True)
100
  all_df = all_df.drop_duplicates(subset=['model'])
101
- all_df = all_df.sort_values(by='gpu_energy_numeric')
 
102
  return generate_html_table_from_df(all_df)
103
 
104
  def get_text_generation_model_names_html(model_class):
105
  df = pd.read_csv('data/energy/text_generation.csv')
106
  if df.columns[0].startswith("Unnamed:"):
107
  df = df.iloc[:, 1:]
 
108
  if 'class' in df.columns:
109
  df = df[df['class'] == model_class]
110
  df['energy_score'] = df['energy_score'].astype(int)
111
  df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
112
  df['Model'] = df['model'].apply(make_link)
113
  df['Score'] = df['energy_score'].apply(format_stars)
114
- df = df.sort_values(by='gpu_energy_numeric')
 
115
  return generate_html_table_from_df(df)
116
 
117
- def update_text_generation(model_class):
 
 
 
 
 
 
 
118
  table_html = get_text_generation_model_names_html(model_class)
119
  return table_html
120
 
@@ -139,17 +146,37 @@ with demo:
139
  ### Welcome to the leaderboard for the [AI Energy Score Project!](https://huggingface.co/AIEnergyScore)
140
  Select different tasks to see scored models. Submit open models for testing and learn about testing proprietary models via the [submission portal](https://huggingface.co/spaces/AIEnergyScore/submission_portal)"""
141
  )
142
-
 
 
 
 
 
 
 
 
 
 
143
  with gr.Tabs():
144
  # --- Text Generation Tab with Dropdown for Model Class ---
145
  with gr.TabItem("Text Generation 💬"):
146
- model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
147
- label="Select Model Class",
148
- value="A")
 
 
 
 
 
 
 
 
149
  tg_table = gr.HTML(get_text_generation_model_names_html("A"))
150
- model_class_dropdown.change(fn=update_text_generation,
151
- inputs=model_class_dropdown,
152
- outputs=tg_table)
 
 
153
 
154
  with gr.TabItem("Image Generation 📷"):
155
  gr.HTML(get_model_names_html('image_generation.csv'))
@@ -189,8 +216,6 @@ Select different tasks to see scored models. Submit open models for testing and
189
  lines=10,
190
  show_copy_button=True,
191
  )
192
- gr.Markdown(
193
- """Last updated: February 2025"""
194
- )
195
 
196
  demo.launch()
 
39
 
40
  def generate_html_table_from_df(df):
41
  """
42
+ Generate an HTML table from the given DataFrame.
43
+ Each GPU Energy cell contains both the numeric energy (Wh) and a horizontal bar
44
+ whose width is computed relative to the maximum energy in the table.
 
 
 
 
45
  """
46
  max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
47
  color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
 
55
  for _, row in df.iterrows():
56
  energy_numeric = row['gpu_energy_numeric']
57
  energy_str = f"{energy_numeric:.4f}"
58
+ # Calculate the relative width as a percentage
59
  bar_width = (energy_numeric / max_energy) * 100
60
  score_val = row['energy_score']
61
  bar_color = color_map.get(str(score_val), "gray")
 
79
  df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
80
  df['Model'] = df['model'].apply(make_link)
81
  df['Score'] = df['energy_score'].apply(format_stars)
82
+ # Sort descending (high to low)
83
+ df = df.sort_values(by='gpu_energy_numeric', ascending=False)
84
  return generate_html_table_from_df(df)
85
 
86
  def get_all_model_names_html():
 
95
  df['Score'] = df['energy_score'].apply(format_stars)
96
  all_df = pd.concat([all_df, df], ignore_index=True)
97
  all_df = all_df.drop_duplicates(subset=['model'])
98
+ # Sort descending
99
+ all_df = all_df.sort_values(by='gpu_energy_numeric', ascending=False)
100
  return generate_html_table_from_df(all_df)
101
 
102
  def get_text_generation_model_names_html(model_class):
103
  df = pd.read_csv('data/energy/text_generation.csv')
104
  if df.columns[0].startswith("Unnamed:"):
105
  df = df.iloc[:, 1:]
106
+ # Filter by model class if the "class" column exists
107
  if 'class' in df.columns:
108
  df = df[df['class'] == model_class]
109
  df['energy_score'] = df['energy_score'].astype(int)
110
  df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
111
  df['Model'] = df['model'].apply(make_link)
112
  df['Score'] = df['energy_score'].apply(format_stars)
113
+ # Sort descending
114
+ df = df.sort_values(by='gpu_energy_numeric', ascending=False)
115
  return generate_html_table_from_df(df)
116
 
117
+ def update_text_generation(selected_display):
118
+ # Mapping from display text to the internal value
119
+ mapping = {
120
+ "A (Single Consumer GPU) <20B parameters": "A",
121
+ "B (Single Cloud GPU) 20-66B parameters": "B",
122
+ "C (Multiple Cloud GPUs) >66B parameters": "C"
123
+ }
124
+ model_class = mapping.get(selected_display, "A")
125
  table_html = get_text_generation_model_names_html(model_class)
126
  return table_html
127
 
 
146
  ### Welcome to the leaderboard for the [AI Energy Score Project!](https://huggingface.co/AIEnergyScore)
147
  Select different tasks to see scored models. Submit open models for testing and learn about testing proprietary models via the [submission portal](https://huggingface.co/spaces/AIEnergyScore/submission_portal)"""
148
  )
149
+
150
+ # Visually appealing header links
151
+ gr.HTML('''
152
+ <div style="text-align: center; margin-bottom: 20px;">
153
+ <a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Submission Portal</a>
154
+ <a href="https://huggingface.co/spaces/AIEnergyScore/README/discussions" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Community</a>
155
+ <a href="https://huggingface.github.io/AIEnergyScore/#faq" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">FAQ</a>
156
+ <a href="https://huggingface.github.io/AIEnergyScore/#documentation" style="margin: 0 15px; text-decoration: none; font-weight: bold; font-size: 1.1em;">Documentation</a>
157
+ </div>
158
+ ''')
159
+
160
  with gr.Tabs():
161
  # --- Text Generation Tab with Dropdown for Model Class ---
162
  with gr.TabItem("Text Generation 💬"):
163
+ # Define the dropdown with descriptive text options.
164
+ model_class_options = [
165
+ "A (Single Consumer GPU) <20B parameters",
166
+ "B (Single Cloud GPU) 20-66B parameters",
167
+ "C (Multiple Cloud GPUs) >66B parameters"
168
+ ]
169
+ model_class_dropdown = gr.Dropdown(
170
+ choices=model_class_options,
171
+ label="Select Model Class",
172
+ value=model_class_options[0]
173
+ )
174
  tg_table = gr.HTML(get_text_generation_model_names_html("A"))
175
+ model_class_dropdown.change(
176
+ fn=update_text_generation,
177
+ inputs=model_class_dropdown,
178
+ outputs=tg_table
179
+ )
180
 
181
  with gr.TabItem("Image Generation 📷"):
182
  gr.HTML(get_model_names_html('image_generation.csv'))
 
216
  lines=10,
217
  show_copy_button=True,
218
  )
219
+ gr.Markdown("""Last updated: February 2025""")
 
 
220
 
221
  demo.launch()