From 9bb6e8919d2aed52d30335a864d1ef109a890898 Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 03:42:52 +0800 Subject: [PATCH 1/8] 'update' --- __init__.py | 242 ++++++++----------------- mz_gen_translate.py | 1 + mz_llama_core_nodes.py | 216 +++++++++++++++++++++++ mz_llama_cpp.py | 302 +++----------------------------- mz_llava.py | 8 +- mz_openaiapi.py | 6 +- mz_prompt_utils.py | 6 + mz_prompt_webserver.py | 2 +- mz_prompts.py | 15 ++ v1/init.py | 195 +++++++++++++++++++++ v1/mz_deprecated.py | 160 +++++++++++++++++ mz_llama3.py => v1/mz_llama3.py | 12 +- mz_phi3.py => v1/mz_phi3.py | 11 +- web/prompt_mz.js | 4 - 14 files changed, 708 insertions(+), 472 deletions(-) create mode 100644 mz_llama_core_nodes.py create mode 100644 v1/init.py create mode 100644 v1/mz_deprecated.py rename mz_llama3.py => v1/mz_llama3.py (92%) rename mz_phi3.py => v1/mz_phi3.py (92%) diff --git a/__init__.py b/__init__.py index 159e56e..1744806 100644 --- a/__init__.py +++ b/__init__.py @@ -8,6 +8,7 @@ from nodes import MAX_RESOLUTION import comfy.utils import shutil import comfy.samplers +import folder_paths WEB_DIRECTORY = "./web" @@ -15,12 +16,12 @@ WEB_DIRECTORY = "./web" AUTHOR_NAME = u"MinusZone" CATEGORY_NAME = f"{AUTHOR_NAME} - Prompt" -sys.path.append(os.path.join(os.path.dirname(__file__))) +# sys.path.append(os.path.join(os.path.dirname(__file__))) import importlib -import mz_prompt_webserver -mz_prompt_webserver.start_server() +# import mz_prompt_webserver +# mz_prompt_webserver.start_server() NODE_CLASS_MAPPINGS = { } @@ -29,11 +30,64 @@ NODE_CLASS_MAPPINGS = { NODE_DISPLAY_NAME_MAPPINGS = { } + +from . import mz_llama_cpp +from . import mz_llava -import mz_llama3 -import mz_phi3 -import mz_llama_cpp -import mz_llava + +class MZ_LLamaCPPModelConfig_ManualSelect: + @classmethod + def INPUT_TYPES(s): + gguf_files = folder_paths.get_filename_list("gguf") + return { + "required": { + "llama_cpp_model": (gguf_files,), + }, + "optional": { + }, + } + + RETURN_TYPES = ("LLamaCPPModelConfig",) + RETURN_NAMES = ("llama_cpp_model_config",) + + FUNCTION = "create" + CATEGORY = CATEGORY_NAME + + def create(self, **kwargs): + return (kwargs,) + + +class MZ_LLamaCPPCLIPTextEncode: + @classmethod + def INPUT_TYPES(s): + importlib.reload(mz_llama_cpp) + + result = { + "required": { + }, + "optional": { + "llama_cpp_model": ("LLamaCPPModelConfig",), + }, + } + + common_input = getCommonCLIPTextEncodeInput() + for key in common_input["required"]: + result["required"][key] = common_input["required"][key] + for key in common_input["optional"]: + result["optional"][key] = common_input["optional"][key] + + return result + RETURN_TYPES = ("STRING", "CONDITIONING",) + RETURN_NAMES = ("text", "conditioning",) + OUTPUT_NODE = True + FUNCTION = "encode" + CATEGORY = CATEGORY_NAME + + def encode(self, **kwargs): + from . import mz_llama_core_nodes + importlib.reload(mz_llama_core_nodes) + + return mz_llama_core_nodes.llama_cpp_node_encode(kwargs) class MZ_LLamaCPPOptions: @@ -83,13 +137,12 @@ NODE_DISPLAY_NAME_MAPPINGS["MZ_LLamaCPPOptions"] = f"{AUTHOR_NAME} - LLamaCPPOpt class MZ_CustomizeInstruct: @classmethod def INPUT_TYPES(s): - import mz_prompts + from . import mz_prompts + return { "required": { "system": ("STRING", {"multiline": True, "default": mz_prompts.Long_prompt}), "instruct": ("STRING", {"multiline": True, "default": "Short: %text%"}), - "start_str": ("STRING", {"default": "Long: "}), - "end_str": ("STRING", {"default": ""}), }, } @@ -107,7 +160,8 @@ NODE_DISPLAY_NAME_MAPPINGS["MZ_CustomizeInstruct"] = f"{AUTHOR_NAME} - Customize def getCommonCLIPTextEncodeInput(): - style_presets = mz_llama_cpp.get_style_presets() + from . import mz_llama_core_nodes + style_presets = mz_llama_core_nodes.get_style_presets() CommonCLIPTextEncodeInput = { "required": { "prompt_version": (["v1"], {"default": "v1"}), @@ -129,162 +183,6 @@ def getCommonCLIPTextEncodeInput(): return CommonCLIPTextEncodeInput -class MZ_LLama3CLIPTextEncode: - @classmethod - def INPUT_TYPES(s): - m_models = mz_llama3.llama3_models.copy() - for i in range(len(m_models)): - if mz_llama3.get_exist_model(m_models[i]) is not None: - m_models[i] += "[downloaded]" - - importlib.reload(mz_llama_cpp) - - result = { - "required": { - "llama_cpp_model": (m_models, {"default": m_models[0]}), - "download_source": ( - ["none", "modelscope", "hf-mirror.com",], - {"default": "none"} - ), - }, - "optional": {}, - } - - common_input = getCommonCLIPTextEncodeInput() - for key in common_input["required"]: - result["required"][key] = common_input["required"][key] - for key in common_input["optional"]: - result["optional"][key] = common_input["optional"][key] - - return result - - RETURN_TYPES = ("STRING", "CONDITIONING",) - RETURN_NAMES = ("text", "conditioning",) - OUTPUT_NODE = True - FUNCTION = "encode" - CATEGORY = CATEGORY_NAME - - def encode(self, **kwargs): - importlib.reload(mz_llama3) - - kwargs["llama_cpp_model"] = kwargs.get( - "llama_cpp_model", "").replace("[downloaded]", "") - - text = mz_llama3.query_beautify_prompt_text(kwargs) - conditionings = None - clip = kwargs.get("clip", None) - if clip is not None: - conditionings = Utils.a1111_clip_text_encode(clip, text, ) - - return {"ui": {"string": [text,]}, "result": (text, conditionings)} - - -NODE_CLASS_MAPPINGS["MZ_LLama3CLIPTextEncode"] = MZ_LLama3CLIPTextEncode -NODE_DISPLAY_NAME_MAPPINGS[ - "MZ_LLama3CLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(LLama3)" - - -class MZ_Phi3CLIPTextEncode: - @classmethod - def INPUT_TYPES(s): - m_models = mz_phi3.phi3_models.copy() - for i in range(len(m_models)): - if mz_llama3.get_exist_model(m_models[i]) is not None: - m_models[i] += "[downloaded]" - - importlib.reload(mz_phi3) - - result = { - "required": { - "llama_cpp_model": (m_models, {"default": m_models[0]}), - "download_source": ( - ["none", "modelscope", "hf-mirror.com",], - {"default": "none"} - ), - }, - "optional": {}, - } - - common_input = getCommonCLIPTextEncodeInput() - for key in common_input["required"]: - result["required"][key] = common_input["required"][key] - for key in common_input["optional"]: - result["optional"][key] = common_input["optional"][key] - - return result - - RETURN_TYPES = ("STRING", "CONDITIONING",) - RETURN_NAMES = ("text", "conditioning",) - OUTPUT_NODE = True - FUNCTION = "encode" - CATEGORY = CATEGORY_NAME - - def encode(self, **kwargs): - importlib.reload(mz_llama3) - - kwargs["llama_cpp_model"] = kwargs.get( - "llama_cpp_model", "").replace("[downloaded]", "") - - text = mz_phi3.query_beautify_prompt_text(kwargs) - conditionings = None - clip = kwargs.get("clip", None) - if clip is not None: - conditionings = Utils.a1111_clip_text_encode(clip, text, ) - - return {"ui": {"string": [text,]}, "result": (text, conditionings)} - - -NODE_CLASS_MAPPINGS["MZ_Phi3CLIPTextEncode"] = MZ_Phi3CLIPTextEncode -NODE_DISPLAY_NAME_MAPPINGS[ - "MZ_Phi3CLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(Phi3)" - - -class MZ_BaseLLamaCPPCLIPTextEncode: - @classmethod - def INPUT_TYPES(s): - importlib.reload(mz_llama_cpp) - - result = { - "required": { - "llama_cpp_model": ("STRING", {"default": "", "placeholder": "model_path"}), - }, - "optional": { - }, - } - - common_input = getCommonCLIPTextEncodeInput() - for key in common_input["required"]: - result["required"][key] = common_input["required"][key] - for key in common_input["optional"]: - result["optional"][key] = common_input["optional"][key] - - return result - RETURN_TYPES = ("STRING", "CONDITIONING",) - RETURN_NAMES = ("text", "conditioning",) - OUTPUT_NODE = True - FUNCTION = "encode" - CATEGORY = CATEGORY_NAME - - def encode(self, **kwargs): - importlib.reload(mz_llama3) - - kwargs["llama_cpp_model"] = kwargs.get( - "llama_cpp_model", "").replace("[downloaded]", "") - - text = mz_llama_cpp.base_query_beautify_prompt_text(kwargs) - conditionings = None - clip = kwargs.get("clip", None) - if clip is not None: - conditionings = Utils.a1111_clip_text_encode(clip, text, ) - - return {"ui": {"string": [text,]}, "result": (text, conditionings)} - - -NODE_CLASS_MAPPINGS["MZ_BaseLLamaCPPCLIPTextEncode"] = MZ_BaseLLamaCPPCLIPTextEncode -NODE_DISPLAY_NAME_MAPPINGS[ - "MZ_BaseLLamaCPPCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(BaseLLamaCPP)" - - class MZ_LLavaImageInterrogator: @classmethod def INPUT_TYPES(s): @@ -518,6 +416,12 @@ NODE_CLASS_MAPPINGS["MZ_OpenAIApiCLIPTextEncode"] = MZ_OpenAIApiCLIPTextEncode NODE_DISPLAY_NAME_MAPPINGS[ "MZ_OpenAIApiCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(OpenAIApi)" - -import mz_gen_translate +from . import mz_gen_translate mz_gen_translate.gen_translate(NODE_DISPLAY_NAME_MAPPINGS, NODE_CLASS_MAPPINGS) + + +from .v1.init import NODE_CLASS_MAPPINGS as DEPRECATED_NODE_CLASS_MAPPINGS +from .v1.init import NODE_DISPLAY_NAME_MAPPINGS as DEPRECATED_NODE_DISPLAY_NAME_MAPPINGS + +NODE_CLASS_MAPPINGS.update(DEPRECATED_NODE_CLASS_MAPPINGS) +NODE_DISPLAY_NAME_MAPPINGS.update(DEPRECATED_NODE_DISPLAY_NAME_MAPPINGS) diff --git a/mz_gen_translate.py b/mz_gen_translate.py index 0baac8b..e395c7f 100644 --- a/mz_gen_translate.py +++ b/mz_gen_translate.py @@ -26,6 +26,7 @@ ZH_Replace_Map = { "ImageInterrogator": "图像反推", "customize_instruct": "自定义指令", "CustomizeInstruct": "自定义指令", + "deprecated": "已废弃", } diff --git a/mz_llama_core_nodes.py b/mz_llama_core_nodes.py new file mode 100644 index 0000000..c3b3308 --- /dev/null +++ b/mz_llama_core_nodes.py @@ -0,0 +1,216 @@ + +import importlib +import json +from . import mz_prompt_utils +from . import mz_llama_cpp +from . import mz_prompts + + +def get_schema_base_type(t): + return { + "type": t, + } + + +def get_schema_obj(keys_type={}, required=[]): + item = {} + for key, value in keys_type.items(): + if type(value) == str: + value = get_schema_base_type(value) + item[key] = value + return { + "type": "object", + "properties": item, + "required": required + } + + +def get_schema_array(item_type="string"): + if type(item_type) == str: + item_type = get_schema_base_type(item_type) + return { + "type": "array", + "items": item_type, + } + + +high_quality_prompt = "((high quality:1.4), (best quality:1.4), (masterpiece:1.4), (8K resolution), (2k wallpaper))" +style_presets_prompt = { + "none": "", + "high_quality": high_quality_prompt, + "photography": f"{high_quality_prompt}, (RAW photo, best quality), (realistic, photo-realistic:1.2), (bokeh, cinematic shot, dynamic composition, incredibly detailed, sharpen, details, intricate detail, professional lighting, film lighting, 35mm, anamorphic, lightroom, cinematography, bokeh, lens flare, film grain, HDR10, 8K)", + "illustration": f"{high_quality_prompt}, ((detailed matte painting, intricate detail, splash screen, complementary colors), (detailed),(intricate details),illustration,an extremely delicate and beautiful,ultra-detailed,highres,extremely detailed)", +} + + +def get_style_presets(): + return [ + "none", + "high_quality", + "photography", + "illustration", + ] + + +def llama_cpp_node_encode(args_dict): + importlib.reload(mz_prompts) + importlib.reload(mz_llama_cpp) + + model_file = args_dict.get("llama_cpp_model", "") + text = args_dict.get("text", "") + style_presets = args_dict.get("style_presets", "") + options = args_dict.get("llama_cpp_options", {}) + keep_device = args_dict.get("keep_device", False) + seed = args_dict.get("seed", -1) + options["seed"] = seed + + customize_instruct = args_dict.get("customize_instruct", None) + mz_prompt_utils.Utils.print_log( + f"customize_instruct: {customize_instruct}") + try: + schema = None + if customize_instruct is None: + schema = get_schema_obj( + keys_type={ + "description": get_schema_base_type("string"), + "long_prompt": get_schema_base_type("string"), + "main_color_word": get_schema_base_type("string"), + "camera_angle_word": get_schema_base_type("string"), + "style_words": get_schema_array("string"), + "subject_words": get_schema_array("string"), + "light_words": get_schema_array("string"), + "environment_words": get_schema_array("string"), + }, + required=[ + "description", + "long_prompt", + "main_color_word", + "camera_angle_word", + "style_words", + "subject_words", + "light_words", + "environment_words", + ] + ) + + question = f"IDEA: {style_presets},{text}" + if style_presets == "none": + question = f"IDEA: {text}" + + system_prompt = mz_prompts.Beautify_Prompt + mz_prompts.Long_prompt + "\n" + + else: + + system_prompt = customize_instruct.get("system", "") + question = customize_instruct.get("instruct", "%text%") + + system_prompt = system_prompt.replace("%text%", text) + question = question.replace("%text%", text) + + mz_prompt_utils.Utils.print_log(f"system_prompt: {system_prompt}") + mz_prompt_utils.Utils.print_log(f"question: {question}") + + if schema is not None: + response_json = mz_llama_cpp.llama_cpp_simple_interrogator_to_json( + model_file=model_file, + system=system_prompt, + question=question, + schema=schema, + options=options, + ) + mz_prompt_utils.Utils.print_log(f"response_json: {response_json}") + + response = json.loads(response_json) + full_responses = [] + + if response["description"] != "": + full_responses.append(f"({response['description']})") + if response["long_prompt"] != "": + full_responses.append(f"({response['long_prompt']})") + if response["main_color_word"] != "": + full_responses.append(f"({response['main_color_word']})") + if response["camera_angle_word"] != "": + full_responses.append(f"({response['camera_angle_word']})") + + response["style_words"] = [ + x for x in response["style_words"] if x != ""] + if len(response["style_words"]) > 0: + full_responses.append( + f"({', '.join(response['style_words'])})") + + response["subject_words"] = [ + x for x in response["subject_words"] if x != ""] + if len(response["subject_words"]) > 0: + full_responses.append( + f"({', '.join(response['subject_words'])})") + + response["light_words"] = [ + x for x in response["light_words"] if x != ""] + if len(response["light_words"]) > 0: + full_responses.append( + f"({', '.join(response['light_words'])})") + + response["environment_words"] = [ + x for x in response["environment_words"] if x != ""] + if len(response["environment_words"]) > 0: + full_responses.append( + f"({', '.join(response['environment_words'])})") + + full_response = ", ".join(full_responses) + else: + full_response = mz_llama_cpp.llama_cpp_simple_interrogator( + model_file=model_file, + system=system_prompt, + question=question, + options=options, + ) + + start_str = customize_instruct.get("start_str", "") + if start_str != "" and full_response.find(start_str) != -1: + full_response_list = full_response.split(start_str) + # 删除第一个元素 + full_response_list.pop(0) + full_response = start_str.join(full_response_list) + + end_str = customize_instruct.get("end_str", "") + if end_str != "" and full_response.find(end_str) != -1: + full_response_list = full_response.split(end_str) + # 删除最后一个元素 + full_response_list.pop() + full_response = end_str.join(full_response_list) + + if keep_device is False: + mz_llama_cpp.freed_gpu_memory(model_file=model_file) + + # 去除换行 + while full_response.find("\n") != -1: + full_response = full_response.replace("\n", " ") + + # 句号换成逗号 + while full_response.find(".") != -1: + full_response = full_response.replace(".", ",") + + # 去除多余逗号 + while full_response.find(",,") != -1: + full_response = full_response.replace(",,", ",") + while full_response.find(", ,") != -1: + full_response = full_response.replace(", ,", ",") + + full_response = mz_prompt_utils.Utils.prompt_zh_to_en(full_response) + + style_presets_prompt_text = style_presets_prompt.get(style_presets, "") + + if style_presets_prompt_text != "": + full_response = f"{style_presets_prompt_text}, {full_response}" + + except Exception as e: + mz_llama_cpp.freed_gpu_memory(model_file=model_file) + raise e + + conditionings = None + clip = args_dict.get("clip", None) + if clip is not None: + conditionings = mz_prompt_utils.Utils.a1111_clip_text_encode( + clip, full_response, ) + + return {"ui": {"string": [full_response,]}, "result": (full_response, conditionings)} diff --git a/mz_llama_cpp.py b/mz_llama_cpp.py index 3a33df4..84a44e8 100644 --- a/mz_llama_cpp.py +++ b/mz_llama_cpp.py @@ -6,40 +6,12 @@ import subprocess import sys import torch try: - import mz_prompt_utils - import mz_prompt_webserver + from . import mz_prompt_utils + from . import mz_prompt_webserver except ImportError: pass -def LlamaCppOptions(): - return { - "n_ctx": 2048, - "n_batch": 2048, - "n_threads": 0, - "n_threads_batch": 0, - "split_mode": ["LLAMA_SPLIT_MODE_NONE", "LLAMA_SPLIT_MODE_LAYER", "LLAMA_SPLIT_MODE_ROW",], - "main_gpu": 0, - "n_gpu_layers": -1, - - - "max_tokens": 4096, - "temperature": 1.6, - "top_p": 0.95, - "min_p": 0.05, - "typical_p": 1.0, - "stop": "", - "frequency_penalty": 0.0, - "presence_penalty": 0.0, - "repeat_penalty": 1.1, - "top_k": 50, - "tfs_z": 1.0, - "mirostat_mode": ["none", "mirostat", "mirostat_v2"], - "mirostat_tau": 5.0, - "mirostat_eta": 0.1, - } - - def check_llama_cpp_requirements(): last_version = "0.2.63" try: @@ -103,6 +75,32 @@ def check_llama_cpp_requirements(): print("llama_cpp installed successfully. (llama_cpp安装成功)") +def LlamaCppOptions(): + return { + "n_ctx": 2048, + "n_batch": 2048, + "n_threads": 0, + "n_threads_batch": 0, + "split_mode": ["LLAMA_SPLIT_MODE_NONE", "LLAMA_SPLIT_MODE_LAYER", "LLAMA_SPLIT_MODE_ROW",], + "main_gpu": 0, + "n_gpu_layers": -1, + "max_tokens": 4096, + "temperature": 1.6, + "top_p": 0.95, + "min_p": 0.05, + "typical_p": 1.0, + "stop": "", + "frequency_penalty": 0.0, + "presence_penalty": 0.0, + "repeat_penalty": 1.1, + "top_k": 50, + "tfs_z": 1.0, + "mirostat_mode": ["none", "mirostat", "mirostat_v2"], + "mirostat_tau": 5.0, + "mirostat_eta": 0.1, + } + + def freed_gpu_memory(model_file): check_llama_cpp_requirements() @@ -237,33 +235,6 @@ def llama_cpp_messages(model_file, chat_handler=None, messages=[], options={}): return result -def get_schema_base_type(t): - return { - "type": t, - } - - -def get_schema_obj(keys_type={}, required=[]): - item = {} - for key, value in keys_type.items(): - if type(value) == str: - value = get_schema_base_type(value) - item[key] = value - return { - "type": "object", - "properties": item, - "required": required - } - - -def get_schema_array(item_type="string"): - if type(item_type) == str: - item_type = get_schema_base_type(item_type) - return { - "type": "array", - "items": item_type, - } - def llama_cpp_simple_interrogator_to_json(model_file, use_system=True, system=None, question="", schema={}, options={}): if system is None: @@ -409,220 +380,3 @@ def llava_cpp_simple_interrogator_to_json( model_file, mmproj_file, system=system, question=question, image=image, options=options) return result - -high_quality_prompt = "((high quality:1.4), (best quality:1.4), (masterpiece:1.4), (8K resolution), (2k wallpaper))" -style_presets_prompt = { - "none": "", - "high_quality": high_quality_prompt, - "photography": f"{high_quality_prompt}, (RAW photo, best quality), (realistic, photo-realistic:1.2), (bokeh, cinematic shot, dynamic composition, incredibly detailed, sharpen, details, intricate detail, professional lighting, film lighting, 35mm, anamorphic, lightroom, cinematography, bokeh, lens flare, film grain, HDR10, 8K)", - "illustration": f"{high_quality_prompt}, ((detailed matte painting, intricate detail, splash screen, complementary colors), (detailed),(intricate details),illustration,an extremely delicate and beautiful,ultra-detailed,highres,extremely detailed)", -} - - -def get_style_presets(): - return [ - "none", - "high_quality", - "photography", - "illustration", - ] - - -def base_query_beautify_prompt_text(args_dict): - model_file = args_dict.get("llama_cpp_model", "") - - text = args_dict.get("text", "") - style_presets = args_dict.get("style_presets", "") - options = args_dict.get("llama_cpp_options", {}) - keep_device = args_dict.get("keep_device", False) - seed = args_dict.get("seed", -1) - options["seed"] = seed - - import mz_prompts - importlib.reload(mz_prompts) - - customize_instruct = args_dict.get("customize_instruct", None) - mz_prompt_utils.Utils.print_log( - f"customize_instruct: {customize_instruct}") - try: - schema = None - if customize_instruct is None: - schema = get_schema_obj( - keys_type={ - "description": get_schema_base_type("string"), - "long_prompt": get_schema_base_type("string"), - "main_color_word": get_schema_base_type("string"), - "camera_angle_word": get_schema_base_type("string"), - "style_words": get_schema_array("string"), - "subject_words": get_schema_array("string"), - "light_words": get_schema_array("string"), - "environment_words": get_schema_array("string"), - }, - required=[ - "description", - "long_prompt", - "main_color_word", - "camera_angle_word", - "style_words", - "subject_words", - "light_words", - "environment_words", - ] - ) - - question = f"IDEA: {style_presets},{text}" - if style_presets == "none": - question = f"IDEA: {text}" - - system_prompt = mz_prompts.Beautify_Prompt + mz_prompts.Long_prompt + "\n" - - else: - - system_prompt = customize_instruct.get("system", "") - question = customize_instruct.get("instruct", "%text%") - - system_prompt = system_prompt.replace("%text%", text) - question = question.replace("%text%", text) - - mz_prompt_utils.Utils.print_log(f"system_prompt: {system_prompt}") - mz_prompt_utils.Utils.print_log(f"question: {question}") - - if schema is not None: - response_json = llama_cpp_simple_interrogator_to_json( - model_file=model_file, - system=system_prompt, - question=question, - schema=schema, - options=options, - ) - mz_prompt_utils.Utils.print_log(f"response_json: {response_json}") - - response = json.loads(response_json) - full_responses = [] - - if response["description"] != "": - full_responses.append(f"({response['description']})") - if response["long_prompt"] != "": - full_responses.append(f"({response['long_prompt']})") - if response["main_color_word"] != "": - full_responses.append(f"({response['main_color_word']})") - if response["camera_angle_word"] != "": - full_responses.append(f"({response['camera_angle_word']})") - - response["style_words"] = [ - x for x in response["style_words"] if x != ""] - if len(response["style_words"]) > 0: - full_responses.append( - f"({', '.join(response['style_words'])})") - - response["subject_words"] = [ - x for x in response["subject_words"] if x != ""] - if len(response["subject_words"]) > 0: - full_responses.append( - f"({', '.join(response['subject_words'])})") - - response["light_words"] = [ - x for x in response["light_words"] if x != ""] - if len(response["light_words"]) > 0: - full_responses.append( - f"({', '.join(response['light_words'])})") - - response["environment_words"] = [ - x for x in response["environment_words"] if x != ""] - if len(response["environment_words"]) > 0: - full_responses.append( - f"({', '.join(response['environment_words'])})") - - full_response = ", ".join(full_responses) - else: - full_response = llama_cpp_simple_interrogator( - model_file=model_file, - system=system_prompt, - question=question, - options=options, - ) - - start_str = customize_instruct.get("start_str", "") - if start_str != "" and full_response.find(start_str) != -1: - full_response_list = full_response.split(start_str) - # 删除第一个元素 - full_response_list.pop(0) - full_response = start_str.join(full_response_list) - - end_str = customize_instruct.get("end_str", "") - if end_str != "" and full_response.find(end_str) != -1: - full_response_list = full_response.split(end_str) - # 删除最后一个元素 - full_response_list.pop() - full_response = end_str.join(full_response_list) - - if keep_device is False: - freed_gpu_memory(model_file=model_file) - - # 去除换行 - while full_response.find("\n") != -1: - full_response = full_response.replace("\n", " ") - - # 句号换成逗号 - while full_response.find(".") != -1: - full_response = full_response.replace(".", ",") - - # 去除多余逗号 - while full_response.find(",,") != -1: - full_response = full_response.replace(",,", ",") - while full_response.find(", ,") != -1: - full_response = full_response.replace(", ,", ",") - - full_response = mz_prompt_utils.Utils.prompt_zh_to_en(full_response) - - style_presets_prompt_text = style_presets_prompt.get(style_presets, "") - - if style_presets_prompt_text != "": - full_response = f"{style_presets_prompt_text}, {full_response}" - - return full_response - - except Exception as e: - freed_gpu_memory(model_file=model_file) - # mz_utils.Utils.print_log(f"Error in auto_prompt_text: {e}") - raise e - - -def get_image_composition_json_schema(): - system = "Please make a specific composition of the proposed content. You need to have the width and height of the overall picture and a list of specific element positions." - return system, { - "type": "object", - "properties": { - "width": { - "type": "number" - }, - "height": { - "type": "number" - }, - "bbox": { - "type": "array", - "items": { - "type": "object", - "properties": { - "english_name": { - "type": "string" - }, - "left": { - "type": "number" - }, - "top": { - "type": "number" - }, - "width": { - "type": "number" - }, - "height": { - "type": "number" - } - }, - "required": ["english_name", "left", "top", "width", "height"] - } - } - }, - "required": ["width", "height", "bbox"] - } diff --git a/mz_llava.py b/mz_llava.py index 7aefab3..7e43491 100644 --- a/mz_llava.py +++ b/mz_llava.py @@ -1,12 +1,12 @@ import json import os -import mz_prompt_utils -import mz_llama_cpp +from . import mz_prompt_utils +from . import mz_llama_cpp +from . import mz_prompts +from . import mz_prompt_webserver import importlib -import mz_prompts -import mz_prompt_webserver LLava_models = [ "llava-1.6-mistral-7b-gguf/llava-v1.6-mistral-7b.Q5_K_M.gguf", diff --git a/mz_openaiapi.py b/mz_openaiapi.py index bdbe9c2..3176d94 100644 --- a/mz_openaiapi.py +++ b/mz_openaiapi.py @@ -3,9 +3,9 @@ import sys import json import subprocess -import mz_prompt_utils -import mz_llama_cpp -import mz_prompts +from . import mz_prompt_utils +from . import mz_llama_cpp +from . import mz_prompts def zhipu_json_fix(input_data): diff --git a/mz_prompt_utils.py b/mz_prompt_utils.py index b061291..d0b3527 100644 --- a/mz_prompt_utils.py +++ b/mz_prompt_utils.py @@ -165,6 +165,12 @@ class Utils: os.makedirs(models_path, exist_ok=True) return models_path + def get_gguf_models_path(): + models_path = os.path.join( + folder_paths.models_dir, "gguf") + os.makedirs(models_path, exist_ok=True) + return models_path + def translate_text(text, from_code, to_code): try: import argostranslate diff --git a/mz_prompt_webserver.py b/mz_prompt_webserver.py index b4e5758..ae0673b 100644 --- a/mz_prompt_webserver.py +++ b/mz_prompt_webserver.py @@ -2,7 +2,7 @@ import asyncio import uuid -import mz_prompt_utils +from . import mz_prompt_utils web_msg_pool = { diff --git a/mz_prompts.py b/mz_prompts.py index c782800..6080cc7 100644 --- a/mz_prompts.py +++ b/mz_prompts.py @@ -18,3 +18,18 @@ Standardize_Prompt = """ Extract the content about Stable Diffusion style from the following input and combine it into a json array. Note that the output will be directly used in the program. Please output the standardized json content. """ + + +# 来自https://github.com/jiayev/GPT4V-Image-Captioner +GPT4VImageCaptioner_Prompt = """ +As an AI image tagging expert, please provide precise tags for these images to enhance CLIP model's understanding of the content. +Employ succinct keywords or phrases, steering clear of elaborate sentences and extraneous conjunctions. +Prioritize the tags by relevance. +Your tags should capture key elements such as the main subject, setting, artistic style, composition, image quality, color tone, filter, and camera specifications, and any other tags crucial for the image. +When tagging photos of people, include specific details like gender, nationality, attire, actions, pose, expressions, accessories, makeup, composition type, age, etc. +For other image categories, apply appropriate and common descriptive tags as well. +Recognize and tag any celebrities, well-known landmark or IPs if clearly featured in the image. +Your tags should be accurate, non-duplicative, and within a 20-75 word count range. +These tags will use for image re-creation, so the closer the resemblance to the original image, the better the tag quality. +Tags should be comma-separated. +""" \ No newline at end of file diff --git a/v1/init.py b/v1/init.py new file mode 100644 index 0000000..3005954 --- /dev/null +++ b/v1/init.py @@ -0,0 +1,195 @@ +from ..mz_prompt_utils import Utils + +NODE_CLASS_MAPPINGS = { +} + + +NODE_DISPLAY_NAME_MAPPINGS = { +} + + +import importlib +from . import mz_llama3 +from . import mz_phi3 +from .. import mz_llama_cpp +from .. import mz_llama_core_nodes + + +AUTHOR_NAME = u"MinusZone" +CATEGORY_NAME = f"{AUTHOR_NAME} - Prompt/deprecated" + + +def getCommonCLIPTextEncodeInput(): + style_presets = mz_llama_core_nodes.get_style_presets() + CommonCLIPTextEncodeInput = { + "required": { + "prompt_version": (["v1"], {"default": "v1"}), + "style_presets": ( + style_presets, {"default": style_presets[1]} + ), + "text": ("STRING", {"multiline": True, }), + "keep_device": ([False, True], {"default": False}), + "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), + }, + "optional": { + "clip": ("CLIP", ), + "llama_cpp_options": ("LLamaCPPOptions", ), + "customize_instruct": ("CustomizeInstruct", ), + # "customize_json_schema": ("STRING", ), + } + } + + return CommonCLIPTextEncodeInput + + +class MZ_LLama3CLIPTextEncode: + @classmethod + def INPUT_TYPES(s): + m_models = mz_llama3.llama3_models.copy() + for i in range(len(m_models)): + if mz_llama3.get_exist_model(m_models[i]) is not None: + m_models[i] += "[downloaded]" + + result = { + "required": { + "llama_cpp_model": (m_models, {"default": m_models[0]}), + "download_source": ( + ["none", "modelscope", "hf-mirror.com",], + {"default": "none"} + ), + }, + "optional": {}, + } + + common_input = getCommonCLIPTextEncodeInput() + for key in common_input["required"]: + result["required"][key] = common_input["required"][key] + for key in common_input["optional"]: + result["optional"][key] = common_input["optional"][key] + + return result + + RETURN_TYPES = ("STRING", "CONDITIONING",) + RETURN_NAMES = ("text", "conditioning",) + OUTPUT_NODE = True + FUNCTION = "encode" + CATEGORY = CATEGORY_NAME + + def encode(self, **kwargs): + + kwargs["llama_cpp_model"] = kwargs.get( + "llama_cpp_model", "").replace("[downloaded]", "") + + text = mz_llama3.query_beautify_prompt_text(kwargs) + conditionings = None + clip = kwargs.get("clip", None) + if clip is not None: + conditionings = Utils.a1111_clip_text_encode(clip, text, ) + + return {"ui": {"string": [text,]}, "result": (text, conditionings)} + + +NODE_CLASS_MAPPINGS["MZ_LLama3CLIPTextEncode"] = MZ_LLama3CLIPTextEncode +NODE_DISPLAY_NAME_MAPPINGS[ + "MZ_LLama3CLIPTextEncode"] = f"{AUTHOR_NAME} - deprecated - CLIPTextEncode(LLama3)" + + +class MZ_Phi3CLIPTextEncode: + @classmethod + def INPUT_TYPES(s): + m_models = mz_phi3.phi3_models.copy() + for i in range(len(m_models)): + if mz_llama3.get_exist_model(m_models[i]) is not None: + m_models[i] += "[downloaded]" + + importlib.reload(mz_phi3) + + result = { + "required": { + "llama_cpp_model": (m_models, {"default": m_models[0]}), + "download_source": ( + ["none", "modelscope", "hf-mirror.com",], + {"default": "none"} + ), + }, + "optional": {}, + } + + common_input = getCommonCLIPTextEncodeInput() + for key in common_input["required"]: + result["required"][key] = common_input["required"][key] + for key in common_input["optional"]: + result["optional"][key] = common_input["optional"][key] + + return result + + RETURN_TYPES = ("STRING", "CONDITIONING",) + RETURN_NAMES = ("text", "conditioning",) + OUTPUT_NODE = True + FUNCTION = "encode" + CATEGORY = CATEGORY_NAME + + def encode(self, **kwargs): + importlib.reload(mz_llama3) + + kwargs["llama_cpp_model"] = kwargs.get( + "llama_cpp_model", "").replace("[downloaded]", "") + + text = mz_phi3.query_beautify_prompt_text(kwargs) + conditionings = None + clip = kwargs.get("clip", None) + if clip is not None: + conditionings = Utils.a1111_clip_text_encode(clip, text, ) + + return {"ui": {"string": [text,]}, "result": (text, conditionings)} + + +NODE_CLASS_MAPPINGS["MZ_Phi3CLIPTextEncode"] = MZ_Phi3CLIPTextEncode +NODE_DISPLAY_NAME_MAPPINGS[ + "MZ_Phi3CLIPTextEncode"] = f"{AUTHOR_NAME} - deprecated - CLIPTextEncode(Phi3)" + + +class MZ_BaseLLamaCPPCLIPTextEncode: + @classmethod + def INPUT_TYPES(s): + importlib.reload(mz_llama_cpp) + + result = { + "required": { + "llama_cpp_model": ("STRING", {"default": "", "placeholder": "model_path"}), + }, + "optional": { + }, + } + + common_input = getCommonCLIPTextEncodeInput() + for key in common_input["required"]: + result["required"][key] = common_input["required"][key] + for key in common_input["optional"]: + result["optional"][key] = common_input["optional"][key] + + return result + RETURN_TYPES = ("STRING", "CONDITIONING",) + RETURN_NAMES = ("text", "conditioning",) + OUTPUT_NODE = True + FUNCTION = "encode" + CATEGORY = CATEGORY_NAME + + def encode(self, **kwargs): + importlib.reload(mz_llama3) + + kwargs["llama_cpp_model"] = kwargs.get( + "llama_cpp_model", "").replace("[downloaded]", "") + + text = mz_llama_cpp.base_query_beautify_prompt_text(kwargs) + conditionings = None + clip = kwargs.get("clip", None) + if clip is not None: + conditionings = Utils.a1111_clip_text_encode(clip, text, ) + + return {"ui": {"string": [text,]}, "result": (text, conditionings)} + + +NODE_CLASS_MAPPINGS["MZ_BaseLLamaCPPCLIPTextEncode"] = MZ_BaseLLamaCPPCLIPTextEncode +NODE_DISPLAY_NAME_MAPPINGS[ + "MZ_BaseLLamaCPPCLIPTextEncode"] = f"{AUTHOR_NAME} - deprecated - CLIPTextEncode(BaseLLamaCPP)" diff --git a/v1/mz_deprecated.py b/v1/mz_deprecated.py new file mode 100644 index 0000000..0d1dbd5 --- /dev/null +++ b/v1/mz_deprecated.py @@ -0,0 +1,160 @@ +from ..mz_prompt_utils import Utils +from ..mz_llama_cpp import * +from ..mz_llama_core_nodes import * +from ..mz_prompts import * + +def base_query_beautify_prompt_text(args_dict): + model_file = args_dict.get("llama_cpp_model", "") + text = args_dict.get("text", "") + style_presets = args_dict.get("style_presets", "") + options = args_dict.get("llama_cpp_options", {}) + keep_device = args_dict.get("keep_device", False) + seed = args_dict.get("seed", -1) + options["seed"] = seed + + + customize_instruct = args_dict.get("customize_instruct", None) + Utils.print_log( + f"customize_instruct: {customize_instruct}") + try: + schema = None + if customize_instruct is None: + schema = get_schema_obj( + keys_type={ + "description": get_schema_base_type("string"), + "long_prompt": get_schema_base_type("string"), + "main_color_word": get_schema_base_type("string"), + "camera_angle_word": get_schema_base_type("string"), + "style_words": get_schema_array("string"), + "subject_words": get_schema_array("string"), + "light_words": get_schema_array("string"), + "environment_words": get_schema_array("string"), + }, + required=[ + "description", + "long_prompt", + "main_color_word", + "camera_angle_word", + "style_words", + "subject_words", + "light_words", + "environment_words", + ] + ) + + question = f"IDEA: {style_presets},{text}" + if style_presets == "none": + question = f"IDEA: {text}" + + system_prompt = mz_prompts.Beautify_Prompt + mz_prompts.Long_prompt + "\n" + + else: + + system_prompt = customize_instruct.get("system", "") + question = customize_instruct.get("instruct", "%text%") + + system_prompt = system_prompt.replace("%text%", text) + question = question.replace("%text%", text) + + Utils.print_log(f"system_prompt: {system_prompt}") + Utils.print_log(f"question: {question}") + + if schema is not None: + response_json = llama_cpp_simple_interrogator_to_json( + model_file=model_file, + system=system_prompt, + question=question, + schema=schema, + options=options, + ) + Utils.print_log(f"response_json: {response_json}") + + response = json.loads(response_json) + full_responses = [] + + if response["description"] != "": + full_responses.append(f"({response['description']})") + if response["long_prompt"] != "": + full_responses.append(f"({response['long_prompt']})") + if response["main_color_word"] != "": + full_responses.append(f"({response['main_color_word']})") + if response["camera_angle_word"] != "": + full_responses.append(f"({response['camera_angle_word']})") + + response["style_words"] = [ + x for x in response["style_words"] if x != ""] + if len(response["style_words"]) > 0: + full_responses.append( + f"({', '.join(response['style_words'])})") + + response["subject_words"] = [ + x for x in response["subject_words"] if x != ""] + if len(response["subject_words"]) > 0: + full_responses.append( + f"({', '.join(response['subject_words'])})") + + response["light_words"] = [ + x for x in response["light_words"] if x != ""] + if len(response["light_words"]) > 0: + full_responses.append( + f"({', '.join(response['light_words'])})") + + response["environment_words"] = [ + x for x in response["environment_words"] if x != ""] + if len(response["environment_words"]) > 0: + full_responses.append( + f"({', '.join(response['environment_words'])})") + + full_response = ", ".join(full_responses) + else: + full_response = llama_cpp_simple_interrogator( + model_file=model_file, + system=system_prompt, + question=question, + options=options, + ) + + start_str = customize_instruct.get("start_str", "") + if start_str != "" and full_response.find(start_str) != -1: + full_response_list = full_response.split(start_str) + # 删除第一个元素 + full_response_list.pop(0) + full_response = start_str.join(full_response_list) + + end_str = customize_instruct.get("end_str", "") + if end_str != "" and full_response.find(end_str) != -1: + full_response_list = full_response.split(end_str) + # 删除最后一个元素 + full_response_list.pop() + full_response = end_str.join(full_response_list) + + if keep_device is False: + freed_gpu_memory(model_file=model_file) + + # 去除换行 + while full_response.find("\n") != -1: + full_response = full_response.replace("\n", " ") + + # 句号换成逗号 + while full_response.find(".") != -1: + full_response = full_response.replace(".", ",") + + # 去除多余逗号 + while full_response.find(",,") != -1: + full_response = full_response.replace(",,", ",") + while full_response.find(", ,") != -1: + full_response = full_response.replace(", ,", ",") + + full_response = Utils.prompt_zh_to_en(full_response) + + style_presets_prompt_text = style_presets_prompt.get(style_presets, "") + + if style_presets_prompt_text != "": + full_response = f"{style_presets_prompt_text}, {full_response}" + + return full_response + + except Exception as e: + freed_gpu_memory(model_file=model_file) + # mz_utils.Utils.print_log(f"Error in auto_prompt_text: {e}") + raise e diff --git a/mz_llama3.py b/v1/mz_llama3.py similarity index 92% rename from mz_llama3.py rename to v1/mz_llama3.py index 6127dd2..06c6005 100644 --- a/mz_llama3.py +++ b/v1/mz_llama3.py @@ -1,7 +1,7 @@ import json -import mz_prompt_utils -import mz_llama_cpp - +from .. import mz_prompt_utils +from .. import mz_llama_cpp +from . import mz_deprecated import importlib @@ -46,10 +46,6 @@ def query_beautify_prompt_text(args_dict): model_name = args_dict.get("llama_cpp_model", "") download_source = args_dict.get("download_source", None) - import mz_prompts - importlib.reload(mz_prompts) - importlib.reload(mz_llama_cpp) - try: model_file = get_exist_model(model_name) @@ -66,7 +62,7 @@ def query_beautify_prompt_text(args_dict): model_file = mz_prompt_utils.Utils.hf_download_model(model_url) args_dict["llama_cpp_model"] = model_file - full_response = mz_llama_cpp.base_query_beautify_prompt_text( + full_response = mz_deprecated.base_query_beautify_prompt_text( args_dict=args_dict) return full_response diff --git a/mz_phi3.py b/v1/mz_phi3.py similarity index 92% rename from mz_phi3.py rename to v1/mz_phi3.py index bb18ce4..1d904a2 100644 --- a/mz_phi3.py +++ b/v1/mz_phi3.py @@ -1,9 +1,6 @@ import json -import mz_prompt_utils -import mz_llama_cpp - -import importlib - +from .. import mz_prompt_utils +from .. import mz_llama_cpp phi3_models = [ "Phi-3-mini-4k-instruct-q4.gguf" @@ -33,10 +30,6 @@ def query_beautify_prompt_text(args_dict): model_name = args_dict.get("llama_cpp_model", "") download_source = args_dict.get("download_source", None) - import mz_prompts - importlib.reload(mz_prompts) - importlib.reload(mz_llama_cpp) - try: model_file = get_exist_model(model_name) diff --git a/web/prompt_mz.js b/web/prompt_mz.js index cf5fd87..7055a59 100644 --- a/web/prompt_mz.js +++ b/web/prompt_mz.js @@ -41,14 +41,10 @@ async function waitMessage() { }; websocket.onclose = async (event) => { console.log("Connection closed", event); - await sleep(1000); - await waitMessage(); }; websocket.onerror = async (event) => { console.log("Connection error", event); - await sleep(1000); - await waitMessage(); }; for (;;) { From 5da9def874340a3f98eac96b313e00194ec7b959 Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 03:49:40 +0800 Subject: [PATCH 2/8] 'update' --- v1/init.py | 11 ++++------- v1/mz_phi3.py | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/v1/init.py b/v1/init.py index 3005954..bcb43a6 100644 --- a/v1/init.py +++ b/v1/init.py @@ -1,5 +1,4 @@ from ..mz_prompt_utils import Utils - NODE_CLASS_MAPPINGS = { } @@ -8,11 +7,12 @@ NODE_DISPLAY_NAME_MAPPINGS = { } -import importlib +import importlib from . import mz_llama3 from . import mz_phi3 from .. import mz_llama_cpp from .. import mz_llama_core_nodes +from . import mz_deprecated AUTHOR_NAME = u"MinusZone" @@ -75,7 +75,7 @@ class MZ_LLama3CLIPTextEncode: FUNCTION = "encode" CATEGORY = CATEGORY_NAME - def encode(self, **kwargs): + def encode(self, **kwargs): kwargs["llama_cpp_model"] = kwargs.get( "llama_cpp_model", "").replace("[downloaded]", "") @@ -176,12 +176,9 @@ class MZ_BaseLLamaCPPCLIPTextEncode: CATEGORY = CATEGORY_NAME def encode(self, **kwargs): - importlib.reload(mz_llama3) - kwargs["llama_cpp_model"] = kwargs.get( "llama_cpp_model", "").replace("[downloaded]", "") - - text = mz_llama_cpp.base_query_beautify_prompt_text(kwargs) + text = mz_deprecated.base_query_beautify_prompt_text(kwargs) conditionings = None clip = kwargs.get("clip", None) if clip is not None: diff --git a/v1/mz_phi3.py b/v1/mz_phi3.py index 1d904a2..a85dfc4 100644 --- a/v1/mz_phi3.py +++ b/v1/mz_phi3.py @@ -1,6 +1,7 @@ import json from .. import mz_prompt_utils from .. import mz_llama_cpp +from . import mz_deprecated phi3_models = [ "Phi-3-mini-4k-instruct-q4.gguf" @@ -46,7 +47,7 @@ def query_beautify_prompt_text(args_dict): model_file = mz_prompt_utils.Utils.hf_download_model(model_url) args_dict["llama_cpp_model"] = model_file - full_response = mz_llama_cpp.base_query_beautify_prompt_text( + full_response = mz_deprecated.base_query_beautify_prompt_text( args_dict=args_dict) return full_response From 91c812971cdf3eb34d07b861b37df518f53e8b3a Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 03:52:35 +0800 Subject: [PATCH 3/8] 'update' --- __init__.py | 3 +++ mz_gen_translate.py | 1 + 2 files changed, 4 insertions(+) diff --git a/__init__.py b/__init__.py index 1744806..f2cd743 100644 --- a/__init__.py +++ b/__init__.py @@ -57,6 +57,9 @@ class MZ_LLamaCPPModelConfig_ManualSelect: return (kwargs,) +NODE_CLASS_MAPPINGS["MZ_LLamaCPPModelConfig_ManualSelect"] = MZ_LLamaCPPModelConfig_ManualSelect +NODE_DISPLAY_NAME_MAPPINGS["MZ_LLamaCPPModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - LLamaCPPModelConfigManualSelect" + class MZ_LLamaCPPCLIPTextEncode: @classmethod def INPUT_TYPES(s): diff --git a/mz_gen_translate.py b/mz_gen_translate.py index e395c7f..4653914 100644 --- a/mz_gen_translate.py +++ b/mz_gen_translate.py @@ -27,6 +27,7 @@ ZH_Replace_Map = { "customize_instruct": "自定义指令", "CustomizeInstruct": "自定义指令", "deprecated": "已废弃", + "LLamaCPPModelConfigManualSelect": "llama.cpp模型配置手动选择", } From 13a1ca31583b56287c4d022dc7ee3211986b7d46 Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 12:33:03 +0800 Subject: [PATCH 4/8] 'update' --- __init__.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index f2cd743..bbd58a1 100644 --- a/__init__.py +++ b/__init__.py @@ -30,7 +30,7 @@ NODE_CLASS_MAPPINGS = { NODE_DISPLAY_NAME_MAPPINGS = { } - + from . import mz_llama_cpp from . import mz_llava @@ -38,7 +38,16 @@ from . import mz_llava class MZ_LLamaCPPModelConfig_ManualSelect: @classmethod def INPUT_TYPES(s): - gguf_files = folder_paths.get_filename_list("gguf") + gguf_dir = Utils.get_gguf_models_path() + if not os.path.exists(gguf_dir): + os.makedirs(gguf_dir) + gguf_files = [] + # walk gguf_dir + for root, dirs, files in os.walk(gguf_dir): + for file in files: + if file.endswith(".gguf"): + gguf_files.append( + os.path.relpath(os.path.join(root, file), gguf_dir)) return { "required": { "llama_cpp_model": (gguf_files,), @@ -54,11 +63,16 @@ class MZ_LLamaCPPModelConfig_ManualSelect: CATEGORY = CATEGORY_NAME def create(self, **kwargs): - return (kwargs,) + return ({ + "type": "ManualSelect", + "model_path": kwargs, + },) NODE_CLASS_MAPPINGS["MZ_LLamaCPPModelConfig_ManualSelect"] = MZ_LLamaCPPModelConfig_ManualSelect -NODE_DISPLAY_NAME_MAPPINGS["MZ_LLamaCPPModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - LLamaCPPModelConfigManualSelect" +NODE_DISPLAY_NAME_MAPPINGS[ + "MZ_LLamaCPPModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - LLamaCPPModelConfigManualSelect" + class MZ_LLamaCPPCLIPTextEncode: @classmethod @@ -141,7 +155,7 @@ class MZ_CustomizeInstruct: @classmethod def INPUT_TYPES(s): from . import mz_prompts - + return { "required": { "system": ("STRING", {"multiline": True, "default": mz_prompts.Long_prompt}), From 3713d50faa5c0190a2236965cb1d9d691657bf9e Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 20:19:05 +0800 Subject: [PATCH 5/8] 'update' --- .gitignore | 5 ++- __init__.py | 46 ++++++++++++++++++---- mz_llama_core_nodes.py | 9 ++++- mz_llama_cpp.py | 28 +++++-------- mz_llava.py | 89 ++++++++++++++++++++++++++++++++---------- mz_prompt_utils.py | 78 ++++++++++++++++++++++++++++++++++++ mz_prompts.py | 5 ++- v1/init.py | 4 ++ web/prompt_mz.js | 13 +++++- 9 files changed, 225 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 732c190..06988b3 100644 --- a/.gitignore +++ b/.gitignore @@ -158,4 +158,7 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -.vscode \ No newline at end of file +.vscode + +*.bat +exclude.txt \ No newline at end of file diff --git a/__init__.py b/__init__.py index bbd58a1..c8ff7ff 100644 --- a/__init__.py +++ b/__init__.py @@ -20,8 +20,8 @@ CATEGORY_NAME = f"{AUTHOR_NAME} - Prompt" import importlib -# import mz_prompt_webserver -# mz_prompt_webserver.start_server() +from . import mz_prompt_webserver +mz_prompt_webserver.start_server() NODE_CLASS_MAPPINGS = { } @@ -63,15 +63,22 @@ class MZ_LLamaCPPModelConfig_ManualSelect: CATEGORY = CATEGORY_NAME def create(self, **kwargs): + kwargs = kwargs.copy() + + llama_cpp_model = kwargs.get("llama_cpp_model", "") + if llama_cpp_model != "": + llama_cpp_model = os.path.join( + Utils.get_gguf_models_path(), llama_cpp_model) + return ({ "type": "ManualSelect", - "model_path": kwargs, + "model_path": llama_cpp_model, },) NODE_CLASS_MAPPINGS["MZ_LLamaCPPModelConfig_ManualSelect"] = MZ_LLamaCPPModelConfig_ManualSelect NODE_DISPLAY_NAME_MAPPINGS[ - "MZ_LLamaCPPModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - LLamaCPPModelConfigManualSelect" + "MZ_LLamaCPPModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - ModelConfigManualSelect" class MZ_LLamaCPPCLIPTextEncode: @@ -94,19 +101,30 @@ class MZ_LLamaCPPCLIPTextEncode: result["optional"][key] = common_input["optional"][key] return result + RETURN_TYPES = ("STRING", "CONDITIONING",) RETURN_NAMES = ("text", "conditioning",) OUTPUT_NODE = True FUNCTION = "encode" CATEGORY = CATEGORY_NAME + DESCRIPTION = """ +llama_cpp_model不设置时,将使用默认模型: Meta-Llama-3-8B-Instruct.Q4_K_M.gguf +""" + def encode(self, **kwargs): + kwargs = kwargs.copy() from . import mz_llama_core_nodes importlib.reload(mz_llama_core_nodes) return mz_llama_core_nodes.llama_cpp_node_encode(kwargs) +NODE_CLASS_MAPPINGS["MZ_LLamaCPPCLIPTextEncode"] = MZ_LLamaCPPCLIPTextEncode +NODE_DISPLAY_NAME_MAPPINGS[ + "MZ_LLamaCPPCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(llama.cpp通用)" + + class MZ_LLamaCPPOptions: @classmethod def INPUT_TYPES(s): @@ -140,6 +158,7 @@ class MZ_LLamaCPPOptions: CATEGORY = CATEGORY_NAME def create(self, **kwargs): + kwargs = kwargs.copy() importlib.reload(mz_llama_cpp) opt = {} for key in kwargs: @@ -169,6 +188,8 @@ class MZ_CustomizeInstruct: CATEGORY = CATEGORY_NAME def create(self, **kwargs): + kwargs = kwargs.copy() + return (kwargs,) @@ -227,7 +248,7 @@ class MZ_LLavaImageInterrogator: {"default": "none"} ), "resolution": ("INT", {"default": 512, "min": 128, "max": 2048}), - "sd_format": (["none", "v1"], {"default": "none"}), + "sd_format": (["none", "v1", ], {"default": "none"}), "keep_device": ([False, True], {"default": False}), "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), }, @@ -246,6 +267,8 @@ class MZ_LLavaImageInterrogator: CATEGORY = CATEGORY_NAME def interrogate(self, **kwargs): + kwargs = kwargs.copy() + importlib.reload(mz_llava) kwargs["llama_cpp_model"] = kwargs.get( @@ -264,7 +287,7 @@ class MZ_LLavaImageInterrogator: if clip is not None: conditionings = Utils.a1111_clip_text_encode(clip, text, ) - return {"ui": {"string": [text,]}, "result": (text, conditionings)} + return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)} NODE_CLASS_MAPPINGS["MZ_LLavaImageInterrogator"] = MZ_LLavaImageInterrogator @@ -299,6 +322,8 @@ class MZ_BaseLLavaImageInterrogator: CATEGORY = CATEGORY_NAME def interrogate(self, **kwargs): + kwargs = kwargs.copy() + importlib.reload(mz_llava) if kwargs.get("image", None) is not None: @@ -312,7 +337,7 @@ class MZ_BaseLLavaImageInterrogator: if clip is not None: conditionings = Utils.a1111_clip_text_encode(clip, text, ) - return {"ui": {"string": [text,]}, "result": (text, conditionings)} + return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)} NODE_CLASS_MAPPINGS["MZ_BaseLLavaImageInterrogator"] = MZ_BaseLLavaImageInterrogator @@ -328,6 +353,7 @@ class MZ_ImageCaptionerConfig: "directory": ("STRING", {"default": "", "placeholder": "directory"}), "caption_suffix": ("STRING", {"default": ".caption"}), "force_update": ([False, True], {"default": False}), + "retry_keyword": ("STRING", {"default": "not,\",error"}), }, "optional": { @@ -341,6 +367,8 @@ class MZ_ImageCaptionerConfig: CATEGORY = CATEGORY_NAME def interrogate_batch(self, **kwargs): + kwargs = kwargs.copy() + return (kwargs, ) @@ -398,6 +426,8 @@ class MZ_OpenAIApiCLIPTextEncode: CATEGORY = CATEGORY_NAME def encode(self, **kwargs): + kwargs = kwargs.copy() + import mz_openaiapi importlib.reload(mz_openaiapi) @@ -426,7 +456,7 @@ class MZ_OpenAIApiCLIPTextEncode: if clip is not None: conditionings = Utils.a1111_clip_text_encode(clip, text, ) - return {"ui": {"string": [text,]}, "result": (text, conditionings)} + return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)} NODE_CLASS_MAPPINGS["MZ_OpenAIApiCLIPTextEncode"] = MZ_OpenAIApiCLIPTextEncode diff --git a/mz_llama_core_nodes.py b/mz_llama_core_nodes.py index c3b3308..d3e1480 100644 --- a/mz_llama_core_nodes.py +++ b/mz_llama_core_nodes.py @@ -56,7 +56,14 @@ def llama_cpp_node_encode(args_dict): importlib.reload(mz_prompts) importlib.reload(mz_llama_cpp) - model_file = args_dict.get("llama_cpp_model", "") + model_config = args_dict.get("llama_cpp_model", {}) + mz_prompt_utils.Utils.print_log(f"model_config: {model_config}") + + model_file = model_config.get("model_path", "auto") + + mz_prompt_utils.Utils.print_log(f"model_file: {model_file}") + + text = args_dict.get("text", "") style_presets = args_dict.get("style_presets", "") options = args_dict.get("llama_cpp_options", {}) diff --git a/mz_llama_cpp.py b/mz_llama_cpp.py index 84a44e8..9bf406d 100644 --- a/mz_llama_cpp.py +++ b/mz_llama_cpp.py @@ -122,6 +122,7 @@ def freed_gpu_memory(model_file): def llama_cpp_messages(model_file, chat_handler=None, messages=[], options={}): if options is None: options = {} + options = options.copy() print(f"Find local model file: {model_file}") init_opts = ["n_ctx", "logits_all", "chat_format", "n_gpu_layers"] @@ -178,6 +179,8 @@ def llama_cpp_messages(model_file, chat_handler=None, messages=[], options={}): f"llama_cpp_model_and_opt_{model_file}", model_and_opt) model = model_and_opt.get("model") + model.set_seed(options.get("seed", -1)) + model.reset() response_format = options.get("response_format", None) mz_prompt_utils.Utils.print_log( @@ -235,8 +238,8 @@ def llama_cpp_messages(model_file, chat_handler=None, messages=[], options={}): return result - def llama_cpp_simple_interrogator_to_json(model_file, use_system=True, system=None, question="", schema={}, options={}): + options = options.copy() if system is None: system = "" messages = [ @@ -288,6 +291,7 @@ def llama_cpp_simple_interrogator_to_json(model_file, use_system=True, system=No def llama_cpp_simple_interrogator(model_file, use_system=True, system=None, question="", options={}): if options is None: options = {} + options = options.copy() if system is None: system = "" messages = [ @@ -328,6 +332,8 @@ def llama_cpp_simple_interrogator(model_file, use_system=True, system=None, ques def llava_cpp_messages(model_file, chat_handler, messages, options={}): if options is None: options = {} + + options = options.copy() options["logits_all"] = True options["n_ctx"] = max(4096, options.get("n_ctx", 4096)) return llama_cpp_messages(model_file, chat_handler, messages, options) @@ -338,7 +344,7 @@ def llava_cpp_simple_interrogator( image=None, options={}): if options is None: options = {} - + options = options.copy() check_llama_cpp_requirements() content = [] @@ -351,6 +357,7 @@ def llava_cpp_simple_interrogator( check_llama_cpp_requirements() from llama_cpp.llama_chat_format import Llava15ChatHandler if mmproj_file is not None: + mz_prompt_utils.Utils.print_log(f"llava_cpp_simple_interrogator mmproj_file: {mmproj_file}") chat_handler = Llava15ChatHandler(clip_model_path=mmproj_file) return llava_cpp_messages(model_file, chat_handler, [ @@ -363,20 +370,3 @@ def llava_cpp_simple_interrogator( "content": content, }, ], options=options) - - -def llava_cpp_simple_interrogator_to_json( - model_file, mmproj_file, system="You are an assistant who perfectly describes images.", question="Describe this image in detail please\nuse json format for output:", - image=None, schema={}, options={}): - - response_format = { - "type": "json_object", - "schema": schema, - } - options["response_format"] = response_format - options["chat_format"] = "chatml" - - result = llava_cpp_simple_interrogator( - model_file, mmproj_file, system=system, question=question, image=image, options=options) - return result - diff --git a/mz_llava.py b/mz_llava.py index 7e43491..c2a0350 100644 --- a/mz_llava.py +++ b/mz_llava.py @@ -3,6 +3,7 @@ import os from . import mz_prompt_utils from . import mz_llama_cpp from . import mz_prompts +from . import mz_llama_core_nodes from . import mz_prompt_webserver import importlib @@ -65,6 +66,7 @@ def get_exist_model(model_name): def image_interrogator(args_dict): + args_dict = args_dict.copy() captioner_config = args_dict.get("captioner_config", None) if captioner_config is not None: @@ -72,6 +74,11 @@ def image_interrogator(args_dict): directory = captioner_config.get("directory", None) force_update = captioner_config.get("force_update", False) caption_suffix = captioner_config.get("caption_suffix", "") + retry_keyword = captioner_config.get("retry_keyword", "") + retry_keywords = retry_keyword.split(",") + + retry_keywords = [k.strip() for k in retry_keywords] + retry_keywords = [k for k in retry_keywords if k != ""] pre_images = [] for root, dirs, files in os.walk(directory): @@ -90,6 +97,8 @@ def image_interrogator(args_dict): }) result = [] + + pb = mz_prompt_utils.Utils.progress_bar(len(pre_images)) for i in range(len(pre_images)): pre_image = pre_images[i] image_path = pre_image["image_path"] @@ -102,23 +111,54 @@ def image_interrogator(args_dict): onec_args_dict["image"] = pil_image if i < len(pre_images) - 1: - onec_args_dict["keep_device"] = True + onec_args_dict["keep_device"] = True - mz_prompt_webserver.show_toast_success( - f"正在处理图片 {image_path}...", 1000) + pb.update( + i, + len(pre_images), + pil_image.copy(), + ) response = image_interrogator(onec_args_dict) response = response.strip() - with open(caption_file, "w") as f: - f.write(response) + is_retry = response == "" + for k in retry_keywords: + if response.find(k) != -1: + print(f"存在需要重试的关键词 ; Retry keyword found: {k}") + is_retry = True + break + + mz_prompt_utils.Utils.print_log( + "\n\nonec_args_dict: ", onec_args_dict) + if is_retry: + for retry_n in range(5): + print(f"Retry {retry_n+1}...") + onec_args_dict["seed"] = onec_args_dict["seed"] + 1 + response = image_interrogator(onec_args_dict) + response = response.strip() + is_retry = response == "" + for k in retry_keywords: + if response.find(k) != -1: + print(f"存在需要重试的关键词 ; Retry keyword found: {k}") + is_retry = True + break + + if is_retry is False: + break + if is_retry: + print(f"重试失败,图片被跳过 ; Retry failed") + response = "" + + if response != "": + with open(caption_file, "w") as f: + f.write(response) result.append(response) - - mz_prompt_webserver.show_toast_success( - f"提示词保存成功(prompt saved successfully): {caption_file}", - 1000, - ) + # mz_prompt_webserver.show_toast_success( + # f"提示词保存成功(prompt saved successfully): {caption_file}", + # 1000, + # ) return result @@ -184,15 +224,25 @@ def base_image_interrogator(args_dict): options = args_dict.get("llama_cpp_options", {}) options["seed"] = seed + mz_prompt_utils.Utils.print_log( + "base_image_interrogator options: ", options) + # input("Press Enter to continue...") + image = mz_prompt_utils.Utils.resize_max(image, resolution, resolution) customize_instruct = args_dict.get("customize_instruct", None) if customize_instruct is None: + + system_text = mz_prompts.GPT4VImageCaptioner_System + question_text = mz_prompts.GPT4VImageCaptioner_Prompt + response = mz_llama_cpp.llava_cpp_simple_interrogator( model_file=model_file, mmproj_file=mmproj_file, image=image, options=options, + system=system_text, + question=question_text, ) else: @@ -226,18 +276,17 @@ def base_image_interrogator(args_dict): response = full_response sd_format = args_dict.get("sd_format", "v1") + if sd_format == "v1" and customize_instruct is None: - - mz_prompt_utils.Utils.print_log(f"response: {response}") - - schema = mz_llama_cpp.get_schema_obj( + mz_prompt_utils.Utils.print_log(f"response v1: {response}") + schema = mz_llama_core_nodes.get_schema_obj( keys_type={ - "short_describes": mz_llama_cpp.get_schema_base_type("string"), - "subject_tags": mz_llama_cpp.get_schema_array("string"), - "action_tags": mz_llama_cpp.get_schema_array("string"), - "light_tags": mz_llama_cpp.get_schema_array("string"), - "scenes_tags": mz_llama_cpp.get_schema_array("string"), - "other_tags": mz_llama_cpp.get_schema_array("string"), + "short_describes": mz_llama_core_nodes.get_schema_base_type("string"), + "subject_tags": mz_llama_core_nodes.get_schema_array("string"), + "action_tags": mz_llama_core_nodes.get_schema_array("string"), + "light_tags": mz_llama_core_nodes.get_schema_array("string"), + "scenes_tags": mz_llama_core_nodes.get_schema_array("string"), + "other_tags": mz_llama_core_nodes.get_schema_array("string"), }, required=[ "short_describes", diff --git a/mz_prompt_utils.py b/mz_prompt_utils.py index d0b3527..30db8d8 100644 --- a/mz_prompt_utils.py +++ b/mz_prompt_utils.py @@ -555,6 +555,84 @@ class Utils: save_path = Utils.download_file(url, save_path) return save_path + def progress_bar(steps): + class pb: + def __init__(self, steps): + self.steps = steps + self.pbar = comfy.utils.ProgressBar(steps) + + def update(self, step, total_steps, pil_img): + self.pbar.update_absolute( + step, total_steps, ("JPEG", pil_img, 512)) + + return pb(steps) + + def split_en_to_zh(text): + # 中文标点转英文标点 + text = text.replace(",", ",") + text = text.replace("。", ".") + text = text.replace("?", "?") + text = text.replace("!", "!") + text = text.replace(";", ";") + + result = [] + if text.find("\n") != -1: + text = text.split("\n") + for t in text: + if t != "": + result.append(Utils.split_en_to_zh(t)) + return "\n".join(result) + + if text.find(".") != -1: + text = text.split(".") + for t in text: + if t != "": + result.append(Utils.split_en_to_zh(t)) + return ". ".join(result) + + if text.find("?") != -1: + text = text.split("?") + for t in text: + if t != "": + result.append(Utils.split_en_to_zh(t)) + return "? ".join(result) + + if text.find("!") != -1: + text = text.split("!") + for t in text: + if t != "": + result.append(Utils.split_en_to_zh(t)) + return "! ".join(result) + + if text.find(";") != -1: + text = text.split(";") + for t in text: + if t != "": + result.append(Utils.split_en_to_zh(t)) + return "; ".join(result) + + if text.find(",") != -1: + text = text.split(",") + for t in text: + if t != "": + result.append(Utils.split_en_to_zh(t)) + return ", ".join(result) + + return Utils.en2zh(text) + + def to_debug_prompt(p): + if p is None: + return "" + zh = Utils.en2zh(p) + p = p.strip() + return f""" +原文: +{p} + +中文翻译: +{zh} +""" + modelscope_models_map = { "llama3": { diff --git a/mz_prompts.py b/mz_prompts.py index 6080cc7..f7e557f 100644 --- a/mz_prompts.py +++ b/mz_prompts.py @@ -20,9 +20,12 @@ Please output the standardized json content. """ +GPT4VImageCaptioner_System = """ +As an AI image tagging expert, please provide precise tags for these images to enhance CLIP model's understanding of the content. +""" + # 来自https://github.com/jiayev/GPT4V-Image-Captioner GPT4VImageCaptioner_Prompt = """ -As an AI image tagging expert, please provide precise tags for these images to enhance CLIP model's understanding of the content. Employ succinct keywords or phrases, steering clear of elaborate sentences and extraneous conjunctions. Prioritize the tags by relevance. Your tags should capture key elements such as the main subject, setting, artistic style, composition, image quality, color tone, filter, and camera specifications, and any other tags crucial for the image. diff --git a/v1/init.py b/v1/init.py index bcb43a6..8d106a3 100644 --- a/v1/init.py +++ b/v1/init.py @@ -130,6 +130,8 @@ class MZ_Phi3CLIPTextEncode: CATEGORY = CATEGORY_NAME def encode(self, **kwargs): + kwargs = kwargs.copy() + importlib.reload(mz_llama3) kwargs["llama_cpp_model"] = kwargs.get( @@ -176,6 +178,8 @@ class MZ_BaseLLamaCPPCLIPTextEncode: CATEGORY = CATEGORY_NAME def encode(self, **kwargs): + kwargs = kwargs.copy() + kwargs["llama_cpp_model"] = kwargs.get( "llama_cpp_model", "").replace("[downloaded]", "") text = mz_deprecated.base_query_beautify_prompt_text(kwargs) diff --git a/web/prompt_mz.js b/web/prompt_mz.js index 7055a59..cb328d4 100644 --- a/web/prompt_mz.js +++ b/web/prompt_mz.js @@ -50,12 +50,17 @@ async function waitMessage() { for (;;) { await sleep(1000); try { + if (websocket.readyState !== WebSocket.OPEN) { + return; + } websocket.send( JSON.stringify({ type: "ping", }) ); - } catch (error) {} + } catch (error) { + return; + } } } @@ -84,6 +89,7 @@ const my_ui = { case "MZ_BaseLLamaCPPCLIPTextEncode": case "MZ_LLavaImageInterrogator": case "MZ_BaseLLavaImageInterrogator": + case "MZ_LLamaCPPCLIPTextEncode": // Node Created const onNodeCreated = nodeType.prototype.onNodeCreated; nodeType.prototype.onNodeCreated = function () { @@ -91,6 +97,7 @@ const my_ui = { ? onNodeCreated.apply(this, arguments) : undefined; + console.log("onNodeCreated:", this); const nodeName = this.name + "_" + "customtext"; const wi = ComfyWidgets.STRING( this, @@ -129,12 +136,14 @@ const my_ui = { const onConfigure = nodeType.prototype.onConfigure; nodeType.prototype.onConfigure = function (w) { onConfigure?.apply(this, arguments); + + // outSet.call(this, a?.string); }; // onExecuted const onExecuted = nodeType.prototype.onExecuted; nodeType.prototype.onExecuted = function (a, b) { - console.log("onExecuted:", arguments); + // console.log("onExecuted:", arguments); onExecuted?.apply(this, arguments); outSet.call(this, a?.string); From e9bdf6ce9056331051babd5e19fa63860d329de2 Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 20:33:24 +0800 Subject: [PATCH 6/8] 'update' --- mz_llava.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mz_llava.py b/mz_llava.py index c2a0350..550e4db 100644 --- a/mz_llava.py +++ b/mz_llava.py @@ -111,7 +111,7 @@ def image_interrogator(args_dict): onec_args_dict["image"] = pil_image if i < len(pre_images) - 1: - onec_args_dict["keep_device"] = True + onec_args_dict["keep_device"] = True pb.update( i, @@ -241,8 +241,8 @@ def base_image_interrogator(args_dict): mmproj_file=mmproj_file, image=image, options=options, - system=system_text, - question=question_text, + # system=system_text, + # question=question_text, ) else: From 7102e655262dd9dc9287f0de6d96bfd118c9a887 Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 20:35:02 +0800 Subject: [PATCH 7/8] 'update' --- v1/init.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/v1/init.py b/v1/init.py index 8d106a3..df3ce6f 100644 --- a/v1/init.py +++ b/v1/init.py @@ -86,7 +86,7 @@ class MZ_LLama3CLIPTextEncode: if clip is not None: conditionings = Utils.a1111_clip_text_encode(clip, text, ) - return {"ui": {"string": [text,]}, "result": (text, conditionings)} + return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)} NODE_CLASS_MAPPINGS["MZ_LLama3CLIPTextEncode"] = MZ_LLama3CLIPTextEncode @@ -143,7 +143,7 @@ class MZ_Phi3CLIPTextEncode: if clip is not None: conditionings = Utils.a1111_clip_text_encode(clip, text, ) - return {"ui": {"string": [text,]}, "result": (text, conditionings)} + return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)} NODE_CLASS_MAPPINGS["MZ_Phi3CLIPTextEncode"] = MZ_Phi3CLIPTextEncode @@ -188,7 +188,7 @@ class MZ_BaseLLamaCPPCLIPTextEncode: if clip is not None: conditionings = Utils.a1111_clip_text_encode(clip, text, ) - return {"ui": {"string": [text,]}, "result": (text, conditionings)} + return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)} NODE_CLASS_MAPPINGS["MZ_BaseLLamaCPPCLIPTextEncode"] = MZ_BaseLLamaCPPCLIPTextEncode From 404879058a42b5ef577fc990b9cf624ada88a483 Mon Sep 17 00:00:00 2001 From: wailovet Date: Sat, 1 Jun 2024 20:35:30 +0800 Subject: [PATCH 8/8] 'update' --- v1/init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v1/init.py b/v1/init.py index df3ce6f..0864781 100644 --- a/v1/init.py +++ b/v1/init.py @@ -16,7 +16,7 @@ from . import mz_deprecated AUTHOR_NAME = u"MinusZone" -CATEGORY_NAME = f"{AUTHOR_NAME} - Prompt/deprecated" +CATEGORY_NAME = f"{AUTHOR_NAME} - Prompt/v1" def getCommonCLIPTextEncodeInput():