Spaces:
Sleeping
Sleeping
VictorKai1996NUS
commited on
Commit
•
0af4f53
1
Parent(s):
d6e8791
Update app.py
Browse files
app.py
CHANGED
@@ -161,7 +161,7 @@ body {
|
|
161 |
|
162 |
.server-status {
|
163 |
margin-top: 20px;
|
164 |
-
background-color:
|
165 |
padding: 10px;
|
166 |
border-radius: 5px;
|
167 |
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
@@ -235,11 +235,10 @@ with gr.Blocks(css=css) as demo:
|
|
235 |
with gr.Row(elem_classes="server-status"):
|
236 |
gr.Markdown("#### Server Status")
|
237 |
with gr.Row():
|
238 |
-
cpu_status = gr.Textbox(label="CPU", scale=1
|
239 |
-
memory_status = gr.Textbox(label="Memory", scale=1
|
240 |
-
disk_status = gr.Textbox(label="Disk", scale=1
|
241 |
-
|
242 |
-
gpu_status = gr.JSON(container=False)
|
243 |
refresh_button = gr.Button("Refresh", scale=1, size="sm")
|
244 |
|
245 |
with gr.Column():
|
@@ -282,13 +281,35 @@ with gr.Blocks(css=css) as demo:
|
|
282 |
def enhance_prompt_func(prompt):
|
283 |
return convert_prompt(prompt, retry_times=1)
|
284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
def update_server_status():
|
286 |
status = get_server_status()
|
287 |
return (
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
status['
|
292 |
)
|
293 |
|
294 |
|
@@ -308,7 +329,7 @@ with gr.Blocks(css=css) as demo:
|
|
308 |
|
309 |
|
310 |
refresh_button.click(update_server_status, outputs=[cpu_status, memory_status, disk_status, gpu_status])
|
311 |
-
demo.load(update_server_status, outputs=[cpu_status, memory_status, disk_status, gpu_status], every=
|
312 |
|
313 |
if __name__ == "__main__":
|
314 |
demo.queue(max_size=10, default_concurrency_limit=1)
|
|
|
161 |
|
162 |
.server-status {
|
163 |
margin-top: 20px;
|
164 |
+
background-color: white;
|
165 |
padding: 10px;
|
166 |
border-radius: 5px;
|
167 |
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
|
235 |
with gr.Row(elem_classes="server-status"):
|
236 |
gr.Markdown("#### Server Status")
|
237 |
with gr.Row():
|
238 |
+
cpu_status = gr.Textbox(label="CPU", scale=1)
|
239 |
+
memory_status = gr.Textbox(label="Memory", scale=1)
|
240 |
+
disk_status = gr.Textbox(label="Disk", scale=1)
|
241 |
+
gpu_status = gr.Textbox(label="GPU Memory", scale=1)
|
|
|
242 |
refresh_button = gr.Button("Refresh", scale=1, size="sm")
|
243 |
|
244 |
with gr.Column():
|
|
|
281 |
def enhance_prompt_func(prompt):
|
282 |
return convert_prompt(prompt, retry_times=1)
|
283 |
|
284 |
+
def get_server_status():
|
285 |
+
cpu_percent = psutil.cpu_percent()
|
286 |
+
memory = psutil.virtual_memory()
|
287 |
+
disk = psutil.disk_usage('/')
|
288 |
+
try:
|
289 |
+
gpus = GPUtil.getGPUs()
|
290 |
+
if gpus:
|
291 |
+
gpu = gpus[0] # 只获取第一个GPU的信息
|
292 |
+
gpu_memory = f"{gpu.memoryUsed}/{gpu.memoryTotal}MB ({gpu.memoryUtil*100:.1f}%)"
|
293 |
+
else:
|
294 |
+
gpu_memory = "No GPU found"
|
295 |
+
except:
|
296 |
+
gpu_memory = "GPU information unavailable"
|
297 |
+
|
298 |
+
return {
|
299 |
+
'cpu': f"{cpu_percent}%",
|
300 |
+
'memory': f"{memory.percent}%",
|
301 |
+
'disk': f"{disk.percent}%",
|
302 |
+
'gpu_memory': gpu_memory
|
303 |
+
}
|
304 |
+
|
305 |
+
|
306 |
def update_server_status():
|
307 |
status = get_server_status()
|
308 |
return (
|
309 |
+
status['cpu'],
|
310 |
+
status['memory'],
|
311 |
+
status['disk'],
|
312 |
+
status['gpu_memory']
|
313 |
)
|
314 |
|
315 |
|
|
|
329 |
|
330 |
|
331 |
refresh_button.click(update_server_status, outputs=[cpu_status, memory_status, disk_status, gpu_status])
|
332 |
+
demo.load(update_server_status, outputs=[cpu_status, memory_status, disk_status, gpu_status], every=1)
|
333 |
|
334 |
if __name__ == "__main__":
|
335 |
demo.queue(max_size=10, default_concurrency_limit=1)
|