Skip to content

Commit

Permalink
Get Paramater From Prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzie1 committed Jan 5, 2024
1 parent 9384e91 commit 9e0dead
Show file tree
Hide file tree
Showing 9 changed files with 1,140 additions and 1,358 deletions.
3 changes: 3 additions & 0 deletions Patch_Notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 🧩 Comfyroll Studio - Patch Notes

## v1.61 Jan 5, 2024
- added CR Get Parameter From Prompt

## v1.60 Jan 4, 2024
- added CR Bit Scheduler
- added CR Loops
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Co-authored by Suzie1 and RockOfFire

Current version: 1.60
Current version: 1.61

# Wiki

Expand Down Expand Up @@ -253,6 +253,7 @@ __⚙️ Utils Other__
* CR Set Value On Boolean (new 29/12/2023)
* CR Set Value On Binary (new 3/1/2024)
* CR Math Operation (new 31/12/2023)
* CR Get Parameter From Prompt (new 5/1/2024)

## Legacy
__💀 Legacy Nodes__
Expand Down Expand Up @@ -295,4 +296,4 @@ pythongosssss/[ComfyUI-Custom-Scripts](https://github.com/pythongosssss/ComfyUI-

bash-j/[mikey_nodes](https://github.com/bash-j/mikey_nodes) - comfy nodes from mikey

ltdrdata/[ComfyUI-Impact-Pack](https://github.com/ltdrdata/ComfyUI-Impact-Pack) -
ltdrdata/[ComfyUI-Impact-Pack](https://github.com/ltdrdata/ComfyUI-Impact-Pack) -
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@author: Suzie1
@title: Comfyroll Studio
@nickname: Comfyroll Studio
@description: 157 custom nodes for artists, designers and animators.
@description: 159 custom nodes for artists, designers and animators.
"""

from .live_node_mappings import LIVE_NODE_CLASS_MAPPINGS, LIVE_NODE_DISPLAY_NAME_MAPPINGS
Expand All @@ -36,7 +36,7 @@
NODE_DISPLAY_NAME_MAPPINGS = LIVE_NODE_DISPLAY_NAME_MAPPINGS

print("------------------------------------------")
print("\033[34mComfyroll Studio v1.60 : \033[92m 157 Nodes Loaded\033[0m")
print("\033[34mComfyroll Studio v1.61 : \033[92m 159 Nodes Loaded\033[0m")
print("------------------------------------------")
print("** For changes, please see patch notes at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/main/Patch_Notes.md")
print("** For help, please see the wiki at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki")
Expand Down
6 changes: 4 additions & 2 deletions live_node_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@
"CR Clamp Value": CR_ClampValue,
"CR Set Value On Boolean": CR_SetValueOnBoolean,
"CR Set Value On Binary": CR_SetValueOnBinary,
"CR Math Operation": CR_MathOperation,
"CR Math Operation": CR_MathOperation,
"CR Get Parameter From Prompt": CR_GetParameterFromPrompt,
#------------------------------------------------------
### Animation Nodes
# Schedules
Expand Down Expand Up @@ -432,7 +433,8 @@
"CR Clamp Value": "⚙️ CR Clamp Value",
"CR Set Value On Boolean": "⚙️ CR Set Value On Boolean",
"CR Set Value On Binary": "⚙️ CR Set Value On Binary",
"CR Math Operation": "⚙️ CR Math Operation",
"CR Math Operation": "⚙️ CR Math Operation",
"CR Get Parameter From Prompt": "⚙️ CR Get Parameter From Prompt",
#------------------------------------------------------
### Animation Nodes
# Schedules
Expand Down
62 changes: 61 additions & 1 deletion nodes/nodes_utils_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,65 @@ def do_math(self, a, operation, decimal_places):

return (result, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
class CR_GetParameterFromPrompt:

@classmethod
def INPUT_TYPES(cls):

return {
"required": {
"prompt": ("STRING", {"multiline": True, "default": "prompt"}),
"search_string": ("STRING", {"multiline": False, "default": "!findme"}),
}
}

RETURN_TYPES =("STRING", "STRING", "FLOAT", "BOOLEAN", "STRING", )
RETURN_NAMES =("prompt", "text", "float", "boolean", "show_help", )
FUNCTION = "get_string"
CATEGORY = icons.get("Comfyroll/Utils/Other")

def get_string(self, prompt, search_string):

show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Other-Nodes#cr-find-string-in-prompt"

return_string = ""
return_value = 0
return_boolean = False
return_prompt = prompt

index = prompt.find(search_string)
if index != -1:
space_index = prompt.find(" ", index)
return_string = prompt[index + len(search_string):space_index] if space_index != -1 else prompt[index + len(search_string):]

print(return_string)
if return_string == "":
return (return_prompt, return_string, return_value, return_boolean, show_help, )

if return_string.startswith("="):
return_string = return_string[1:]
else:
return_string = ""

return_boolean = return_string.lower() == "true"

# Check if return_string is an integer or a float
try:
return_value = int(return_string)
except ValueError:
try:
return_value = float(return_string)
except ValueError:
return_value = 0

remove_string = " " + search_string + "=" + return_string

# The return_prompt should have the search_string and the return_text removed
return_prompt = prompt.replace(remove_string, "")

return (return_prompt, return_string, return_value, return_boolean, show_help, )

#---------------------------------------------------------------------------------------------------------------------#
# MAPPINGS
#---------------------------------------------------------------------------------------------------------------------#
Expand All @@ -194,7 +253,8 @@ def do_math(self, a, operation, decimal_places):
"CR Set Value On Boolean": CR_SetValueOnBoolean,
"CR Set Value On Binary": CR_SetValueOnBinary,
"CR Integer Multiple": CR_IntegerMultipleOf,
"CR Math Operation": CR_MathOperation,
"CR Math Operation": CR_MathOperation,
"CR Get Parameter From Prompt": CR_GetParameterFromPrompt,
}
'''

Loading

0 comments on commit 9e0dead

Please sign in to comment.