lunarflu HF staff commited on
Commit
0b7628c
Β·
verified Β·
1 Parent(s): b64de75

adjust test

Browse files
Files changed (1) hide show
  1. app.py +43 -44
app.py CHANGED
@@ -578,65 +578,64 @@ def format_hyperlink(username):
578
  return f'<a target="_blank" href="https://huggingface.co/{username}" style="color: var(--link-text-color);">{username}</a>'
579
 
580
 
 
581
  @tasks.loop(minutes=10)
582
  async def remove_huggingfolks():
583
  try:
584
- # remove huggingfolks
585
- global community_global_df
586
- global community_global_df_with_id
587
- global community_global_df_gradio
588
-
589
- community_global_df = global_df.copy()
590
-
591
  guild = bot.get_guild(879548962464493619)
592
  role = discord.utils.get(guild.roles, id=897376942817419265)
 
593
  members_with_role = [member.id for member in guild.members if role in member.roles]
594
 
595
- # remove L formatting (doesn't affect main global_df)
596
- community_global_df['discord_user_id'] = community_global_df['discord_user_id'].str.strip('L').astype(str)
597
-
598
- for member_id in members_with_role:
599
- community_global_df = community_global_df[community_global_df.iloc[:, 0] != str(member_id)]
600
-
601
- # make a copy while discord id column still exists -> use for rank in discord embeds
602
- community_global_df_with_id = community_global_df_with_id.copy()
603
-
604
- # reorder (switching from discord_user_name to hf_user_name)
605
- reorder = ['discord_user_id', 'hf_user_name', 'discord_exp','discord_level', 'discord_user_name', 'hub_exp', 'total_exp', 'verified_date']
606
- community_global_df = community_global_df[reorder]
607
-
608
- # drop first column (discord id -> this is so we can display the important stuff in the leaderboard)
609
- community_global_df.drop(community_global_df.columns[0], axis=1, inplace=True)
610
- community_global_df.drop(community_global_df.columns[1], axis=1, inplace=True)
611
- community_global_df.drop(community_global_df.columns[2], axis=1, inplace=True)
612
- community_global_df.drop(community_global_df.columns[2], axis=1, inplace=True)
613
- community_global_df.drop(community_global_df.columns[3], axis=1, inplace=True)
614
- # drop rows (records) where hf_user_name does not exist (we display only verified users)
615
- community_global_df = community_global_df.dropna(subset=['hf_user_name'])
616
- community_global_df['total_exp'] = community_global_df['total_exp'].str.strip('L').astype(int)
617
- community_global_df['total_exp'] = pd.to_numeric(community_global_df['total_exp'], errors='coerce').fillna(0).astype(int)
618
- community_global_df = community_global_df.nlargest(len(community_global_df), 'total_exp')
619
- # add profile hyperlinks to gradio demo
620
- community_global_df_gradio = community_global_df.copy() # must be a COPY, otherwise it adds a new name for the same dataframe.
621
- community_global_df_gradio['hf_user_name'] = community_global_df_gradio['hf_user_name'].apply(format_hyperlink)
622
-
623
- top_num = 30
624
- top_num_exp = community_global_df.nlargest(top_num, 'total_exp')
625
-
626
- top_num_exp['D'] = ['πŸ₯‡','πŸ₯ˆ','πŸ₯‰'] + [''] * (top_num - 3)
627
- top_num_rows = top_num_exp.values.tolist()
628
 
629
- #print(top_30_rows)
630
  channel = bot.get_channel(1197143964994773023)
631
  message = await channel.fetch_message(1197148293164187678)
632
 
633
- # put into message / leaderboard
634
  new_table = tabulate(top_num_rows, headers=["Name", "Level", "Experience", "Rank"], tablefmt="plain")
635
  await message.edit(content=f"Updated Leaderboard:\n```\n{new_table}\n```")
636
  print("Updated discord leaderboard!")
637
- print("------------------------------------------------------------------------")
638
  except Exception as e:
639
- print(f"remove_huggingfolks Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
 
641
 
642
  @bot.command(name='xp_help')
 
578
  return f'<a target="_blank" href="https://huggingface.co/{username}" style="color: var(--link-text-color);">{username}</a>'
579
 
580
 
581
+
582
  @tasks.loop(minutes=10)
583
  async def remove_huggingfolks():
584
  try:
 
 
 
 
 
 
 
585
  guild = bot.get_guild(879548962464493619)
586
  role = discord.utils.get(guild.roles, id=897376942817419265)
587
+ await guild.chunk()
588
  members_with_role = [member.id for member in guild.members if role in member.roles]
589
 
590
+ top_num_rows = await asyncio.to_thread(_remove_huggingfolks_sync, members_with_role)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
 
 
592
  channel = bot.get_channel(1197143964994773023)
593
  message = await channel.fetch_message(1197148293164187678)
594
 
 
595
  new_table = tabulate(top_num_rows, headers=["Name", "Level", "Experience", "Rank"], tablefmt="plain")
596
  await message.edit(content=f"Updated Leaderboard:\n```\n{new_table}\n```")
597
  print("Updated discord leaderboard!")
598
+ print("------------------------------------------------------------------------")
599
  except Exception as e:
600
+ print(f"remove_huggingfolks Error: {e}")
601
+
602
+
603
+ def _remove_huggingfolks_sync(members_with_role):
604
+ global community_global_df
605
+ global community_global_df_with_id
606
+ global community_global_df_gradio
607
+
608
+
609
+ community_global_df = global_df.copy()
610
+
611
+ community_global_df['discord_user_id'] = community_global_df['discord_user_id'].str.strip('L').astype(str)
612
+
613
+ for member_id in members_with_role:
614
+ community_global_df = community_global_df[community_global_df['discord_user_id'] != str(member_id)]
615
+
616
+ community_global_df_with_id = community_global_df.copy()
617
+
618
+ reorder = ['discord_user_id', 'hf_user_name', 'discord_exp', 'discord_level', 'discord_user_name', 'hub_exp', 'total_exp', 'verified_date']
619
+ community_global_df = community_global_df[reorder]
620
+
621
+ columns_to_drop = ['discord_user_id', 'discord_exp', 'discord_level', 'discord_user_name', 'hub_exp']
622
+ community_global_df.drop(columns=columns_to_drop, inplace=True)
623
+
624
+ community_global_df.dropna(subset=['hf_user_name'], inplace=True)
625
+
626
+ community_global_df['total_exp'] = community_global_df['total_exp'].str.strip('L').astype(int)
627
+ community_global_df['total_exp'] = pd.to_numeric(community_global_df['total_exp'], errors='coerce').fillna(0).astype(int)
628
+ community_global_df.sort_values(by='total_exp', ascending=False, inplace=True)
629
+
630
+ community_global_df_gradio = community_global_df.copy()
631
+ community_global_df_gradio['hf_user_name'] = community_global_df_gradio['hf_user_name'].apply(format_hyperlink)
632
+
633
+ top_num = 30
634
+ top_num_exp = community_global_df.head(top_num).copy()
635
+ top_num_exp['Rank'] = ['πŸ₯‡', 'πŸ₯ˆ', 'πŸ₯‰'] + [''] * (top_num - 3)
636
+ top_num_rows = top_num_exp.values.tolist()
637
+ return top_num_rows
638
+
639
 
640
 
641
  @bot.command(name='xp_help')