File size: 5,672 Bytes
460fdc7
 
bff1996
 
49e7f66
42e8f64
c40907d
2ec9b03
4f8bac4
2ec9b03
 
4f8bac4
2ec9b03
4f8bac4
 
0a8b643
4f8bac4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3f4f1f
4f8bac4
 
 
 
c3f4f1f
 
 
 
ab1e3f0
c3f4f1f
 
dd0d99f
ab1e3f0
dd0d99f
 
 
 
ab1e3f0
c3f4f1f
 
ab1e3f0
c3f4f1f
 
ab1e3f0
c3f4f1f
 
 
ab1e3f0
c3f4f1f
ab1e3f0
 
 
c3f4f1f
 
ab1e3f0
c3f4f1f
828c71e
22ec62d
ab1e3f0
22ec62d
 
 
 
c3f4f1f
22ec62d
 
ab1e3f0
b3f5a49
c3f4f1f
22ec62d
ab1e3f0
 
 
 
22ec62d
 
 
c3f4f1f
 
22ec62d
c3f4f1f
 
 
22ec62d
 
ab1e3f0
b3f5a49
c3f4f1f
22ec62d
c3f4f1f
4567668
 
 
 
 
 
 
 
 
 
 
 
f7b4006
7022131
ab1e3f0
361f8d0
88fbc65
f7b4006
296b387
b3f5a49
 
 
ab1e3f0
b3f5a49
ab1e3f0
b3f5a49
 
40e7d39
4f8bac4
 
 
 
 
 
 
88fbc65
4f8bac4
ab1e3f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import gradio as gr
import pandas as pd
import os
import zipfile
import base64

CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
CITATION_BUTTON_TEXT = r"""@misc{aienergyscore-leaderboard,
    author = {Sasha Luccioni and Boris Gamazaychikov and Emma Strubell and Sara Hooker and Yacine Jernite and Carole-Jean Wu and Margaret Mitchell},
    title = {AI Energy Score Leaderboard - February 2025},
    year = {2025},
    publisher = {Hugging Face},
    howpublished = "\url{https://huggingface.co/spaces/AIEnergyScore/Leaderboard}",
}"""

# List of tasks (CSV filenames)
tasks = [
    'asr.csv',
    'object_detection.csv',
    'text_classification.csv',
    'image_captioning.csv',
    'question_answering.csv',
    'text_generation.csv',
    'image_classification.csv',
    'sentence_similarity.csv',
    'image_generation.csv',
    'summarization.csv'
]

def format_stars(score):
    try:
        score_int = int(score)
    except Exception:
        score_int = 0
    return f'<span style="color: black; font-size:1.5em;">{"★" * score_int}</span>'

def make_link(mname):
    parts = str(mname).split('/')
    display_name = parts[1] if len(parts) > 1 else mname
    return f'<a href="https://huggingface.co/{mname}" target="_blank">{display_name}</a>'

def generate_html_table_from_df(df):
    """
    Generates an HTML table with tooltips for column headers.
    """
    max_energy = df['gpu_energy_numeric'].max() if not df.empty else 1
    color_map = {"1": "black", "2": "black", "3": "black", "4": "black", "5": "black"}
    
    html = '<table style="width:100%; border-collapse: collapse; font-family: Inter, sans-serif;">'
    html += '<thead><tr style="background-color: #f2f2f2;">'
    html += '<th style="text-align: left; padding: 8px;" title="Model name with link to Hugging Face">Model</th>'
    html += '<th style="text-align: left; padding: 8px;" title="GPU energy consumed in Watt-hours for 1,000 queries">GPU Energy (Wh)</th>'
    html += '<th style="text-align: left; padding: 8px;" title="5 is most efficient, 1 is least. Relative energy efficiency score at launch">Score</th>'
    html += '</tr></thead>'
    html += '<tbody>'
    
    for _, row in df.iterrows():
        energy_numeric = row['gpu_energy_numeric']
        energy_str = f"{energy_numeric:.2f}"  # Display GPU energy with 2 decimal places
        bar_width = (energy_numeric / max_energy) * 100
        score_val = row['energy_score']
        bar_color = color_map.get(str(score_val), "gray")
        
        html += '<tr>'
        html += f'<td style="padding: 8px;">{row["Model"]}</td>'
        html += f'<td style="padding: 8px;">{energy_str}<br>'
        html += f'<div style="background-color: {bar_color}; width: {bar_width:.1f}%; height: 10px;"></div></td>'
        html += f'<td style="padding: 8px;">{row["Score"]}</td>'
        html += '</tr>'
    
    html += '</tbody></table>'
    return html

def get_model_names_html(task, sort_order="Low to High"):
    df = pd.read_csv('data/energy/' + task)
    if df.columns[0].startswith("Unnamed:"):
        df = df.iloc[:, 1:]
    df['energy_score'] = df['energy_score'].astype(int)
    df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
    df['Model'] = df['model'].apply(make_link)
    df['Score'] = df['energy_score'].apply(format_stars)
    ascending = True  # Always default to Low to High
    df = df.sort_values(by='gpu_energy_numeric', ascending=ascending)
    return generate_html_table_from_df(df)

def update_all_tasks(sort_order):
    return get_all_model_names_html(sort_order)

def get_all_model_names_html(sort_order="Low to High"):
    all_df = pd.DataFrame()
    for task in tasks:
        df = pd.read_csv('data/energy/' + task)
        if df.columns[0].startswith("Unnamed:"):
            df = df.iloc[:, 1:]
        df['energy_score'] = df['energy_score'].astype(int)
        df['gpu_energy_numeric'] = pd.to_numeric(df['total_gpu_energy'], errors='raise') * 1000
        df['Model'] = df['model'].apply(make_link)
        df['Score'] = df['energy_score'].apply(format_stars)
        all_df = pd.concat([all_df, df], ignore_index=True)
    all_df = all_df.drop_duplicates(subset=['model'])
    ascending = True  # Default to Low to High
    all_df = all_df.sort_values(by='gpu_energy_numeric', ascending=ascending)
    return generate_html_table_from_df(all_df)

# --- Build the Gradio Interface ---
demo = gr.Blocks(css="""
.gr-dataframe table {
    table-layout: fixed;
    width: 100%;
}
.gr-dataframe th, .gr-dataframe td {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
""")

with demo:
    gr.HTML('<div style="text-align: center;"><img src="logo.png" alt="Logo" style="width: 200px;"></div>')
    gr.HTML('<div style="text-align: center; font-size: 1.2em;">Welcome to the AI Energy Score Leaderboard</div>')
    
    with gr.Tabs():
        with gr.TabItem("All Tasks 💡"):
            sort_dropdown_all = gr.Dropdown(
                choices=["Low to High", "High to Low"],
                label="Sort",
                value="Low to High"
            )
            all_table = gr.HTML(get_all_model_names_html("Low to High"))
            sort_dropdown_all.change(fn=update_all_tasks, inputs=sort_dropdown_all, outputs=all_table)
    
    with gr.Accordion("📙 Citation", open=False):
        citation_button = gr.Textbox(
            value=CITATION_BUTTON_TEXT,
            label=CITATION_BUTTON_LABEL,
            elem_id="citation-button",
            lines=10,
            show_copy_button=True,
        )
    gr.Markdown("""Last updated: February 2025""")

demo.launch()