Spaces:
Sleeping
Sleeping
import gradio as gr | |
from gradio_client import Client | |
import time | |
from threading import Thread | |
spaces = [] | |
def update(name): | |
print("being kept alive!") | |
return "alive" | |
def add_space(name): | |
global spaces | |
try: | |
client = Client(name) | |
spaces.append(client) | |
print("<usersuccess>") | |
print(name) | |
print("</usersuccess>") | |
return "success" | |
except Exception as e: | |
print("<userissue>") | |
print(e) | |
print("</userissue>") | |
return "failed" | |
def run(): | |
global spaces | |
while True: | |
time.sleep(300) | |
for i in spaces: | |
try: | |
i.predict(api_name="/update") | |
except: | |
pass | |
with gr.Blocks() as demo: | |
inp = gr.Textbox(label="space name (Username/Space)") | |
ka = gr.Button("keep alive!") | |
btn = gr.Button("this button does nothing") | |
ka.click(add_space, (inp, ), (inp, )) | |
btn.click(fn=update) | |
t=Thread(target=run) | |
t.start() | |
demo.launch() |