Schedule automatic space restart for gradio app

Hi!

I wish to schedule an automatic daily restart of my hugging face space where I host a gradio app. Is it possible to do that? I have created a user access token with permission to write for this purpose and I set up the scheduler within the gradio app as I have been instructed by chatgpt.
I was searching for similar questions I couldn’t find one, if this topic already exists sorry for the repetition.

import gradio as gr
import threading
import time
import schedule
import requests
from datetime import datetime

current_date = datetime.now().strftime(“%Y-%m-%d %H:%M”)

def restart_space():
print(“Restarting the space…”)
response = requests.get(f"https://huggingface.co/api/spaces/drkvcsstvn/kenetoszto",
params={},
headers={“Authorization”:“Bearer HF_API_TOKEN”}
)
if response.status_code == 200:
print(“Space restarted successfully.”)
else:
print(f"Failed to restart space: {response.status_code}, {response.text}")

def schedule_restart():
schedule.every(2).minutes.do(restart_space)

while True:
    schedule.run_pending()
    time.sleep(1)

def start_scheduler():
scheduler_thread = threading.Thread(target=schedule_restart, daemon=True)
scheduler_thread.start()

def greet(name):
return f"Hello {name}!"

iface = gr.Interface(fn=greet, inputs=“text”, outputs=“text”,title= f’{current_date}')

start_scheduler()
iface.launch()