TimWindecker commited on
Commit
21e4633
·
verified ·
1 Parent(s): 074a26b

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +52 -4
src/streamlit_app.py CHANGED
@@ -154,7 +154,7 @@ def create_bar_chart(df, view_type):
154
 
155
  if view_type == "Total Score":
156
 
157
- # Format df
158
  df_fig = df.copy()
159
  df_fig = df_fig[df_fig["score"] != np.inf]
160
 
@@ -211,7 +211,7 @@ def create_bar_chart(df, view_type):
211
 
212
  elif view_type == "Per Embodiment":
213
 
214
- # Format df
215
  df_fig = df.copy()
216
  df_fig = df_fig[df_fig["score"] != np.inf]
217
 
@@ -293,7 +293,7 @@ def create_bar_chart(df, view_type):
293
 
294
  else: # Per Category
295
 
296
- # Format df
297
  df_fig = df.copy()
298
  df_fig = df_fig[df_fig["score"] != np.inf]
299
 
@@ -377,6 +377,42 @@ def create_bar_chart(df, view_type):
377
 
378
  return fig
379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  # Header
381
  st.markdown("""
382
  <div class="header-container">
@@ -429,7 +465,19 @@ st.caption("🔹 Note: Lower scores indicate better performance.")
429
 
430
  # Detailed table
431
  with st.expander("View Detailed Scores"):
432
- st.dataframe(df.style.background_gradient(cmap='Blues_r', subset=df.columns), width="stretch") #TODO
 
 
 
 
 
 
 
 
 
 
 
 
433
 
434
  with st.expander("How to Test Your Model", expanded=True):
435
  # Step 1
 
154
 
155
  if view_type == "Total Score":
156
 
157
+ # Copy df
158
  df_fig = df.copy()
159
  df_fig = df_fig[df_fig["score"] != np.inf]
160
 
 
211
 
212
  elif view_type == "Per Embodiment":
213
 
214
+ # Copy df
215
  df_fig = df.copy()
216
  df_fig = df_fig[df_fig["score"] != np.inf]
217
 
 
293
 
294
  else: # Per Category
295
 
296
+ # Copy df
297
  df_fig = df.copy()
298
  df_fig = df_fig[df_fig["score"] != np.inf]
299
 
 
377
 
378
  return fig
379
 
380
+ def create_summary_table(df):
381
+
382
+ # Copy df
383
+ df_table = df.copy()
384
+ df_table = df_table[df_table["score"] != np.inf]
385
+
386
+ # Calculate total score per model
387
+ df_total = df_table.groupby("model")[["score"]].mean().reset_index()
388
+ df_total.columns = ["model", "Total Score"]
389
+
390
+ # Calculate scores per embodiment
391
+ df_embodiment = df_table.groupby(["model", "embodiment"])[["score"]].mean().reset_index()
392
+ df_embodiment_pivot = df_embodiment.pivot(index="model", columns="embodiment", values="score")
393
+ df_embodiment_pivot.columns = [f"{col}" for col in df_embodiment_pivot.columns]
394
+
395
+ # Calculate scores per category
396
+ df_category = df_table.copy()
397
+ df_category["category"] = df_category["category"].apply(ast.literal_eval)
398
+ df_category = df_category.explode("category")
399
+ df_category = df_category.groupby(["model", "category"])[["score"]].mean().reset_index()
400
+ df_category_pivot = df_category.pivot(index="model", columns="category", values="score")
401
+ df_category_pivot.columns = [f"{col}" for col in df_category_pivot.columns]
402
+
403
+ # Combine all tables
404
+ df_summary = df_total.set_index("model")
405
+ df_summary = df_summary.join(df_embodiment_pivot)
406
+ df_summary = df_summary.join(df_category_pivot)
407
+
408
+ # Sort by total score
409
+ df_summary = df_summary.sort_values(by="Total Score", ascending=True)
410
+
411
+ # Reset index to make model a column again
412
+ df_summary = df_summary.reset_index()
413
+
414
+ return df_summary
415
+
416
  # Header
417
  st.markdown("""
418
  <div class="header-container">
 
465
 
466
  # Detailed table
467
  with st.expander("View Detailed Scores"):
468
+ # Create the summary table
469
+ df_summary = create_summary_table(df)
470
+
471
+ # Display table
472
+ st.dataframe(
473
+ df_summary.style.background_gradient(
474
+ cmap='Blues_r',
475
+ subset=[col for col in df_summary.columns if col != 'model']
476
+ ).format("{:.2f}", subset=[col for col in df_summary.columns if col != 'model']),
477
+ use_container_width=True
478
+ )
479
+
480
+ #st.dataframe(df.style.background_gradient(cmap='Blues_r', subset=df.columns), width="stretch") #TODO
481
 
482
  with st.expander("How to Test Your Model", expanded=True):
483
  # Step 1