lunarflu HF staff commited on
Commit
0915c28
1 Parent(s): 0f9c956

gradio/hub version of display dataframe -> hyperlink to profiles

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -58,6 +58,7 @@ global_df = pd.DataFrame()
58
  print(type(global_df))
59
  community_global_df = pd.DataFrame()
60
  community_global_df_with_id = pd.DataFrame()
 
61
  test_merge = pd.read_csv("https://docs.google.com/spreadsheets/d/1C8aLqgCqLYcMiIFf-P_Aosaa03C_WLIB_UyqvjSdWg8/export?format=csv&gid=0")
62
  data = pd.read_csv("https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/export?format=csv&gid=0")
63
  data2 = pd.read_csv("https://docs.google.com/spreadsheets/d/1T_twNONDSZ8zw7aDcYhw92DlawqPktti1xFw9ssJ13Y/export?format=csv&gid=0")
@@ -543,12 +544,17 @@ async def on_reaction_add(reaction, user):
543
  print(f"on_reaction_add Error: {e}")
544
 
545
 
 
 
 
 
546
  @tasks.loop(minutes=1)
547
  async def remove_huggingfolks():
548
  try:
549
  # remove huggingfolks
550
  global community_global_df
551
- global community_global_df_with_id
 
552
 
553
  community_global_df = global_df.copy()
554
 
@@ -579,7 +585,10 @@ async def remove_huggingfolks():
579
  community_global_df = community_global_df.dropna(subset=['hf_user_name'])
580
  community_global_df['total_exp'] = community_global_df['total_exp'].str.strip('L').astype(int)
581
  community_global_df['total_exp'] = pd.to_numeric(community_global_df['total_exp'], errors='coerce').fillna(0).astype(int)
582
- community_global_df = community_global_df.nlargest(len(community_global_df), 'total_exp')
 
 
 
583
 
584
  top_30_exp = community_global_df.nlargest(30, 'total_exp')
585
 
@@ -639,7 +648,7 @@ csv_url = URL.replace('/edit#gid=', '/export?format=csv&gid=')
639
 
640
  def get_data():
641
  try:
642
- return community_global_df
643
  except Exception as e:
644
  print(f"get_data Error: {e}")
645
 
 
58
  print(type(global_df))
59
  community_global_df = pd.DataFrame()
60
  community_global_df_with_id = pd.DataFrame()
61
+ community_global_df_gradio = pd.DataFrame()
62
  test_merge = pd.read_csv("https://docs.google.com/spreadsheets/d/1C8aLqgCqLYcMiIFf-P_Aosaa03C_WLIB_UyqvjSdWg8/export?format=csv&gid=0")
63
  data = pd.read_csv("https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/export?format=csv&gid=0")
64
  data2 = pd.read_csv("https://docs.google.com/spreadsheets/d/1T_twNONDSZ8zw7aDcYhw92DlawqPktti1xFw9ssJ13Y/export?format=csv&gid=0")
 
544
  print(f"on_reaction_add Error: {e}")
545
 
546
 
547
+ def format_hyperlink(username):
548
+ return f'<a target="_blank" href="https://huggingface.co/{username}" style="color: var(--link-text-color);">{username}</a>'
549
+
550
+
551
  @tasks.loop(minutes=1)
552
  async def remove_huggingfolks():
553
  try:
554
  # remove huggingfolks
555
  global community_global_df
556
+ global community_global_df_with_id
557
+ global community_global_df_gradio
558
 
559
  community_global_df = global_df.copy()
560
 
 
585
  community_global_df = community_global_df.dropna(subset=['hf_user_name'])
586
  community_global_df['total_exp'] = community_global_df['total_exp'].str.strip('L').astype(int)
587
  community_global_df['total_exp'] = pd.to_numeric(community_global_df['total_exp'], errors='coerce').fillna(0).astype(int)
588
+ community_global_df = community_global_df.nlargest(len(community_global_df), 'total_exp')
589
+ # add profile hyperlinks to gradio demo
590
+ community_global_df_gradio = community_global_df
591
+ community_global_df_gradio['hf_user_name'] = community_global_df_gradio['hf_user_name'].apply(format_hyperlink)
592
 
593
  top_30_exp = community_global_df.nlargest(30, 'total_exp')
594
 
 
648
 
649
  def get_data():
650
  try:
651
+ return community_global_df_gradio
652
  except Exception as e:
653
  print(f"get_data Error: {e}")
654