Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ def generate_html_table_from_df(df):
|
|
59 |
|
60 |
max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
|
61 |
color_map = {"1": "black", "2": "black", "3": "black", "4": "black", "5": "black"}
|
62 |
-
html = '<table style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
|
63 |
html += '<thead><tr style="background-color: #f2f2f2;">'
|
64 |
html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
|
65 |
html += '<th style="text-align: left; padding: 8px;" title="AI Provider extracted from the model name">Provider</th>'
|
@@ -114,7 +114,7 @@ def generate_info_callout(ratio, scope_text):
|
|
114 |
"""
|
115 |
return (
|
116 |
f'<div style="text-align: right;">'
|
117 |
-
f'<div style="display:inline-block; max-width:250px; font-size:0.8em; background-color:#e6ffe6; padding:8px; border-radius:5px;">'
|
118 |
f'💡 There\'s a <strong>{ratio:,.1f}x</strong> difference between the highest and lowest energy use in {scope_text}.'
|
119 |
f'</div></div>'
|
120 |
)
|
@@ -170,7 +170,7 @@ def update_text_generation(selected_display, sort_order):
|
|
170 |
return df
|
171 |
df = process_df('text_generation.csv', sort_order, filter_fn)
|
172 |
ratio = compute_efficiency_ratio(df)
|
173 |
-
#
|
174 |
callout = generate_info_callout(ratio, "this class")
|
175 |
table_html = generate_html_table_from_df(df)
|
176 |
return callout, table_html
|
@@ -258,22 +258,27 @@ def update_all_tasks(sort_order):
|
|
258 |
table_html = generate_html_table_from_df(all_df)
|
259 |
return callout, table_html
|
260 |
|
261 |
-
###
|
262 |
|
263 |
-
#
|
264 |
-
# and the global callout is positioned at the right edge (20px from the right).
|
265 |
global_header_html = f"""
|
266 |
<div style="position: relative; width: 100%; text-align: center; margin-bottom: 20px;">
|
267 |
-
<
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
270 |
<div style="position: absolute; top: 50%; right: 20px; transform: translateY(-50%);">
|
271 |
{get_global_callout()}
|
272 |
</div>
|
273 |
</div>
|
274 |
"""
|
275 |
|
276 |
-
|
|
|
|
|
|
|
277 |
.gr-dataframe table {
|
278 |
table-layout: fixed;
|
279 |
width: 100%;
|
@@ -289,7 +294,34 @@ demo = gr.Blocks(css="""
|
|
289 |
margin-left: auto;
|
290 |
margin-right: auto;
|
291 |
}
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
with demo:
|
295 |
# --- Header Links ---
|
@@ -309,7 +341,7 @@ with demo:
|
|
309 |
|
310 |
# --- Tabs for the different tasks ---
|
311 |
with gr.Tabs():
|
312 |
-
# --- Text Generation Tab
|
313 |
with gr.TabItem("Text Generation 💬"):
|
314 |
with gr.Row():
|
315 |
with gr.Column(scale=4):
|
|
|
59 |
|
60 |
max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
|
61 |
color_map = {"1": "black", "2": "black", "3": "black", "4": "black", "5": "black"}
|
62 |
+
html = '<table class="data-table" style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
|
63 |
html += '<thead><tr style="background-color: #f2f2f2;">'
|
64 |
html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
|
65 |
html += '<th style="text-align: left; padding: 8px;" title="AI Provider extracted from the model name">Provider</th>'
|
|
|
114 |
"""
|
115 |
return (
|
116 |
f'<div style="text-align: right;">'
|
117 |
+
f'<div class="info-callout" style="display:inline-block; max-width:250px; font-size:0.8em; background-color:#e6ffe6; padding:8px; border-radius:5px;">'
|
118 |
f'💡 There\'s a <strong>{ratio:,.1f}x</strong> difference between the highest and lowest energy use in {scope_text}.'
|
119 |
f'</div></div>'
|
120 |
)
|
|
|
170 |
return df
|
171 |
df = process_df('text_generation.csv', sort_order, filter_fn)
|
172 |
ratio = compute_efficiency_ratio(df)
|
173 |
+
# For Text Generation, use "this class" at the end.
|
174 |
callout = generate_info_callout(ratio, "this class")
|
175 |
table_html = generate_html_table_from_df(df)
|
176 |
return callout, table_html
|
|
|
258 |
table_html = generate_html_table_from_df(all_df)
|
259 |
return callout, table_html
|
260 |
|
261 |
+
### GLOBAL HEADER (Logo & Global Callout) ###
|
262 |
|
263 |
+
# Use a <picture> element so that dark mode uses logodark.png.
|
|
|
264 |
global_header_html = f"""
|
265 |
<div style="position: relative; width: 100%; text-align: center; margin-bottom: 20px;">
|
266 |
+
<picture style="display:inline-block;">
|
267 |
+
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logodark.png">
|
268 |
+
<img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png"
|
269 |
+
alt="Logo"
|
270 |
+
style="width:300px; max-width:300px; height:auto; display:inline-block;">
|
271 |
+
</picture>
|
272 |
<div style="position: absolute; top: 50%; right: 20px; transform: translateY(-50%);">
|
273 |
{get_global_callout()}
|
274 |
</div>
|
275 |
</div>
|
276 |
"""
|
277 |
|
278 |
+
### GRADIO INTERFACE ###
|
279 |
+
|
280 |
+
# Additional CSS for dark mode and mobile responsiveness
|
281 |
+
custom_css = """
|
282 |
.gr-dataframe table {
|
283 |
table-layout: fixed;
|
284 |
width: 100%;
|
|
|
294 |
margin-left: auto;
|
295 |
margin-right: auto;
|
296 |
}
|
297 |
+
|
298 |
+
/* Dark mode styles */
|
299 |
+
@media (prefers-color-scheme: dark) {
|
300 |
+
body {
|
301 |
+
background-color: #121212;
|
302 |
+
color: #e0e0e0;
|
303 |
+
}
|
304 |
+
.gr-dataframe th {
|
305 |
+
background-color: #333;
|
306 |
+
color: #e0e0e0;
|
307 |
+
}
|
308 |
+
.gr-dataframe td {
|
309 |
+
color: #e0e0e0;
|
310 |
+
}
|
311 |
+
a {
|
312 |
+
color: #bb86fc;
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
/* Mobile styles: hide callout boxes on small screens */
|
317 |
+
@media (max-width: 600px) {
|
318 |
+
.info-callout {
|
319 |
+
display: none;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
"""
|
323 |
+
|
324 |
+
demo = gr.Blocks(css=custom_css)
|
325 |
|
326 |
with demo:
|
327 |
# --- Header Links ---
|
|
|
341 |
|
342 |
# --- Tabs for the different tasks ---
|
343 |
with gr.Tabs():
|
344 |
+
# --- Text Generation Tab ---
|
345 |
with gr.TabItem("Text Generation 💬"):
|
346 |
with gr.Row():
|
347 |
with gr.Column(scale=4):
|