mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-21 12:42:11 -03:00
0.21
This commit is contained in:
12
README.md
12
README.md
@@ -1,4 +1,4 @@
|
|||||||
# 🔗 Comfyui : Bjornulf_custom_nodes v0.19 🔗
|
# 🔗 Comfyui : Bjornulf_custom_nodes v0.21 🔗
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
@@ -29,16 +29,19 @@
|
|||||||
- **v0.17**: New loop node, combine by lines.
|
- **v0.17**: New loop node, combine by lines.
|
||||||
- **v0.18**: New loop node, Free VRAM hack
|
- **v0.18**: New loop node, Free VRAM hack
|
||||||
- **v0.19**: Changes for save to folder node : ignore missing images filenames, will use the highest number found + 1.
|
- **v0.19**: Changes for save to folder node : ignore missing images filenames, will use the highest number found + 1.
|
||||||
|
- **v0.20**: Changes for lobechat save image : include the code of free VRAM hack + ignore missing images filenames
|
||||||
|
- **v0.21**: Add a write text node that also display the text in the comfyui console (good for debugging)
|
||||||
|
|
||||||
# 📝 Nodes descriptions
|
# 📝 Nodes descriptions
|
||||||
|
|
||||||
## 1/2 - 👁 + ✒ Show/Write Text
|
## 1/2 - 👁 + ✒ Show/Write Text
|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
Two simple nodes to write and show text.
|
Three simple nodes to write and show text.
|
||||||
Write node is a textarea where you can write your text.
|
Write node is a textarea where you can write your text.
|
||||||
The show text node will only display the text. (That's why I made it a different color : green, uneditable, display only.)
|
The show text node will only display the text. (That's why I made it a different color : green, uneditable, display only.)
|
||||||
|
|
||||||
## 3 - 🔗 Combine Texts
|
## 3 - 🔗 Combine Texts
|
||||||

|

|
||||||
@@ -286,4 +289,5 @@ For me, on launch ComfyUI is using 180MB of VRAM, after my clean up VRAM node it
|
|||||||
I don't think there is a clean way to do that, so I'm using a hacky way.
|
I don't think there is a clean way to do that, so I'm using a hacky way.
|
||||||
So, not perfect but better than being stuck at 6GB of VRAM used if I know I won't be using it again...
|
So, not perfect but better than being stuck at 6GB of VRAM used if I know I won't be using it again...
|
||||||
Just connect this node with your workflow, it takes an image as input and return the same image without any changes.
|
Just connect this node with your workflow, it takes an image as input and return the same image without any changes.
|
||||||
❗ Comfyui is using cache to run faster (like not reloading checkpoints), so only use this free VRAM node when you need it.
|
❗ Comfyui is using cache to run faster (like not reloading checkpoints), so only use this free VRAM node when you need it.
|
||||||
|
❗ For this node to work properly, you need to enable the dev/api mode in ComfyUI. (You can do that in the settings)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from .images_to_video import imagesToVideo
|
from .images_to_video import imagesToVideo
|
||||||
from .write_text import WriteText
|
from .write_text import WriteText
|
||||||
|
from .write_text_console import WriteTextInConsole
|
||||||
from .write_image_environment import WriteImageEnvironment
|
from .write_image_environment import WriteImageEnvironment
|
||||||
from .write_image_characters import WriteImageCharacters
|
from .write_image_characters import WriteImageCharacters
|
||||||
from .write_image_character import WriteImageCharacter
|
from .write_image_character import WriteImageCharacter
|
||||||
@@ -61,6 +62,7 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
# "Bjornulf_ClearVRAM": ClearVRAM,
|
# "Bjornulf_ClearVRAM": ClearVRAM,
|
||||||
"Bjornulf_SaveBjornulfLobeChat": SaveBjornulfLobeChat,
|
"Bjornulf_SaveBjornulfLobeChat": SaveBjornulfLobeChat,
|
||||||
"Bjornulf_WriteText": WriteText,
|
"Bjornulf_WriteText": WriteText,
|
||||||
|
"Bjornulf_WriteTextInConsole": WriteTextInConsole,
|
||||||
"Bjornulf_RemoveTransparency": RemoveTransparency,
|
"Bjornulf_RemoveTransparency": RemoveTransparency,
|
||||||
"Bjornulf_GrayscaleTransform": GrayscaleTransform,
|
"Bjornulf_GrayscaleTransform": GrayscaleTransform,
|
||||||
"Bjornulf_CombineBackgroundOverlay": CombineBackgroundOverlay,
|
"Bjornulf_CombineBackgroundOverlay": CombineBackgroundOverlay,
|
||||||
@@ -121,6 +123,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
|||||||
"Bjornulf_SaveText": "💾 Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion...
|
"Bjornulf_SaveText": "💾 Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion...
|
||||||
"Bjornulf_LoadText": "📥 Load Text", #Make LoadCharacter, LoadLocation, LoadCamera, LoadAction, LoadClothes, LoadEmotion...
|
"Bjornulf_LoadText": "📥 Load Text", #Make LoadCharacter, LoadLocation, LoadCamera, LoadAction, LoadClothes, LoadEmotion...
|
||||||
"Bjornulf_WriteText": "✒ Write Text",
|
"Bjornulf_WriteText": "✒ Write Text",
|
||||||
|
"Bjornulf_WriteTextInConsole": "✒🗔 Write Text (Console too) ",
|
||||||
# "Bjornulf_WriteImageEnvironment": "✒ Write Image Environment",
|
# "Bjornulf_WriteImageEnvironment": "✒ Write Image Environment",
|
||||||
# "Bjornulf_WriteImageCharacters": "✒ Write Image Characters",
|
# "Bjornulf_WriteImageCharacters": "✒ Write Image Characters",
|
||||||
# "Bjornulf_WriteImageCharacter": "✒ Write Image Character",
|
# "Bjornulf_WriteImageCharacter": "✒ Write Image Character",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "bjornulf_custom_nodes"
|
name = "bjornulf_custom_nodes"
|
||||||
description = "Nodes: Ollama, Text to Speech, Save image for Bjornulf LobeChat, Text with random Seed, Random line from input, Combine images (Background+Overlay alpha), Image to grayscale (black & white), Remove image Transparency (alpha), Resize Image, ..."
|
description = "Nodes: Ollama, Text to Speech, Save image for Bjornulf LobeChat, Text with random Seed, Random line from input, Combine images (Background+Overlay alpha), Image to grayscale (black & white), Remove image Transparency (alpha), Resize Image, ..."
|
||||||
version = "0.19"
|
version = "0.21"
|
||||||
license = {file = "LICENSE"}
|
license = {file = "LICENSE"}
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import numpy as np
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
import json
|
import json
|
||||||
from PIL.PngImagePlugin import PngInfo
|
from PIL.PngImagePlugin import PngInfo
|
||||||
|
import torch
|
||||||
|
import gc
|
||||||
|
import requests
|
||||||
|
|
||||||
class SaveBjornulfLobeChat:
|
class SaveBjornulfLobeChat:
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -20,6 +23,9 @@ class SaveBjornulfLobeChat:
|
|||||||
CATEGORY = "Bjornulf"
|
CATEGORY = "Bjornulf"
|
||||||
|
|
||||||
def save_bjornulf_lobe_chat(self, image, prompt=None, extra_pnginfo=None):
|
def save_bjornulf_lobe_chat(self, image, prompt=None, extra_pnginfo=None):
|
||||||
|
# First, attempt to free VRAM
|
||||||
|
self.free_vram()
|
||||||
|
|
||||||
# Ensure the output directory exists
|
# Ensure the output directory exists
|
||||||
output_dir = "./output/BJORNULF_LOBECHAT/"
|
output_dir = "./output/BJORNULF_LOBECHAT/"
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
@@ -33,13 +39,16 @@ class SaveBjornulfLobeChat:
|
|||||||
|
|
||||||
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
|
||||||
|
|
||||||
# Determine the next available filename
|
# Find the highest existing file number
|
||||||
counter = 1
|
existing_files = [f for f in os.listdir(output_dir) if f.startswith('api_') and f.endswith('.png') and f[4:-4].isdigit()]
|
||||||
while True:
|
if existing_files:
|
||||||
filename = f"{output_dir}api_{counter:05d}.png"
|
highest_num = max(int(f[4:-4]) for f in existing_files)
|
||||||
if not os.path.exists(filename):
|
counter = highest_num + 1
|
||||||
break
|
else:
|
||||||
counter += 1
|
counter = 1
|
||||||
|
|
||||||
|
# Determine the filename
|
||||||
|
filename = f"{output_dir}api_{counter:05d}.png"
|
||||||
|
|
||||||
# Prepare metadata
|
# Prepare metadata
|
||||||
metadata = PngInfo()
|
metadata = PngInfo()
|
||||||
@@ -60,4 +69,44 @@ class SaveBjornulfLobeChat:
|
|||||||
|
|
||||||
print(f"Image saved as: {filename}")
|
print(f"Image saved as: {filename}")
|
||||||
|
|
||||||
return {"ui": {"images": [{"filename": filename, "type": "output"}]}}
|
return {"ui": {"images": [{"filename": filename, "type": "output"}]}}
|
||||||
|
|
||||||
|
def free_vram(self):
|
||||||
|
print("Attempting to free VRAM...")
|
||||||
|
|
||||||
|
# Clear CUDA cache
|
||||||
|
if torch.cuda.is_available():
|
||||||
|
torch.cuda.empty_cache()
|
||||||
|
print("CUDA cache cleared.")
|
||||||
|
|
||||||
|
# Run garbage collection
|
||||||
|
collected = gc.collect()
|
||||||
|
print(f"Garbage collector: collected {collected} objects.")
|
||||||
|
|
||||||
|
# Trigger the HTTP request
|
||||||
|
self.trigger_http_request()
|
||||||
|
|
||||||
|
def trigger_http_request(self):
|
||||||
|
url = "http://localhost:8188/prompt"
|
||||||
|
headers = {"Content-Type": "application/json"}
|
||||||
|
payload = {
|
||||||
|
"prompt": {
|
||||||
|
"3": {
|
||||||
|
"inputs": {"text": "free VRAM hack"},
|
||||||
|
"class_type": "Bjornulf_WriteText",
|
||||||
|
"_meta": {"title": "✒ Write Text"}
|
||||||
|
},
|
||||||
|
"4": {
|
||||||
|
"inputs": {"text_value": ["3", 0], "text": "free VRAM hack"},
|
||||||
|
"class_type": "Bjornulf_ShowText",
|
||||||
|
"_meta": {"title": "👁 Show (Text)"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
||||||
|
response.raise_for_status()
|
||||||
|
print("HTTP request triggered successfully")
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Failed to trigger HTTP request: {e}")
|
||||||
BIN
screenshots/write_in_console.png
Normal file
BIN
screenshots/write_in_console.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
21
write_text_console.py
Normal file
21
write_text_console.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import logging
|
||||||
|
class WriteTextInConsole:
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"text": ("STRING", {"multiline": True}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# INPUT_IS_LIST = True
|
||||||
|
RETURN_TYPES = ("STRING",)
|
||||||
|
RETURN_NAMES = ("text",)
|
||||||
|
FUNCTION = "write_text_in_console"
|
||||||
|
OUTPUT_NODE = True
|
||||||
|
OUTPUT_IS_LIST = (False,)
|
||||||
|
CATEGORY = "Bjornulf"
|
||||||
|
|
||||||
|
def write_text_in_console(self, text):
|
||||||
|
logging.info(f"Text: {text}")
|
||||||
|
return {"ui": {"text": text}, "result": (text,)}
|
||||||
Reference in New Issue
Block a user