bhaskartripathi
commited on
Commit
•
16eefe3
1
Parent(s):
0e7fccd
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,15 @@ 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):
|
@@ -46,18 +44,66 @@ def scrape_leaderboard(leaderboard):
|
|
46 |
def update_leaderboard(leaderboard):
|
47 |
try:
|
48 |
df = scrape_leaderboard(leaderboard)
|
49 |
-
return df
|
50 |
except Exception as e:
|
51 |
-
return f"An error occurred: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Create Gradio interface
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# Launch the app
|
63 |
iface.launch()
|
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
import pandas as pd
|
4 |
import gradio as gr
|
5 |
+
import io
|
6 |
|
7 |
BASE_URL = "https://scale.com/leaderboard"
|
8 |
|
9 |
LEADERBOARDS = {
|
|
|
|
|
10 |
"Coding": "/coding",
|
11 |
+
"Adversarial Robustness": "/adversarial_robustness",
|
12 |
"Instruction Following": "/instruction_following",
|
13 |
+
"Math": "/math"
|
|
|
|
|
14 |
}
|
15 |
|
16 |
def scrape_leaderboard(leaderboard):
|
|
|
44 |
def update_leaderboard(leaderboard):
|
45 |
try:
|
46 |
df = scrape_leaderboard(leaderboard)
|
47 |
+
return df, create_interactive_table(df)
|
48 |
except Exception as e:
|
49 |
+
return None, f"An error occurred: {str(e)}"
|
50 |
+
|
51 |
+
def create_interactive_table(df):
|
52 |
+
html = f"""
|
53 |
+
<script src="https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"></script>
|
54 |
+
<div id="myGrid" style="height: 500px; width: 100%;" class="ag-theme-alpine"></div>
|
55 |
+
<script>
|
56 |
+
var gridOptions = {{
|
57 |
+
columnDefs: [
|
58 |
+
{{field: "Rank", sortable: true, filter: true}},
|
59 |
+
{{field: "Model", sortable: true, filter: true}},
|
60 |
+
{{field: "Score", sortable: true, filter: true}},
|
61 |
+
{{field: "95% Confidence", sortable: true, filter: true}}
|
62 |
+
],
|
63 |
+
rowData: {df.to_dict(orient='records')},
|
64 |
+
defaultColDef: {{
|
65 |
+
flex: 1,
|
66 |
+
minWidth: 100,
|
67 |
+
resizable: true,
|
68 |
+
}},
|
69 |
+
domLayout: 'autoHeight'
|
70 |
+
}};
|
71 |
+
|
72 |
+
document.addEventListener('DOMContentLoaded', function() {{
|
73 |
+
var gridDiv = document.querySelector('#myGrid');
|
74 |
+
new agGrid.Grid(gridDiv, gridOptions);
|
75 |
+
}});
|
76 |
+
</script>
|
77 |
+
"""
|
78 |
+
return html
|
79 |
+
|
80 |
+
def export_to_excel(df):
|
81 |
+
if df is not None:
|
82 |
+
output = io.BytesIO()
|
83 |
+
with pd.ExcelWriter(output, engine='openpyxl') as writer:
|
84 |
+
df.to_excel(writer, index=False, sheet_name='Leaderboard')
|
85 |
+
output.seek(0)
|
86 |
+
return output
|
87 |
+
return None
|
88 |
|
89 |
# Create Gradio interface
|
90 |
+
with gr.Blocks() as iface:
|
91 |
+
gr.Markdown("# Scale AI Leaderboard Viewer")
|
92 |
+
with gr.Row():
|
93 |
+
dropdown = gr.Dropdown(choices=list(LEADERBOARDS.keys()), label="Select Leaderboard", value="Coding")
|
94 |
+
export_button = gr.Button("Export to Excel")
|
95 |
+
|
96 |
+
table_output = gr.HTML()
|
97 |
+
df_state = gr.State()
|
98 |
+
|
99 |
+
def on_load():
|
100 |
+
df, html = update_leaderboard("Coding")
|
101 |
+
return df, html
|
102 |
+
|
103 |
+
dropdown.change(update_leaderboard, inputs=[dropdown], outputs=[df_state, table_output])
|
104 |
+
export_button.click(export_to_excel, inputs=[df_state], outputs=[gr.File(label="Download Excel")])
|
105 |
+
|
106 |
+
iface.load(on_load, outputs=[df_state, table_output])
|
107 |
|
108 |
# Launch the app
|
109 |
iface.launch()
|