Skip to content

Commit

Permalink
Merge pull request #295 from shadowcz007/0.36.0-py5-processing
Browse files Browse the repository at this point in the history
Lama 改成手动安装,新增JsonRepair
  • Loading branch information
shadowcz007 authored Aug 6, 2024
2 parents ae4a17d + 5d4567b commit fc9a1c6
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 49 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- 增加 Edit Mask,方便在生成的时候手动绘制 mask [workflow](./workflow/edit-mask-workflow.json)

- LaMaInpainting 调整为手动安装

<!-- - ChatGPT 节点支持 Local LLM(llama.cpp),Phi3、llama3 都可以直接一个节点运行了。模型下载后,放置到 `models/llamafile/` -->

<!-- - 右键菜单支持 text-to-text,方便对 prompt 词补全 -->
Expand Down Expand Up @@ -120,7 +122,7 @@ https://github.com/shadowcz007/comfyui-mixlab-nodes/assets/12645064/e7e77f90-e43

### GPT

> Support for calling multiple GPTs.Local LLM(llama.cpp)、 ChatGPT、ChatGLM3 、ChatGLM4 , Some code provided by rui. If you are using OpenAI's service, fill in https://api.openai.com/v1 . If you are using a local LLM service, fill in http://127.0.0.1:xxxx/v1 . Azure OpenAI:https://xxxx.openai.azure.com
> Support for calling multiple GPTs.Local LLM 、 ChatGPT、ChatGLM3 、ChatGLM4 , Some code provided by rui. If you are using OpenAI's service, fill in https://api.openai.com/v1 . If you are using a local LLM service, fill in http://127.0.0.1:xxxx/v1 . Azure OpenAI:https://xxxx.openai.azure.com
[LLM_base_workflow](./workflow/LLM_base_workflow.json)

Expand Down Expand Up @@ -259,10 +261,14 @@ Add edges to an image.

![FeatheredMask](./assets/FlVou_Y6kaGWYoEj1Tn0aTd4AjMI.jpg)

> LaMaInpainting
> LaMaInpainting(需要手动安装)
* simple-lama-inpainting 里的pillow造成冲突,暂时从依赖里移除,如果有安装 simple-lama-inpainting ,节点会自动添加,没有,则不会自动添加。

from [simple-lama-inpainting](https://github.com/enesmsahin/simple-lama-inpainting)

* [问题汇总](https://github.com/shadowcz007/comfyui-mixlab-nodes/issues/294)

> rembgNode
"briarmbg","u2net","u2netp","u2net_human_seg","u2net_cloth_seg","silueta","isnet-general-use","isnet-anime"
Expand Down
44 changes: 28 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,35 @@
print("or")
print("pip install -r requirements.txt")
sys.exit()

def is_installed(package, package_overwrite=None):


def is_installed(package, package_overwrite=None,auto_install=True):
is_has=False
try:
spec = importlib.util.find_spec(package)
is_has=spec is not None
except ModuleNotFoundError:
pass

package = package_overwrite or package

if spec is None:
print(f"Installing {package}...")
# 清华源 -i https://pypi.tuna.tsinghua.edu.cn/simple
command = f'"{python}" -m pip install {package}'

result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ)

if result.returncode != 0:
print(f"Couldn't install\nCommand: {command}\nError code: {result.returncode}")
if auto_install==True:
print(f"Installing {package}...")
# 清华源 -i https://pypi.tuna.tsinghua.edu.cn/simple
command = f'"{python}" -m pip install {package}'

result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ)

is_has=True

if result.returncode != 0:
print(f"Couldn't install\nCommand: {command}\nError code: {result.returncode}")
is_has=False
else:
print(package+'## OK')

return is_has

try:
import OpenSSL
Expand All @@ -88,7 +97,6 @@ def is_installed(package, package_overwrite=None):
sys.exit()



def install_openai():
# Helper function to install the OpenAI module if not already installed
try:
Expand Down Expand Up @@ -1172,7 +1180,7 @@ def mix_status(request):
# print('\033[91m ### Mixlab Nodes: \033[93mLoaded')

try:
from .nodes.ChatGPT import ChatGPTNode,ShowTextForGPT,CharacterInText,TextSplitByDelimiter,SiliconflowFreeNode
from .nodes.ChatGPT import JsonRepair,ChatGPTNode,ShowTextForGPT,CharacterInText,TextSplitByDelimiter,SiliconflowFreeNode
logging.info('ChatGPT.available True')

NODE_CLASS_MAPPINGS_V = {
Expand All @@ -1181,6 +1189,7 @@ def mix_status(request):
"ShowTextForGPT":ShowTextForGPT,
"CharacterInText":CharacterInText,
"TextSplitByDelimiter":TextSplitByDelimiter,
"JsonRepair":JsonRepair
}

# 一个包含节点友好/可读的标题的字典
Expand All @@ -1190,6 +1199,7 @@ def mix_status(request):
"ShowTextForGPT":"Show Text ♾️MixlabApp",
"CharacterInText":"Character In Text",
"TextSplitByDelimiter":"Text Split By Delimiter",
"JsonRepair":"Json Repair"
}


Expand All @@ -1209,10 +1219,12 @@ def mix_status(request):
logging.info('edit_mask.available False')

try:
from .nodes.Lama import LaMaInpainting
logging.info('LaMaInpainting.available {}'.format(LaMaInpainting.available))
if LaMaInpainting.available:
NODE_CLASS_MAPPINGS['LaMaInpainting']=LaMaInpainting
is_has=is_installed('simple_lama_inpainting',None,False)
if is_has:
from .nodes.Lama import LaMaInpainting
logging.info('LaMaInpainting.available {}'.format(LaMaInpainting.available))
if LaMaInpainting.available:
NODE_CLASS_MAPPINGS['LaMaInpainting']=LaMaInpainting
except Exception as e:
logging.info('LaMaInpainting.available False')

Expand Down
115 changes: 94 additions & 21 deletions nodes/ChatGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,69 @@
import hashlib
import codecs,sys
import importlib.util
import subprocess

python = sys.executable

def is_installed(package):
# 从文本中提取json
def extract_json_strings(text):
json_strings = []
brace_level = 0
json_str = ''
in_json = False

for char in text:
if char == '{':
brace_level += 1
in_json = True
if in_json:
json_str += char
if char == '}':
brace_level -= 1
if in_json and brace_level == 0:
json_strings.append(json_str)
json_str = ''
in_json = False

return json_strings[0] if len(json_strings)>0 else "{}"


def is_installed(package, package_overwrite=None,auto_install=True):
is_has=False
try:
spec = importlib.util.find_spec(package)
is_has=spec is not None
except ModuleNotFoundError:
return False
return spec is not None
pass

package = package_overwrite or package

if spec is None:
if auto_install==True:
print(f"Installing {package}...")
# 清华源 -i https://pypi.tuna.tsinghua.edu.cn/simple
command = f'"{python}" -m pip install {package}'

result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ)

is_has=True

if result.returncode != 0:
print(f"Couldn't install\nCommand: {command}\nError code: {result.returncode}")
is_has=False
else:
print(package+'## OK')

return is_has



# def is_installed(package):
# try:
# spec = importlib.util.find_spec(package)
# except ModuleNotFoundError:
# return False
# return spec is not None


def get_unique_hash(string):
Expand Down Expand Up @@ -59,24 +114,8 @@ def openai_client(key,url):
return client

def ZhipuAI_client(key):

try:
if is_installed('zhipuai')==False:
import subprocess

# 安装
print('#pip install zhipuai')

result = subprocess.run([sys.executable, '-s', '-m', 'pip', 'install', 'zhipuai'], capture_output=True, text=True)

#检查命令执行结果
if result.returncode == 0:
print("#install success")
from zhipuai import ZhipuAI
else:
print("#install error")

else:
if is_installed('zhipuai')==True:
from zhipuai import ZhipuAI
except:
print("#install zhipuai error")
Expand Down Expand Up @@ -160,7 +199,9 @@ def get_llama_path():

# return llm



if is_installed('json_repair'):
from json_repair import repair_json


def chat(client, model_name,messages ):
Expand Down Expand Up @@ -645,3 +686,35 @@ def run(self, text,delimiter,start_index,skip_every,max_count):
arr= arr[start_index:start_index + max_count * (skip_every+1):(skip_every+1)]

return (arr,)


class JsonRepair:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"json_string":("STRING", {"forceInput": True,}),
}
}

INPUT_IS_LIST = False
RETURN_TYPES = ("STRING",)
FUNCTION = "run"
# OUTPUT_NODE = True
OUTPUT_IS_LIST = (False,)

CATEGORY = "♾️Mixlab/GPT"

def run(self, json_string):

json_string=extract_json_strings(json_string)
# print(json_string)
good_json_string = repair_json(json_string)

# 将 JSON 字符串解析为 Python 对象
data = json.loads(good_json_string)

# 将 Python 对象转换回 JSON 字符串,确保中文字符不被转义
json_str_with_chinese = json.dumps(data, ensure_ascii=False)

return (json_str_with_chinese,)
14 changes: 7 additions & 7 deletions nodes/ImageNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,29 +1515,29 @@ def INPUT_TYPES(s):
"font": (get_files_with_extension(FONT_PATH,['.ttf','.otf']),),#后缀为 ttf
"font_size": ("INT",{
"default":100,
"min": 100, #Minimum value
"max": 1000, #Maximum value
"min": 1, #Minimum value
"max": 10000000, #Maximum value
"step": 1, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider"
}),
"spacing": ("INT",{
"default":12,
"min": -200, #Minimum value
"max": 200, #Maximum value
"min": -2000000000, #Minimum value
"max": 2000000000, #Maximum value
"step": 1, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider"
}),
"line_spacing": ("INT",{
"default":12,
"min": -200, #Minimum value
"max": 200, #Maximum value
"min": -2000000000, #Minimum value
"max": 2000000000, #Maximum value
"step": 1, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider"
}),
"padding": ("INT",{
"default":8,
"min": 0, #Minimum value
"max": 200, #Maximum value
"max": 2000000000, #Maximum value
"step": 1, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider"
}),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-mixlab-nodes"
description = "3D, ScreenShareNode & FloatingVideoNode, SpeechRecognition & SpeechSynthesis, GPT, LoadImagesFromLocal, Layers, Other Nodes, ..."
version = "0.35.1"
version = "0.35.2"
license = "MIT"
dependencies = ["numpy", "pyOpenSSL", "watchdog", "opencv-python-headless", "matplotlib", "openai", "simple-lama-inpainting", "clip-interrogator==0.6.0", "transformers>=4.36.0", "lark-parser", "imageio-ffmpeg", "rembg[gpu]", "omegaconf==2.3.0", "Pillow>=9.5.0", "einops==0.7.0", "trimesh>=4.0.5", "huggingface-hub", "scikit-image"]

Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ watchdog
opencv-python-headless
matplotlib
openai
simple-lama-inpainting
# simple-lama-inpainting
clip-interrogator==0.6.0
transformers>=4.36.0
lark-parser
Expand All @@ -17,4 +17,5 @@ trimesh>=4.0.5
huggingface-hub
scikit-image
torchaudio
soundfile>=0.12.1
soundfile>=0.12.1
json-repair

0 comments on commit fc9a1c6

Please sign in to comment.