Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -431,7 +431,9 @@ with gr.Column(visible=True) as leaderboard_tab:
|
|
| 431 |
|
| 432 |
def create_category_chart(selected_models, selected_categories):
|
| 433 |
if not selected_models:
|
| 434 |
-
|
|
|
|
|
|
|
| 435 |
|
| 436 |
# Sort categories before processing
|
| 437 |
selected_categories = sort_categories(selected_categories)
|
|
@@ -453,17 +455,19 @@ def create_category_chart(selected_models, selected_categories):
|
|
| 453 |
data.append({
|
| 454 |
'Model': model,
|
| 455 |
'Category': category,
|
| 456 |
-
'
|
| 457 |
})
|
| 458 |
|
| 459 |
df = pd.DataFrame(data)
|
| 460 |
if df.empty:
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
-
fig
|
| 464 |
-
title='AI Model Scores by Category',
|
| 465 |
-
labels={'Score Percentage': 'Score Percentage'},
|
| 466 |
-
category_orders={"Category": selected_categories})
|
| 467 |
return fig
|
| 468 |
|
| 469 |
def update_detailed_scorecard(model, selected_categories):
|
|
@@ -1238,111 +1242,94 @@ with gr.Blocks(css=css) as demo:
|
|
| 1238 |
interactive=True,
|
| 1239 |
visible=False,
|
| 1240 |
info="Select one or more models")
|
| 1241 |
-
|
| 1242 |
# Category filter now visible for all tabs
|
| 1243 |
category_filter = gr.CheckboxGroup(choices=category_choices,
|
| 1244 |
label="Filter Categories",
|
| 1245 |
value=category_choices)
|
| 1246 |
|
| 1247 |
with gr.Column(visible=True) as leaderboard_tab:
|
|
|
|
|
|
|
| 1248 |
leaderboard_output = gr.DataFrame(
|
| 1249 |
-
value=
|
| 1250 |
interactive=False,
|
| 1251 |
wrap=True
|
| 1252 |
-
|
| 1253 |
|
| 1254 |
with gr.Column(visible=False) as category_analysis_tab:
|
| 1255 |
-
|
|
|
|
|
|
|
| 1256 |
|
| 1257 |
with gr.Column(visible=False) as detailed_scorecard_tab:
|
| 1258 |
model_metadata = gr.HTML()
|
| 1259 |
all_category_cards = gr.HTML()
|
| 1260 |
total_score = gr.Markdown()
|
| 1261 |
|
| 1262 |
-
# Initialize the dashboard
|
| 1263 |
-
def init_leaderboard():
|
| 1264 |
-
df = create_leaderboard(category_filter.value)
|
| 1265 |
-
return df
|
| 1266 |
-
|
| 1267 |
-
leaderboard_output.value = init_leaderboard()
|
| 1268 |
-
|
| 1269 |
-
# Update handlers
|
| 1270 |
def update_dashboard(tab, selected_models, selected_model, selected_categories):
|
| 1271 |
-
|
| 1272 |
-
|
| 1273 |
-
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
|
| 1278 |
-
|
| 1279 |
-
df = create_leaderboard(selected_categories)
|
| 1280 |
-
return [leaderboard_visibility, category_chart_visibility, detailed_scorecard_visibility,
|
| 1281 |
-
model_chooser_visibility, model_multi_chooser_visibility,
|
| 1282 |
-
gr.update(value=df), gr.update(), gr.update(), gr.update(), gr.update()]
|
| 1283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1284 |
|
| 1285 |
elif tab == "Category Analysis":
|
| 1286 |
-
|
| 1287 |
-
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
|
| 1291 |
-
model_chooser_visibility, model_multi_chooser_visibility, category_filter_visibility,
|
| 1292 |
-
None, gr.update(value=category_plot), gr.update(), gr.update(), gr.update()]
|
| 1293 |
-
|
| 1294 |
elif tab == "Detailed Scorecard":
|
| 1295 |
-
|
| 1296 |
-
|
| 1297 |
-
category_filter_visibility = gr.update(visible=True)
|
| 1298 |
if selected_model:
|
| 1299 |
scorecard_updates = update_detailed_scorecard(selected_model, selected_categories)
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
| 1304 |
-
|
| 1305 |
-
|
| 1306 |
-
|
| 1307 |
-
|
| 1308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1309 |
|
| 1310 |
# Set up event handlers
|
| 1311 |
-
tab_selection
|
| 1312 |
-
|
| 1313 |
-
|
| 1314 |
-
|
| 1315 |
-
|
| 1316 |
-
|
| 1317 |
-
|
| 1318 |
-
|
| 1319 |
-
|
| 1320 |
-
model_chooser.change(
|
| 1321 |
-
fn=update_dashboard,
|
| 1322 |
-
inputs=[tab_selection, model_multi_chooser, model_chooser, category_filter],
|
| 1323 |
-
outputs=[leaderboard_tab, category_analysis_tab, detailed_scorecard_tab,
|
| 1324 |
-
model_chooser, model_multi_chooser, category_filter,
|
| 1325 |
-
leaderboard_output, category_chart, model_metadata,
|
| 1326 |
-
all_category_cards, total_score]
|
| 1327 |
-
)
|
| 1328 |
-
|
| 1329 |
-
model_multi_chooser.change(
|
| 1330 |
-
fn=update_dashboard,
|
| 1331 |
-
inputs=[tab_selection, model_multi_chooser, model_chooser, category_filter],
|
| 1332 |
-
outputs=[leaderboard_tab, category_analysis_tab, detailed_scorecard_tab,
|
| 1333 |
-
model_chooser, model_multi_chooser, category_filter,
|
| 1334 |
-
leaderboard_output, category_chart, model_metadata,
|
| 1335 |
-
all_category_cards, total_score]
|
| 1336 |
-
)
|
| 1337 |
-
|
| 1338 |
-
category_filter.change(
|
| 1339 |
-
fn=update_dashboard,
|
| 1340 |
-
inputs=[tab_selection, model_multi_chooser, model_chooser, category_filter],
|
| 1341 |
-
outputs=[leaderboard_tab, category_analysis_tab, detailed_scorecard_tab,
|
| 1342 |
-
model_chooser, model_multi_chooser,
|
| 1343 |
-
leaderboard_output, category_chart, model_metadata,
|
| 1344 |
-
all_category_cards, total_score]
|
| 1345 |
-
)
|
| 1346 |
|
| 1347 |
# Launch the app
|
| 1348 |
if __name__ == "__main__":
|
|
|
|
| 431 |
|
| 432 |
def create_category_chart(selected_models, selected_categories):
|
| 433 |
if not selected_models:
|
| 434 |
+
fig = px.bar(title='Please select at least one model for comparison')
|
| 435 |
+
fig.update_layout(showlegend=True) # Ensure legend remains visible
|
| 436 |
+
return fig
|
| 437 |
|
| 438 |
# Sort categories before processing
|
| 439 |
selected_categories = sort_categories(selected_categories)
|
|
|
|
| 455 |
data.append({
|
| 456 |
'Model': model,
|
| 457 |
'Category': category,
|
| 458 |
+
'Completion Rate': score_percentage
|
| 459 |
})
|
| 460 |
|
| 461 |
df = pd.DataFrame(data)
|
| 462 |
if df.empty:
|
| 463 |
+
fig = px.bar(title='No data available for the selected models and categories')
|
| 464 |
+
else:
|
| 465 |
+
fig = px.bar(df, x='Model', y='Completion Rate', color='Category',
|
| 466 |
+
title='AI Model Evaluation Completion Rates by Category',
|
| 467 |
+
labels={'Completion Rate': 'Completion Rate (%)'},
|
| 468 |
+
category_orders={"Category": selected_categories})
|
| 469 |
|
| 470 |
+
fig.update_layout(showlegend=True) # Ensure legend remains visible
|
|
|
|
|
|
|
|
|
|
| 471 |
return fig
|
| 472 |
|
| 473 |
def update_detailed_scorecard(model, selected_categories):
|
|
|
|
| 1242 |
interactive=True,
|
| 1243 |
visible=False,
|
| 1244 |
info="Select one or more models")
|
| 1245 |
+
|
| 1246 |
# Category filter now visible for all tabs
|
| 1247 |
category_filter = gr.CheckboxGroup(choices=category_choices,
|
| 1248 |
label="Filter Categories",
|
| 1249 |
value=category_choices)
|
| 1250 |
|
| 1251 |
with gr.Column(visible=True) as leaderboard_tab:
|
| 1252 |
+
# Initialize with data
|
| 1253 |
+
initial_df = create_leaderboard(category_choices)
|
| 1254 |
leaderboard_output = gr.DataFrame(
|
| 1255 |
+
value=initial_df,
|
| 1256 |
interactive=False,
|
| 1257 |
wrap=True
|
| 1258 |
+
)
|
| 1259 |
|
| 1260 |
with gr.Column(visible=False) as category_analysis_tab:
|
| 1261 |
+
# Initialize with empty plot
|
| 1262 |
+
initial_plot = create_category_chart([], category_choices)
|
| 1263 |
+
category_chart = gr.Plot(value=initial_plot)
|
| 1264 |
|
| 1265 |
with gr.Column(visible=False) as detailed_scorecard_tab:
|
| 1266 |
model_metadata = gr.HTML()
|
| 1267 |
all_category_cards = gr.HTML()
|
| 1268 |
total_score = gr.Markdown()
|
| 1269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1270 |
def update_dashboard(tab, selected_models, selected_model, selected_categories):
|
| 1271 |
+
# Default visibility states
|
| 1272 |
+
component_states = {
|
| 1273 |
+
"leaderboard": False,
|
| 1274 |
+
"category_chart": False,
|
| 1275 |
+
"detailed_scorecard": False,
|
| 1276 |
+
"model_chooser": False,
|
| 1277 |
+
"model_multi_chooser": False
|
| 1278 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1279 |
|
| 1280 |
+
# Initialize outputs with None
|
| 1281 |
+
outputs = {
|
| 1282 |
+
"leaderboard": None,
|
| 1283 |
+
"category_chart": None,
|
| 1284 |
+
"model_metadata": None,
|
| 1285 |
+
"category_cards": None,
|
| 1286 |
+
"total_score": None
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
# Update visibility based on selected tab
|
| 1290 |
+
if tab == "Leaderboard":
|
| 1291 |
+
component_states["leaderboard"] = True
|
| 1292 |
+
outputs["leaderboard"] = create_leaderboard(selected_categories)
|
| 1293 |
|
| 1294 |
elif tab == "Category Analysis":
|
| 1295 |
+
component_states["category_chart"] = True
|
| 1296 |
+
component_states["model_multi_chooser"] = True
|
| 1297 |
+
if selected_models: # Only update chart if models are selected
|
| 1298 |
+
outputs["category_chart"] = create_category_chart(selected_models, selected_categories)
|
| 1299 |
+
|
|
|
|
|
|
|
|
|
|
| 1300 |
elif tab == "Detailed Scorecard":
|
| 1301 |
+
component_states["detailed_scorecard"] = True
|
| 1302 |
+
component_states["model_chooser"] = True
|
|
|
|
| 1303 |
if selected_model:
|
| 1304 |
scorecard_updates = update_detailed_scorecard(selected_model, selected_categories)
|
| 1305 |
+
outputs["model_metadata"] = scorecard_updates[0]
|
| 1306 |
+
outputs["category_cards"] = scorecard_updates[1]
|
| 1307 |
+
outputs["total_score"] = scorecard_updates[2]
|
| 1308 |
+
|
| 1309 |
+
# Return updates in the correct order
|
| 1310 |
+
return [
|
| 1311 |
+
gr.update(visible=component_states["leaderboard"]),
|
| 1312 |
+
gr.update(visible=component_states["category_chart"]),
|
| 1313 |
+
gr.update(visible=component_states["detailed_scorecard"]),
|
| 1314 |
+
gr.update(visible=component_states["model_chooser"]),
|
| 1315 |
+
gr.update(visible=component_states["model_multi_chooser"]),
|
| 1316 |
+
outputs["leaderboard"] if outputs["leaderboard"] is not None else gr.update(),
|
| 1317 |
+
outputs["category_chart"] if outputs["category_chart"] is not None else gr.update(),
|
| 1318 |
+
outputs["model_metadata"] if outputs["model_metadata"] is not None else gr.update(),
|
| 1319 |
+
outputs["category_cards"] if outputs["category_cards"] is not None else gr.update(),
|
| 1320 |
+
outputs["total_score"] if outputs["total_score"] is not None else gr.update()
|
| 1321 |
+
]
|
| 1322 |
|
| 1323 |
# Set up event handlers
|
| 1324 |
+
for component in [tab_selection, model_chooser, model_multi_chooser, category_filter]:
|
| 1325 |
+
component.change(
|
| 1326 |
+
fn=update_dashboard,
|
| 1327 |
+
inputs=[tab_selection, model_multi_chooser, model_chooser, category_filter],
|
| 1328 |
+
outputs=[leaderboard_tab, category_analysis_tab, detailed_scorecard_tab,
|
| 1329 |
+
model_chooser, model_multi_chooser,
|
| 1330 |
+
leaderboard_output, category_chart, model_metadata,
|
| 1331 |
+
all_category_cards, total_score]
|
| 1332 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1333 |
|
| 1334 |
# Launch the app
|
| 1335 |
if __name__ == "__main__":
|