Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import json
|
2 |
import os
|
3 |
import psutil
|
|
|
4 |
from threading import Timer
|
5 |
import librosa
|
6 |
import numpy as np
|
@@ -89,13 +90,26 @@ def system_monitor():
|
|
89 |
return f"{bs:.2f}{unit}{suffix}"
|
90 |
bs /= factor
|
91 |
|
|
|
|
|
|
|
|
|
92 |
def print_sys_status():
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
print("=" * 10, "Disk Information", "=" * 10)
|
100 |
# get all disk partitions
|
101 |
partitions = psutil.disk_partitions()
|
@@ -108,6 +122,7 @@ def system_monitor():
|
|
108 |
continue
|
109 |
disk_info += f"{partition_usage.percent}%({get_size(partition_usage.total)}), "
|
110 |
print(disk_info)
|
|
|
111 |
tr = Timer(60, print_sys_status)
|
112 |
tr.start()
|
113 |
|
@@ -133,7 +148,8 @@ css = """
|
|
133 |
"""
|
134 |
|
135 |
if __name__ == '__main__':
|
136 |
-
|
|
|
137 |
models = []
|
138 |
with open("saved_model/names.json", "r", encoding="utf-8") as f:
|
139 |
models_names = json.load(f)
|
|
|
1 |
import json
|
2 |
import os
|
3 |
import psutil
|
4 |
+
import time
|
5 |
from threading import Timer
|
6 |
import librosa
|
7 |
import numpy as np
|
|
|
90 |
return f"{bs:.2f}{unit}{suffix}"
|
91 |
bs /= factor
|
92 |
|
93 |
+
def read_int(path):
|
94 |
+
with open(path, "r") as f:
|
95 |
+
return int(f.read())
|
96 |
+
|
97 |
def print_sys_status():
|
98 |
+
try:
|
99 |
+
cpu_t1 = read_int("/sys/fs/cgroup/cpu/cpuacct.usage")
|
100 |
+
t1 = time.time() * 1000000000
|
101 |
+
time.sleep(1)
|
102 |
+
cpu_t2 = read_int("/sys/fs/cgroup/cpu/cpuacct.usage")
|
103 |
+
t2 = time.time() * 1000000000
|
104 |
+
cpu_percent = (cpu_t2 - cpu_t1) / (t2 - t1) * 100
|
105 |
+
mem_total = get_size(read_int("/sys/fs/cgroup/memory/memory.limit_in_bytes"))
|
106 |
+
mem_usage = get_size(read_int("/sys/fs/cgroup/memory/memory.usage_in_bytes"))
|
107 |
+
print("=" * 10, "CPU & Mem Information", "=" * 10)
|
108 |
+
print(f"CPU: {cpu_percent}%, "
|
109 |
+
f"Mem: {mem_usage}/{mem_total}")
|
110 |
+
except FileNotFoundError:
|
111 |
+
pass
|
112 |
+
|
113 |
print("=" * 10, "Disk Information", "=" * 10)
|
114 |
# get all disk partitions
|
115 |
partitions = psutil.disk_partitions()
|
|
|
122 |
continue
|
123 |
disk_info += f"{partition_usage.percent}%({get_size(partition_usage.total)}), "
|
124 |
print(disk_info)
|
125 |
+
|
126 |
tr = Timer(60, print_sys_status)
|
127 |
tr.start()
|
128 |
|
|
|
148 |
"""
|
149 |
|
150 |
if __name__ == '__main__':
|
151 |
+
if os.getenv("SYSTEM") == "spaces":
|
152 |
+
system_monitor() # debug
|
153 |
models = []
|
154 |
with open("saved_model/names.json", "r", encoding="utf-8") as f:
|
155 |
models_names = json.load(f)
|