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 ( 'Download Logs' ) with gr.Blocks() as demo: # --- Custom CSS for layout and styling --- gr.HTML(''' ''') # --- Header Links --- with gr.Row(elem_classes="header-links"): leaderboard_link = gr.HTML( 'Leaderboard' ) submission_link = gr.HTML( 'Submission Portal' ) label_link = gr.HTML( 'Label Generator' ) faq_link = gr.HTML( 'FAQ' ) documentation_link = gr.HTML( 'Documentation' ) download_link = gr.HTML(get_zip_data_link()) community_link = gr.HTML( 'Community' ) # --- Logo (Centered) --- gr.HTML('''
Welcome to the AI Energy Score Leaderboard. Explore the top-performing models below.
') # --- 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()