Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,9 +41,9 @@ def get_plots(task):
|
|
| 41 |
df = pd.read_csv('data/energy/' + task)
|
| 42 |
if df.columns[0].startswith("Unnamed:"):
|
| 43 |
df = df.iloc[:, 1:]
|
| 44 |
-
#
|
| 45 |
df['total_gpu_energy'] = df['total_gpu_energy'].astype(float)
|
| 46 |
-
# Convert energy_score to
|
| 47 |
df['energy_score'] = df['energy_score'].astype(int).astype(str)
|
| 48 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
| 49 |
|
|
@@ -59,10 +59,11 @@ def get_plots(task):
|
|
| 59 |
width=800,
|
| 60 |
color_discrete_map=color_map
|
| 61 |
)
|
|
|
|
| 62 |
fig.update_traces(
|
| 63 |
hovertemplate="<br>".join([
|
| 64 |
"Model: %{y}",
|
| 65 |
-
"GPU Energy (Wh): %{x}",
|
| 66 |
"Energy Score: %{customdata[0]}"
|
| 67 |
])
|
| 68 |
)
|
|
@@ -96,7 +97,7 @@ def get_all_plots():
|
|
| 96 |
fig.update_traces(
|
| 97 |
hovertemplate="<br>".join([
|
| 98 |
"Model: %{y}",
|
| 99 |
-
"GPU Energy (Wh): %{x}",
|
| 100 |
"Energy Score: %{customdata[0]}"
|
| 101 |
])
|
| 102 |
)
|
|
@@ -108,16 +109,12 @@ def get_model_names(task):
|
|
| 108 |
if df.columns[0].startswith("Unnamed:"):
|
| 109 |
df = df.iloc[:, 1:]
|
| 110 |
df['energy_score'] = df['energy_score'].astype(int)
|
|
|
|
| 111 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].astype(float).apply(lambda x: f"{x:.4f}")
|
| 112 |
df['Model'] = df['model'].apply(make_link)
|
| 113 |
df['Score'] = df['energy_score'].apply(format_stars)
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
df['Class'] = df['class']
|
| 117 |
-
df = df[['Model', 'GPU Energy (Wh)', 'Score', 'Class']]
|
| 118 |
-
else:
|
| 119 |
-
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
| 120 |
-
|
| 121 |
df = df.sort_values(by='GPU Energy (Wh)')
|
| 122 |
return df
|
| 123 |
|
|
@@ -139,7 +136,7 @@ def get_text_generation_plots(model_class):
|
|
| 139 |
df = pd.read_csv('data/energy/text_generation.csv')
|
| 140 |
if df.columns[0].startswith("Unnamed:"):
|
| 141 |
df = df.iloc[:, 1:]
|
| 142 |
-
# Filter
|
| 143 |
if 'class' in df.columns:
|
| 144 |
df = df[df['class'] == model_class]
|
| 145 |
df['total_gpu_energy'] = df['total_gpu_energy'].astype(float)
|
|
@@ -161,7 +158,7 @@ def get_text_generation_plots(model_class):
|
|
| 161 |
fig.update_traces(
|
| 162 |
hovertemplate="<br>".join([
|
| 163 |
"Model: %{y}",
|
| 164 |
-
"GPU Energy (Wh): %{x}",
|
| 165 |
"Energy Score: %{customdata[0]}"
|
| 166 |
])
|
| 167 |
)
|
|
@@ -178,11 +175,8 @@ def get_text_generation_model_names(model_class):
|
|
| 178 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].astype(float).apply(lambda x: f"{x:.4f}")
|
| 179 |
df['Model'] = df['model'].apply(make_link)
|
| 180 |
df['Score'] = df['energy_score'].apply(format_stars)
|
| 181 |
-
if
|
| 182 |
-
|
| 183 |
-
df = df[['Model', 'GPU Energy (Wh)', 'Score', 'Class']]
|
| 184 |
-
else:
|
| 185 |
-
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
| 186 |
df = df.sort_values(by='GPU Energy (Wh)')
|
| 187 |
return df
|
| 188 |
|
|
@@ -218,14 +212,16 @@ Click through the tasks below to see how different models measure up in terms of
|
|
| 218 |
with gr.Tabs():
|
| 219 |
# --- Text Generation Tab with Dropdown for Model Class ---
|
| 220 |
with gr.TabItem("Text Generation 💬"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
with gr.Row():
|
| 222 |
with gr.Column(scale=1.3):
|
| 223 |
tg_plot = gr.Plot(get_text_generation_plots("A"))
|
| 224 |
with gr.Column(scale=1):
|
| 225 |
tg_table = gr.Dataframe(get_text_generation_model_names("A"), datatype="markdown")
|
| 226 |
-
|
| 227 |
-
label="Select Model Class",
|
| 228 |
-
value="A")
|
| 229 |
model_class_dropdown.change(fn=update_text_generation,
|
| 230 |
inputs=model_class_dropdown,
|
| 231 |
outputs=[tg_plot, tg_table])
|
|
|
|
| 41 |
df = pd.read_csv('data/energy/' + task)
|
| 42 |
if df.columns[0].startswith("Unnamed:"):
|
| 43 |
df = df.iloc[:, 1:]
|
| 44 |
+
# Convert GPU energy to float so that very small numbers are preserved
|
| 45 |
df['total_gpu_energy'] = df['total_gpu_energy'].astype(float)
|
| 46 |
+
# Convert energy_score to categorical string for proper discrete coloring
|
| 47 |
df['energy_score'] = df['energy_score'].astype(int).astype(str)
|
| 48 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
| 49 |
|
|
|
|
| 59 |
width=800,
|
| 60 |
color_discrete_map=color_map
|
| 61 |
)
|
| 62 |
+
# GPU Energy now shows 4 decimals in the hover text
|
| 63 |
fig.update_traces(
|
| 64 |
hovertemplate="<br>".join([
|
| 65 |
"Model: %{y}",
|
| 66 |
+
"GPU Energy (Wh): %{x:.4f}",
|
| 67 |
"Energy Score: %{customdata[0]}"
|
| 68 |
])
|
| 69 |
)
|
|
|
|
| 97 |
fig.update_traces(
|
| 98 |
hovertemplate="<br>".join([
|
| 99 |
"Model: %{y}",
|
| 100 |
+
"GPU Energy (Wh): %{x:.4f}",
|
| 101 |
"Energy Score: %{customdata[0]}"
|
| 102 |
])
|
| 103 |
)
|
|
|
|
| 109 |
if df.columns[0].startswith("Unnamed:"):
|
| 110 |
df = df.iloc[:, 1:]
|
| 111 |
df['energy_score'] = df['energy_score'].astype(int)
|
| 112 |
+
# Ensure GPU Energy is a float and format it to 4 decimals
|
| 113 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].astype(float).apply(lambda x: f"{x:.4f}")
|
| 114 |
df['Model'] = df['model'].apply(make_link)
|
| 115 |
df['Score'] = df['energy_score'].apply(format_stars)
|
| 116 |
+
# Remove any Class column
|
| 117 |
+
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
df = df.sort_values(by='GPU Energy (Wh)')
|
| 119 |
return df
|
| 120 |
|
|
|
|
| 136 |
df = pd.read_csv('data/energy/text_generation.csv')
|
| 137 |
if df.columns[0].startswith("Unnamed:"):
|
| 138 |
df = df.iloc[:, 1:]
|
| 139 |
+
# Filter by the selected model class if the "class" column exists
|
| 140 |
if 'class' in df.columns:
|
| 141 |
df = df[df['class'] == model_class]
|
| 142 |
df['total_gpu_energy'] = df['total_gpu_energy'].astype(float)
|
|
|
|
| 158 |
fig.update_traces(
|
| 159 |
hovertemplate="<br>".join([
|
| 160 |
"Model: %{y}",
|
| 161 |
+
"GPU Energy (Wh): %{x:.4f}",
|
| 162 |
"Energy Score: %{customdata[0]}"
|
| 163 |
])
|
| 164 |
)
|
|
|
|
| 175 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].astype(float).apply(lambda x: f"{x:.4f}")
|
| 176 |
df['Model'] = df['model'].apply(make_link)
|
| 177 |
df['Score'] = df['energy_score'].apply(format_stars)
|
| 178 |
+
# Remove the Class column if it exists
|
| 179 |
+
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
|
|
|
|
|
|
|
|
|
| 180 |
df = df.sort_values(by='GPU Energy (Wh)')
|
| 181 |
return df
|
| 182 |
|
|
|
|
| 212 |
with gr.Tabs():
|
| 213 |
# --- Text Generation Tab with Dropdown for Model Class ---
|
| 214 |
with gr.TabItem("Text Generation 💬"):
|
| 215 |
+
# Dropdown moved above the plot and leaderboard
|
| 216 |
+
model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
|
| 217 |
+
label="Select Model Class",
|
| 218 |
+
value="A")
|
| 219 |
with gr.Row():
|
| 220 |
with gr.Column(scale=1.3):
|
| 221 |
tg_plot = gr.Plot(get_text_generation_plots("A"))
|
| 222 |
with gr.Column(scale=1):
|
| 223 |
tg_table = gr.Dataframe(get_text_generation_model_names("A"), datatype="markdown")
|
| 224 |
+
# Update plot and table when the dropdown value changes
|
|
|
|
|
|
|
| 225 |
model_class_dropdown.change(fn=update_text_generation,
|
| 226 |
inputs=model_class_dropdown,
|
| 227 |
outputs=[tg_plot, tg_table])
|