Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,13 +63,11 @@ def generate_html_table_from_df(df):
|
|
| 63 |
max_length = max(len(extract_link_text(link)) for link in df['Model'])
|
| 64 |
else:
|
| 65 |
max_length = 10
|
| 66 |
-
# Multiply by an estimated average character width (10 pixels) and add some extra padding.
|
| 67 |
static_width = max_length * 10 + 16
|
| 68 |
|
| 69 |
max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
|
| 70 |
color_map = {"1": "black", "2": "black", "3": "black", "4": "black", "5": "black"}
|
| 71 |
html = '<table style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
|
| 72 |
-
# Keep only one header (the one with hover text)
|
| 73 |
html += '<thead><tr style="background-color: #f2f2f2;">'
|
| 74 |
html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
|
| 75 |
html += '<th style="text-align: left; padding: 8px;" title="GPU energy consumed in Watt-hours for 1,000 queries">GPU Energy (Wh)</th>'
|
|
@@ -79,7 +77,6 @@ def generate_html_table_from_df(df):
|
|
| 79 |
for _, row in df.iterrows():
|
| 80 |
energy_numeric = row['gpu_energy_numeric']
|
| 81 |
energy_str = f"{energy_numeric:.2f}"
|
| 82 |
-
# Compute the relative width (as a percentage)
|
| 83 |
bar_width = (energy_numeric / max_energy) * 100
|
| 84 |
score_val = row['energy_score']
|
| 85 |
bar_color = color_map.get(str(score_val), "gray")
|
|
@@ -92,7 +89,8 @@ def generate_html_table_from_df(df):
|
|
| 92 |
html += f'<td style="padding: 8px;">{row["Score"]}</td>'
|
| 93 |
html += '</tr>'
|
| 94 |
html += '</tbody></table>'
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
# --- Function to zip all CSV files ---
|
| 98 |
def zip_csv_files():
|
|
@@ -114,7 +112,7 @@ def get_zip_data_link():
|
|
| 114 |
href = (
|
| 115 |
f'<a href="data:application/zip;base64,{b64}" '
|
| 116 |
'download="data.zip" '
|
| 117 |
-
'style="
|
| 118 |
'color: black; font-family: \'Inter\', sans-serif;">Download Data</a>'
|
| 119 |
)
|
| 120 |
return href
|
|
@@ -125,7 +123,6 @@ def get_model_names_html(task, sort_order="Low to High"):
|
|
| 125 |
if df.columns[0].startswith("Unnamed:"):
|
| 126 |
df = df.iloc[:, 1:]
|
| 127 |
df['energy_score'] = df['energy_score'].astype(int)
|
| 128 |
-
# Convert kWh to Wh:
|
| 129 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
| 130 |
df['Model'] = df['model'].apply(make_link)
|
| 131 |
df['Score'] = df['energy_score'].apply(format_stars)
|
|
@@ -164,8 +161,6 @@ def get_text_generation_model_names_html(model_class, sort_order="Low to High"):
|
|
| 164 |
return generate_html_table_from_df(df)
|
| 165 |
|
| 166 |
# --- Update functions for dropdown changes ---
|
| 167 |
-
|
| 168 |
-
# For Text Generation, two dropdowns: model class and sort order.
|
| 169 |
def update_text_generation(selected_display, sort_order):
|
| 170 |
mapping = {
|
| 171 |
"A (Single Consumer GPU) <20B parameters": "A",
|
|
@@ -175,7 +170,6 @@ def update_text_generation(selected_display, sort_order):
|
|
| 175 |
model_class = mapping.get(selected_display, "A")
|
| 176 |
return get_text_generation_model_names_html(model_class, sort_order)
|
| 177 |
|
| 178 |
-
# For the other tabs, each update function simply takes the sort_order.
|
| 179 |
def update_image_generation(sort_order):
|
| 180 |
return get_model_names_html('image_generation.csv', sort_order)
|
| 181 |
|
|
@@ -207,7 +201,6 @@ def update_all_tasks(sort_order):
|
|
| 207 |
return get_all_model_names_html(sort_order)
|
| 208 |
|
| 209 |
# --- Build the Gradio Interface ---
|
| 210 |
-
|
| 211 |
demo = gr.Blocks(css="""
|
| 212 |
.gr-dataframe table {
|
| 213 |
table-layout: fixed;
|
|
@@ -219,49 +212,37 @@ demo = gr.Blocks(css="""
|
|
| 219 |
overflow: hidden;
|
| 220 |
text-overflow: ellipsis;
|
| 221 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
""")
|
| 223 |
|
| 224 |
with demo:
|
| 225 |
-
# --- Header Links (at the very top) ---
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
faq_link = gr.HTML(
|
| 238 |
-
'<a href="https://huggingface.github.io/AIEnergyScore/#faq" '
|
| 239 |
-
'style="margin: 0 10px; text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
| 240 |
-
'color: black; font-family: \'Inter\', sans-serif;">FAQ</a>'
|
| 241 |
-
)
|
| 242 |
-
documentation_link = gr.HTML(
|
| 243 |
-
'<a href="https://huggingface.github.io/AIEnergyScore/#documentation" '
|
| 244 |
-
'style="margin: 0 10px; text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
| 245 |
-
'color: black; font-family: \'Inter\', sans-serif;">Documentation</a>'
|
| 246 |
-
)
|
| 247 |
-
download_link = gr.HTML(get_zip_data_link())
|
| 248 |
-
community_link = gr.HTML(
|
| 249 |
-
'<a href="https://huggingface.co/spaces/AIEnergyScore/README/discussions" '
|
| 250 |
-
'style="margin: 0 10px; text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
| 251 |
-
'color: black; font-family: \'Inter\', sans-serif;">Community</a>'
|
| 252 |
-
)
|
| 253 |
-
|
| 254 |
# --- Logo (centered) ---
|
| 255 |
gr.HTML('''
|
| 256 |
-
<div style="
|
| 257 |
<img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
|
| 258 |
alt="Logo"
|
| 259 |
-
style="max-width: 300px; height: auto;">
|
| 260 |
</div>
|
| 261 |
''')
|
| 262 |
|
| 263 |
# --- Subtitle (centered) ---
|
| 264 |
-
gr.Markdown('<
|
| 265 |
|
| 266 |
# --- Tabs for the different tasks ---
|
| 267 |
with gr.Tabs():
|
|
@@ -284,7 +265,6 @@ with demo:
|
|
| 284 |
value="Low to High"
|
| 285 |
)
|
| 286 |
tg_table = gr.HTML(get_text_generation_model_names_html("A", "Low to High"))
|
| 287 |
-
# When either dropdown changes, update the table.
|
| 288 |
model_class_dropdown.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=tg_table)
|
| 289 |
sort_dropdown_tg.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=tg_table)
|
| 290 |
|
|
@@ -396,6 +376,6 @@ with demo:
|
|
| 396 |
lines=10,
|
| 397 |
show_copy_button=True,
|
| 398 |
)
|
| 399 |
-
gr.Markdown("
|
| 400 |
|
| 401 |
-
demo.launch()
|
|
|
|
| 63 |
max_length = max(len(extract_link_text(link)) for link in df['Model'])
|
| 64 |
else:
|
| 65 |
max_length = 10
|
|
|
|
| 66 |
static_width = max_length * 10 + 16
|
| 67 |
|
| 68 |
max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
|
| 69 |
color_map = {"1": "black", "2": "black", "3": "black", "4": "black", "5": "black"}
|
| 70 |
html = '<table style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
|
|
|
|
| 71 |
html += '<thead><tr style="background-color: #f2f2f2;">'
|
| 72 |
html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
|
| 73 |
html += '<th style="text-align: left; padding: 8px;" title="GPU energy consumed in Watt-hours for 1,000 queries">GPU Energy (Wh)</th>'
|
|
|
|
| 77 |
for _, row in df.iterrows():
|
| 78 |
energy_numeric = row['gpu_energy_numeric']
|
| 79 |
energy_str = f"{energy_numeric:.2f}"
|
|
|
|
| 80 |
bar_width = (energy_numeric / max_energy) * 100
|
| 81 |
score_val = row['energy_score']
|
| 82 |
bar_color = color_map.get(str(score_val), "gray")
|
|
|
|
| 89 |
html += f'<td style="padding: 8px;">{row["Score"]}</td>'
|
| 90 |
html += '</tr>'
|
| 91 |
html += '</tbody></table>'
|
| 92 |
+
# Wrap the table in a container so its edges match the dropdown menus.
|
| 93 |
+
return f'<div class="table-container">{html}</div>'
|
| 94 |
|
| 95 |
# --- Function to zip all CSV files ---
|
| 96 |
def zip_csv_files():
|
|
|
|
| 112 |
href = (
|
| 113 |
f'<a href="data:application/zip;base64,{b64}" '
|
| 114 |
'download="data.zip" '
|
| 115 |
+
'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
|
| 116 |
'color: black; font-family: \'Inter\', sans-serif;">Download Data</a>'
|
| 117 |
)
|
| 118 |
return href
|
|
|
|
| 123 |
if df.columns[0].startswith("Unnamed:"):
|
| 124 |
df = df.iloc[:, 1:]
|
| 125 |
df['energy_score'] = df['energy_score'].astype(int)
|
|
|
|
| 126 |
df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
|
| 127 |
df['Model'] = df['model'].apply(make_link)
|
| 128 |
df['Score'] = df['energy_score'].apply(format_stars)
|
|
|
|
| 161 |
return generate_html_table_from_df(df)
|
| 162 |
|
| 163 |
# --- Update functions for dropdown changes ---
|
|
|
|
|
|
|
| 164 |
def update_text_generation(selected_display, sort_order):
|
| 165 |
mapping = {
|
| 166 |
"A (Single Consumer GPU) <20B parameters": "A",
|
|
|
|
| 170 |
model_class = mapping.get(selected_display, "A")
|
| 171 |
return get_text_generation_model_names_html(model_class, sort_order)
|
| 172 |
|
|
|
|
| 173 |
def update_image_generation(sort_order):
|
| 174 |
return get_model_names_html('image_generation.csv', sort_order)
|
| 175 |
|
|
|
|
| 201 |
return get_all_model_names_html(sort_order)
|
| 202 |
|
| 203 |
# --- Build the Gradio Interface ---
|
|
|
|
| 204 |
demo = gr.Blocks(css="""
|
| 205 |
.gr-dataframe table {
|
| 206 |
table-layout: fixed;
|
|
|
|
| 212 |
overflow: hidden;
|
| 213 |
text-overflow: ellipsis;
|
| 214 |
}
|
| 215 |
+
.table-container {
|
| 216 |
+
max-width: 800px;
|
| 217 |
+
margin-left: auto;
|
| 218 |
+
margin-right: auto;
|
| 219 |
+
}
|
| 220 |
""")
|
| 221 |
|
| 222 |
with demo:
|
| 223 |
+
# --- Header Links (at the very top, evenly spaced) ---
|
| 224 |
+
gr.HTML(f'''
|
| 225 |
+
<div style="display: flex; justify-content: space-evenly; align-items: center; margin-bottom: 20px;">
|
| 226 |
+
<a href="https://huggingface.co/spaces/AIEnergyScore/submission_portal" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">Submission Portal</a>
|
| 227 |
+
<a href="https://huggingface.co/spaces/AIEnergyScore/Label" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">Label Generator</a>
|
| 228 |
+
<a href="https://huggingface.github.io/AIEnergyScore/#faq" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">FAQ</a>
|
| 229 |
+
<a href="https://huggingface.github.io/AIEnergyScore/#documentation" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">Documentation</a>
|
| 230 |
+
{get_zip_data_link()}
|
| 231 |
+
<a href="https://huggingface.co/spaces/AIEnergyScore/README/discussions" style="text-decoration: none; font-weight: bold; font-size: 1.1em; color: black; font-family: 'Inter', sans-serif;">Community</a>
|
| 232 |
+
</div>
|
| 233 |
+
''')
|
| 234 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
# --- Logo (centered) ---
|
| 236 |
gr.HTML('''
|
| 237 |
+
<div style="margin-top: 20px;">
|
| 238 |
<img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
|
| 239 |
alt="Logo"
|
| 240 |
+
style="display: block; margin: 0 auto; max-width: 300px; height: auto;">
|
| 241 |
</div>
|
| 242 |
''')
|
| 243 |
|
| 244 |
# --- Subtitle (centered) ---
|
| 245 |
+
gr.Markdown('<div style="text-align: center;">Welcome to the AI Energy Score leaderboard. Select different tasks to see scored models.</div>')
|
| 246 |
|
| 247 |
# --- Tabs for the different tasks ---
|
| 248 |
with gr.Tabs():
|
|
|
|
| 265 |
value="Low to High"
|
| 266 |
)
|
| 267 |
tg_table = gr.HTML(get_text_generation_model_names_html("A", "Low to High"))
|
|
|
|
| 268 |
model_class_dropdown.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=tg_table)
|
| 269 |
sort_dropdown_tg.change(fn=update_text_generation, inputs=[model_class_dropdown, sort_dropdown_tg], outputs=tg_table)
|
| 270 |
|
|
|
|
| 376 |
lines=10,
|
| 377 |
show_copy_button=True,
|
| 378 |
)
|
| 379 |
+
gr.Markdown("Last updated: February 2025")
|
| 380 |
|
| 381 |
+
demo.launch()
|