File size: 909 Bytes
3f93532
 
 
41d3b75
3f93532
 
 
 
 
 
 
 
 
 
d1b89a7
700412f
d1b89a7
700412f
3f93532
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41d3b75
 
3f93532
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
        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()