Add a Send Text node
- converts any input to string and sends it as output (websocket message)
This commit is contained in:
@@ -18,6 +18,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"ETN_NSFWFilter": nsfw.NSFWFilter,
|
||||
"ETN_Translate": translation.Translate,
|
||||
"ETN_KritaOutput": krita.KritaOutput,
|
||||
"ETN_KritaSendText": krita.KritaSendText,
|
||||
"ETN_KritaCanvas": krita.KritaCanvas,
|
||||
"ETN_KritaSelection": krita.KritaSelection,
|
||||
"ETN_KritaImageLayer": krita.KritaImageLayer,
|
||||
@@ -43,6 +44,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"ETN_NSFWFilter": "NSFW Filter",
|
||||
"ETN_Translate": "Translate Text",
|
||||
"ETN_KritaOutput": "Krita Output",
|
||||
"ETN_KritaSendText": "Send Text",
|
||||
"ETN_KritaCanvas": "Krita Canvas",
|
||||
"ETN_KritaSelection": "Krita Selection",
|
||||
"ETN_KritaImageLayer": "Krita Image Layer",
|
||||
|
||||
@@ -186,8 +186,14 @@ app.registerExtension({
|
||||
setIconImage(nodeType, canvasIcon, [200, 100], 0, 2)
|
||||
} else if (nodeData.name === "ETN_KritaOutput") {
|
||||
setIconImage(nodeType, outputIcon, [200, 120], 2, 0)
|
||||
} else if (nodeData.name == "ETN_Parameter") {
|
||||
} else if (nodeData.name === "ETN_Parameter") {
|
||||
setupParameterNode(nodeType)
|
||||
} else if (nodeData.name === "ETN_SendText") {
|
||||
const onAdded = nodeType.prototype.onAdded
|
||||
nodeType.prototype.onAdded = function() {
|
||||
onAdded?.apply(this, arguments)
|
||||
this.inputs[0].type = "*"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import torch
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
from typing import Any, NamedTuple
|
||||
from PIL import Image
|
||||
|
||||
import server
|
||||
@@ -55,6 +55,25 @@ def _placeholder_image():
|
||||
return torch.from_numpy(image)[None,]
|
||||
|
||||
|
||||
class _AnyType(str):
|
||||
def __ne__(self, other):
|
||||
return False
|
||||
|
||||
|
||||
class _BasicTypes(str):
|
||||
basic_types = ["INT", "FLOAT", "STRING", "BOOL"]
|
||||
|
||||
def __eq__(self, other):
|
||||
return other in self.basic_types or isinstance(other, (list, _BasicTypes))
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
AnyType = _AnyType("*")
|
||||
BasicTypes = _BasicTypes("BASIC")
|
||||
|
||||
|
||||
class KritaOutput(SendImageWebSocket):
|
||||
RETURN_TYPES = ()
|
||||
FUNCTION = "send_images"
|
||||
@@ -62,6 +81,39 @@ class KritaOutput(SendImageWebSocket):
|
||||
CATEGORY = "krita"
|
||||
|
||||
|
||||
class KritaSendText:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": (AnyType, {}),
|
||||
"name": ("STRING", {"default": "Output"}),
|
||||
"type": (["text", "markdown", "html"], {"default": "text"}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ()
|
||||
FUNCTION = "send"
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "krita"
|
||||
|
||||
def send(self, value: Any, name: str, type: str):
|
||||
mime = {
|
||||
"text": "text/plain",
|
||||
"markdown": "text/markdown",
|
||||
"html": "text/html",
|
||||
}[type]
|
||||
text = "None"
|
||||
if value is not None:
|
||||
try:
|
||||
text = str(value)
|
||||
except Exception as e:
|
||||
text = f"Could not convert to text: {e}"
|
||||
|
||||
print(f"Sending text: {name} = {text}")
|
||||
return {"ui": {"text": [{"name": name, "text": text, "content-type": mime}]}}
|
||||
|
||||
|
||||
class KritaCanvas:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
@@ -126,20 +178,6 @@ class KritaMaskLayer:
|
||||
return (torch.ones(1, 512, 512),)
|
||||
|
||||
|
||||
class _BasicTypes(str):
|
||||
basic_types = ["INT", "FLOAT", "STRING", "BOOL"]
|
||||
|
||||
def __eq__(self, other):
|
||||
return other in self.basic_types or isinstance(other, (list, _BasicTypes))
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __str__(self):
|
||||
return "BASIC"
|
||||
|
||||
|
||||
BasicTypes = _BasicTypes()
|
||||
_param_types = [
|
||||
"auto",
|
||||
"number",
|
||||
|
||||
Reference in New Issue
Block a user