File size: 2,386 Bytes
23dea16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import time
from supabase import create_client, Client
import os
from dotenv import load_dotenv
import pandas as pd

# Load environment variables
load_dotenv()

# Initialize Supabase client
SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_KEY = os.getenv("SUPABASE_KEY")
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)


def get_active_round():
    # Fetch the active round data and return both round ID and round number
    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 both round ID and round number
    return None, None


def get_elo_ratings(round_id):
    # Query the ELO ratings based on the 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():
    # Get the active round ID and round number
    round_id, round_number = get_active_round()
    print("Active Round ID:", round_id, "Round Number:", round_number)  # This will print both round ID and round number
    if round_id:
        # Fetch the ELO ratings based on the round ID
        elo_ratings = get_elo_ratings(round_id)
        return f"Active Round: {round_number}", elo_ratings  # Display the round number in the UI
    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"])

    # Create a periodic update function
    def periodic_update():
        round_status, ratings = update_info()
        return round_status, ratings

    # Load initial values
    demo.load(update_info, outputs=[round_info, elo_table])

    # Use gr.Timer to trigger updates every 5 seconds
    timer = gr.Timer(value=5, active=True)  # Set timer to tick every 5 seconds
    timer.tick(periodic_update, outputs=[round_info, elo_table])

if __name__ == "__main__":
    demo.queue()
    demo.launch()