Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
import time
|
4 |
+
spaces = []
|
5 |
+
def update(name):
|
6 |
+
print("being kept alive!")
|
7 |
+
return "alive"
|
8 |
+
def add_space(name):
|
9 |
+
global spaces
|
10 |
+
try:
|
11 |
+
client = Client(name)
|
12 |
+
spaces.append(client)
|
13 |
+
return "success"
|
14 |
+
except:
|
15 |
+
return "failed"
|
16 |
+
def run():
|
17 |
+
global spaces
|
18 |
+
while True:
|
19 |
+
time.sleep(300)
|
20 |
+
for i in spaces:
|
21 |
+
try:
|
22 |
+
i.predict(api_name="/update")
|
23 |
+
except:
|
24 |
+
pass
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
inp = gr.Textbox(label="space name (Username/Space)")
|
27 |
+
ka = gr.Button("keep alive!")
|
28 |
+
btn = gr.Button("this button does nothing")
|
29 |
+
ka.click(add_space, (inp, ), (inp, ))
|
30 |
+
btn.click(fn=update)
|
31 |
+
|
32 |
+
demo.launch()
|