Nicolás Larenas commited on
Commit
9285239
·
verified ·
1 Parent(s): 7acdd8f

Create keep_awake.py

Browse files

This file sends periodic requests to keep the Hugging Face Space from sleeping due to inactivity.

Files changed (1) hide show
  1. keep_awake.py +13 -0
keep_awake.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+ from discord.ext import tasks
4
+
5
+ HUGGING_FACE_SPACE_URL = os.getenv("HUGGING_FACE_SPACE_URL")
6
+
7
+ @tasks.loop(minutes=20)
8
+ async def keep_space_awake():
9
+ try:
10
+ requests.get(HUGGING_FACE_SPACE_URL)
11
+ print(f"Pinged {HUGGING_FACE_SPACE_URL} to keep it awake.")
12
+ except requests.RequestException as e:
13
+ print(f"Failed to ping Hugging Face Space: {e}")