Upload restart_space.py
Browse files- restart_space.py +24 -0
restart_space.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
|
| 4 |
+
import requests
|
| 5 |
+
import schedule
|
| 6 |
+
|
| 7 |
+
HF_TOKEN = os.getenv("RESTART_SPACE_TOKEN")
|
| 8 |
+
url = "https://huggingface.co/api/spaces/dedoc/README/restart"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def restart_space():
|
| 12 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 13 |
+
response = requests.post(url, headers=headers)
|
| 14 |
+
if response.status_code == 200:
|
| 15 |
+
print("Space restarted successfully!")
|
| 16 |
+
else:
|
| 17 |
+
print(f"Failed to restart: {response.status_code}")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
schedule.every().hour.do(restart_space)
|
| 22 |
+
while True:
|
| 23 |
+
schedule.run_pending()
|
| 24 |
+
time.sleep(1)
|