Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
BASE_URL = "https://scale.com/leaderboard"
|
| 7 |
+
|
| 8 |
+
LEADERBOARDS = {
|
| 9 |
+
"Main Leaderboard": "",
|
| 10 |
+
"Adversarial Robustness": "/adversarial_robustness",
|
| 11 |
+
"Coding": "/coding",
|
| 12 |
+
"Instruction Following": "/instruction_following",
|
| 13 |
+
"Math": "/math",
|
| 14 |
+
"Spanish": "/spanish",
|
| 15 |
+
"Methodology": "/methodology"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def scrape_leaderboard(leaderboard):
|
| 19 |
+
url = BASE_URL + LEADERBOARDS[leaderboard]
|
| 20 |
+
|
| 21 |
+
response = requests.get(url)
|
| 22 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 23 |
+
|
| 24 |
+
leaderboard_div = soup.find('div', class_='flex flex-col gap-4 sticky top-20')
|
| 25 |
+
|
| 26 |
+
if not leaderboard_div:
|
| 27 |
+
raise ValueError("Leaderboard div not found. The page structure might have changed.")
|
| 28 |
+
|
| 29 |
+
table = leaderboard_div.find('table', class_='w-full caption-bottom text-sm')
|
| 30 |
+
|
| 31 |
+
if not table:
|
| 32 |
+
raise ValueError("Leaderboard table not found within the div.")
|
| 33 |
+
|
| 34 |
+
data = []
|
| 35 |
+
for row in table.find('tbody').find_all('tr'):
|
| 36 |
+
cols = row.find_all('td')
|
| 37 |
+
rank = cols[0].find('div', class_='flex').text.strip().split()[0]
|
| 38 |
+
model = cols[0].find('a').text.strip()
|
| 39 |
+
score = cols[1].text.strip()
|
| 40 |
+
confidence = cols[2].text.strip()
|
| 41 |
+
data.append([rank, model, score, confidence])
|
| 42 |
+
|
| 43 |
+
df = pd.DataFrame(data, columns=['Rank', 'Model', 'Score', '95% Confidence'])
|
| 44 |
+
return df
|
| 45 |
+
|
| 46 |
+
def update_leaderboard(leaderboard):
|
| 47 |
+
try:
|
| 48 |
+
df = scrape_leaderboard(leaderboard)
|
| 49 |
+
return df.to_html(index=False)
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return f"An error occurred: {str(e)}"
|
| 52 |
+
|
| 53 |
+
# Create Gradio interface
|
| 54 |
+
iface = gr.Interface(
|
| 55 |
+
fn=update_leaderboard,
|
| 56 |
+
inputs=gr.Dropdown(choices=list(LEADERBOARDS.keys()), label="Select Leaderboard"),
|
| 57 |
+
outputs=gr.HTML(label="Leaderboard Data"),
|
| 58 |
+
title="Scale AI Leaderboard Viewer",
|
| 59 |
+
description="Select a leaderboard to view the latest data from Scale.com"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Launch the app
|
| 63 |
+
iface.launch()
|