Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def make_link(mname):
|
|
| 38 |
display_name = parts[1] if len(parts) > 1 else mname
|
| 39 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
| 40 |
|
| 41 |
-
# --- Plot Functions (
|
| 42 |
|
| 43 |
def get_plots(task):
|
| 44 |
df = pd.read_csv('data/energy/' + task)
|
|
@@ -53,8 +53,8 @@ def get_plots(task):
|
|
| 53 |
# Use the energy score to control color
|
| 54 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
| 55 |
|
| 56 |
-
# Now plot
|
| 57 |
-
fig = px.
|
| 58 |
df,
|
| 59 |
x="Display Model",
|
| 60 |
y="total_gpu_energy",
|
|
@@ -75,9 +75,9 @@ def get_plots(task):
|
|
| 75 |
fig.update_layout(
|
| 76 |
xaxis_title="Model",
|
| 77 |
yaxis_title="GPU Energy (Wh)",
|
| 78 |
-
yaxis_tickformat=".4f", # Add this line to format y-axis ticks
|
| 79 |
yaxis = dict(
|
| 80 |
-
tickformat=".4f" # Ensure tickformat is set within yaxis dict as well
|
| 81 |
)
|
| 82 |
)
|
| 83 |
return fig
|
|
@@ -96,7 +96,7 @@ def get_all_plots():
|
|
| 96 |
|
| 97 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
| 98 |
|
| 99 |
-
fig = px.
|
| 100 |
all_df,
|
| 101 |
x="Display Model",
|
| 102 |
y="total_gpu_energy",
|
|
@@ -116,43 +116,14 @@ def get_all_plots():
|
|
| 116 |
fig.update_layout(
|
| 117 |
xaxis_title="Model",
|
| 118 |
yaxis_title="GPU Energy (Wh)",
|
| 119 |
-
yaxis_tickformat=".4f", # Add this line to format y-axis ticks
|
| 120 |
yaxis = dict(
|
| 121 |
-
tickformat=".4f" # Ensure tickformat is set within yaxis dict as well
|
| 122 |
)
|
| 123 |
)
|
| 124 |
return fig
|
| 125 |
|
| 126 |
-
# ---
|
| 127 |
-
|
| 128 |
-
def get_model_names(task):
|
| 129 |
-
df = pd.read_csv('data/energy/' + task)
|
| 130 |
-
if df.columns[0].startswith("Unnamed:"):
|
| 131 |
-
df = df.iloc[:, 1:]
|
| 132 |
-
df['energy_score'] = df['energy_score'].astype(int)
|
| 133 |
-
# For leaderboard display, format GPU Energy to 4 decimals
|
| 134 |
-
df['GPU Energy (Wh)'] = pd.to_numeric(df['total_gpu_energy'], errors='raise').apply(lambda x: f"{x:.4f}")
|
| 135 |
-
df['Model'] = df['model'].apply(make_link)
|
| 136 |
-
df['Score'] = df['energy_score'].apply(format_stars)
|
| 137 |
-
# Remove any Class column if it exists
|
| 138 |
-
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
| 139 |
-
df = df.sort_values(by='GPU Energy (Wh)')
|
| 140 |
-
return df
|
| 141 |
-
|
| 142 |
-
def get_all_model_names():
|
| 143 |
-
all_df = pd.DataFrame()
|
| 144 |
-
for task in tasks:
|
| 145 |
-
df = pd.read_csv('data/energy/' + task)
|
| 146 |
-
df['energy_score'] = df['energy_score'].astype(int)
|
| 147 |
-
df['GPU Energy (Wh)'] = pd.to_numeric(df['total_gpu_energy'], errors='raise').apply(lambda x: f"{x:.4f}")
|
| 148 |
-
df['Model'] = df['model'].apply(make_link)
|
| 149 |
-
df['Score'] = df['energy_score'].apply(format_stars)
|
| 150 |
-
all_df = pd.concat([all_df, df], ignore_index=True)
|
| 151 |
-
all_df = all_df.drop_duplicates(subset=['model'])
|
| 152 |
-
all_df = all_df.sort_values(by='GPU Energy (Wh)')
|
| 153 |
-
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
| 154 |
-
|
| 155 |
-
# --- New functions for Text Generation filtering by model class (with swapped axes) ---
|
| 156 |
|
| 157 |
def get_text_generation_plots(model_class):
|
| 158 |
df = pd.read_csv('data/energy/text_generation.csv')
|
|
@@ -167,7 +138,7 @@ def get_text_generation_plots(model_class):
|
|
| 167 |
|
| 168 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
| 169 |
|
| 170 |
-
fig = px.
|
| 171 |
df,
|
| 172 |
x="Display Model",
|
| 173 |
y="total_gpu_energy",
|
|
@@ -177,7 +148,6 @@ def get_text_generation_plots(model_class):
|
|
| 177 |
width=800,
|
| 178 |
color_discrete_map=color_map
|
| 179 |
)
|
| 180 |
-
# Update hover text to show the model and GPU Energy (with 4 decimals)
|
| 181 |
fig.update_traces(
|
| 182 |
hovertemplate="<br>".join([
|
| 183 |
"Model: %{x}",
|
|
@@ -188,13 +158,45 @@ def get_text_generation_plots(model_class):
|
|
| 188 |
fig.update_layout(
|
| 189 |
xaxis_title="Model",
|
| 190 |
yaxis_title="GPU Energy (Wh)",
|
| 191 |
-
yaxis_tickformat=".4f", # Add this line to format y-axis ticks
|
| 192 |
yaxis = dict(
|
| 193 |
-
tickformat=".4f" # Ensure tickformat is set within yaxis dict as well
|
| 194 |
)
|
| 195 |
)
|
| 196 |
return fig
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
def get_text_generation_model_names(model_class):
|
| 199 |
df = pd.read_csv('data/energy/text_generation.csv')
|
| 200 |
if df.columns[0].startswith("Unnamed:"):
|
|
@@ -243,12 +245,12 @@ Select different tasks to see scored models. Submit open models for testing and
|
|
| 243 |
# Dropdown moved above the plot and leaderboard
|
| 244 |
model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
|
| 245 |
label="Select Model Class",
|
| 246 |
-
value="
|
| 247 |
with gr.Row():
|
| 248 |
with gr.Column(scale=1.3):
|
| 249 |
-
tg_plot = gr.Plot(get_text_generation_plots("
|
| 250 |
with gr.Column(scale=1):
|
| 251 |
-
tg_table = gr.Dataframe(get_text_generation_model_names("
|
| 252 |
# Update plot and table when the dropdown value changes
|
| 253 |
model_class_dropdown.change(fn=update_text_generation,
|
| 254 |
inputs=model_class_dropdown,
|
|
|
|
| 38 |
display_name = parts[1] if len(parts) > 1 else mname
|
| 39 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
| 40 |
|
| 41 |
+
# --- Plot Functions (Bar Chart) ---
|
| 42 |
|
| 43 |
def get_plots(task):
|
| 44 |
df = pd.read_csv('data/energy/' + task)
|
|
|
|
| 53 |
# Use the energy score to control color
|
| 54 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
| 55 |
|
| 56 |
+
# Now plot as a bar chart
|
| 57 |
+
fig = px.bar(
|
| 58 |
df,
|
| 59 |
x="Display Model",
|
| 60 |
y="total_gpu_energy",
|
|
|
|
| 75 |
fig.update_layout(
|
| 76 |
xaxis_title="Model",
|
| 77 |
yaxis_title="GPU Energy (Wh)",
|
| 78 |
+
yaxis_tickformat=".4f", # Add this line to format y-axis ticks - might not be needed for bar chart
|
| 79 |
yaxis = dict(
|
| 80 |
+
tickformat=".4f" # Ensure tickformat is set within yaxis dict as well - might not be needed for bar chart
|
| 81 |
)
|
| 82 |
)
|
| 83 |
return fig
|
|
|
|
| 96 |
|
| 97 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
| 98 |
|
| 99 |
+
fig = px.bar(
|
| 100 |
all_df,
|
| 101 |
x="Display Model",
|
| 102 |
y="total_gpu_energy",
|
|
|
|
| 116 |
fig.update_layout(
|
| 117 |
xaxis_title="Model",
|
| 118 |
yaxis_title="GPU Energy (Wh)",
|
| 119 |
+
yaxis_tickformat=".4f", # Add this line to format y-axis ticks - might not be needed for bar chart
|
| 120 |
yaxis = dict(
|
| 121 |
+
tickformat=".4f" # Ensure tickformat is set within yaxis dict as well - might not be needed for bar chart
|
| 122 |
)
|
| 123 |
)
|
| 124 |
return fig
|
| 125 |
|
| 126 |
+
# --- New functions for Text Generation filtering by model class (with Bar Chart) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
def get_text_generation_plots(model_class):
|
| 129 |
df = pd.read_csv('data/energy/text_generation.csv')
|
|
|
|
| 138 |
|
| 139 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
| 140 |
|
| 141 |
+
fig = px.bar(
|
| 142 |
df,
|
| 143 |
x="Display Model",
|
| 144 |
y="total_gpu_energy",
|
|
|
|
| 148 |
width=800,
|
| 149 |
color_discrete_map=color_map
|
| 150 |
)
|
|
|
|
| 151 |
fig.update_traces(
|
| 152 |
hovertemplate="<br>".join([
|
| 153 |
"Model: %{x}",
|
|
|
|
| 158 |
fig.update_layout(
|
| 159 |
xaxis_title="Model",
|
| 160 |
yaxis_title="GPU Energy (Wh)",
|
| 161 |
+
yaxis_tickformat=".4f", # Add this line to format y-axis ticks - might not be needed for bar chart
|
| 162 |
yaxis = dict(
|
| 163 |
+
tickformat=".4f" # Ensure tickformat is set within yaxis dict as well - might not be needed for bar chart
|
| 164 |
)
|
| 165 |
)
|
| 166 |
return fig
|
| 167 |
|
| 168 |
+
|
| 169 |
+
# --- Leaderboard Table Functions and Gradio Interface are unchanged ---
|
| 170 |
+
# (Keep the rest of the code same as previous response)
|
| 171 |
+
|
| 172 |
+
def get_model_names(task):
|
| 173 |
+
df = pd.read_csv('data/energy/' + task)
|
| 174 |
+
if df.columns[0].startswith("Unnamed:"):
|
| 175 |
+
df = df.iloc[:, 1:]
|
| 176 |
+
df['energy_score'] = df['energy_score'].astype(int)
|
| 177 |
+
# For leaderboard display, format GPU Energy to 4 decimals
|
| 178 |
+
df['GPU Energy (Wh)'] = pd.to_numeric(df['total_gpu_energy'], errors='raise').apply(lambda x: f"{x:.4f}")
|
| 179 |
+
df['Model'] = df['model'].apply(make_link)
|
| 180 |
+
df['Score'] = df['energy_score'].apply(format_stars)
|
| 181 |
+
# Remove any Class column if it exists
|
| 182 |
+
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
| 183 |
+
df = df.sort_values(by='GPU Energy (Wh)')
|
| 184 |
+
return df
|
| 185 |
+
|
| 186 |
+
def get_all_model_names():
|
| 187 |
+
all_df = pd.DataFrame()
|
| 188 |
+
for task in tasks:
|
| 189 |
+
df = pd.read_csv('data/energy/' + task)
|
| 190 |
+
df['energy_score'] = df['energy_score'].astype(int)
|
| 191 |
+
df['GPU Energy (Wh)'] = pd.to_numeric(df['total_gpu_energy'], errors='raise').apply(lambda x: f"{x:.4f}")
|
| 192 |
+
df['Model'] = df['model'].apply(make_link)
|
| 193 |
+
df['Score'] = df['energy_score'].apply(format_stars)
|
| 194 |
+
all_df = pd.concat([all_df, df], ignore_index=True)
|
| 195 |
+
all_df = all_df.drop_duplicates(subset=['model'])
|
| 196 |
+
all_df = all_df.sort_values(by='GPU Energy (Wh)')
|
| 197 |
+
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
| 198 |
+
|
| 199 |
+
|
| 200 |
def get_text_generation_model_names(model_class):
|
| 201 |
df = pd.read_csv('data/energy/text_generation.csv')
|
| 202 |
if df.columns[0].startswith("Unnamed:"):
|
|
|
|
| 245 |
# Dropdown moved above the plot and leaderboard
|
| 246 |
model_class_dropdown = gr.Dropdown(choices=["A", "B", "C"],
|
| 247 |
label="Select Model Class",
|
| 248 |
+
value="A")
|
| 249 |
with gr.Row():
|
| 250 |
with gr.Column(scale=1.3):
|
| 251 |
+
tg_plot = gr.Plot(get_text_generation_plots("A"))
|
| 252 |
with gr.Column(scale=1):
|
| 253 |
+
tg_table = gr.Dataframe(get_text_generation_model_names("A"), datatype="markdown")
|
| 254 |
# Update plot and table when the dropdown value changes
|
| 255 |
model_class_dropdown.change(fn=update_text_generation,
|
| 256 |
inputs=model_class_dropdown,
|