track1lb / app.py
szz1's picture
Update app.py
64a2b39 verified
import gradio as gr
import pandas as pd
import requests
import io
from datetime import datetime
# csv file
CSV_URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vR66Wy-eHXPDCEFksh3SD4SzIFeB7pnmNFHBDkGtrkSFliy6Ef6vdyijfFP-FCuBkqWwXy7qQYRIvCM/pub?gid=0&single=true&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))
# Normalize column names (lowercase & strip spaces)
data.columns = data.columns.str.strip().str.lower()
# Ensure "Rank" is treated as a number for sorting
if 'rank' in data.columns:
data['rank'] = pd.to_numeric(data['rank'], errors='coerce')
# Handle date parsing (optional)
if 'date and time' in data.columns:
data['date and time'] = pd.to_datetime(data['date and time'], errors='coerce')
# Sort by rank (ascending order)
data = data.sort_values(by='rank', ascending=True)
# Capitalize column names before returning
data.columns = data.columns.str.title()
return data
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 <b>registered teams</b>. Only the <b>last submission</b> from each team in the <b>previous day</b> will be evaluated.</p>
<p>Can't find your submission? Check <a href="https://szz1-failed-jobs.hf.space">Failed Jobs</a>.</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()