Spaces:
Sleeping
Sleeping
Feat: stuff works and looks human-ish?
Browse files- app.py +73 -26
- src/retrieve_data.py +3 -2
app.py
CHANGED
@@ -27,11 +27,22 @@ def background_update():
|
|
27 |
time.sleep(300) # 5 minutes
|
28 |
|
29 |
|
30 |
-
def create_table_for_lb(lb_name):
|
31 |
"""Create a formatted table for a specific leaderboard and GPU"""
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
lb_data = leaderboard_data[lb_name]
|
35 |
|
36 |
headers = ["Rank", "Submission Name", "User ID", "Score", "Date"]
|
37 |
|
@@ -58,43 +69,79 @@ def create_table_for_lb(lb_name):
|
|
58 |
def refresh_ui():
|
59 |
"""Force refresh the UI with latest data"""
|
60 |
asyncio.run(fetch_data())
|
61 |
-
return "Data refreshed!"
|
62 |
|
63 |
|
64 |
-
def
|
65 |
-
"""
|
66 |
-
|
67 |
|
68 |
-
with gr.Blocks(title="ML Leaderboards") as app:
|
69 |
-
gr.Markdown("# Machine Learning Leaderboards")
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
# Initial data fetch
|
78 |
asyncio.run(fetch_data())
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
return app
|
91 |
|
92 |
|
93 |
if __name__ == "__main__":
|
94 |
-
# Start the background update thread
|
95 |
update_thread = threading.Thread(target=background_update, daemon=True)
|
96 |
update_thread.start()
|
97 |
-
|
98 |
-
# Launch the Gradio app
|
99 |
app = build_ui()
|
100 |
app.launch()
|
|
|
27 |
time.sleep(300) # 5 minutes
|
28 |
|
29 |
|
30 |
+
def create_table_for_lb(lb_name, gpu_name):
|
31 |
"""Create a formatted table for a specific leaderboard and GPU"""
|
32 |
+
if (
|
33 |
+
not lb_name
|
34 |
+
or not gpu_name
|
35 |
+
or lb_name not in leaderboard_data
|
36 |
+
or gpu_name not in leaderboard_data[lb_name]
|
37 |
+
):
|
38 |
+
return gr.Dataframe(
|
39 |
+
headers=["Rank", "Submission Name", "User ID", "Score", "Date"],
|
40 |
+
datatype=["number", "str", "str", "str", "str"],
|
41 |
+
value=[],
|
42 |
+
interactive=False,
|
43 |
+
)
|
44 |
|
45 |
+
lb_data = leaderboard_data[lb_name][gpu_name]
|
46 |
|
47 |
headers = ["Rank", "Submission Name", "User ID", "Score", "Date"]
|
48 |
|
|
|
69 |
def refresh_ui():
|
70 |
"""Force refresh the UI with latest data"""
|
71 |
asyncio.run(fetch_data())
|
72 |
+
return "Data refreshed!", get_lb_names(), [], None
|
73 |
|
74 |
|
75 |
+
def get_lb_names():
|
76 |
+
"""Get list of available leaderboard names"""
|
77 |
+
return list(leaderboard_data.keys())
|
78 |
|
|
|
|
|
79 |
|
80 |
+
def get_gpu_names(lb_name):
|
81 |
+
"""Get list of available GPUs for a specific leaderboard"""
|
82 |
+
if not lb_name or lb_name not in leaderboard_data:
|
83 |
+
return []
|
84 |
+
return list(leaderboard_data[lb_name].keys())
|
85 |
+
|
86 |
+
|
87 |
+
def on_lb_change(lb_name):
|
88 |
+
gpu_choices = get_gpu_names(lb_name)
|
89 |
+
|
90 |
+
return (
|
91 |
+
gr.update(choices=gpu_choices, value=gpu_choices[0] if gpu_choices else None),
|
92 |
+
update_table(lb_name, gpu_choices[0]),
|
93 |
+
)
|
94 |
+
|
95 |
|
96 |
+
def update_table(lb_name, gpu_name):
|
97 |
+
"""Update the table based on selected leaderboard and GPU"""
|
98 |
+
if not lb_name or not gpu_name:
|
99 |
+
return None
|
100 |
+
return create_table_for_lb(lb_name, gpu_name)
|
101 |
+
|
102 |
+
|
103 |
+
def build_ui():
|
104 |
+
with gr.Blocks(title="ML Leaderboards", theme=gr.themes.Soft()) as app:
|
105 |
+
gr.Markdown("# 🍿 KernelBot Leaderboard 🍿")
|
106 |
|
|
|
107 |
asyncio.run(fetch_data())
|
108 |
|
109 |
+
with gr.Row():
|
110 |
+
with gr.Column(scale=1):
|
111 |
+
lb_dropdown = gr.Dropdown(
|
112 |
+
choices=get_lb_names(),
|
113 |
+
label="Select Leaderboard",
|
114 |
+
interactive=True,
|
115 |
+
)
|
116 |
+
gpu_dropdown = gr.Dropdown(
|
117 |
+
choices=get_gpu_names(lb_dropdown.value),
|
118 |
+
label="Select GPU",
|
119 |
+
interactive=True,
|
120 |
+
)
|
121 |
+
|
122 |
+
with gr.Row():
|
123 |
+
results_table = gr.Dataframe(
|
124 |
+
headers=["Rank", "Submission Name", "User ID", "Score", "Date"],
|
125 |
+
datatype=["number", "str", "str", "str", "str"],
|
126 |
+
interactive=False,
|
127 |
+
label="Results",
|
128 |
+
)
|
129 |
+
|
130 |
+
lb_dropdown.change(
|
131 |
+
fn=on_lb_change,
|
132 |
+
inputs=[lb_dropdown],
|
133 |
+
outputs=[gpu_dropdown, results_table],
|
134 |
+
)
|
135 |
+
|
136 |
+
gpu_dropdown.change(
|
137 |
+
fn=update_table, inputs=[lb_dropdown, gpu_dropdown], outputs=results_table
|
138 |
+
)
|
139 |
|
140 |
return app
|
141 |
|
142 |
|
143 |
if __name__ == "__main__":
|
|
|
144 |
update_thread = threading.Thread(target=background_update, daemon=True)
|
145 |
update_thread.start()
|
|
|
|
|
146 |
app = build_ui()
|
147 |
app.launch()
|
src/retrieve_data.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import asyncio
|
|
|
2 |
|
3 |
from httpx import AsyncClient
|
4 |
|
@@ -32,12 +33,12 @@ async def get_submissions(lb_name: str, gpu: str) -> LbData:
|
|
32 |
|
33 |
|
34 |
async def populate_lb_data():
|
35 |
-
leaderboards: dict[str, LbData] =
|
36 |
lb_names = await get_leaderboards()
|
37 |
for lb_name in lb_names:
|
38 |
gpus = await get_lb_gpus(lb_name)
|
39 |
for gpu in gpus:
|
40 |
lb_data = await get_submissions(lb_name, gpu)
|
41 |
-
leaderboards[
|
42 |
|
43 |
return leaderboards
|
|
|
1 |
import asyncio
|
2 |
+
from collections import defaultdict
|
3 |
|
4 |
from httpx import AsyncClient
|
5 |
|
|
|
33 |
|
34 |
|
35 |
async def populate_lb_data():
|
36 |
+
leaderboards: dict[str, dict[str, LbData]] = defaultdict(dict)
|
37 |
lb_names = await get_leaderboards()
|
38 |
for lb_name in lb_names:
|
39 |
gpus = await get_lb_gpus(lb_name)
|
40 |
for gpu in gpus:
|
41 |
lb_data = await get_submissions(lb_name, gpu)
|
42 |
+
leaderboards[lb_name][gpu] = lb_data
|
43 |
|
44 |
return leaderboards
|