bgamazay commited on
Commit
2af0c24
·
verified ·
1 Parent(s): 2ec9b03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -30,12 +30,13 @@ def format_stars(score):
30
  Convert the energy_score (assumed to be an integer from 1 to 5)
31
  into that many star characters wrapped in a span styled with color #3fa45bff
32
  and with a font size increased to 2em.
 
33
  """
34
  try:
35
  score_int = int(score)
36
  except Exception:
37
  score_int = 0
38
- return f'<span style="color: #3fa45bff; font-size:2em;">{"★" * score_int}</span>'
39
 
40
  def make_link(mname):
41
  """
@@ -49,13 +50,15 @@ def make_link(mname):
49
  def get_plots(task):
50
  """
51
  Read the energy CSV for a given task and return a Plotly scatter plot.
52
- Now the x-axis is the numeric energy (GPU Energy (Wh)) and
53
- the y-axis displays the model name.
54
  """
55
  df = pd.read_csv('data/energy/' + task)
56
  df['energy_score'] = df['energy_score'].astype(int)
57
- # Do not multiply by 1000; simply round to 4 decimals
58
  df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
 
 
59
 
60
  # Define a 5-level color mapping: 1 = red, 5 = green.
61
  color_map = {
@@ -66,11 +69,10 @@ def get_plots(task):
66
  5: "green"
67
  }
68
 
69
- # Create a horizontal scatter plot: x is the energy, y is the model.
70
  fig = px.scatter(
71
  df,
72
  x="GPU Energy (Wh)",
73
- y="model",
74
  custom_data=['energy_score'],
75
  height=500,
76
  width=800,
@@ -97,6 +99,7 @@ def get_all_plots():
97
  df = pd.read_csv('data/energy/' + task)
98
  df['energy_score'] = df['energy_score'].astype(int)
99
  df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
 
100
  all_df = pd.concat([all_df, df], ignore_index=True)
101
  all_df = all_df.drop_duplicates(subset=['model'])
102
 
@@ -110,7 +113,7 @@ def get_all_plots():
110
  fig = px.scatter(
111
  all_df,
112
  x="GPU Energy (Wh)",
113
- y="model",
114
  custom_data=['energy_score'],
115
  height=500,
116
  width=800,
@@ -131,18 +134,18 @@ def get_model_names(task):
131
  """
132
  For a given task, load the energy CSV and return a dataframe with the following columns:
133
  - Model (a markdown link)
134
- - GPU Energy (Wh)
135
  - Score (a star rating based on energy_score)
136
  For text_generation.csv only, also add the "Class" column from the CSV.
137
- The final order is: Model, GPU Energy (Wh), Score, [Class].
138
  """
139
  df = pd.read_csv('data/energy/' + task)
140
  df['energy_score'] = df['energy_score'].astype(int)
141
- df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
 
142
  df['Model'] = df['model'].apply(make_link)
143
  df['Score'] = df['energy_score'].apply(format_stars)
144
 
145
- # If this CSV contains a "class" column (e.g., for Text Generation), add it.
146
  if 'class' in df.columns:
147
  df['Class'] = df['class']
148
  df = df[['Model', 'GPU Energy (Wh)', 'Score', 'Class']]
@@ -162,7 +165,7 @@ def get_all_model_names():
162
  for task in tasks:
163
  df = pd.read_csv('data/energy/' + task)
164
  df['energy_score'] = df['energy_score'].astype(int)
165
- df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
166
  df['Model'] = df['model'].apply(make_link)
167
  df['Score'] = df['energy_score'].apply(format_stars)
168
  all_df = pd.concat([all_df, df], ignore_index=True)
@@ -189,7 +192,6 @@ Click through the tasks below to see how different models measure up in terms of
189
  with gr.Column(scale=1.3):
190
  plot = gr.Plot(get_plots('text_generation.csv'))
191
  with gr.Column(scale=1):
192
- # For text generation, the CSV is assumed to have a "class" column.
193
  table = gr.Dataframe(get_model_names('text_generation.csv'), datatype="markdown")
194
 
195
  with gr.TabItem("Image Generation 📷"):
@@ -274,4 +276,4 @@ Click through the tasks below to see how different models measure up in terms of
274
  """Last updated: February 2025"""
275
  )
276
 
277
- demo.launch()
 
30
  Convert the energy_score (assumed to be an integer from 1 to 5)
31
  into that many star characters wrapped in a span styled with color #3fa45bff
32
  and with a font size increased to 2em.
33
+ The use of '!important' forces the styling immediately.
34
  """
35
  try:
36
  score_int = int(score)
37
  except Exception:
38
  score_int = 0
39
+ return f'<span style="color: #3fa45bff !important; font-size:2em !important;">{"★" * score_int}</span>'
40
 
41
  def make_link(mname):
42
  """
 
50
  def get_plots(task):
51
  """
52
  Read the energy CSV for a given task and return a Plotly scatter plot.
53
+ X-axis: Numeric GPU Energy (Wh) (rounded to 4 decimals)
54
+ Y-axis: Display only the model name (extracted from the model field)
55
  """
56
  df = pd.read_csv('data/energy/' + task)
57
  df['energy_score'] = df['energy_score'].astype(int)
58
+ # Use the raw energy (no multiplication) rounded to 4 decimals for plotting
59
  df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
60
+ # Create a column that displays only the model name (the part after '/')
61
+ df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
62
 
63
  # Define a 5-level color mapping: 1 = red, 5 = green.
64
  color_map = {
 
69
  5: "green"
70
  }
71
 
 
72
  fig = px.scatter(
73
  df,
74
  x="GPU Energy (Wh)",
75
+ y="Display Model",
76
  custom_data=['energy_score'],
77
  height=500,
78
  width=800,
 
99
  df = pd.read_csv('data/energy/' + task)
100
  df['energy_score'] = df['energy_score'].astype(int)
101
  df['GPU Energy (Wh)'] = df['total_gpu_energy'].round(4)
102
+ df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
103
  all_df = pd.concat([all_df, df], ignore_index=True)
104
  all_df = all_df.drop_duplicates(subset=['model'])
105
 
 
113
  fig = px.scatter(
114
  all_df,
115
  x="GPU Energy (Wh)",
116
+ y="Display Model",
117
  custom_data=['energy_score'],
118
  height=500,
119
  width=800,
 
134
  """
135
  For a given task, load the energy CSV and return a dataframe with the following columns:
136
  - Model (a markdown link)
137
+ - GPU Energy (Wh) formatted as a string with 4 decimal places
138
  - Score (a star rating based on energy_score)
139
  For text_generation.csv only, also add the "Class" column from the CSV.
140
+ The final column order is: Model, GPU Energy (Wh), Score, [Class].
141
  """
142
  df = pd.read_csv('data/energy/' + task)
143
  df['energy_score'] = df['energy_score'].astype(int)
144
+ # Format the energy as a string with 4 decimals so that very small values display correctly
145
+ df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
146
  df['Model'] = df['model'].apply(make_link)
147
  df['Score'] = df['energy_score'].apply(format_stars)
148
 
 
149
  if 'class' in df.columns:
150
  df['Class'] = df['class']
151
  df = df[['Model', 'GPU Energy (Wh)', 'Score', 'Class']]
 
165
  for task in tasks:
166
  df = pd.read_csv('data/energy/' + task)
167
  df['energy_score'] = df['energy_score'].astype(int)
168
+ df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
169
  df['Model'] = df['model'].apply(make_link)
170
  df['Score'] = df['energy_score'].apply(format_stars)
171
  all_df = pd.concat([all_df, df], ignore_index=True)
 
192
  with gr.Column(scale=1.3):
193
  plot = gr.Plot(get_plots('text_generation.csv'))
194
  with gr.Column(scale=1):
 
195
  table = gr.Dataframe(get_model_names('text_generation.csv'), datatype="markdown")
196
 
197
  with gr.TabItem("Image Generation 📷"):
 
276
  """Last updated: February 2025"""
277
  )
278
 
279
+ demo.launch()