Added autotranslator
Added autotranslator based on Google Translate
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import re
|
||||
import random
|
||||
import time
|
||||
from deep_translator import GoogleTranslator
|
||||
from langdetect import detect
|
||||
|
||||
class TextChoiceParser:
|
||||
@classmethod
|
||||
@@ -51,11 +53,55 @@ class TextChoiceParser:
|
||||
def IS_CHANGED(s, text, variables="", seed=None):
|
||||
return (text, variables, seed)
|
||||
|
||||
class CLIPTextEncodeTranslate:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"text": ("STRING", {"multiline": True, "dynamicPrompts": True}), "clip": ("CLIP", )}}
|
||||
RETURN_TYPES = ("CONDITIONING",)
|
||||
FUNCTION = "clip_text_encode_translate"
|
||||
CATEGORY = "LevelPixel/Text"
|
||||
|
||||
def clip_text_encode_translate(self, clip, text):
|
||||
if text.strip():
|
||||
detected_lang = detect(text)
|
||||
if detected_lang != 'en':
|
||||
try:
|
||||
translator = GoogleTranslator(source='auto', target='en')
|
||||
text = translator.translate(text)
|
||||
except Exception as e:
|
||||
print(f"Translation error: {e}")
|
||||
tokens = clip.tokenize(text)
|
||||
cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True)
|
||||
return ([[cond, {"pooled_output": pooled}]], )
|
||||
|
||||
class TextTranslate:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": {"text": ("STRING", {"default": "text", "multiline": True})}}
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("text",)
|
||||
FUNCTION = "text_translate"
|
||||
CATEGORY = "LevelPixel/Text"
|
||||
|
||||
def text_translate(self, prompt):
|
||||
if prompt.strip():
|
||||
detected_lang = detect(prompt)
|
||||
if detected_lang != 'en':
|
||||
try:
|
||||
translator = GoogleTranslator(source='auto', target='en')
|
||||
prompt = translator.translate(prompt)
|
||||
except Exception as e:
|
||||
print(f"Translation error: {e}")
|
||||
return (prompt,)
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"TextChoiceParser|LP": TextChoiceParser,
|
||||
"CLIPTextEncodeTranslate|LP": CLIPTextEncodeTranslate,
|
||||
"TextTranslate|LP": TextTranslate,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"TextChoiceParser|LP": "Text Choice Parser [LP]",
|
||||
}
|
||||
|
||||
"CLIPTextEncodeTranslate|LP": "CLIP Text Encode Translate [LP]",
|
||||
"TextTranslate|LP": "Text Translate [LP]",
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
[project]
|
||||
name = "comfyui_level_pixel"
|
||||
description = "Various nodes of the Level Pixel company. Includes convenient advanced nodes for working with images from folders; counting files in a folder; cleaning memory; tag filters. Model Unloader, LLM Unloader (GGUF unloaders), Free memory, Tag Filters, Tag Category Filters, Tag Choice Parser, File counter, Image Loader From Path (with counters), Image Remove Background based on RemBG, Autotagger."
|
||||
version = "1.0.9"
|
||||
version = "1.1.0"
|
||||
license = { file = "LICENSE" }
|
||||
dependencies = ["torch>=2.0.1", "torchvision>=0.15.2", "numpy", "matplotlib", "scikit-build-core>=0.10.7", "rembg>=2.0.59", "onnxruntime-gpu>=1.18.0", "onnxruntime>=1.20.0"]
|
||||
dependencies = ["torch>=2.0.1", "torchvision>=0.15.2", "pillow>=9.4.0", "numpy", "matplotlib", "scikit-build-core>=0.10.7", "rembg>=2.0.59", "onnxruntime-gpu>=1.20.0", "onnxruntime>=1.20.0", "googletrans", "langdetect", "httpcore", "deep_translator"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/LevelPixel/ComfyUI-LevelPixel"
|
||||
|
||||
+5
-1
@@ -6,4 +6,8 @@ matplotlib
|
||||
scikit-build-core>=0.10.7
|
||||
rembg>=2.0.59
|
||||
onnxruntime-gpu>=1.20.0
|
||||
onnxruntime>=1.20.0
|
||||
onnxruntime>=1.20.0
|
||||
googletrans
|
||||
langdetect
|
||||
httpcore
|
||||
deep_translator
|
||||
Reference in New Issue
Block a user