lexicalspace commited on
Commit
dd667a6
·
verified ·
1 Parent(s): b8a1f05

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests, gradio as gr
2
+
3
+ SPACES = {
4
+ "Space One": "https://space-one.hf.space",
5
+ "Space Two": "https://space-two.hf.space",
6
+ "Space Three": "https://space-three.hf.space",
7
+ "Space Four": "https://space-four.hf.space",
8
+ "Space Five": "https://space-five.hf.space",
9
+ "Space Six": "https://space-six.hf.space",
10
+ "Space Seven": "https://space-seven.hf.space",
11
+ }
12
+
13
+ def get_status():
14
+ data = []
15
+ for name, url in SPACES.items():
16
+ try:
17
+ r = requests.get(url, timeout=3)
18
+ if r.status_code == 200:
19
+ j = r.json()
20
+ data.append({
21
+ "Space": name,
22
+ "Status": "RUNNING",
23
+ "CPU %": j["cpu"],
24
+ "RAM %": j["ram"],
25
+ "RAM MB": j["ram_mb"]
26
+ })
27
+ else:
28
+ raise Exception()
29
+ except:
30
+ data.append({
31
+ "Space": name,
32
+ "Status": "SLEEPING / OFF",
33
+ "CPU %": 0,
34
+ "RAM %": 0,
35
+ "RAM MB": 0
36
+ })
37
+ return data
38
+
39
+ demo = gr.Interface(
40
+ fn=get_status,
41
+ inputs=None,
42
+ outputs="json",
43
+ title="🚀 Hugging Face Spaces Monitor",
44
+ live=False
45
+ )
46
+
47
+ demo.launch()