Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
shifting away from tasks.loop (discord reliant) for heavy I/O operations (hub stat updates)
Browse files
app.py
CHANGED
|
@@ -104,6 +104,7 @@ def update_google_sheet():
|
|
| 104 |
executor = ThreadPoolExecutor(max_workers=2)
|
| 105 |
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 106 |
scheduler.add_job(update_google_sheet, trigger='interval', minutes=1, max_instances=2)
|
|
|
|
| 107 |
scheduler.start()
|
| 108 |
|
| 109 |
|
|
@@ -613,20 +614,19 @@ async def remove_huggingfolks():
|
|
| 613 |
#---------------------------------------------------------------------------------------------
|
| 614 |
# UPDATE dataframe WITH HFAPI INFO on a timer
|
| 615 |
|
| 616 |
-
|
| 617 |
-
|
| 618 |
try:
|
| 619 |
global global_df
|
| 620 |
-
|
| 621 |
-
|
|
|
|
| 622 |
for index, row in global_df.iterrows():
|
| 623 |
-
|
| 624 |
-
#column = global_df['hf_user_name']
|
| 625 |
|
| 626 |
# data type of value?
|
|
|
|
| 627 |
|
| 628 |
-
#for index, user in column:
|
| 629 |
-
#print(f"index: {index}")
|
| 630 |
user = row['hf_user_name']
|
| 631 |
if pd.notna(user):
|
| 632 |
print(f"user: {user}")
|
|
@@ -659,23 +659,16 @@ async def update_hub_stats():
|
|
| 659 |
except Exception as e:
|
| 660 |
print(f"{e} error updating the dataframe")
|
| 661 |
|
| 662 |
-
|
| 663 |
-
#sheet1.update(f'I{i+1}:O{i+1}',[[likes, models, datasets, spaces, discussions, papers, upvotes]])
|
| 664 |
-
# update df instead
|
| 665 |
-
#updated_df.loc[index, ['likes', 'models', 'datasets', 'spaces', 'discussions', 'papers', 'upvotes']] = [likes, models, datasets, spaces, discussions, papers, upvotes]
|
| 666 |
-
#print(f"likes: {likes}")
|
| 667 |
-
#global_df.loc[index, 'likes'] = likes
|
| 668 |
-
#print(f"updated row {index} for user {user}")
|
| 669 |
else:
|
| 670 |
print(f"Failed to retrieve data for user {user}. Status code: {response.status_code}")
|
| 671 |
|
| 672 |
-
#print(global_df)
|
| 673 |
|
| 674 |
except Exception as e:
|
| 675 |
print(f"Failed to parse data for user {user}. {e}")
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
|
|
|
| 679 |
|
| 680 |
|
| 681 |
#---------------------------------------------------------------------------------------------
|
|
|
|
| 104 |
executor = ThreadPoolExecutor(max_workers=2)
|
| 105 |
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 106 |
scheduler.add_job(update_google_sheet, trigger='interval', minutes=1, max_instances=2)
|
| 107 |
+
scheduler.add_job(update_hub_stats, trigger='interval', minutes=1, max_instances=2)
|
| 108 |
scheduler.start()
|
| 109 |
|
| 110 |
|
|
|
|
| 614 |
#---------------------------------------------------------------------------------------------
|
| 615 |
# UPDATE dataframe WITH HFAPI INFO on a timer
|
| 616 |
|
| 617 |
+
#@tasks.loop(minutes=1) tasks.loop leads to heartbeat blocked issues (merging calculations too much with normal discord bot functions)
|
| 618 |
+
def update_hub_stats():
|
| 619 |
try:
|
| 620 |
global global_df
|
| 621 |
+
print("Updating hub stats...")
|
| 622 |
+
print(f"------------------------------------------------------------------------")
|
| 623 |
+
|
| 624 |
for index, row in global_df.iterrows():
|
| 625 |
+
# fill blank values with n/a for now? then replace if they try to verify
|
|
|
|
| 626 |
|
| 627 |
# data type of value?
|
| 628 |
+
# may need this to be fairly long -> complete cycles successfully before starting new job
|
| 629 |
|
|
|
|
|
|
|
| 630 |
user = row['hf_user_name']
|
| 631 |
if pd.notna(user):
|
| 632 |
print(f"user: {user}")
|
|
|
|
| 659 |
except Exception as e:
|
| 660 |
print(f"{e} error updating the dataframe")
|
| 661 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
else:
|
| 663 |
print(f"Failed to retrieve data for user {user}. Status code: {response.status_code}")
|
| 664 |
|
|
|
|
| 665 |
|
| 666 |
except Exception as e:
|
| 667 |
print(f"Failed to parse data for user {user}. {e}")
|
| 668 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 669 |
+
print(f"------------------------------------------------------------------------")
|
| 670 |
+
print(f"Hub stats successfully updated at {timestamp}! \n{global_df}")
|
| 671 |
+
print(f"------------------------------------------------------------------------")
|
| 672 |
|
| 673 |
|
| 674 |
#---------------------------------------------------------------------------------------------
|