Spaces:
Sleeping
Sleeping
Add project files.
Browse files- 2023-10-17-daily-demo-screenshot.png +0 -0
- README.md +12 -2
- app.py +73 -0
- requirements.txt +2 -0
2023-10-17-daily-demo-screenshot.png
ADDED
![]() |
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: System Monitor
|
3 |
-
emoji:
|
4 |
colorFrom: purple
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
@@ -10,4 +10,14 @@ pinned: false
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: System Monitor
|
3 |
+
emoji: π
|
4 |
colorFrom: purple
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
10 |
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
+
# 2023-10-17 Daily Demo - System Monitor
|
14 |
+
|
15 |
+
A daily demo space created by [@gstaff](https://huggingface.co/gstaff).
|
16 |
+
|
17 |
+
## Description
|
18 |
+
A tool similar to task manager to report system resource usage e.g. CPU, RAM, VRAM, etc .
|
19 |
+
|
20 |
+

|
21 |
+
|
22 |
+
## Credits
|
23 |
+
See `requirements.txt` for the python libraries used.
|
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import GPUtil
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import os
|
4 |
+
import psutil
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
|
8 |
+
# TODO: Use plotly trace to update a plot of the stats; try to get near parity to system monitor
|
9 |
+
# Ask: what stats are users most interested in knowing?
|
10 |
+
def get_stats(plot):
|
11 |
+
stats = ""
|
12 |
+
|
13 |
+
# Get CPU usage
|
14 |
+
cpu_percent = psutil.cpu_percent(interval=0)
|
15 |
+
|
16 |
+
# Get the number of CPU cores
|
17 |
+
num_cores = os.cpu_count()
|
18 |
+
|
19 |
+
# Get RAM usage
|
20 |
+
ram = psutil.virtual_memory()
|
21 |
+
total_ram = psutil.virtual_memory().total
|
22 |
+
|
23 |
+
stats += f"CPU Usage: {cpu_percent}%\n"
|
24 |
+
stats += f"Number of CPU Cores: {num_cores}\n"
|
25 |
+
stats += f"RAM Usage: {ram.percent}%\n"
|
26 |
+
stats += f"RAM Used: {ram.used / (1024 ** 3):.2f} GB\n"
|
27 |
+
stats += f"Total RAM: {total_ram / (1024 ** 3):.2f} GB\n"
|
28 |
+
# print(f"CPU Usage: {cpu_percent}%")
|
29 |
+
# print(f"Number of CPU Cores: {num_cores}")
|
30 |
+
# print(f"RAM Usage: {ram.percent}%")
|
31 |
+
# print(f"RAM Used: {ram.used / (1024 ** 3):.2f} GB")
|
32 |
+
# print(f"Total RAM: {total_ram / (1024 ** 3):.2f} GB")
|
33 |
+
|
34 |
+
# Get GPU usage and memory info
|
35 |
+
gpu_info = GPUtil.getGPUs()
|
36 |
+
|
37 |
+
for i, gpu in enumerate(gpu_info):
|
38 |
+
stats += f"GPU {i + 1}:\n"
|
39 |
+
stats += f" GPU Name: {gpu.name}\n"
|
40 |
+
stats += f" GPU Usage: {gpu.load * 100}%\n"
|
41 |
+
stats += f" GPU VRAM Usage: {(gpu.memoryUtil * 100):.2f}%\n"
|
42 |
+
stats += f" GPU Free VRAM: {(gpu.memoryFree / 1024):.2f} MB\n"
|
43 |
+
stats += f" GPU Total VRAM: {gpu.memoryTotal / 1024} MB\n\n"
|
44 |
+
# print(f"GPU {i + 1}:")
|
45 |
+
# print(f" GPU Name: {gpu.name}")
|
46 |
+
# print(f" GPU Usage: {gpu.load * 100}%")
|
47 |
+
# print(f" GPU VRAM Usage: {(gpu.memoryUtil * 100):.2f}%")
|
48 |
+
# print(f" GPU Free VRAM: {(gpu.memoryFree / 1024):.2f} MB")
|
49 |
+
# print(f" GPU Total VRAM: {gpu.memoryTotal / 1024} MB\n")
|
50 |
+
|
51 |
+
return stats, None
|
52 |
+
|
53 |
+
|
54 |
+
with gr.Blocks() as demo:
|
55 |
+
gr.Markdown(value='# System Monitor')
|
56 |
+
with gr.Row():
|
57 |
+
with gr.Column(scale=1):
|
58 |
+
gr.Markdown('## View system resource usage for the demo')
|
59 |
+
stats_box = gr.TextArea(label="System Stats")
|
60 |
+
with gr.Column(scale=1):
|
61 |
+
plot = gr.Plot(label="Plot", value=None)
|
62 |
+
|
63 |
+
dep = demo.load(get_stats, [plot], [stats_box, plot], every=5)
|
64 |
+
stats_box.change(get_stats, [plot], [stats_box, plot], every=5, cancels=[dep])
|
65 |
+
|
66 |
+
with gr.Accordion('Developer Notes:', open=False):
|
67 |
+
gr.Markdown('I\'ve seen a number of Ai tools that report system resource usage and think that is a good trend.\n\n'
|
68 |
+
'With more time I could see a "Task Manager" component for gradio being useful for demos.\n\n'
|
69 |
+
'The plot for this demo is broken but I may revisit this later.')
|
70 |
+
|
71 |
+
|
72 |
+
if __name__ == '__main__':
|
73 |
+
demo.queue().launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GPUtil
|
2 |
+
psutil
|