Style the first few rows of cells (gold silver bronze, first 2nd 3rd etc)

#12
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -685,9 +685,27 @@ def run_bot():
685
  threading.Thread(target=run_bot).start()
686
 
687
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688
  def get_data():
689
  try:
690
- return community_global_df_gradio
691
  except Exception as e:
692
  print(f"get_data Error: {e}")
693
 
@@ -745,4 +763,4 @@ with demo:
745
  #with gr.TabItem("πŸ“ˆ Hub-only leaderboard", elem_id="hub-table", id=2):
746
  except Exception as e:
747
  print(f"gradio demo Error: {e}")
748
- demo.queue().launch()
 
685
  threading.Thread(target=run_bot).start()
686
 
687
 
688
+ def highlight_rows(dataframe):
689
+ # Define a function that applies styling based on the row index
690
+ def apply_row_styles(row):
691
+ # Check the row index and apply styles accordingly
692
+ if row.name == 0: # first row
693
+ return ['background-color: rgba(255, 232, 170, 0.5)'] * len(row)
694
+ elif row.name == 1: # second row
695
+ return ['background-color: rgba(217, 217, 217, 0.5)'] * len(row)
696
+ elif row.name == 2: # third row
697
+ return ['background-color: rgba(232, 167, 106, 0.5)'] * len(row)
698
+ else:
699
+ return [''] * len(row) # Apply no style for other rows
700
+
701
+ # Apply the styling function to each row
702
+ styled = dataframe.style.apply(apply_row_styles, axis=1)
703
+ return styled
704
+
705
+
706
  def get_data():
707
  try:
708
+ return highlight_rows(community_global_df)
709
  except Exception as e:
710
  print(f"get_data Error: {e}")
711
 
 
763
  #with gr.TabItem("πŸ“ˆ Hub-only leaderboard", elem_id="hub-table", id=2):
764
  except Exception as e:
765
  print(f"gradio demo Error: {e}")
766
+ demo.queue().launch()