mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-24 05:52:11 -03:00
v0.9, add node random line from input
This commit is contained in:
12
README.md
12
README.md
@@ -1,4 +1,4 @@
|
||||
# 🔗 Comfyui : Bjornulf_custom_nodes v0.8 🔗
|
||||
# 🔗 Comfyui : Bjornulf_custom_nodes v0.9 🔗
|
||||
|
||||
# Dependencies
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
- **v0.8**: Combine images : add an option to put image top, bottom or center.
|
||||
- **v0.8**: Combine texts : add option for slashes /
|
||||
- **v0.8**: Add basic node to transform greenscreen in to transparency.
|
||||
- **v0.9**: Add a new node : Return one random line from input.
|
||||
|
||||
# 📝 Nodes descriptions
|
||||
|
||||
@@ -178,4 +179,11 @@ Update 0.8 : Also have a option to put image top, bottom or center.
|
||||
|
||||
**Description:**
|
||||
Transform greenscreen into transparency.
|
||||
Need clean greenscreen ofc. (Can adjust threshold but very basic node.)
|
||||
Need clean greenscreen ofc. (Can adjust threshold but very basic node.)
|
||||
|
||||
## 26 - 🎲 Random line from input
|
||||

|
||||
|
||||
**Description:**
|
||||
Take a random line from an input text. (When using multiple "Write Text" nodes is annoying for example, you can use that and just copy/paste a list from outside.)
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ from .image_to_grayscale import GrayscaleTransform
|
||||
from .combine_background_overlay import CombineBackgroundOverlay
|
||||
from .save_bjornulf_lobechat import SaveBjornulfLobeChat
|
||||
from .green_to_transparency import GreenScreenToTransparency
|
||||
from .random_line_from_input import RandomLineFromInput
|
||||
# from .check_black_image import CheckBlackImage
|
||||
# from .clear_vram import ClearVRAM
|
||||
|
||||
@@ -39,6 +40,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
# "Bjornulf_CustomStringType": CustomStringType,
|
||||
"Bjornulf_ollamaLoader": ollamaLoader,
|
||||
"Bjornulf_GreenScreenToTransparency": GreenScreenToTransparency,
|
||||
"Bjornulf_RandomLineFromInput": RandomLineFromInput,
|
||||
# "Bjornulf_CheckBlackImage": CheckBlackImage,
|
||||
# "Bjornulf_ClearVRAM": ClearVRAM,
|
||||
"Bjornulf_SaveBjornulfLobeChat": SaveBjornulfLobeChat,
|
||||
@@ -80,6 +82,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
# "Bjornulf_CheckBlackImage": "🔲 Check Black Image (Empty mask)",
|
||||
"Bjornulf_SaveBjornulfLobeChat": "🖼💬 Save image for Bjornulf LobeChat",
|
||||
# "Bjornulf_ClearVRAM": "🧹 Clear VRAM",
|
||||
"Bjornulf_RandomLineFromInput": "🎲 Random line from input",
|
||||
"Bjornulf_ShowText": "👁 Show (Text)",
|
||||
"Bjornulf_ShowInt": "👁 Show (Int)",
|
||||
"Bjornulf_ShowFloat": "👁 Show (Float)",
|
||||
@@ -89,7 +92,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
# "🔲➜⬛ Transparency to color",
|
||||
"Bjornulf_ResizeImage": "📏 Resize Image",
|
||||
"Bjornulf_SaveImagePath": "🖼 Save Image (exact path, exact name) ⚠️💣",
|
||||
"Bjornulf_SaveImageToFolder": "🖼📁 Save Image to a folder",
|
||||
"Bjornulf_SaveImageToFolder": "🖼📁 Save Image(s) to a folder",
|
||||
"Bjornulf_SaveTmpImage": "🖼 Save Image (tmp_api.png) ⚠️💣",
|
||||
# "Bjornulf_SaveApiImage": "🖼 Save Image (./output/api_00001.png...)",
|
||||
"Bjornulf_SaveText": "💾 Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion...
|
||||
|
||||
34
random_line_from_input.py
Normal file
34
random_line_from_input.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import random
|
||||
|
||||
class RandomLineFromInput:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING", {"forceInput": True}),
|
||||
"seed": ("INT", {"default": 1}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "random_line"
|
||||
OUTPUT_IS_LIST = (False,)
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def random_line(self, text, seed):
|
||||
random.seed(seed)
|
||||
|
||||
# Split the input text into lines
|
||||
lines = text.split('\n')
|
||||
|
||||
# Remove empty lines and strip whitespace
|
||||
lines = [line.strip() for line in lines if line.strip()]
|
||||
|
||||
if not lines:
|
||||
return ([""],)
|
||||
|
||||
# Select a random line
|
||||
chosen_line = random.choice(lines)
|
||||
|
||||
# Return as a list with one element
|
||||
return ([chosen_line],)
|
||||
@@ -41,9 +41,6 @@ class SaveBjornulfLobeChat:
|
||||
break
|
||||
counter += 1
|
||||
|
||||
# Save the image with the determined filename
|
||||
img.save(filename, format="PNG")
|
||||
|
||||
# Prepare metadata
|
||||
metadata = PngInfo()
|
||||
if prompt is not None:
|
||||
@@ -57,6 +54,9 @@ class SaveBjornulfLobeChat:
|
||||
if os.path.exists(link_path):
|
||||
os.remove(link_path)
|
||||
os.symlink(os.path.abspath(filename), link_path)
|
||||
|
||||
# Save the image with the determined filename
|
||||
img.save(os.path.abspath(filename), format="PNG", pnginfo=metadata)
|
||||
|
||||
print(f"Image saved as: {filename}")
|
||||
|
||||
|
||||
@@ -47,4 +47,4 @@ class SaveImageToFolder:
|
||||
print(f"Image saved as: {filename}")
|
||||
results.append({"filename": filename})
|
||||
|
||||
return {"ui": {"images": results}}
|
||||
return {"ui": {"images": [{"filename": filename, "type": "output"}]}}
|
||||
BIN
screenshots/random_line_from_input.png
Normal file
BIN
screenshots/random_line_from_input.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
14
web/js/random_line_from_input.js
Normal file
14
web/js/random_line_from_input.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.RandomLineFromInput",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_RandomLineFromInput") {
|
||||
// Set seed widget to hidden input
|
||||
const seedWidget = node.widgets.find(w => w.name === "seed");
|
||||
if (seedWidget) {
|
||||
seedWidget.type = "HIDDEN";
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user