Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -61,8 +61,6 @@ 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")
|
65 |
-
|
66 |
|
67 |
@bot.event
|
68 |
async def on_ready():
|
@@ -77,10 +75,7 @@ async def on_ready():
|
|
77 |
print(f"csv successfully retrieved: \n {global_df}")
|
78 |
|
79 |
# updates both leaderboards
|
80 |
-
#await remove_huggingfolks() # to initialize
|
81 |
-
#print(community_global_df_with_id)
|
82 |
remove_huggingfolks.start()
|
83 |
-
#await periodic_api_test()
|
84 |
print(f"------------------------------------------------------------------------")
|
85 |
except Exception as e:
|
86 |
print(f"on_ready Error: {e}")
|
@@ -108,11 +103,6 @@ def update_hub_stats():
|
|
108 |
print(f"------------------------------------------------------------------------")
|
109 |
|
110 |
for index, row in global_df.iterrows():
|
111 |
-
# fill blank values with n/a for now? then replace if they try to verify
|
112 |
-
|
113 |
-
# data type of value?
|
114 |
-
# may need this to be fairly long -> complete cycles successfully before starting new job
|
115 |
-
|
116 |
user = row['hf_user_name']
|
117 |
if pd.notna(user):
|
118 |
#print(f"user: {user}")
|
@@ -132,8 +122,6 @@ def update_hub_stats():
|
|
132 |
upvotes = data["numUpvotes"]
|
133 |
|
134 |
# recalculate level as well (no longer only depends on discord activity)
|
135 |
-
# + total_exp as well (with multipliers)
|
136 |
-
|
137 |
try:
|
138 |
global_df.loc[index, 'likes'] = likes
|
139 |
global_df.loc[index, 'models'] = models
|
@@ -262,28 +250,18 @@ async def add_exp(member_id):
|
|
262 |
41: lvl41, 42: lvl42, 43: lvl43, 44: lvl44, 45: lvl45, 46: lvl46, 47: lvl47, 48: lvl48, 49: lvl49, 50: lvl50,
|
263 |
}
|
264 |
|
265 |
-
# xp = int64
|
266 |
-
# member_name = string
|
267 |
-
# discord_user_id = string
|
268 |
-
|
269 |
member_found = False
|
270 |
|
271 |
print(f"Searching for member_id {member_id} in dataframe...")
|
272 |
# discord_user_id column
|
273 |
# iterate over items of first column (discord_user_id)
|
274 |
for index, cell_value in global_df.iloc[:, 0].items():
|
275 |
-
# print("test2")
|
276 |
-
# remove L (read, so no need to replace)
|
277 |
# tldr; set_as_dataframe forces scientific notation which corrupts discord_user_id data.
|
278 |
# set_as_dataframe is still highly efficient (1 API call), so we format numerical data as strings,
|
279 |
# which results in efficient google sheet updating + data integrity
|
280 |
cell_value = str(cell_value)
|
281 |
if cell_value.startswith("L") and cell_value.endswith("L"):
|
282 |
-
# print("test3")
|
283 |
cell_value_clipped = cell_value[1:-1]
|
284 |
-
# cell_value_clipped = 1234567890
|
285 |
-
#print(f"cell_value_clipped: {cell_value_clipped}, type: {type(cell_value_clipped)}")
|
286 |
-
#print(f"member_id: {member_id}, type: {type(member_id)}")
|
287 |
if cell_value_clipped == str(member_id): # str(member_id) needed, it is int by default
|
288 |
print("test4")
|
289 |
# if found, update that row...
|
@@ -300,8 +278,7 @@ async def add_exp(member_id):
|
|
300 |
|
301 |
# str -> int temporarily for adding
|
302 |
new_xp = int(old_xp) + XP_PER_MESSAGE
|
303 |
-
|
304 |
-
# ----------------------------------------------------
|
305 |
total_exp = global_df.loc[index, 'total_exp']
|
306 |
hub_xp = global_df.loc[index, 'hub_exp']
|
307 |
|
@@ -321,8 +298,7 @@ async def add_exp(member_id):
|
|
321 |
if hub_xp.strip():
|
322 |
total_exp = int(new_xp) + int(hub_xp)
|
323 |
else:
|
324 |
-
total_exp = int(new_xp)
|
325 |
-
# ----------------------------------------------------
|
326 |
|
327 |
# total v
|
328 |
current_level = calculate_level(total_exp)
|
@@ -355,10 +331,6 @@ async def add_exp(member_id):
|
|
355 |
print("test7")
|
356 |
# finding leaderboard rank + excluding huggingfolks (still need exclusion)
|
357 |
try:
|
358 |
-
# cell_value = L1234567890L
|
359 |
-
# make copy
|
360 |
-
# remove L
|
361 |
-
# do calculations
|
362 |
print("Calculating rank...")
|
363 |
copy_df = global_df.copy()
|
364 |
copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
|
@@ -371,7 +343,6 @@ async def add_exp(member_id):
|
|
371 |
print(f"Discord ID {member} {member_id} not found in the DataFrame.")
|
372 |
rank = "🤗"
|
373 |
|
374 |
-
# temporary fix: remove ~100 exp when not verified, send embed on "levelup" prompting to verify
|
375 |
# if level 3 -> then send embed, remove some exp
|
376 |
if current_level >= 3: # could change to 4 maybe
|
377 |
if verified_role not in member.roles:
|
@@ -425,7 +396,6 @@ async def add_exp(member_id):
|
|
425 |
await member.add_roles(current_role)
|
426 |
print(f"Level Up! Gave {member} {current_role}")
|
427 |
|
428 |
-
#print(f"{member} Level up! {old_level} -> {current_level}!")
|
429 |
if current_level == 2: # special embed with opt-out instructions for discord newcomers
|
430 |
embed = Embed(color=Color.blue())
|
431 |
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
@@ -443,11 +413,7 @@ async def add_exp(member_id):
|
|
443 |
print(f"Sent levelup embed to {member}")
|
444 |
return
|
445 |
|
446 |
-
if current_role in member.roles:
|
447 |
-
#await member.send(f"Level up! {old_level} -> {current_level}!")
|
448 |
-
#if member_id == 811235357663297546:
|
449 |
-
|
450 |
-
|
451 |
# send embed
|
452 |
embed = Embed(color=Color.blue())
|
453 |
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
@@ -455,13 +421,6 @@ async def add_exp(member_id):
|
|
455 |
msg = f'🤗 Congrats {member}! You just leveled up in the Hugging Face Discord server'
|
456 |
embed.description = f"{msg}."
|
457 |
embed.add_field(name="Leaderboard Ranking:", value=f"👑 **{rank}**\n\nhttps://discord.com/channels/879548962464493619/1197143964994773023", inline=True)
|
458 |
-
# can use ^ to track changes in leaderboard ranking and display in levelup message when climbing
|
459 |
-
# (green red arrow thingies)
|
460 |
-
# could also pull ranks above and below yourself (if they exist, i.e.)
|
461 |
-
# 1 nateraw
|
462 |
-
# 2 [you are here]
|
463 |
-
# 3 osanseviero
|
464 |
-
# also, ahead by how much exp, how many levels maybe
|
465 |
msg3 = "- Posting\n- Reacting / being reacted to\n- Being active on the Hugging Face Hub (verify to link your Hub + Discord accounts!)"
|
466 |
embed.add_field(name="How to Level Up:", value=msg3, inline=True)
|
467 |
verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
|
@@ -470,10 +429,7 @@ async def add_exp(member_id):
|
|
470 |
lunar = bot.get_user(811235357663297546)
|
471 |
await member.send(embed=embed)
|
472 |
await lunar.send(embed=embed)
|
473 |
-
print(f"Sent levelup embed to {member}")
|
474 |
-
#You can verify your account to earn 100 points! To verify, do A.
|
475 |
-
|
476 |
-
|
477 |
print(f"------------------------------------------------------------------------")
|
478 |
if not member_found: # this only checks if discord_user_id (with L) is present in discord_user_id column,
|
479 |
# if not, create new record
|
@@ -518,9 +474,8 @@ async def on_message(message):
|
|
518 |
print(f"adding exp from message {message.author}")
|
519 |
await asyncio.sleep(0.1)
|
520 |
await add_exp(message.author.id)
|
|
|
521 |
# add check for verification
|
522 |
-
# could add !help to bot description
|
523 |
-
|
524 |
if message.content.find("!help") != -1:
|
525 |
await message.channel.send(
|
526 |
"To verify your 🤗 account, message me '!auth <TOKEN>' using your API token found here: https://huggingface.co/settings/token"
|
@@ -727,16 +682,10 @@ async def count_users_with_role(ctx, role_id):
|
|
727 |
await ctx.send(f"Number of users with the role '{role.name}': {count}")
|
728 |
|
729 |
|
730 |
-
""""""
|
731 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
732 |
def run_bot():
|
733 |
bot.run(DISCORD_TOKEN)
|
734 |
threading.Thread(target=run_bot).start()
|
735 |
-
# 1C8aLqgCqLYcMiIFf-P_Aosaa03C_WLIB_UyqvjSdWg8
|
736 |
-
# 1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w
|
737 |
-
URL = "https://docs.google.com/spreadsheets/d/1C8aLqgCqLYcMiIFf-P_Aosaa03C_WLIB_UyqvjSdWg8/export?format=csv&gid=0"
|
738 |
-
#URL = "https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/edit#gid=0"
|
739 |
-
#csv_url = URL.replace('/edit#gid=', '/export?format=csv&gid=')
|
740 |
|
741 |
|
742 |
def get_data():
|
@@ -761,11 +710,11 @@ def get_data2():
|
|
761 |
demo = gr.Blocks()
|
762 |
with demo:
|
763 |
try:
|
764 |
-
dataframe1 = pd.read_csv(
|
765 |
column_values_unique = sorted(dataframe1.iloc[:, 3].unique())
|
766 |
dataframe2 = pd.DataFrame({'Levels': column_values_unique})
|
767 |
counts = {}
|
768 |
-
for value in
|
769 |
counts[value] = counts.get(value, 0) + 1
|
770 |
dataframe2['Members'] = dataframe2['Levels'].map(counts)
|
771 |
|
|
|
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 |
|
65 |
@bot.event
|
66 |
async def on_ready():
|
|
|
75 |
print(f"csv successfully retrieved: \n {global_df}")
|
76 |
|
77 |
# updates both leaderboards
|
|
|
|
|
78 |
remove_huggingfolks.start()
|
|
|
79 |
print(f"------------------------------------------------------------------------")
|
80 |
except Exception as e:
|
81 |
print(f"on_ready Error: {e}")
|
|
|
103 |
print(f"------------------------------------------------------------------------")
|
104 |
|
105 |
for index, row in global_df.iterrows():
|
|
|
|
|
|
|
|
|
|
|
106 |
user = row['hf_user_name']
|
107 |
if pd.notna(user):
|
108 |
#print(f"user: {user}")
|
|
|
122 |
upvotes = data["numUpvotes"]
|
123 |
|
124 |
# recalculate level as well (no longer only depends on discord activity)
|
|
|
|
|
125 |
try:
|
126 |
global_df.loc[index, 'likes'] = likes
|
127 |
global_df.loc[index, 'models'] = models
|
|
|
250 |
41: lvl41, 42: lvl42, 43: lvl43, 44: lvl44, 45: lvl45, 46: lvl46, 47: lvl47, 48: lvl48, 49: lvl49, 50: lvl50,
|
251 |
}
|
252 |
|
|
|
|
|
|
|
|
|
253 |
member_found = False
|
254 |
|
255 |
print(f"Searching for member_id {member_id} in dataframe...")
|
256 |
# discord_user_id column
|
257 |
# iterate over items of first column (discord_user_id)
|
258 |
for index, cell_value in global_df.iloc[:, 0].items():
|
|
|
|
|
259 |
# tldr; set_as_dataframe forces scientific notation which corrupts discord_user_id data.
|
260 |
# set_as_dataframe is still highly efficient (1 API call), so we format numerical data as strings,
|
261 |
# which results in efficient google sheet updating + data integrity
|
262 |
cell_value = str(cell_value)
|
263 |
if cell_value.startswith("L") and cell_value.endswith("L"):
|
|
|
264 |
cell_value_clipped = cell_value[1:-1]
|
|
|
|
|
|
|
265 |
if cell_value_clipped == str(member_id): # str(member_id) needed, it is int by default
|
266 |
print("test4")
|
267 |
# if found, update that row...
|
|
|
278 |
|
279 |
# str -> int temporarily for adding
|
280 |
new_xp = int(old_xp) + XP_PER_MESSAGE
|
281 |
+
|
|
|
282 |
total_exp = global_df.loc[index, 'total_exp']
|
283 |
hub_xp = global_df.loc[index, 'hub_exp']
|
284 |
|
|
|
298 |
if hub_xp.strip():
|
299 |
total_exp = int(new_xp) + int(hub_xp)
|
300 |
else:
|
301 |
+
total_exp = int(new_xp)
|
|
|
302 |
|
303 |
# total v
|
304 |
current_level = calculate_level(total_exp)
|
|
|
331 |
print("test7")
|
332 |
# finding leaderboard rank + excluding huggingfolks (still need exclusion)
|
333 |
try:
|
|
|
|
|
|
|
|
|
334 |
print("Calculating rank...")
|
335 |
copy_df = global_df.copy()
|
336 |
copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
|
|
|
343 |
print(f"Discord ID {member} {member_id} not found in the DataFrame.")
|
344 |
rank = "🤗"
|
345 |
|
|
|
346 |
# if level 3 -> then send embed, remove some exp
|
347 |
if current_level >= 3: # could change to 4 maybe
|
348 |
if verified_role not in member.roles:
|
|
|
396 |
await member.add_roles(current_role)
|
397 |
print(f"Level Up! Gave {member} {current_role}")
|
398 |
|
|
|
399 |
if current_level == 2: # special embed with opt-out instructions for discord newcomers
|
400 |
embed = Embed(color=Color.blue())
|
401 |
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
|
|
413 |
print(f"Sent levelup embed to {member}")
|
414 |
return
|
415 |
|
416 |
+
if current_role in member.roles:
|
|
|
|
|
|
|
|
|
417 |
# send embed
|
418 |
embed = Embed(color=Color.blue())
|
419 |
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
|
|
421 |
msg = f'🤗 Congrats {member}! You just leveled up in the Hugging Face Discord server'
|
422 |
embed.description = f"{msg}."
|
423 |
embed.add_field(name="Leaderboard Ranking:", value=f"👑 **{rank}**\n\nhttps://discord.com/channels/879548962464493619/1197143964994773023", inline=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
msg3 = "- Posting\n- Reacting / being reacted to\n- Being active on the Hugging Face Hub (verify to link your Hub + Discord accounts!)"
|
425 |
embed.add_field(name="How to Level Up:", value=msg3, inline=True)
|
426 |
verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
|
|
|
429 |
lunar = bot.get_user(811235357663297546)
|
430 |
await member.send(embed=embed)
|
431 |
await lunar.send(embed=embed)
|
432 |
+
print(f"Sent levelup embed to {member}")
|
|
|
|
|
|
|
433 |
print(f"------------------------------------------------------------------------")
|
434 |
if not member_found: # this only checks if discord_user_id (with L) is present in discord_user_id column,
|
435 |
# if not, create new record
|
|
|
474 |
print(f"adding exp from message {message.author}")
|
475 |
await asyncio.sleep(0.1)
|
476 |
await add_exp(message.author.id)
|
477 |
+
|
478 |
# add check for verification
|
|
|
|
|
479 |
if message.content.find("!help") != -1:
|
480 |
await message.channel.send(
|
481 |
"To verify your 🤗 account, message me '!auth <TOKEN>' using your API token found here: https://huggingface.co/settings/token"
|
|
|
682 |
await ctx.send(f"Number of users with the role '{role.name}': {count}")
|
683 |
|
684 |
|
|
|
685 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
686 |
def run_bot():
|
687 |
bot.run(DISCORD_TOKEN)
|
688 |
threading.Thread(target=run_bot).start()
|
|
|
|
|
|
|
|
|
|
|
689 |
|
690 |
|
691 |
def get_data():
|
|
|
710 |
demo = gr.Blocks()
|
711 |
with demo:
|
712 |
try:
|
713 |
+
dataframe1 = pd.read_csv('https://docs.google.com/spreadsheets/d/1C8aLqgCqLYcMiIFf-P_Aosaa03C_WLIB_UyqvjSdWg8/export?format=csv&gid=0')
|
714 |
column_values_unique = sorted(dataframe1.iloc[:, 3].unique())
|
715 |
dataframe2 = pd.DataFrame({'Levels': column_values_unique})
|
716 |
counts = {}
|
717 |
+
for value in test_merge.iloc[:, 3]:
|
718 |
counts[value] = counts.get(value, 0) + 1
|
719 |
dataframe2['Members'] = dataframe2['Levels'].map(counts)
|
720 |
|