File size: 2,580 Bytes
0e7fccd
 
 
 
0dc6eb9
0e7fccd
 
 
 
 
16eefe3
0e7fccd
16eefe3
0e7fccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dc6eb9
0e7fccd
 
0dc6eb9
 
 
 
 
 
 
0e7fccd
 
 
0dc6eb9
dfdb820
0e7fccd
dfdb820
0e7fccd
 
16eefe3
cf86fa8
0dc6eb9
16eefe3
0dc6eb9
dfdb820
16eefe3
 
dfdb820
 
16eefe3
dfdb820
16eefe3
dfdb820
0e7fccd
 
 
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
71
72
73
74
75
76
77
import requests
from bs4 import BeautifulSoup
import pandas as pd
import gradio as gr
import plotly.express as px

BASE_URL = "https://scale.com/leaderboard"

LEADERBOARDS = {
    "Coding": "/coding",
    "Adversarial Robustness": "/adversarial_robustness",
    "Instruction Following": "/instruction_following",
    "Math": "/math"
}

def scrape_leaderboard(leaderboard):
    url = BASE_URL + LEADERBOARDS[leaderboard]
    
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')
    
    leaderboard_div = soup.find('div', class_='flex flex-col gap-4 sticky top-20')
    
    if not leaderboard_div:
        raise ValueError("Leaderboard div not found. The page structure might have changed.")
    
    table = leaderboard_div.find('table', class_='w-full caption-bottom text-sm')
    
    if not table:
        raise ValueError("Leaderboard table not found within the div.")
    
    data = []
    for row in table.find('tbody').find_all('tr'):
        cols = row.find_all('td')
        rank = cols[0].find('div', class_='flex').text.strip().split()[0]
        model = cols[0].find('a').text.strip()
        score = cols[1].text.strip()
        confidence = cols[2].text.strip()
        data.append([rank, model, score, confidence])
    
    df = pd.DataFrame(data, columns=['Rank', 'Model', 'Score', '95% Confidence'])
    df['Score'] = pd.to_numeric(df['Score'])  # Convert Score to numeric
    return df

def create_chart(df):
    fig = px.bar(df, x='Model', y='Score', title='Model Scores Comparison',
                 labels={'Score': 'Overall Score', 'Model': 'Model Name'},
                 color='Score', color_continuous_scale='viridis')
    fig.update_layout(xaxis_tickangle=-45, xaxis_title=None)
    return fig

def update_leaderboard(leaderboard):
    try:
        df = scrape_leaderboard(leaderboard)
        chart = create_chart(df)
        return chart, df.to_html(index=False)
    except Exception as e:
        return None, f"An error occurred: {str(e)}"

# Create Gradio interface
with gr.Blocks() as iface:
    gr.Markdown("# AI Leaderboard Viewer")
    dropdown = gr.Dropdown(choices=list(LEADERBOARDS.keys()), label="Select Leaderboard", value="Coding")
    
    chart_output = gr.Plot()
    table_output = gr.HTML()
    
    def on_load():
        chart, html = update_leaderboard("Coding")
        return chart, html
    
    dropdown.change(update_leaderboard, inputs=[dropdown], outputs=[chart_output, table_output])
    
    iface.load(on_load, outputs=[chart_output, table_output])

# Launch the app
iface.launch()