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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -32
app.py CHANGED
@@ -1,47 +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()
 
1
+ import requests
2
+ import gradio as gr
3
+ import time
4
 
5
  SPACES = {
6
+ "Space One": "https://lexicalspace-test.hf.space",
7
+ "Space Two": "https://lexicalspace-Blogger-Toolkit.hf.space",
8
+ "Space Three": "https://lexicalspace-.hf.space",
9
  "Space Four": "https://space-four.hf.space",
10
  "Space Five": "https://space-five.hf.space",
11
  "Space Six": "https://space-six.hf.space",
12
  "Space Seven": "https://space-seven.hf.space",
13
  }
14
 
15
+ def fetch():
16
+ rows = []
17
  for name, url in SPACES.items():
18
  try:
19
  r = requests.get(url, timeout=3)
20
+ j = r.json()
21
+ rows.append([
22
+ name,
23
+ "🟢 RUNNING",
24
+ j["cpu"],
25
+ j["ram"]
26
+ ])
 
 
 
 
27
  except:
28
+ rows.append([
29
+ name,
30
+ " SLEEPING",
31
+ 0,
32
+ 0
33
+ ])
34
+ return rows
 
35
 
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("## 🚀 Hugging Face Spaces Monitor")
38
+
39
+ table = gr.Dataframe(
40
+ headers=["Space", "Status", "CPU %", "RAM %"],
41
+ datatype=["str", "str", "number", "number"],
42
+ interactive=False
43
+ )
44
+
45
+ demo.load(fetch, None, table, every=30)
46
 
47
  demo.launch()