README / restart_space.py
nastyboget's picture
Upload restart_space.py
96d2a3e verified
Raw
History Blame Contribute Delete
586 Bytes
import os
import time
import requests
import schedule
HF_TOKEN = os.getenv("RESTART_SPACE_TOKEN")
url = "https://huggingface.co/api/spaces/dedoc/README/restart"
def restart_space():
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
response = requests.post(url, headers=headers)
if response.status_code == 200:
print("Space restarted successfully!")
else:
print(f"Failed to restart: {response.status_code}")
if __name__ == "__main__":
schedule.every().hour.do(restart_space)
while True:
schedule.run_pending()
time.sleep(1)