From f90745c5a14a462375ffc032963a781389f69928 Mon Sep 17 00:00:00 2001 From: AlekPet Date: Sun, 11 May 2025 12:16:52 +0300 Subject: [PATCH 1/3] update extras_node (PreviewImageSize) --- ExtrasNode/js/extras_node.js | 5 +++++ ExtrasNode/lib/extras_node_widgets.js | 1 + pyproject.toml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ExtrasNode/js/extras_node.js b/ExtrasNode/js/extras_node.js index c2da292..67bc027 100644 --- a/ExtrasNode/js/extras_node.js +++ b/ExtrasNode/js/extras_node.js @@ -363,6 +363,11 @@ app.registerExtension({ onchange: (e) => { const checked = !!e.target.checked; PreviewImageSize = checked; + + localStorage.setItem( + `Comfy.Settings.${idExt}.PreviewImage`, + checked + ); sett(checked); }, }), diff --git a/ExtrasNode/lib/extras_node_widgets.js b/ExtrasNode/lib/extras_node_widgets.js index 4683656..c7605df 100644 --- a/ExtrasNode/lib/extras_node_widgets.js +++ b/ExtrasNode/lib/extras_node_widgets.js @@ -766,6 +766,7 @@ function createPreiviewSize(node, name, options) { fontSize: "0.8rem", color: color, fontFamily: "monospace", + textAlign: "center", padding: 0, margin: 0, outline: 0, diff --git a/pyproject.toml b/pyproject.toml index 5c9557c..0d3b62a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_custom_nodes_alekpet" description = "Nodes: PoseNode, PainterNode, TranslateTextNode, TranslateCLIPTextEncodeNode, DeepTranslatorTextNode, DeepTranslatorCLIPTextEncodeNode, ArgosTranslateTextNode, ArgosTranslateCLIPTextEncodeNode, ChatGLM4TranslateCLIPTextEncodeNode, ChatGLM4TranslateTextNode, ChatGLM4InstructNode, ChatGLM4InstructMediaNode, DeepLXTranslateTextNode, DeepLXTranslateCLIPTextEncodeNode, PreviewTextNode, HexToHueNode, ColorsCorrectNode, IDENode." -version = "1.0.64" +version = "1.0.65" license = { file = "LICENSE" } [project.urls] From eff8b1209fc216cffd9f824273aebb5e6764e374 Mon Sep 17 00:00:00 2001 From: AlekPet Date: Tue, 13 May 2025 12:13:09 +0300 Subject: [PATCH 2/3] update painter node, extras nodes, pose node ExtrasNode fix not showing speech and recognation buttons. PainterNode removed unused and obsolete code. Pose node removed obolete code. Update version. --- ExtrasNode/js/extras_node.js | 15 +++++++++---- ExtrasNode/lib/extras_node_widgets.js | 15 ++++--------- PainterNode/js/painter_node.js | 31 --------------------------- PoseNode/js/pose_node.js | 1 - pyproject.toml | 2 +- 5 files changed, 16 insertions(+), 48 deletions(-) diff --git a/ExtrasNode/js/extras_node.js b/ExtrasNode/js/extras_node.js index 67bc027..bf82516 100644 --- a/ExtrasNode/js/extras_node.js +++ b/ExtrasNode/js/extras_node.js @@ -8,7 +8,7 @@ import { app } from "../../scripts/app.js"; import { api } from "../../scripts/api.js"; import { ComfyWidgets } from "../../scripts/widgets.js"; import { $el } from "../../scripts/ui.js"; -import { isValidStyle } from "./utils.js"; +import { isValidStyle, comfyuiDesktopConfirm } from "./utils.js"; import { addStylesheet } from "../../scripts/utils.js"; import { SpeechWidget, @@ -493,9 +493,16 @@ app.registerExtension({ ), type: "checkbox", checked: val, - onchange: (e) => { + onchange: async (e) => { const checked = !!e.target.checked; SpeechAndRecognationSpeech = checked; + localStorage.setItem( + `Comfy.Settings.${idExt}.SpeechAndRecognationSpeech`, + checked + ); + if (await comfyuiDesktopConfirm("Reload page?")) { + location.reload(); + } sett(checked); }, }), @@ -816,7 +823,7 @@ app.registerExtension({ await new Promise((res) => setTimeout(() => { res(); - }, 16 * this.widgets.length) + }, 16 * this.widgets?.length ?? 1) ); if (!isIncludesSpeech && widgetsTextMulti.length) { @@ -838,7 +845,7 @@ app.registerExtension({ await new Promise((res) => setTimeout(() => { res(); - }, 16 * this.widgets.length) + }, 16 * this.widgets?.length ?? 1) ); const ids_speech_clear = this.widgets.reduce(function ( diff --git a/ExtrasNode/lib/extras_node_widgets.js b/ExtrasNode/lib/extras_node_widgets.js index c7605df..460a7c7 100644 --- a/ExtrasNode/lib/extras_node_widgets.js +++ b/ExtrasNode/lib/extras_node_widgets.js @@ -219,15 +219,9 @@ function SpeechWidget(node, inputName, inputData, widgetsText) { draw(ctx, node, widget_width, y, widget_height) { const hidden = widgetsText?.element?.hidden; - widget.element.dataset.shouldHide = hidden ? "true" : "false"; - const isInVisibleNodes = - widget.element.dataset.isInVisibleNodes === "true"; - const isCollapsed = widget.element.dataset.collapsed === "true"; - const actualHidden = hidden || !isInVisibleNodes || isCollapsed; - const wasHidden = widget.element.hidden; - widget.element.hidden = actualHidden; - widget.element.style.display = actualHidden ? "none" : "flex"; - if (actualHidden && !wasHidden) { + widget.element.style.display = + hidden || app.canvas.ds.scale < 0.6 ? "none" : "flex"; + if (hidden) { widget.options.onHide?.(widget); } @@ -653,7 +647,7 @@ function SpeechWidget(node, inputName, inputData, widgetsText) { widget.element = $el( "div.alekpet_extras_node_speechrecognition_box", - { hidden: true, style: { display: "none" } }, + { style: { display: "none" } }, [ $el("div.alekpet_extras_node_speechrecognition_row", [...buttons]), $el("div.alekpet_extras_node_info", [ @@ -704,7 +698,6 @@ function makeColorWidget(node, inputName, inputData, widget) { style: { textAlign: "center", fontSize: "20px", - height: "20px", fontWeight: "600", lineHeight: 1.5, background: "var(--comfy-menu-bg)", diff --git a/PainterNode/js/painter_node.js b/PainterNode/js/painter_node.js index 5b2126d..b16c751 100644 --- a/PainterNode/js/painter_node.js +++ b/PainterNode/js/painter_node.js @@ -167,36 +167,6 @@ class Painter { return callb.apply(this, arguments); } }; - - let default_value = this.image.value; - Object.defineProperty(this.image, "value", { - set: function (value) { - this._real_value = value; - }, - - get: function () { - let value = ""; - if (this._real_value) { - value = this._real_value; - } else { - return default_value; - } - - if (value.filename) { - let real_value = value; - value = ""; - if (real_value.subfolder) { - value = real_value.subfolder + "/"; - } - - value += real_value.filename; - - if (real_value.type && real_value.type !== "input") - value += ` [${real_value.type}]`; - } - return value; - }, - }); } async saveSettingsPainterNode() { @@ -2187,7 +2157,6 @@ class Painter { img.src = api.apiURL( `/view?filename=${name}&type=input&subfolder=${subfolder}${app.getPreviewFormatParam()}&${new Date().getTime()}` ); - this.node.setSizeForImage?.(); } async uploadPaintFile(fileName) { diff --git a/PoseNode/js/pose_node.js b/PoseNode/js/pose_node.js index 27c60ce..832b4b2 100644 --- a/PoseNode/js/pose_node.js +++ b/PoseNode/js/pose_node.js @@ -465,7 +465,6 @@ class OpenPose { img.src = api.apiURL( `/view?filename=${name}&type=input&subfolder=${subfolder}${app.getPreviewFormatParam()}&${app.getRandParam()}` ); - this.node.setSizeForImage?.(); } uploadPoseFile(fileName) { diff --git a/pyproject.toml b/pyproject.toml index 0d3b62a..7412fb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_custom_nodes_alekpet" description = "Nodes: PoseNode, PainterNode, TranslateTextNode, TranslateCLIPTextEncodeNode, DeepTranslatorTextNode, DeepTranslatorCLIPTextEncodeNode, ArgosTranslateTextNode, ArgosTranslateCLIPTextEncodeNode, ChatGLM4TranslateCLIPTextEncodeNode, ChatGLM4TranslateTextNode, ChatGLM4InstructNode, ChatGLM4InstructMediaNode, DeepLXTranslateTextNode, DeepLXTranslateCLIPTextEncodeNode, PreviewTextNode, HexToHueNode, ColorsCorrectNode, IDENode." -version = "1.0.65" +version = "1.0.66" license = { file = "LICENSE" } [project.urls] From c81bc1e882bbbc35d40c99b7232ece5090ef7daf Mon Sep 17 00:00:00 2001 From: AlekPet Date: Sat, 17 May 2025 16:03:11 +0300 Subject: [PATCH 3/3] update ChatGLMNode --- ChatGLMNode/.gitignore | 1 + ChatGLMNode/README.md | 152 +++++++++++++++++++++++++++++++- ChatGLMNode/chatglm_node.py | 62 ++++++++----- ChatGLMNode/config.json | 4 - ChatGLMNode/config.json.example | 6 ++ pyproject.toml | 2 +- 6 files changed, 200 insertions(+), 27 deletions(-) create mode 100644 ChatGLMNode/.gitignore delete mode 100644 ChatGLMNode/config.json create mode 100644 ChatGLMNode/config.json.example diff --git a/ChatGLMNode/.gitignore b/ChatGLMNode/.gitignore new file mode 100644 index 0000000..0cffcb3 --- /dev/null +++ b/ChatGLMNode/.gitignore @@ -0,0 +1 @@ +config.json \ No newline at end of file diff --git a/ChatGLMNode/README.md b/ChatGLMNode/README.md index c2eb89d..89261b5 100644 --- a/ChatGLMNode/README.md +++ b/ChatGLMNode/README.md @@ -2,13 +2,163 @@ Translation is carried out with the help of artificial intelligence using GLM models. +
+Language Codes List + +- af – Afrikaans +- sq – Albanian +- am – Amharic +- ar – Arabic +- hy – Armenian +- as – Assamese +- ay – Aymara +- az – Azerbaijani +- bm – Bambara +- eu – Basque +- be – Belarusian +- bn – Bengali +- bho – Bhojpuri +- bs – Bosnian +- bg – Bulgarian +- ca – Catalan +- ceb – Cebuano +- ny – Chichewa +- zh-CN – Chinese (Simplified) +- zh-TW – Chinese (Traditional) +- co – Corsican +- hr – Croatian +- cs – Czech +- da – Danish +- dv – Divehi +- doi – Dogri +- nl – Dutch +- en – English +- eo – Esperanto +- et – Estonian +- ee – Ewe +- tl – Filipino +- fi – Finnish +- fr – French +- fy – Frisian +- gl – Galician +- ka – Georgian +- de – German +- el – Greek +- gn – Guarani +- gu – Gujarati +- ht – Haitian Creole +- ha – Hausa +- haw – Hawaiian +- iw – Hebrew +- hi – Hindi +- hmn – Hmong +- hu – Hungarian +- is – Icelandic +- ig – Igbo +- ilo – Ilocano +- id – Indonesian +- ga – Irish +- it – Italian +- ja – Japanese +- jw – Javanese +- kn – Kannada +- kk – Kazakh +- km – Khmer +- rw – Kinyarwanda +- gom – Konkani +- ko – Korean +- kri – Krio +- ku – Kurdish (Kurmanji) +- ckb – Kurdish (Sorani) +- ky – Kyrgyz +- lo – Lao +- la – Latin +- lv – Latvian +- ln – Lingala +- lt – Lithuanian +- lg – Luganda +- lb – Luxembourgish +- mk – Macedonian +- mai – Maithili +- mg – Malagasy +- ms – Malay +- ml – Malayalam +- mt – Maltese +- mi – Maori +- mr – Marathi +- mni-Mtei – Meiteilon (Manipuri) +- lus – Mizo +- mn – Mongolian +- my – Myanmar (Burmese) +- ne – Nepali +- no – Norwegian +- or – Odia (Oriya) +- om – Oromo +- ps – Pashto +- fa – Persian +- pl – Polish +- pt – Portuguese +- pa – Punjabi +- qu – Quechua +- ro – Romanian +- ru – Russian +- sm – Samoan +- sa – Sanskrit +- gd – Scots Gaelic +- nso – Sepedi +- sr – Serbian +- st – Sesotho +- sn – Shona +- sd – Sindhi +- si – Sinhala +- sk – Slovak +- sl – Slovenian +- so – Somali +- es – Spanish +- su – Sundanese +- sw – Swahili +- sv – Swedish +- tg – Tajik +- ta – Tamil +- tt – Tatar +- te – Telugu +- th – Thai +- ti – Tigrinya +- ts – Tsonga +- tr – Turkish +- tk – Turkmen +- ak – Twi +- uk – Ukrainian +- ur – Urdu +- ug – Uyghur +- uz – Uzbek +- vi – Vietnamese +- cy – Welsh +- xh – Xhosa +- yi – Yiddish +- yo – Yoruba +- zu – Zulu + +
+ ### Install and use: 1. Install my custom nodes in ComfyUI, used [HERE](https://github.com/AlekPet/ComfyUI_Custom_Nodes_AlekPet#installing) 2. To use ChatGMLNode, you need to register on the site [bigmodel.cn](https://bigmodel.cn/) and get an API key. Free model is the `'glm-4-flash'`! -3. Inside folder **ChatGMLNode** find file `config.json` and add API key geting in point 2, and change `"ZHIPUAI_API_KEY": "your_api_key"` on your API Key. +3. Inside folder **ChatGMLNode** find file `config.json.example` rename to config.json and add API key geting in point 2 in propertu `"ZHIPUAI_API_KEY": "your_api_key"` on your API Key. 4. Run comfyui and add node `ChatGLM4TranslateCLIPTextEncodeNode` or `ChatGLM4TranslateTextNode`. +Optional: You can also set initial language values ​​when creating nodes in the file `config.json`. + +```json +{ + "__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY. Change default translate languages ​​'from' and 'to' you use", + "from_translate": "ru", + "to_translate": "en", + "ZHIPUAI_API_KEY": "your_api_key" +} +``` + > Includes: > **ChatGLM4TranslateCLIPTextEncodeNode** - translate text, and return CONDITIONING diff --git a/ChatGLMNode/chatglm_node.py b/ChatGLMNode/chatglm_node.py index bfe8dcc..0f62cfb 100644 --- a/ChatGLMNode/chatglm_node.py +++ b/ChatGLMNode/chatglm_node.py @@ -13,34 +13,52 @@ ALL_CODES_LANGS = ['af', 'sq', 'am', 'ar', 'hy', 'as', 'ay', 'az', 'bm', 'eu', ' ENDPOINT_URL = "https://open.bigmodel.cn/api/paas/v4/chat/completions" -ZHIPUAI_API_KEY = None +def getConfigData(): + # Directory node and config file + dir_node = os.path.dirname(__file__) + config_path = os.path.join(os.path.abspath(dir_node), "config.json") + config = { + "__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY. Change default translate languages ​​'from' and 'to' you use", + "from_translate": "ru", + "to_translate": "en", + "ZHIPUAI_API_KEY": "your_api_key" + } -# Directory node and config file -dir_node = os.path.dirname(__file__) -config_path = os.path.join(os.path.abspath(dir_node), "config.json") + # Load config.js file + if not os.path.exists(config_path): + print("[ChatGLMNode] File config.js file not found! Create default config.json...") + with open(config_path, "w", encoding="utf-8") as f: + json.dump(config, f, ensure_ascii=False, indent=4) + return config + else: + with open(config_path, "r") as f: + config = json.load(f) + return config + # ===== -# Load config.js file -if not os.path.exists(config_path): - print("File config.js file not found! Reinstall extensions!") -else: - with open(config_path, "r") as f: - CONFIG = json.load(f) +def checkPropValue(obj, key, not_include = []): + checkVal = lambda v: v is None or v.strip() == "" or v in not_include - # GET ZHIPUAI_API_KEY from json - ZHIPUAI_API_KEY = CONFIG.get("ZHIPUAI_API_KEY") - # ===== + prop_val = obj.get(key) + if checkVal(prop_val): + obj.update(getConfigData()) + return True if checkVal(obj.get(key)) else False + + else: + return False + + +CONFIG = getConfigData() def createRequest(payload): - global ZHIPUAI_API_KEY + global CONFIG - if ( - ZHIPUAI_API_KEY is None - or ZHIPUAI_API_KEY.strip() == "" - or ZHIPUAI_API_KEY == "your_api_key" - ): + if checkPropValue(CONFIG, "ZHIPUAI_API_KEY", ["your_api_key"]): raise ValueError("ZHIPUAI_API_KEY value is empty or missing") + ZHIPUAI_API_KEY = CONFIG.get("ZHIPUAI_API_KEY") + # Headers headers = { "Authorization": f"Bearer {ZHIPUAI_API_KEY}", @@ -92,15 +110,17 @@ def translate(prompt, srcTrans, toTrans, model, max_tokens, temperature, top_p): class ChatGLM4TranslateCLIPTextEncodeNode: @classmethod def INPUT_TYPES(self): + from_lng = CONFIG.get("from_translate") if CONFIG.get("from_translate") in ALL_CODES_LANGS else "ru" + to_lng = CONFIG.get("to_translate") if CONFIG.get("to_translate") in ALL_CODES_LANGS else "en" return { "required": { "from_translate": ( ALL_CODES_LANGS, - {"default": "ru", "tooltip": "Translation from"}, + {"default": from_lng, "tooltip": "Translation from"}, ), "to_translate": ( ALL_CODES_LANGS, - {"default": "en", "tooltip": "Translation to"}, + {"default": to_lng, "tooltip": "Translation to"}, ), "model": ( [ diff --git a/ChatGLMNode/config.json b/ChatGLMNode/config.json deleted file mode 100644 index 95b4391..0000000 --- a/ChatGLMNode/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY", - "ZHIPUAI_API_KEY": "your_api_key" -} diff --git a/ChatGLMNode/config.json.example b/ChatGLMNode/config.json.example new file mode 100644 index 0000000..87958b1 --- /dev/null +++ b/ChatGLMNode/config.json.example @@ -0,0 +1,6 @@ +{ + "__comment": "Register on the site https://bigmodel.cn and get a key and add it to the field ZHIPUAI_API_KEY. Change default translate languages ​​'from' and 'to' you use", + "from_translate": "ru", + "to_translate": "en", + "ZHIPUAI_API_KEY": "your_api_key" +} diff --git a/pyproject.toml b/pyproject.toml index 7412fb3..e82122d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_custom_nodes_alekpet" description = "Nodes: PoseNode, PainterNode, TranslateTextNode, TranslateCLIPTextEncodeNode, DeepTranslatorTextNode, DeepTranslatorCLIPTextEncodeNode, ArgosTranslateTextNode, ArgosTranslateCLIPTextEncodeNode, ChatGLM4TranslateCLIPTextEncodeNode, ChatGLM4TranslateTextNode, ChatGLM4InstructNode, ChatGLM4InstructMediaNode, DeepLXTranslateTextNode, DeepLXTranslateCLIPTextEncodeNode, PreviewTextNode, HexToHueNode, ColorsCorrectNode, IDENode." -version = "1.0.66" +version = "1.0.67" license = { file = "LICENSE" } [project.urls]