leaderboard / app.py
heiditeng25's picture
update link + refresh button
2c9fc1c verified
import gradio as gr
import pandas as pd
import requests
import io
from datetime import datetime
# test csv file
CSV_URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vR66Wy-eHXPDCEFksh3SD4SzIFeB7pnmNFHBDkGtrkSFliy6Ef6vdyijfFP-FCuBkqWwXy7qQYRIvCM/pub?output=csv"
# fetch data from google sheets
def fetch_leaderboard_data():
try:
response = requests.get(CSV_URL)
response.raise_for_status()
data = pd.read_csv(io.StringIO(response.text))
# print("Raw CSV Data:\n", data) # Debugging
# normalize column names
data.rename(columns={"Perfomance Score": "Performance Score"}, inplace=True)
data.columns = data.columns.str.strip().str.lower()
# required columns
required_columns = {'rank', 'team', 'date and time', 'time(microsec)', 'accuracy', 'performance score'}
for col in required_columns:
if col not in data.columns:
data[col] = "N/A"
if data.empty:
print("DataFrame is empty, filling with placeholder row.")
data = pd.DataFrame({col: ["N/A"] for col in required_columns})
# handle date parsing safely
data['date and time'] = pd.to_datetime(data['date and time'], errors='coerce')
data['date and time'].fillna('N/A', inplace=True)
if not data.empty:
last_submission = data.sort_values(by='date and time', ascending=False).groupby('team', as_index=False).first()
else:
last_submission = data
# Sorting and keeping last submission
last_submission.columns = last_submission.columns.str.title()
# print("Final Leaderboard Data:\n", last_submission) # Debugging
return last_submission
except Exception as e:
print(f"Error fetching data: {e}")
return pd.DataFrame({"Error": ["Unable to fetch data"]})
# title for the leaderboard
title = """
<center>
<h1> IEEE Low-Power Computer Vision Challenge </h1>
<b> 2025 CVPR WORKSHOP </b>
</center>
"""
description = """
<p><b>Important:</b> The leaderboard only shows results from registered teams. Only the last submission from each team in the previous day will be evaluated.</p>
"""
# gradio app
def create_gradio_app():
with gr.Blocks(theme="gradio/soft") as app:
# gr.HTML(title)
gr.HTML(description)
with gr.Column():
refresh_button = gr.Button("Refresh Leaderboard")
leaderboard = gr.DataFrame(
value=fetch_leaderboard_data(),
interactive=False,
label="Leaderboard",
)
refresh_button.click(lambda: fetch_leaderboard_data(), outputs=leaderboard)
return app
# launch gradio app
def run_gradio_app():
app = create_gradio_app()
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
if __name__ == "__main__":
run_gradio_app()