Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ CITATION_BUTTON_TEXT = r"""@misc{aienergyscore-leaderboard,
|
|
11 |
howpublished = "\url{https://huggingface.co/spaces/AIEnergyScore/Leaderboard}",
|
12 |
}"""
|
13 |
|
14 |
-
# List of CSV filenames
|
15 |
tasks = [
|
16 |
'asr.csv',
|
17 |
'object_detection.csv',
|
@@ -30,64 +30,49 @@ def format_stars(score):
|
|
30 |
score_int = int(score)
|
31 |
except Exception:
|
32 |
score_int = 0
|
33 |
-
return f'<span style="color: #3fa45bff; font-size:2em;">{"★" * score_int}</span>'
|
34 |
|
35 |
def make_link(mname):
|
36 |
parts = str(mname).split('/')
|
37 |
display_name = parts[1] if len(parts) > 1 else mname
|
38 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
39 |
|
40 |
-
def read_csv_file(task):
|
41 |
-
"""
|
42 |
-
Reads a CSV from the data/energy folder using the first column as the index
|
43 |
-
and strips any extraneous whitespace from the column names.
|
44 |
-
"""
|
45 |
-
df = pd.read_csv('data/energy/' + task, index_col=0)
|
46 |
-
df.columns = df.columns.str.strip() # remove any extra whitespace
|
47 |
-
return df
|
48 |
-
|
49 |
def get_plots(task):
|
50 |
-
df =
|
51 |
-
|
52 |
-
|
53 |
-
df['energy_score'] =
|
54 |
-
# Create a short model name for display on the y-axis.
|
55 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
56 |
|
57 |
-
# Define a discrete color mapping for energy scores.
|
58 |
color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
|
59 |
|
60 |
-
# Build the scatter plot.
|
61 |
fig = px.scatter(
|
62 |
df,
|
63 |
-
x="total_gpu_energy",
|
64 |
-
y="Display Model",
|
65 |
-
color="energy_score",
|
66 |
-
custom_data=['
|
67 |
height=500,
|
68 |
width=800,
|
69 |
-
color_discrete_map=color_map
|
70 |
)
|
71 |
fig.update_traces(
|
72 |
-
hovertemplate=(
|
73 |
-
"Model: %{
|
74 |
-
"
|
75 |
-
"Energy Score: %{customdata[
|
76 |
-
)
|
77 |
-
)
|
78 |
-
fig.update_layout(
|
79 |
-
xaxis_title="Total GPU Energy (Wh)",
|
80 |
-
yaxis_title="Model",
|
81 |
-
margin=dict(l=40, r=40, t=40, b=40)
|
82 |
)
|
|
|
83 |
return fig
|
84 |
|
85 |
def get_all_plots():
|
86 |
all_df = pd.DataFrame()
|
87 |
for task in tasks:
|
88 |
-
df =
|
89 |
-
df[
|
90 |
-
|
|
|
91 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
92 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
93 |
all_df = all_df.drop_duplicates(subset=['model'])
|
@@ -96,39 +81,38 @@ def get_all_plots():
|
|
96 |
|
97 |
fig = px.scatter(
|
98 |
all_df,
|
99 |
-
x="total_gpu_energy",
|
100 |
y="Display Model",
|
101 |
-
color="energy_score",
|
102 |
-
custom_data=['
|
103 |
height=500,
|
104 |
width=800,
|
105 |
-
color_discrete_map=color_map
|
106 |
)
|
107 |
fig.update_traces(
|
108 |
-
hovertemplate=(
|
109 |
-
"Model: %{
|
110 |
-
"
|
111 |
-
"Energy Score: %{customdata[
|
112 |
-
)
|
113 |
-
)
|
114 |
-
fig.update_layout(
|
115 |
-
xaxis_title="Total GPU Energy (Wh)",
|
116 |
-
yaxis_title="Model",
|
117 |
-
margin=dict(l=40, r=40, t=40, b=40)
|
118 |
)
|
|
|
119 |
return fig
|
120 |
|
121 |
def get_model_names(task):
|
122 |
"""
|
123 |
-
For a given task, load the energy CSV and return a
|
124 |
- Model (a markdown link)
|
125 |
-
- GPU Energy (Wh) formatted
|
126 |
- Score (a star rating based on energy_score)
|
127 |
-
For text_generation.csv only, also
|
|
|
128 |
"""
|
129 |
-
df =
|
130 |
-
df[
|
131 |
-
|
|
|
|
|
132 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
133 |
df['Model'] = df['model'].apply(make_link)
|
134 |
df['Score'] = df['energy_score'].apply(format_stars)
|
@@ -139,30 +123,31 @@ def get_model_names(task):
|
|
139 |
else:
|
140 |
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
141 |
|
142 |
-
|
143 |
-
df = df.sort_values(by='total_gpu_energy')
|
144 |
return df
|
145 |
|
146 |
def get_all_model_names():
|
147 |
"""
|
148 |
-
Combine data from all tasks and return a leaderboard
|
149 |
-
- Model, GPU Energy (Wh), Score
|
150 |
Duplicate models are dropped.
|
151 |
"""
|
152 |
all_df = pd.DataFrame()
|
153 |
for task in tasks:
|
154 |
-
df =
|
155 |
-
df[
|
156 |
-
|
|
|
157 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
158 |
df['Model'] = df['model'].apply(make_link)
|
159 |
df['Score'] = df['energy_score'].apply(format_stars)
|
160 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
161 |
all_df = all_df.drop_duplicates(subset=['model'])
|
162 |
-
all_df = all_df.sort_values(by='
|
163 |
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
164 |
|
165 |
# Build the Gradio interface.
|
|
|
166 |
demo = gr.Blocks(css="""
|
167 |
.gr-dataframe table {
|
168 |
table-layout: fixed;
|
@@ -189,7 +174,7 @@ Click through the tasks below to see how different models measure up in terms of
|
|
189 |
with gr.Tabs():
|
190 |
with gr.TabItem("Text Generation 💬"):
|
191 |
with gr.Row():
|
192 |
-
with gr.Column(scale=
|
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")
|
@@ -272,6 +257,8 @@ Click through the tasks below to see how different models measure up in terms of
|
|
272 |
lines=10,
|
273 |
show_copy_button=True,
|
274 |
)
|
275 |
-
gr.Markdown(
|
|
|
|
|
276 |
|
277 |
-
demo.launch()
|
|
|
11 |
howpublished = "\url{https://huggingface.co/spaces/AIEnergyScore/Leaderboard}",
|
12 |
}"""
|
13 |
|
14 |
+
# List of tasks (CSV filenames)
|
15 |
tasks = [
|
16 |
'asr.csv',
|
17 |
'object_detection.csv',
|
|
|
30 |
score_int = int(score)
|
31 |
except Exception:
|
32 |
score_int = 0
|
33 |
+
return f'<span style="color: #3fa45bff !important; font-size:2em !important;">{"★" * score_int}</span>'
|
34 |
|
35 |
def make_link(mname):
|
36 |
parts = str(mname).split('/')
|
37 |
display_name = parts[1] if len(parts) > 1 else mname
|
38 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
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 |
+
df['energy_score'] = df['energy_score'].astype(int)
|
|
|
45 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
46 |
|
|
|
47 |
color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
|
48 |
|
|
|
49 |
fig = px.scatter(
|
50 |
df,
|
51 |
+
x="total_gpu_energy", # Ensure correct column for x-axis
|
52 |
+
y="Display Model", # Keep model name for y-axis
|
53 |
+
color="energy_score", # Ensure correct column for point color
|
54 |
+
custom_data=['energy_score'],
|
55 |
height=500,
|
56 |
width=800,
|
57 |
+
color_discrete_map=color_map
|
58 |
)
|
59 |
fig.update_traces(
|
60 |
+
hovertemplate="<br>".join([
|
61 |
+
"Model: %{y}",
|
62 |
+
"GPU Energy (Wh): %{x}",
|
63 |
+
"Energy Score: %{customdata[0]}"
|
64 |
+
])
|
|
|
|
|
|
|
|
|
|
|
65 |
)
|
66 |
+
fig.update_layout(xaxis_title="GPU Energy (Wh)", yaxis_title="Model")
|
67 |
return fig
|
68 |
|
69 |
def get_all_plots():
|
70 |
all_df = pd.DataFrame()
|
71 |
for task in tasks:
|
72 |
+
df = pd.read_csv('data/energy/' + task)
|
73 |
+
if df.columns[0].startswith("Unnamed:"):
|
74 |
+
df = df.iloc[:, 1:]
|
75 |
+
df['energy_score'] = df['energy_score'].astype(int)
|
76 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
77 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
78 |
all_df = all_df.drop_duplicates(subset=['model'])
|
|
|
81 |
|
82 |
fig = px.scatter(
|
83 |
all_df,
|
84 |
+
x="total_gpu_energy", # Ensure correct column for x-axis
|
85 |
y="Display Model",
|
86 |
+
color="energy_score", # Ensure correct column for point color
|
87 |
+
custom_data=['energy_score'],
|
88 |
height=500,
|
89 |
width=800,
|
90 |
+
color_discrete_map=color_map
|
91 |
)
|
92 |
fig.update_traces(
|
93 |
+
hovertemplate="<br>".join([
|
94 |
+
"Model: %{y}",
|
95 |
+
"GPU Energy (Wh): %{x}",
|
96 |
+
"Energy Score: %{customdata[0]}"
|
97 |
+
])
|
|
|
|
|
|
|
|
|
|
|
98 |
)
|
99 |
+
fig.update_layout(xaxis_title="GPU Energy (Wh)", yaxis_title="Model")
|
100 |
return fig
|
101 |
|
102 |
def get_model_names(task):
|
103 |
"""
|
104 |
+
For a given task, load the energy CSV and return a dataframe with the following columns:
|
105 |
- Model (a markdown link)
|
106 |
+
- GPU Energy (Wh) formatted as a string with 4 decimal places
|
107 |
- Score (a star rating based on energy_score)
|
108 |
+
For text_generation.csv only, also add the "Class" column from the CSV.
|
109 |
+
The final column order is: Model, GPU Energy (Wh), Score, [Class].
|
110 |
"""
|
111 |
+
df = pd.read_csv('data/energy/' + task)
|
112 |
+
if df.columns[0].startswith("Unnamed:"):
|
113 |
+
df = df.iloc[:, 1:]
|
114 |
+
df['energy_score'] = df['energy_score'].astype(int)
|
115 |
+
# Format the energy as a string with 4 decimals
|
116 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
117 |
df['Model'] = df['model'].apply(make_link)
|
118 |
df['Score'] = df['energy_score'].apply(format_stars)
|
|
|
123 |
else:
|
124 |
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
125 |
|
126 |
+
df = df.sort_values(by='GPU Energy (Wh)')
|
|
|
127 |
return df
|
128 |
|
129 |
def get_all_model_names():
|
130 |
"""
|
131 |
+
Combine data from all tasks and return a leaderboard table with:
|
132 |
+
- Model, GPU Energy (Wh), Score
|
133 |
Duplicate models are dropped.
|
134 |
"""
|
135 |
all_df = pd.DataFrame()
|
136 |
for task in tasks:
|
137 |
+
df = pd.read_csv('data/energy/' + task)
|
138 |
+
if df.columns[0].startswith("Unnamed:"):
|
139 |
+
df = df.iloc[:, 1:]
|
140 |
+
df['energy_score'] = df['energy_score'].astype(int)
|
141 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
142 |
df['Model'] = df['model'].apply(make_link)
|
143 |
df['Score'] = df['energy_score'].apply(format_stars)
|
144 |
all_df = pd.concat([all_df, df], ignore_index=True)
|
145 |
all_df = all_df.drop_duplicates(subset=['model'])
|
146 |
+
all_df = all_df.sort_values(by='GPU Energy (Wh)')
|
147 |
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
148 |
|
149 |
# Build the Gradio interface.
|
150 |
+
# The css argument below makes all tables (e.g. leaderboard) use a fixed layout with narrower columns.
|
151 |
demo = gr.Blocks(css="""
|
152 |
.gr-dataframe table {
|
153 |
table-layout: fixed;
|
|
|
174 |
with gr.Tabs():
|
175 |
with gr.TabItem("Text Generation 💬"):
|
176 |
with gr.Row():
|
177 |
+
with gr.Column(scale=1.3):
|
178 |
plot = gr.Plot(get_plots('text_generation.csv'))
|
179 |
with gr.Column(scale=1):
|
180 |
table = gr.Dataframe(get_model_names('text_generation.csv'), datatype="markdown")
|
|
|
257 |
lines=10,
|
258 |
show_copy_button=True,
|
259 |
)
|
260 |
+
gr.Markdown(
|
261 |
+
"""Last updated: February 2025"""
|
262 |
+
)
|
263 |
|
264 |
+
demo.launch()
|