Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import requests
|
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
-
import
|
| 6 |
|
| 7 |
BASE_URL = "https://scale.com/leaderboard"
|
| 8 |
|
|
@@ -39,42 +39,39 @@ def scrape_leaderboard(leaderboard):
|
|
| 39 |
data.append([rank, model, score, confidence])
|
| 40 |
|
| 41 |
df = pd.DataFrame(data, columns=['Rank', 'Model', 'Score', '95% Confidence'])
|
|
|
|
| 42 |
return df
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def update_leaderboard(leaderboard):
|
| 45 |
try:
|
| 46 |
df = scrape_leaderboard(leaderboard)
|
| 47 |
-
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
-
return None, f"An error occurred: {str(e)}"
|
| 50 |
-
|
| 51 |
-
def export_to_excel(df):
|
| 52 |
-
if df is not None:
|
| 53 |
-
output = io.BytesIO()
|
| 54 |
-
with pd.ExcelWriter(output, engine='openpyxl') as writer:
|
| 55 |
-
df.to_excel(writer, index=False, sheet_name='Leaderboard')
|
| 56 |
-
output.seek(0)
|
| 57 |
-
return output
|
| 58 |
-
return None
|
| 59 |
|
| 60 |
# Create Gradio interface
|
| 61 |
with gr.Blocks() as iface:
|
| 62 |
gr.Markdown("# Scale AI Leaderboard Viewer")
|
| 63 |
-
|
| 64 |
-
dropdown = gr.Dropdown(choices=list(LEADERBOARDS.keys()), label="Select Leaderboard", value="Coding")
|
| 65 |
-
export_button = gr.Button("Export to Excel")
|
| 66 |
|
| 67 |
table_output = gr.HTML()
|
| 68 |
-
|
| 69 |
|
| 70 |
def on_load():
|
| 71 |
-
df, html = update_leaderboard("Coding")
|
| 72 |
-
return
|
| 73 |
|
| 74 |
-
dropdown.change(update_leaderboard, inputs=[dropdown], outputs=[
|
| 75 |
-
export_button.click(export_to_excel, inputs=[df_state], outputs=[gr.File(label="Download Excel")])
|
| 76 |
|
| 77 |
-
iface.load(on_load, outputs=[
|
| 78 |
|
| 79 |
# Launch the app
|
| 80 |
iface.launch()
|
|
|
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
+
import plotly.express as px
|
| 6 |
|
| 7 |
BASE_URL = "https://scale.com/leaderboard"
|
| 8 |
|
|
|
|
| 39 |
data.append([rank, model, score, confidence])
|
| 40 |
|
| 41 |
df = pd.DataFrame(data, columns=['Rank', 'Model', 'Score', '95% Confidence'])
|
| 42 |
+
df['Score'] = pd.to_numeric(df['Score']) # Convert Score to numeric
|
| 43 |
return df
|
| 44 |
|
| 45 |
+
def create_chart(df):
|
| 46 |
+
fig = px.bar(df, x='Model', y='Score', title='Model Scores Comparison',
|
| 47 |
+
labels={'Score': 'Overall Score', 'Model': 'Model Name'},
|
| 48 |
+
color='Score', color_continuous_scale='viridis')
|
| 49 |
+
fig.update_layout(xaxis_tickangle=-45, xaxis_title=None)
|
| 50 |
+
return fig
|
| 51 |
+
|
| 52 |
def update_leaderboard(leaderboard):
|
| 53 |
try:
|
| 54 |
df = scrape_leaderboard(leaderboard)
|
| 55 |
+
chart = create_chart(df)
|
| 56 |
+
return df, df.to_html(index=False), chart
|
| 57 |
except Exception as e:
|
| 58 |
+
return None, f"An error occurred: {str(e)}", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Create Gradio interface
|
| 61 |
with gr.Blocks() as iface:
|
| 62 |
gr.Markdown("# Scale AI Leaderboard Viewer")
|
| 63 |
+
dropdown = gr.Dropdown(choices=list(LEADERBOARDS.keys()), label="Select Leaderboard", value="Coding")
|
|
|
|
|
|
|
| 64 |
|
| 65 |
table_output = gr.HTML()
|
| 66 |
+
chart_output = gr.Plot()
|
| 67 |
|
| 68 |
def on_load():
|
| 69 |
+
df, html, chart = update_leaderboard("Coding")
|
| 70 |
+
return html, chart
|
| 71 |
|
| 72 |
+
dropdown.change(update_leaderboard, inputs=[dropdown], outputs=[table_output, table_output, chart_output])
|
|
|
|
| 73 |
|
| 74 |
+
iface.load(on_load, outputs=[table_output, chart_output])
|
| 75 |
|
| 76 |
# Launch the app
|
| 77 |
iface.launch()
|