|
|
# system_stats
|
|
|
import json
|
|
|
import urllib.parse
|
|
|
import urllib.request
|
|
|
|
|
|
import urllib.parse
|
|
|
import urllib.request
|
|
|
from Util import ConfigUtil
|
|
|
from Util.ComfyUIUtil import *
|
|
|
from Util.CommonUtil import *
|
|
|
|
|
|
|
|
|
def queue_prompt(server_address, client_id, prompt):
|
|
|
p = {"prompt": prompt, "client_id": client_id}
|
|
|
data = json.dumps(p).encode('utf-8')
|
|
|
req = urllib.request.Request("http://{}/prompt".format(server_address), data=data)
|
|
|
try:
|
|
|
urllib.request.urlopen(req)
|
|
|
except Exception as err:
|
|
|
print(err)
|
|
|
return json.loads(urllib.request.urlopen(req).read())
|
|
|
|
|
|
|
|
|
# GET /system_stats
|
|
|
# 系统统计信息接口
|
|
|
|
|
|
# 打开配置文件
|
|
|
config = ConfigUtil.getConfig()
|
|
|
|
|
|
server_address = config.get('comfyui', 'server_address')
|
|
|
req = urllib.request.Request("http://{}/system_stats".format(server_address))
|
|
|
res = json.loads(urllib.request.urlopen(req).read())
|
|
|
|
|
|
vram_total = res['devices'][0]['vram_total']
|
|
|
vram_free = res['devices'][0]['vram_free']
|
|
|
used_vram = 1.0 * (vram_total - vram_free) / vram_total * 100
|
|
|
print(str(used_vram) + "%")
|
|
|
# vram_total # 显存容量:25756696576 即24GB
|
|
|
# vram_free # 显存剩余:25756696576
|
|
|
# torch_vram_total 16005464064
|
|
|
# torch_vram_free 331041996
|
|
|
|
|
|
# 打开文件并读取内容
|
|
|
file_path = r'../JSON/clearGPU.json'
|
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
|
content = file.read()
|
|
|
|
|
|
# 如何清空Comfyui的gpu缓存
|
|
|
# https://wailikeji.blog.csdn.net/article/details/140035515
|
|
|
#queue_prompt(server_address, "cleanGpuRam", content)
|