mrfakename's picture
Update app.py
96944a8
raw
history blame
748 Bytes
import time
last_run = 0
import os
from huggingface_hub import HfApi
api = HfApi(
token=os.getenv('HF_TOKEN'),
)
import gradio as gr
def reboot():
global last_run
current_time = time.time()
if current_time - last_run >= 300:
api.restart_space('mrfakename/OpenDalleV1.1-GPU-Demo', factory_reboot=True)
last_run = current_time
return "Rebooted"
else:
raise gr.Error("The Space has already been rebooted recently")
with gr.Blocks() as demo:
gr.Markdown("# Request a Reboot of OpenDalle v1.1 GPU Demo\n\nIs [the demo](https://huggingface.co/spaces/mrfakename/OpenDalleV1.1-GPU-Demo) not working? Request a reboot!")
btn = gr.Button("Reboot")
btn.click(reboot, outputs=[btn])
demo.launch()