Merge branch 'master' of https://github.com/AlekPet/ComfyUI_Custom_Nodes_AlekPet into new_init_config_disabled

This commit is contained in:
AlekPet
2025-05-17 16:07:20 +03:00
10 changed files with 221 additions and 74 deletions
+1
View File
@@ -0,0 +1 @@
config.json
+151 -1
View File
@@ -2,13 +2,163 @@
Translation is carried out with the help of artificial intelligence using GLM models.
<details>
<summary><strong>Language Codes List</strong></summary>
- 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
</details>
### 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
+41 -21
View File
@@ -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": (
[
-4
View File
@@ -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"
}
+6
View File
@@ -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"
}
+16 -4
View File
@@ -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,
@@ -363,6 +363,11 @@ app.registerExtension({
onchange: (e) => {
const checked = !!e.target.checked;
PreviewImageSize = checked;
localStorage.setItem(
`Comfy.Settings.${idExt}.PreviewImage`,
checked
);
sett(checked);
},
}),
@@ -488,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);
},
}),
@@ -811,7 +823,7 @@ app.registerExtension({
await new Promise((res) =>
setTimeout(() => {
res();
}, 16 * this.widgets.length)
}, 16 * this.widgets?.length ?? 1)
);
if (!isIncludesSpeech && widgetsTextMulti.length) {
@@ -833,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 (
+5 -11
View File
@@ -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)",
@@ -766,6 +759,7 @@ function createPreiviewSize(node, name, options) {
fontSize: "0.8rem",
color: color,
fontFamily: "monospace",
textAlign: "center",
padding: 0,
margin: 0,
outline: 0,
-31
View File
@@ -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) {
-1
View File
@@ -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) {
+1 -1
View File
@@ -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.67"
license = { file = "LICENSE" }
[project.urls]