Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,40 +30,34 @@ def format_stars(score):
|
|
30 |
score_int = int(score)
|
31 |
except Exception:
|
32 |
score_int = 0
|
33 |
-
# Display a star rating (★) based on the energy score.
|
34 |
return f'<span style="color: #3fa45bff; font-size:2em;">{"★" * score_int}</span>'
|
35 |
|
36 |
def make_link(mname):
|
37 |
-
# Make a Markdown link from the model name.
|
38 |
parts = str(mname).split('/')
|
39 |
display_name = parts[1] if len(parts) > 1 else mname
|
40 |
return f'[{display_name}](https://huggingface.co/{mname})'
|
41 |
|
42 |
-
def
|
43 |
-
|
44 |
df = pd.read_csv('data/energy/' + task)
|
45 |
-
# If the
|
46 |
-
if df.columns
|
47 |
df = df.iloc[:, 1:]
|
48 |
-
|
|
|
|
|
|
|
49 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
50 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
51 |
-
# Create a short version of the model name for display on the y-axis.
|
52 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
53 |
|
54 |
-
# Define a discrete color mapping for energy scores.
|
55 |
color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
|
56 |
|
57 |
-
# Build a scatter plot:
|
58 |
-
# - x-axis: total_gpu_energy
|
59 |
-
# - y-axis: Display Model (short model name)
|
60 |
-
# - Color: energy_score
|
61 |
-
# - Custom tooltip will include the full model name, energy value and energy score.
|
62 |
fig = px.scatter(
|
63 |
df,
|
64 |
-
x="total_gpu_energy",
|
65 |
y="Display Model",
|
66 |
-
color="energy_score",
|
67 |
custom_data=['model', 'total_gpu_energy', 'energy_score'],
|
68 |
height=500,
|
69 |
width=800,
|
@@ -84,12 +78,9 @@ def get_plots(task):
|
|
84 |
return fig
|
85 |
|
86 |
def get_all_plots():
|
87 |
-
# Combine data from all tasks.
|
88 |
all_df = pd.DataFrame()
|
89 |
for task in tasks:
|
90 |
-
df =
|
91 |
-
if df.columns[0].startswith("Unnamed:"):
|
92 |
-
df = df.iloc[:, 1:]
|
93 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
94 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
95 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
@@ -126,13 +117,11 @@ def get_model_names(task):
|
|
126 |
"""
|
127 |
For a given task, load the energy CSV and return a dataframe with the following columns:
|
128 |
- Model (a markdown link)
|
129 |
-
- GPU Energy (Wh)
|
130 |
- Score (a star rating based on energy_score)
|
131 |
-
For text_generation.csv only, also
|
132 |
"""
|
133 |
-
df =
|
134 |
-
if df.columns[0].startswith("Unnamed:"):
|
135 |
-
df = df.iloc[:, 1:]
|
136 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
137 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
138 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
@@ -145,7 +134,7 @@ def get_model_names(task):
|
|
145 |
else:
|
146 |
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
147 |
|
148 |
-
# Sort by the numeric
|
149 |
df = df.sort_values(by='total_gpu_energy')
|
150 |
return df
|
151 |
|
@@ -157,9 +146,7 @@ def get_all_model_names():
|
|
157 |
"""
|
158 |
all_df = pd.DataFrame()
|
159 |
for task in tasks:
|
160 |
-
df =
|
161 |
-
if df.columns[0].startswith("Unnamed:"):
|
162 |
-
df = df.iloc[:, 1:]
|
163 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
164 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
165 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
@@ -171,7 +158,6 @@ def get_all_model_names():
|
|
171 |
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
172 |
|
173 |
# Build the Gradio interface.
|
174 |
-
# The CSS below sets fixed layouts for tables.
|
175 |
demo = gr.Blocks(css="""
|
176 |
.gr-dataframe table {
|
177 |
table-layout: fixed;
|
@@ -198,7 +184,8 @@ Click through the tasks below to see how different models measure up in terms of
|
|
198 |
with gr.Tabs():
|
199 |
with gr.TabItem("Text Generation 💬"):
|
200 |
with gr.Row():
|
201 |
-
|
|
|
202 |
plot = gr.Plot(get_plots('text_generation.csv'))
|
203 |
with gr.Column(scale=1):
|
204 |
table = gr.Dataframe(get_model_names('text_generation.csv'), datatype="markdown")
|
|
|
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_drop_extra(task):
|
41 |
+
"""Helper to load CSV and drop the first column if necessary."""
|
42 |
df = pd.read_csv('data/energy/' + task)
|
43 |
+
# If the expected "total_gpu_energy" column is missing, drop the first column.
|
44 |
+
if "total_gpu_energy" not in df.columns:
|
45 |
df = df.iloc[:, 1:]
|
46 |
+
return df
|
47 |
+
|
48 |
+
def get_plots(task):
|
49 |
+
df = read_csv_drop_extra(task)
|
50 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
51 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
|
|
52 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
53 |
|
|
|
54 |
color_map = {1: "red", 2: "orange", 3: "yellow", 4: "lightgreen", 5: "green"}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
56 |
fig = px.scatter(
|
57 |
df,
|
58 |
+
x="total_gpu_energy", # Use the correct energy column
|
59 |
y="Display Model",
|
60 |
+
color="energy_score", # Map energy score to the color
|
61 |
custom_data=['model', 'total_gpu_energy', 'energy_score'],
|
62 |
height=500,
|
63 |
width=800,
|
|
|
78 |
return fig
|
79 |
|
80 |
def get_all_plots():
|
|
|
81 |
all_df = pd.DataFrame()
|
82 |
for task in tasks:
|
83 |
+
df = read_csv_drop_extra(task)
|
|
|
|
|
84 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
85 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
86 |
df['Display Model'] = df['model'].apply(lambda m: m.split('/')[-1])
|
|
|
117 |
"""
|
118 |
For a given task, load the energy CSV and return a dataframe with the following columns:
|
119 |
- Model (a markdown link)
|
120 |
+
- GPU Energy (Wh) formatted to 4 decimal places
|
121 |
- Score (a star rating based on energy_score)
|
122 |
+
For text_generation.csv only, also add the "Class" column if present.
|
123 |
"""
|
124 |
+
df = read_csv_drop_extra(task)
|
|
|
|
|
125 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
126 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
127 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
|
|
134 |
else:
|
135 |
df = df[['Model', 'GPU Energy (Wh)', 'Score']]
|
136 |
|
137 |
+
# Sort by the numeric value (not the formatted string)
|
138 |
df = df.sort_values(by='total_gpu_energy')
|
139 |
return df
|
140 |
|
|
|
146 |
"""
|
147 |
all_df = pd.DataFrame()
|
148 |
for task in tasks:
|
149 |
+
df = read_csv_drop_extra(task)
|
|
|
|
|
150 |
df['total_gpu_energy'] = pd.to_numeric(df['total_gpu_energy'], errors='coerce')
|
151 |
df['energy_score'] = pd.to_numeric(df['energy_score'], errors='coerce').astype(int)
|
152 |
df['GPU Energy (Wh)'] = df['total_gpu_energy'].apply(lambda x: f"{x:.4f}")
|
|
|
158 |
return all_df[['Model', 'GPU Energy (Wh)', 'Score']]
|
159 |
|
160 |
# Build the Gradio interface.
|
|
|
161 |
demo = gr.Blocks(css="""
|
162 |
.gr-dataframe table {
|
163 |
table-layout: fixed;
|
|
|
184 |
with gr.Tabs():
|
185 |
with gr.TabItem("Text Generation 💬"):
|
186 |
with gr.Row():
|
187 |
+
# Changed scale to an integer (2 vs 1) to avoid warnings.
|
188 |
+
with gr.Column(scale=2):
|
189 |
plot = gr.Plot(get_plots('text_generation.csv'))
|
190 |
with gr.Column(scale=1):
|
191 |
table = gr.Dataframe(get_model_names('text_generation.csv'), datatype="markdown")
|