File size: 1,148 Bytes
0284629
 
 
 
 
 
 
 
 
 
c9ae7aa
 
0284629
 
 
f2dc975
c9ae7aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26b12e1
c9ae7aa
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : megradio.
# @File         : app
# @Time         : 2022/9/23 上午11:11
# @Author       : yuanjie
# @WeChat       : meutils
# @Software     : PyCharm
# @Description  : 

import psutil
import numpy as np
import gradio as gr


def source_info(*k):
    cpu_per = psutil.cpu_percent(True, True)
    cpu_per = round(np.array(cpu_per).mean(), 2)
    mem = psutil.virtual_memory()
    cpu_num = psutil.cpu_count(logical=True)
    mem_total = round(mem.total / 2 ** 32, 2)
    mem_per = round(mem.percent, 2)
    disk = []
    partitions = psutil.disk_partitions()
    for i in partitions:
        info = psutil.disk_usage(i[1])
        disk.append([info.total, info.used])
    disk = np.array(disk)
    disk = disk.sum(axis=0)
    disk_pre = round(disk[1] / disk[0] * 100, 2)
    disk_total = round(disk[0] / 2 ** 30, 2)

    return {
        "cpu数量": f"{cpu_num} | {cpu_per}%",
        "内存总量": f"{mem_total}GB | {mem_per}%",
        "磁盘总量": f"{disk_total}GB | {disk_pre}%"
    }


(
    gr.Interface(fn=source_info, inputs="text", outputs=gr.JSON())
        .launch()
)