mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-21 20:52:11 -03:00
Replace Save API node with Save Bjornulf Lobechat node
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ web/js/clear_vram.js
|
||||
CUSTOM_STRING.py.txt
|
||||
web/js/BJORNULF_TYPES.js.txt
|
||||
web/js/CUSTOM_STRING.js.txt
|
||||
save_api_image.py.txt
|
||||
14
README.md
14
README.md
@@ -1,4 +1,4 @@
|
||||
# 🔗 Comfyui : Bjornulf_custom_nodes v0.6 🔗
|
||||
# 🔗 Comfyui : Bjornulf_custom_nodes v0.7 🔗
|
||||
|
||||
# Dependencies
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
- **v0.5**: New node : Remove image transparency (alpha) - Fill alpha channel with solid color.
|
||||
- **v0.5**: New node : Image to grayscale (black & white) - Convert an image to grayscale.
|
||||
- **v0.6**: New node : Combine images (Background + Overlay) - Combine two images into a single image.
|
||||
- **v0.7**: Replace Save API node with Save Bjornulf Lobechat node. (For my custom lobe-chat)
|
||||
|
||||
# 📝 Nodes descriptions
|
||||
|
||||
@@ -97,13 +98,15 @@ Resize an image to exact dimensions. The other node will save the image to the e
|
||||
**Description:**
|
||||
Save the given text input to a file. Useful for logging and storing text data.
|
||||
|
||||
## 16 - 🖼 Save image for API (❗For my custom [lobe-chat](https://github.com/justUmen/lobe-chat)❗)
|
||||

|
||||
## 16 - 🖼💬 Save image for Bjornulf LobeChat (❗For my custom [lobe-chat](https://github.com/justUmen/Bjornulf_lobe-chat)❗)
|
||||

|
||||
|
||||
**Description:**
|
||||
It will save the image with the name of `api_next_image.txt`, which will be incremented each time you run the node.
|
||||
❓ I made that node for my custom lobe-chat to send+receive images from Comfyui API : [lobe-chat](https://github.com/justUmen/Bjornulf_lobe-chat)
|
||||
It will save the image in the folder `output/BJORNULF_LOBECHAT/`.
|
||||
The name will start at `api_00001.png`, then `api_00002.png`, etc...
|
||||
❓ I made that for my custom lobe-chat to send+receive images from Comfyui API : [lobe-chat](https://github.com/justUmen/lobe-chat)
|
||||
It will also create a link to the last generated image at the location `output/BJORNULF_API_LAST_IMAGE.png`.
|
||||
This link will be used by my custom lobe-chat to copy the image inside the lobe-chat project.
|
||||
|
||||
## 17 - 🖼 Save image as `tmp_api.png` Temporary API ⚠️💣
|
||||

|
||||
@@ -111,7 +114,6 @@ The name will start at `api_00001.png`, then `api_00002.png`, etc...
|
||||
**Description:**
|
||||
Save image for short-term use : ./output/tmp_api.png ⚠️💣
|
||||
|
||||
|
||||
## 18 - 🖼📁 Save image to a chosen folder name
|
||||

|
||||
|
||||
|
||||
12
__init__.py
12
__init__.py
@@ -21,13 +21,15 @@ from .show_float import ShowFloat
|
||||
from .save_text import SaveText
|
||||
from .save_tmp_image import SaveTmpImage
|
||||
from .save_image_path import SaveImagePath
|
||||
from .save_api_image import SaveApiImage
|
||||
# from .save_api_image import SaveApiImage
|
||||
from .save_img_to_folder import SaveImageToFolder
|
||||
from .resize_image import ResizeImage
|
||||
from .loop_my_combos_samplers_schedulers import LoopCombosSamplersSchedulers
|
||||
from .remove_transparency import RemoveTransparency
|
||||
from .image_to_grayscale import GrayscaleTransform
|
||||
from .combine_background_overlay import CombineBackgroundOverlay
|
||||
from .save_bjornulf_lobechat import SaveBjornulfLobeChat
|
||||
# from .check_black_image import CheckBlackImage
|
||||
# from .clear_vram import ClearVRAM
|
||||
|
||||
# from .CUSTOM_STRING import CustomStringType
|
||||
@@ -35,7 +37,9 @@ from .combine_background_overlay import CombineBackgroundOverlay
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
# "Bjornulf_CustomStringType": CustomStringType,
|
||||
"Bjornulf_ollamaLoader": ollamaLoader,
|
||||
# "Bjornulf_CheckBlackImage": CheckBlackImage,
|
||||
# "Bjornulf_ClearVRAM": ClearVRAM,
|
||||
"Bjornulf_SaveBjornulfLobeChat": SaveBjornulfLobeChat,
|
||||
"Bjornulf_WriteText": WriteText,
|
||||
"Bjornulf_RemoveTransparency": RemoveTransparency,
|
||||
"Bjornulf_GrayscaleTransform": GrayscaleTransform,
|
||||
@@ -52,7 +56,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
"Bjornulf_SaveImageToFolder": SaveImageToFolder,
|
||||
"Bjornulf_SaveTmpImage": SaveTmpImage,
|
||||
"Bjornulf_SaveImagePath": SaveImagePath,
|
||||
"Bjornulf_SaveApiImage": SaveApiImage,
|
||||
# "Bjornulf_SaveApiImage": SaveApiImage,
|
||||
"Bjornulf_CombineTexts": CombineTexts,
|
||||
"Bjornulf_LoopTexts": LoopTexts,
|
||||
"Bjornulf_RandomTexts": RandomTexts,
|
||||
@@ -70,6 +74,8 @@ NODE_CLASS_MAPPINGS = {
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
# "Bjornulf_CustomStringType": "!!! CUSTOM STRING TYPE !!!",
|
||||
"Bjornulf_ollamaLoader": "🦙 Ollama (Description)",
|
||||
# "Bjornulf_CheckBlackImage": "🔲 Check Black Image (Empty mask)",
|
||||
"Bjornulf_SaveBjornulfLobeChat": "🖼💬 Save image for Bjornulf LobeChat",
|
||||
# "Bjornulf_ClearVRAM": "🧹 Clear VRAM",
|
||||
"Bjornulf_ShowText": "👁 Show (Text)",
|
||||
"Bjornulf_ShowInt": "👁 Show (Int)",
|
||||
@@ -81,7 +87,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"Bjornulf_SaveImagePath": "🖼 Save Image (exact path, exact name) ⚠️💣",
|
||||
"Bjornulf_SaveImageToFolder": "🖼📁 Save Image to a folder",
|
||||
"Bjornulf_SaveTmpImage": "🖼 Save Image (tmp_api.png) ⚠️💣",
|
||||
"Bjornulf_SaveApiImage": "🖼 Save Image (./output/api_00001.png...)",
|
||||
# "Bjornulf_SaveApiImage": "🖼 Save Image (./output/api_00001.png...)",
|
||||
"Bjornulf_SaveText": "💾 Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion...
|
||||
"Bjornulf_LoadText": "📥 Load Text", #Make LoadCharacter, LoadLocation, LoadCamera, LoadAction, LoadClothes, LoadEmotion...
|
||||
"Bjornulf_WriteText": "✒ Write Text",
|
||||
|
||||
@@ -4,7 +4,7 @@ from PIL import Image
|
||||
import json
|
||||
from PIL.PngImagePlugin import PngInfo
|
||||
|
||||
class SaveApiImage:
|
||||
class SaveBjornulfLobeChat:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
@@ -14,14 +14,15 @@ class SaveApiImage:
|
||||
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
|
||||
}
|
||||
|
||||
FUNCTION = "save_api_image"
|
||||
FUNCTION = "save_bjornulf_lobe_chat"
|
||||
RETURN_TYPES = ()
|
||||
OUTPUT_NODE = True
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def save_api_image(self, image, prompt=None, extra_pnginfo=None):
|
||||
def save_bjornulf_lobe_chat(self, image, prompt=None, extra_pnginfo=None):
|
||||
# Ensure the output directory exists
|
||||
os.makedirs("./output/", exist_ok=True)
|
||||
output_dir = "./output/BJORNULF_LOBECHAT/"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
# Convert the image from ComfyUI format to PIL Image
|
||||
i = 255. * image.cpu().numpy()
|
||||
@@ -35,11 +36,14 @@ class SaveApiImage:
|
||||
# Determine the next available filename
|
||||
counter = 1
|
||||
while True:
|
||||
filename = f"./output/api_{counter:05d}.png"
|
||||
filename = f"{output_dir}api_{counter:05d}.png"
|
||||
if not os.path.exists(filename):
|
||||
break
|
||||
counter += 1
|
||||
|
||||
# Save the image with the determined filename
|
||||
img.save(filename, format="PNG")
|
||||
|
||||
# Prepare metadata
|
||||
metadata = PngInfo()
|
||||
if prompt is not None:
|
||||
@@ -48,12 +52,11 @@ class SaveApiImage:
|
||||
for k, v in extra_pnginfo.items():
|
||||
metadata.add_text(k, json.dumps(v))
|
||||
|
||||
# Save the image with the determined filename and metadata
|
||||
img.save(filename, format="PNG", pnginfo=metadata)
|
||||
|
||||
# Write the number of the last image to a text file with leading zeroes
|
||||
with open("./output/api_next_image.txt", "w") as f:
|
||||
f.write(f"api_{counter+1:05d}.png")
|
||||
# Update the symbolic link in the output directory
|
||||
link_path = "./output/BJORNULF_API_LAST_IMAGE.png"
|
||||
if os.path.exists(link_path):
|
||||
os.remove(link_path)
|
||||
os.symlink(os.path.abspath(filename), link_path)
|
||||
|
||||
print(f"Image saved as: {filename}")
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 292 KiB |
BIN
screenshots/save_bjornulf_lobechat.png
Normal file
BIN
screenshots/save_bjornulf_lobechat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 464 KiB |
Reference in New Issue
Block a user