File size: 5,202 Bytes
e7cbd6a
460fdc7
e7cbd6a
d3ee32e
 
e7cbd6a
 
 
 
 
d3ee32e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7cbd6a
 
d3ee32e
 
 
e7cbd6a
 
 
 
 
 
 
 
 
 
 
 
 
d3ee32e
e7cbd6a
 
 
5dc7166
d3ee32e
 
 
e7cbd6a
 
 
 
fe6b2ac
5dc7166
e7cbd6a
 
 
 
 
 
 
 
 
 
 
 
 
 
d3ee32e
e7cbd6a
 
 
 
 
 
 
 
f7b4006
d3ee32e
e7cbd6a
d3ee32e
 
 
 
 
fe6b2ac
 
e7cbd6a
fe6b2ac
 
 
 
e7cbd6a
fe6b2ac
 
 
 
e7cbd6a
fe6b2ac
 
 
 
e7cbd6a
fe6b2ac
 
 
 
 
e7cbd6a
fe6b2ac
 
 
d3ee32e
f66e432
d3ee32e
f66e432
 
d3ee32e
f66e432
 
 
d3ee32e
 
e7cbd6a
d3ee32e
e7cbd6a
d3ee32e
 
 
 
e7cbd6a
d3ee32e
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
import os, glob
import pandas as pd
import gradio as gr
from datasets import load_dataset
from huggingface_hub import HfApi

OWNER = "AIEnergyScore"
TOKEN = os.environ.get("DEBUG")
API = HfApi(token=TOKEN)

def get_leaderboard_models():
    """
    Reads CSV files from the leaderboard directory and returns a DataFrame
    containing the 'model' and 'task' columns.
    If no CSV files are found, returns an empty DataFrame with those columns.
    """
    path = r'leaderboard_v0_data/energy'
    filenames = glob.glob(os.path.join(path, "*.csv"))
    data = []
    for filename in filenames:
        data.append(pd.read_csv(filename))
    if not data:
        return pd.DataFrame(columns=['model', 'task'])
    leaderboard_data = pd.concat(data, ignore_index=True)
    return leaderboard_data[['model', 'task']]

def print_existing_models():
    """
    Loads a dataset of requests and returns the models that have been benchmarked.
    """
    requests = load_dataset("AIEnergyScore/requests_debug", split="test", token=TOKEN)
    requests_dset = requests.to_pandas()
    model_df = requests_dset[['model', 'status']]
    model_df = model_df[model_df['status'] == 'COMPLETED']
    return model_df

def highlight_cols(x):
    df = x.copy()
    df[df['status'] == 'COMPLETED'] = 'color: green'
    df[df['status'] == 'PENDING'] = 'color: orange'
    df[df['status'] == 'FAILED'] = 'color: red'
    return df

# Apply styling to the recently benchmarked models table.
existing_models = print_existing_models()
formatted_df = existing_models.style.apply(highlight_cols, axis=None)

def get_zip_data_link():
    """
    Returns an HTML link for downloading logs.
    """
    return (
        '<a href="https://example.com/download.zip" '
        'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
        'color: black; font-family: \'Inter\', sans-serif;">Download Logs</a>'
    )

with gr.Blocks() as demo:
    # --- Custom CSS for layout and styling ---
    gr.HTML('''
    <style>
      /* Evenly space the header links */
      .header-links {
          display: flex;
          justify-content: space-evenly;
          align-items: center;
          margin: 10px 0;
      }
      /* Center the subtitle text */
      .centered-subtitle {
          text-align: center;
          font-size: 1.4em;
          margin-bottom: 20px;
      }
      /* Full width container for matching widget edges */
      .full-width {
          width: 100% !important;
      }
    </style>
    ''')

    # --- Header Links ---
    with gr.Row(elem_classes="header-links"):
        leaderboard_link = gr.HTML(
            '<a href="https://huggingface.co/spaces/AIEnergyScore/Leaderboard" '
            'style="text-decoration: none; font-weight: bold; font-size: 1.1em; '
            'color: black; font-family: \'Inter\', sans-serif;">Leaderboard</a>'
        )
        submission_link = gr.HTML(
            '<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>'
        )
        label_link = gr.HTML(
            '<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>'
        )
        faq_link = gr.HTML(
            '<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>'
        )
        documentation_link = gr.HTML(
            '<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>'
        )
        download_link = gr.HTML(get_zip_data_link())
        community_link = gr.HTML(
            '<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>'
        )
    
    # --- Logo (Centered) ---
    gr.HTML('''
    <div style="text-align: center; margin-top: 20px;">
        <img src="https://huggingface.co/spaces/AIEnergyScore/Leaderboard/resolve/main/logo.png" 
             alt="Logo" 
             style="max-width: 500px; height: auto;">
    </div>
    ''')

    # --- Centered Subtitle ---
    gr.Markdown('<p class="centered-subtitle">Welcome to the AI Energy Score Leaderboard. Explore the top-performing models below.</p>')

    # --- Leaderboard Tables ---
    with gr.Column(elem_classes="full-width"):
        with gr.Accordion("Latest Leaderboard", open=True):
            gr.Dataframe(get_leaderboard_models(), elem_classes="full-width")
        with gr.Accordion("Recently Benchmarked Models", open=False):
            gr.Dataframe(formatted_df, elem_classes="full-width")

demo.launch()