import time last_run = 0 olast_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. Thank you!" else: raise gr.Error("The Space has already been rebooted recently, please try again in 5 minutes.") def rebootorig(): global olast_run current_time = time.time() if current_time - olast_run >= 300: api.restart_space('mrfakename/OpenDalle-GPU-Demo', factory_reboot=True) olast_run = current_time return "Rebooted. Thank you!" else: raise gr.Error("The Space has already been rebooted recently, please try again in 5 minutes.") def rebootvc(): api.restart_space('mrfakename/MegaTTS3-Voice-Cloning') with gr.Blocks() as demo: gr.Markdown("# Request a reboot on demo spaces") btn = gr.Button("Reboot MegaTTS3 Voice Cloning Demo") btn.click(rebootvc, outputs=[btn]) btn = gr.Button("Reboot OpenDALLE V1.1 GPU DEMO") btn.click(reboot, outputs=[btn]) #btnorig = gr.Button("Reboot V1 (original) GPU DEMO") #btnorig.click(rebootorig, outputs=[btnorig]) demo.launch()