| import gradio as gr |
| import time |
| from supabase import create_client, Client |
| import os |
| from dotenv import load_dotenv |
| import pandas as pd |
|
|
| |
| load_dotenv() |
|
|
| |
| SUPABASE_URL = os.getenv("SUPABASE_URL") |
| SUPABASE_KEY = os.getenv("SUPABASE_KEY") |
| supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) |
|
|
|
|
| def get_active_round(): |
| |
| response = supabase.table("round_status").select("id, round").eq("is_eval_active", True).single().execute() |
| if response.data: |
| return response.data['id'], response.data['round'] |
| return None, None |
|
|
|
|
| def get_elo_ratings(round_id): |
| |
| response = supabase.table("elos").select("user_id, rating").eq("round", round_id).execute() |
|
|
| print("get_elo_ratings: ", response.data) |
| if response.data: |
| df = pd.DataFrame(response.data) |
| df = df.sort_values(by='rating', ascending=False) |
| print(df.head()) |
| return df |
| return pd.DataFrame(columns=['user_id', 'rating']) |
|
|
|
|
| def update_info(): |
| |
| round_id, round_number = get_active_round() |
| print("Active Round ID:", round_id, "Round Number:", round_number) |
| if round_id: |
| |
| elo_ratings = get_elo_ratings(round_id) |
| return f"Active Round: {round_number}", elo_ratings |
| else: |
| return "No active round found", pd.DataFrame(columns=['user_id', 'rating']) |
|
|
|
|
| with gr.Blocks() as demo: |
| gr.Markdown("## Leaderboard") |
| round_info = gr.Textbox(label="") |
| elo_table = gr.DataFrame(label="ELO Ratings", headers=["User ID", "Rating"]) |
|
|
| |
| def periodic_update(): |
| round_status, ratings = update_info() |
| return round_status, ratings |
|
|
| |
| demo.load(update_info, outputs=[round_info, elo_table]) |
|
|
| |
| timer = gr.Timer(value=5, active=True) |
| timer.tick(periodic_update, outputs=[round_info, elo_table]) |
|
|
| if __name__ == "__main__": |
| demo.queue() |
| demo.launch() |
|
|