Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,46 +30,51 @@ def format_stars(score):
|
|
30 |
score_int = int(score)
|
31 |
except Exception:
|
32 |
score_int = 0
|
33 |
-
|
|
|
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 |
-
# Use the raw numeric value from the CSV
|
45 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='raise')
|
46 |
df['energy_score'] = df['energy_score'].astype(int).astype(str)
|
|
|
47 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
48 |
|
|
|
49 |
color_map = {"1": "red", "2": "orange", "3": "yellow", "4": "lightgreen", "5": "green"}
|
50 |
|
|
|
51 |
fig = px.scatter(
|
52 |
df,
|
53 |
-
x="
|
54 |
-
y="
|
55 |
color="energy_score",
|
56 |
custom_data=['energy_score'],
|
57 |
height=500,
|
58 |
width=800,
|
59 |
color_discrete_map=color_map
|
60 |
)
|
61 |
-
#
|
62 |
-
# but note that no formatting is applied to the x-axis ticks.
|
63 |
fig.update_traces(
|
64 |
hovertemplate="<br>".join([
|
65 |
-
"Model: %{
|
66 |
-
"GPU Energy (Wh): %{
|
67 |
"Energy Score: %{customdata[0]}"
|
68 |
])
|
69 |
)
|
70 |
fig.update_layout(
|
71 |
-
xaxis_title="
|
72 |
-
yaxis_title="
|
73 |
)
|
74 |
return fig
|
75 |
|
@@ -89,8 +94,8 @@ def get_all_plots():
|
|
89 |
|
90 |
fig = px.scatter(
|
91 |
all_df,
|
92 |
-
x="
|
93 |
-
y="
|
94 |
color="energy_score",
|
95 |
custom_data=['energy_score'],
|
96 |
height=500,
|
@@ -99,17 +104,19 @@ def get_all_plots():
|
|
99 |
)
|
100 |
fig.update_traces(
|
101 |
hovertemplate="<br>".join([
|
102 |
-
"Model: %{
|
103 |
-
"GPU Energy (Wh): %{
|
104 |
"Energy Score: %{customdata[0]}"
|
105 |
])
|
106 |
)
|
107 |
fig.update_layout(
|
108 |
-
xaxis_title="
|
109 |
-
yaxis_title="
|
110 |
)
|
111 |
return fig
|
112 |
|
|
|
|
|
113 |
def get_model_names(task):
|
114 |
df = pd.read_csv('data/energy/' + task)
|
115 |
if df.columns[0].startswith("Unnamed:"):
|
@@ -137,7 +144,8 @@ def get_all_model_names():
|
|
137 |
all_df = all_df.sort_values(by='GPU Energy (Wh)')
|
138 |
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
139 |
|
140 |
-
#
|
|
|
141 |
def get_text_generation_plots(model_class):
|
142 |
df = pd.read_csv('data/energy/text_generation.csv')
|
143 |
if df.columns[0].startswith("Unnamed:"):
|
@@ -145,7 +153,6 @@ def get_text_generation_plots(model_class):
|
|
145 |
# Filter by the selected model class if the "class" column exists
|
146 |
if 'class' in df.columns:
|
147 |
df = df[df['class'] == model_class]
|
148 |
-
# Use the raw numeric value from the CSV
|
149 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='raise')
|
150 |
df['energy_score'] = df['energy_score'].astype(int).astype(str)
|
151 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
@@ -154,8 +161,8 @@ def get_text_generation_plots(model_class):
|
|
154 |
|
155 |
fig = px.scatter(
|
156 |
df,
|
157 |
-
x="
|
158 |
-
y="
|
159 |
color="energy_score",
|
160 |
custom_data=['energy_score'],
|
161 |
height=500,
|
@@ -164,14 +171,14 @@ def get_text_generation_plots(model_class):
|
|
164 |
)
|
165 |
fig.update_traces(
|
166 |
hovertemplate="<br>".join([
|
167 |
-
"Model: %{
|
168 |
-
"GPU Energy (Wh): %{
|
169 |
"Energy Score: %{customdata[0]}"
|
170 |
])
|
171 |
)
|
172 |
fig.update_layout(
|
173 |
-
xaxis_title="
|
174 |
-
yaxis_title="
|
175 |
)
|
176 |
return fig
|
177 |
|
@@ -195,7 +202,8 @@ def update_text_generation(model_class):
|
|
195 |
table = get_text_generation_model_names(model_class)
|
196 |
return plot, table
|
197 |
|
198 |
-
#
|
|
|
199 |
demo = gr.Blocks(css="""
|
200 |
.gr-dataframe table {
|
201 |
table-layout: fixed;
|
|
|
30 |
score_int = int(score)
|
31 |
except Exception:
|
32 |
score_int = 0
|
33 |
+
# Render stars in black with a slightly larger font
|
34 |
+
return f'<span style="color: black !important; font-size:1.5em !important;">{"★" * score_int}</span>'
|
35 |
|
36 |
def make_link(mname):
|
37 |
parts = str(mname).split('/')
|
38 |
display_name = parts[1] if len(parts) > 1 else mname
|
39 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
40 |
|
41 |
+
# --- Plot Functions (Axes swapped) ---
|
42 |
+
|
43 |
def get_plots(task):
|
44 |
df = pd.read_csv('data/energy/' + task)
|
45 |
if df.columns[0].startswith("Unnamed:"):
|
46 |
df = df.iloc[:, 1:]
|
47 |
+
# Use the raw numeric value from the CSV for GPU Energy
|
48 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='raise')
|
49 |
df['energy_score'] = df['energy_score'].astype(int).astype(str)
|
50 |
+
# Create a display model column for labeling
|
51 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
52 |
|
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 with the model name on the X axis and GPU Energy on the Y axis.
|
57 |
fig = px.scatter(
|
58 |
df,
|
59 |
+
x="Display Model",
|
60 |
+
y="total_gpu_energy",
|
61 |
color="energy_score",
|
62 |
custom_data=['energy_score'],
|
63 |
height=500,
|
64 |
width=800,
|
65 |
color_discrete_map=color_map
|
66 |
)
|
67 |
+
# Update hover text to show the model and GPU Energy (with 4 decimals)
|
|
|
68 |
fig.update_traces(
|
69 |
hovertemplate="<br>".join([
|
70 |
+
"Model: %{x}",
|
71 |
+
"GPU Energy (Wh): %{y:.4f}",
|
72 |
"Energy Score: %{customdata[0]}"
|
73 |
])
|
74 |
)
|
75 |
fig.update_layout(
|
76 |
+
xaxis_title="Model",
|
77 |
+
yaxis_title="GPU Energy (Wh)"
|
78 |
)
|
79 |
return fig
|
80 |
|
|
|
94 |
|
95 |
fig = px.scatter(
|
96 |
all_df,
|
97 |
+
x="Display Model",
|
98 |
+
y="total_gpu_energy",
|
99 |
color="energy_score",
|
100 |
custom_data=['energy_score'],
|
101 |
height=500,
|
|
|
104 |
)
|
105 |
fig.update_traces(
|
106 |
hovertemplate="<br>".join([
|
107 |
+
"Model: %{x}",
|
108 |
+
"GPU Energy (Wh): %{y:.4f}",
|
109 |
"Energy Score: %{customdata[0]}"
|
110 |
])
|
111 |
)
|
112 |
fig.update_layout(
|
113 |
+
xaxis_title="Model",
|
114 |
+
yaxis_title="GPU Energy (Wh)"
|
115 |
)
|
116 |
return fig
|
117 |
|
118 |
+
# --- Leaderboard Table Functions (unchanged except stars) ---
|
119 |
+
|
120 |
def get_model_names(task):
|
121 |
df = pd.read_csv('data/energy/' + task)
|
122 |
if df.columns[0].startswith("Unnamed:"):
|
|
|
144 |
all_df = all_df.sort_values(by='GPU Energy (Wh)')
|
145 |
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
146 |
|
147 |
+
# --- New functions for Text Generation filtering by model class (with swapped axes) ---
|
148 |
+
|
149 |
def get_text_generation_plots(model_class):
|
150 |
df = pd.read_csv('data/energy/text_generation.csv')
|
151 |
if df.columns[0].startswith("Unnamed:"):
|
|
|
153 |
# Filter by the selected model class if the "class" column exists
|
154 |
if 'class' in df.columns:
|
155 |
df = df[df['class'] == model_class]
|
|
|
156 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='raise')
|
157 |
df['energy_score'] = df['energy_score'].astype(int).astype(str)
|
158 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
|
|
161 |
|
162 |
fig = px.scatter(
|
163 |
df,
|
164 |
+
x="Display Model",
|
165 |
+
y="total_gpu_energy",
|
166 |
color="energy_score",
|
167 |
custom_data=['energy_score'],
|
168 |
height=500,
|
|
|
171 |
)
|
172 |
fig.update_traces(
|
173 |
hovertemplate="<br>".join([
|
174 |
+
"Model: %{x}",
|
175 |
+
"GPU Energy (Wh): %{y:.4f}",
|
176 |
"Energy Score: %{customdata[0]}"
|
177 |
])
|
178 |
)
|
179 |
fig.update_layout(
|
180 |
+
xaxis_title="Model",
|
181 |
+
yaxis_title="GPU Energy (Wh)"
|
182 |
)
|
183 |
return fig
|
184 |
|
|
|
202 |
table = get_text_generation_model_names(model_class)
|
203 |
return plot, table
|
204 |
|
205 |
+
# --- Build the Gradio Interface ---
|
206 |
+
|
207 |
demo = gr.Blocks(css="""
|
208 |
.gr-dataframe table {
|
209 |
table-layout: fixed;
|