Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
re
Browse files
app.py
CHANGED
|
@@ -51,6 +51,7 @@ api = HfApi()
|
|
| 51 |
#csv_file = 'data.csv'
|
| 52 |
global_df = pd.DataFrame()
|
| 53 |
print(type(global_df))
|
|
|
|
| 54 |
|
| 55 |
@bot.event
|
| 56 |
async def on_ready():
|
|
@@ -60,9 +61,8 @@ async def on_ready():
|
|
| 60 |
# testing sheet -> read -> paste sheet
|
| 61 |
|
| 62 |
"""import data from google sheets -> HF Space .csv (doesn't make API call this way, as it's read-only)"""
|
| 63 |
-
|
| 64 |
data['discord_user_id'] = data['discord_user_id'].astype(str)
|
| 65 |
-
print(data)
|
| 66 |
global_df = data
|
| 67 |
print(f"csv successfully retrieved: {global_df}")
|
| 68 |
#data.to_csv(csv_file, index=False)
|
|
@@ -211,11 +211,11 @@ async def add_exp(member_id):
|
|
| 211 |
xp = 10 # define somewhere else?
|
| 212 |
current_level = calculate_level(xp)
|
| 213 |
member_name = member.name
|
| 214 |
-
member_id_str = str(member_id)
|
| 215 |
print(f"test")
|
| 216 |
row_data = [member_id, member_name, xp, current_level]
|
| 217 |
print(f"test")
|
| 218 |
new_row_df = pd.DataFrame([row_data], columns=global_df.columns)
|
|
|
|
| 219 |
#updated_df = global_df.append(new_row_df, ignore_index=True) deprecated
|
| 220 |
updated_df = pd.concat([global_df, pd.DataFrame([new_row_df])], ignore_index=True)
|
| 221 |
print(f"test")
|
|
@@ -315,9 +315,6 @@ async def xp_help(ctx):
|
|
| 315 |
help_message = "How to earn Discord / Hub exp: Post messages, react, Like, discuss, create repos and papers"
|
| 316 |
await ctx.author.send(help_message)
|
| 317 |
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
# embeds with user pfps?
|
| 322 |
# name, pfp, time in server....
|
| 323 |
|
|
@@ -334,21 +331,27 @@ async def xp_help(ctx):
|
|
| 334 |
# check if members are still in the server
|
| 335 |
|
| 336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
""""""
|
| 338 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 339 |
def run_bot():
|
| 340 |
bot.run(DISCORD_TOKEN)
|
| 341 |
threading.Thread(target=run_bot).start()
|
| 342 |
|
| 343 |
-
|
| 344 |
URL = "https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/edit#gid=0"
|
| 345 |
csv_url = URL.replace('/edit#gid=', '/export?format=csv&gid=')
|
| 346 |
|
|
|
|
| 347 |
def get_data():
|
| 348 |
-
|
| 349 |
-
first_3_columns =
|
| 350 |
first_3_columns.to_csv('first_3_columns.csv', index=False)
|
| 351 |
-
return first_3_columns
|
|
|
|
| 352 |
# csv
|
| 353 |
# read into pandas dataframe1
|
| 354 |
# read levels column and create pandas dataframe2 with first column containing levels from 2-max found in dataframe1
|
|
@@ -360,7 +363,7 @@ with demo:
|
|
| 360 |
column_values_unique = sorted(dataframe1.iloc[:, 3].unique())
|
| 361 |
dataframe2 = pd.DataFrame({'Levels': column_values_unique})
|
| 362 |
counts = {}
|
| 363 |
-
for value in
|
| 364 |
counts[value] = counts.get(value, 0) + 1
|
| 365 |
dataframe2['Members'] = dataframe2['Levels'].map(counts)
|
| 366 |
|
|
@@ -394,4 +397,3 @@ demo.queue().launch()
|
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
-
|
|
|
|
| 51 |
#csv_file = 'data.csv'
|
| 52 |
global_df = pd.DataFrame()
|
| 53 |
print(type(global_df))
|
| 54 |
+
data = pd.read_csv("https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/export?format=csv&gid=0")
|
| 55 |
|
| 56 |
@bot.event
|
| 57 |
async def on_ready():
|
|
|
|
| 61 |
# testing sheet -> read -> paste sheet
|
| 62 |
|
| 63 |
"""import data from google sheets -> HF Space .csv (doesn't make API call this way, as it's read-only)"""
|
| 64 |
+
|
| 65 |
data['discord_user_id'] = data['discord_user_id'].astype(str)
|
|
|
|
| 66 |
global_df = data
|
| 67 |
print(f"csv successfully retrieved: {global_df}")
|
| 68 |
#data.to_csv(csv_file, index=False)
|
|
|
|
| 211 |
xp = 10 # define somewhere else?
|
| 212 |
current_level = calculate_level(xp)
|
| 213 |
member_name = member.name
|
|
|
|
| 214 |
print(f"test")
|
| 215 |
row_data = [member_id, member_name, xp, current_level]
|
| 216 |
print(f"test")
|
| 217 |
new_row_df = pd.DataFrame([row_data], columns=global_df.columns)
|
| 218 |
+
print(type(global_df))
|
| 219 |
#updated_df = global_df.append(new_row_df, ignore_index=True) deprecated
|
| 220 |
updated_df = pd.concat([global_df, pd.DataFrame([new_row_df])], ignore_index=True)
|
| 221 |
print(f"test")
|
|
|
|
| 315 |
help_message = "How to earn Discord / Hub exp: Post messages, react, Like, discuss, create repos and papers"
|
| 316 |
await ctx.author.send(help_message)
|
| 317 |
|
|
|
|
|
|
|
|
|
|
| 318 |
# embeds with user pfps?
|
| 319 |
# name, pfp, time in server....
|
| 320 |
|
|
|
|
| 331 |
# check if members are still in the server
|
| 332 |
|
| 333 |
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
|
| 339 |
""""""
|
| 340 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 341 |
def run_bot():
|
| 342 |
bot.run(DISCORD_TOKEN)
|
| 343 |
threading.Thread(target=run_bot).start()
|
| 344 |
|
|
|
|
| 345 |
URL = "https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/edit#gid=0"
|
| 346 |
csv_url = URL.replace('/edit#gid=', '/export?format=csv&gid=')
|
| 347 |
|
| 348 |
+
|
| 349 |
def get_data():
|
| 350 |
+
data = pd.read_csv(csv_url)
|
| 351 |
+
first_3_columns = data.iloc[:, 1:4]
|
| 352 |
first_3_columns.to_csv('first_3_columns.csv', index=False)
|
| 353 |
+
return first_3_columns
|
| 354 |
+
|
| 355 |
# csv
|
| 356 |
# read into pandas dataframe1
|
| 357 |
# read levels column and create pandas dataframe2 with first column containing levels from 2-max found in dataframe1
|
|
|
|
| 363 |
column_values_unique = sorted(dataframe1.iloc[:, 3].unique())
|
| 364 |
dataframe2 = pd.DataFrame({'Levels': column_values_unique})
|
| 365 |
counts = {}
|
| 366 |
+
for value in data.iloc[:, 3]:
|
| 367 |
counts[value] = counts.get(value, 0) + 1
|
| 368 |
dataframe2['Members'] = dataframe2['Levels'].map(counts)
|
| 369 |
|
|
|
|
| 397 |
|
| 398 |
|
| 399 |
|
|
|