From 99c0e90525e9e69039df96d989a2606a82e5c174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Tue, 2 Jul 2024 14:58:15 +0800 Subject: [PATCH] 'commit' --- BaiHu/Config.ini | 1 + BaiHu/Tools/TestComfyUIApi.py | 33 ++++++++++++++---- BaiHu/Util/ComfyUIUtil.py | 10 +++--- .../__pycache__/ComfyUIUtil.cpython-310.pyc | Bin 4481 -> 4499 bytes 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/BaiHu/Config.ini b/BaiHu/Config.ini index 106bdcb1..4489061d 100644 --- a/BaiHu/Config.ini +++ b/BaiHu/Config.ini @@ -15,6 +15,7 @@ webui_server = http://192.168.1.21:7860 txt2img_url = /sdapi/v1/txt2img img2img_url = /sdapi/v1/img2img get_vram_url = /sdapi/v1/get_vram +empty_cache_url = /sdapi/v1/empty_cache ; WEB服务器地址 [webServer] ; web_url = https://www.hzkjai.com diff --git a/BaiHu/Tools/TestComfyUIApi.py b/BaiHu/Tools/TestComfyUIApi.py index 0e3b11c0..6fb11b94 100644 --- a/BaiHu/Tools/TestComfyUIApi.py +++ b/BaiHu/Tools/TestComfyUIApi.py @@ -5,12 +5,9 @@ from Util.ComfyUIUtil import * config = ConfigUtil.getConfig() server_address = config.get('comfyui', 'server_address') -# 清理GPU缓存 -# info = getUse(server_address) -# print(info) -# clear_cache(server_address) -def get_vram(): +# 获取webui使用情况 +def get_webui_used(): # webui 服务器地址 webui_server = config['webui']['webui_server'] vram_url = webui_server + config['webui']['get_vram_url'] @@ -20,5 +17,29 @@ def get_vram(): else: print("调用集成的获取显卡显存代码失败!") -get_vram() +# 清理webui的缓存 +def clear_webui_cache(): + # webui 服务器地址 + webui_server = config['webui']['webui_server'] + empty_cache_url = webui_server + config['webui']['empty_cache_url'] + res = submit_post(empty_cache_url, None) + if res.status_code == 200: + print(res.text) + else: + print("调用集成的清理显卡显存代码失败!") + + +# 清理GPU缓存 +info = get_comfyui_used(server_address) +print(info) +clear_comfyui_cache(server_address) +info = get_comfyui_used(server_address) +print(info) + +# 获取使显存数量 +get_webui_used() +# 清理缓存 +clear_webui_cache() +# 获取使显存数量 +get_webui_used() diff --git a/BaiHu/Util/ComfyUIUtil.py b/BaiHu/Util/ComfyUIUtil.py index 275338a1..c1759e8a 100644 --- a/BaiHu/Util/ComfyUIUtil.py +++ b/BaiHu/Util/ComfyUIUtil.py @@ -85,7 +85,7 @@ def get_images(ws, server_address, client_id, prompt): # 获取显卡使用率 -def getUse(server_address): +def get_comfyui_used(server_address): req = urllib.request.Request("http://{}/system_stats".format(server_address)) res = json.loads(urllib.request.urlopen(req).read()) @@ -101,9 +101,9 @@ def getUse(server_address): # 参考文档:如何清空Comfyui的gpu缓存 # https://wailikeji.blog.csdn.net/article/details/140035515 # 清理GPU显存 -def clear_cache(server_address): +def clear_comfyui_cache(server_address): # 显示显卡使用率 - print('清理显存前:' + getUse(server_address)) + print('清理显存前:' + get_comfyui_used(server_address)) # 打开文件并读取内容 file_path = r'../JSON/clearGPU.json' if not os.path.exists(file_path): @@ -115,7 +115,7 @@ def clear_cache(server_address): # 显示显卡使用率 time.sleep(2) - print('清理显存后:' + getUse(server_address)) + print('清理显存后:' + get_comfyui_used(server_address)) # 生成图像 @@ -140,7 +140,7 @@ def generate_clip(server_address, prompt_data, client_id, output_path, myfilter) binary_file.write(image_data) ws.close() # 清理GPU缓存 - clear_cache(server_address) + clear_comfyui_cache(server_address) return files diff --git a/BaiHu/Util/__pycache__/ComfyUIUtil.cpython-310.pyc b/BaiHu/Util/__pycache__/ComfyUIUtil.cpython-310.pyc index ad1567359f4e9a4908008600326b04dec4d7ad5d..0646df14404ba2a88c0a0afff71167fb9c6f445c 100644 GIT binary patch delta 83 zcmZovo~+E9&&$ij00bOMn$yfS^5$|03Z$o$$Hrd5_^#+MeSrfhEH+Q-NzoSc)I eSOk;U?8>v5neo=-pZq%*<0fwsXabU^f<6E(6dUOP delta 65 zcmbQN+^Ec(&&$ij00ifmn$kEn^5$}}v!$n&gchf6?&jLZ$i|(VlbTqxIhK_37?x)SpM