Closed rethink-studios closed 4 months ago
Okay, firstly I think update to latest. That should handle the part where it tries to talk instead of code.
And okay, so I have this workflow I will paste in /workflows now which does image manipulation with an example in the node.
Often times when working with LLMs, if they won't do what you ask, you have to prod them by giving them examples of the type of thing you want it to do. In this case, manipulating images, you need to have an example of the shape and contents of the output, since comfy doesn't work with normal image format but instead wraps the data in a Tensor.
TLDR; Copy my anynode from here, and edit the top part of the prompt https://github.com/lks-ai/anynode/blob/main/workflows/anynode_hsl-tweak.json ... this is what I was using in my videos.
Okay, firstly I think update to latest. That should handle the part where it tries to talk instead of code.
And okay, so I have this workflow I will paste in /workflows now which does image manipulation with an example in the node.
Often times when working with LLMs, if they won't do what you ask, you have to prod them by giving them examples of the type of thing you want it to do. In this case, manipulating images, you need to have an example of the shape and contents of the output, since comfy doesn't work with normal image format but instead wraps the data in a Tensor.
TLDR; Copy my anynode from here, and edit the top part of the prompt https://github.com/lks-ai/anynode/blob/main/workflows/anynode_hsl-tweak.json ... this is what I was using in my videos.
i got error too
Okay, firstly I think update to latest. That should handle the part where it tries to talk instead of code.
And okay, so I have this workflow I will paste in /workflows now which does image manipulation with an example in the node.
Often times when working with LLMs, if they won't do what you ask, you have to prod them by giving them examples of the type of thing you want it to do. In this case, manipulating images, you need to have an example of the shape and contents of the output, since comfy doesn't work with normal image format but instead wraps the data in a Tensor.
TLDR; Copy my anynode from here, and edit the top part of the prompt https://github.com/lks-ai/anynode/blob/main/workflows/anynode_hsl-tweak.json ... this is what I was using in my videos.
Thanks for the explanation, and on certain levels, makes sense.
First, workflows: When updating, this workflow worked: https://github.com/lks-ai/anynode/blob/main/workflows/anynode_hsl-tweak.json
I saw the example python code injected inside the Any Node (ah-Ha moment), and now get it, however I'm not the best programmer (a visual guy) and I'm wondering: if I feed ChatGPT examples of what I'm looking for, how would I verbalize the need?
This workflow did not work: sobel-charcoal.json
I switched the generic anyNode for the Local LLM, same line of code inserted:
(snip) got prompt Last Error: None Generating Node function... INPUT tensor([[[[0.0824, 0.0588, 0.1255], [0.0941, 0.0627, 0.1255], [0.0941, 0.0627, 0.1412], ..., [0.1020, 0.0510, 0.1412], [0.0941, 0.0510, 0.1373], [0.1020, 0.0549, 0.1176]],
[[0.0941, 0.0627, 0.1294],
[0.0980, 0.0667, 0.1412],
[0.0941, 0.0667, 0.1373],
...,
[0.0980, 0.0549, 0.1412],
[0.0980, 0.0588, 0.1412],
[0.0941, 0.0588, 0.1412]],
[[0.0980, 0.0627, 0.1333],
[0.0941, 0.0627, 0.1333],
[0.0941, 0.0667, 0.1333],
...,
[0.0980, 0.0588, 0.1412],
[0.1020, 0.0588, 0.1412],
[0.1020, 0.0549, 0.1412]],
...,
[[0.0588, 0.0588, 0.1255],
[0.0627, 0.0627, 0.1294],
[0.0549, 0.0667, 0.1176],
...,
[0.0863, 0.0667, 0.1373],
[0.0902, 0.0706, 0.1333],
[0.0902, 0.0627, 0.1373]],
[[0.0667, 0.0510, 0.1333],
[0.0706, 0.0549, 0.1333],
[0.0706, 0.0549, 0.1333],
...,
[0.0980, 0.0588, 0.1412],
[0.0980, 0.0588, 0.1373],
[0.0941, 0.0588, 0.1451]],
[[0.0588, 0.0588, 0.1373],
[0.0745, 0.0471, 0.1412],
[0.0706, 0.0510, 0.1333],
...,
[0.0941, 0.0627, 0.1333],
[0.0980, 0.0588, 0.1333],
[0.0980, 0.0706, 0.1216]]]])
LE: None
{'id': 'chatcmpl-584', 'object': 'chat.completion', 'created': 1716906074, 'model': 'llama3', 'system_fingerprint': 'fp_ollama', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': 'Here is the code for a Sobel edge filter and inverting it without using OpenCV:\n\nimport torch\nimport numpy as np\n\ndef generated_function(input_data):\n # Convert input RGB tensor to a numpy array and normalize\n rgb_array = input_data.numpy() / 255.0\n\n # Define the Sobel kernel for horizontal and vertical edges\n sobel_kernel_x = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])\n sobel_kernel_y = np.array([[1, 0, -1], [2, 0, -2], [1, 0, -1]])\n\n # Apply the Sobel filter to each image in the batch\n edges_x = torch.zeros_like(input_data)\n edges_y = torch.zeros_like(input_data)\n\n for i in range(rgb_array.shape[0]):\n for j in range(rgb_array.shape[1]):\n for k in range(rgb_array.shape[2]):\n r, g, b = rgb_array[i, j, k]\n x = np.dot([r, g, b], sobel_kernel_x) + np.dot([g, b, r], sobel_kernel_y)\n y = np.dot([r, g, b], sobel_kernel_y) + np.dot([b, r, g], sobel_kernel_x)\n\n edges_x[i, j, k] = x\n edges_y[i, j, k] = y\n\n # Invert the Sobel filter by taking the absolute value of each edge map\n edges_x_abs = torch.abs(edges_x)\n edges_y_abs = torch.abs(edges_y)\n\n return edges_x_abs, edges_y_abs\n
\nThis code applies a Sobel filter to each image in the input batch, and then inverts the filter by taking the absolute value of each edge map. The output is two tensors representing the horizontal and vertical edge maps, respectively.'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 1331, 'completion_tokens': 413, 'total_tokens': 1744}}
Imports in code: ['import torch', 'import numpy as np']
Stored script:
Here is the code for a Sobel edge filter and inverting it without using OpenCV:
def generated_function(input_data):
# Convert input RGB tensor to a numpy array and normalize
rgb_array = input_data.numpy() / 255.0
# Define the Sobel kernel for horizontal and vertical edges
sobel_kernel_x = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])
sobel_kernel_y = np.array([[1, 0, -1], [2, 0, -2], [1, 0, -1]])
# Apply the Sobel filter to each image in the batch
edges_x = torch.zeros_like(input_data)
edges_y = torch.zeros_like(input_data)
for i in range(rgb_array.shape[0]):
for j in range(rgb_array.shape[1]):
for k in range(rgb_array.shape[2]):
r, g, b = rgb_array[i, j, k]
x = np.dot([r, g, b], sobel_kernel_x) + np.dot([g, b, r], sobel_kernel_y)
y = np.dot([r, g, b], sobel_kernel_y) + np.dot([b, r, g], sobel_kernel_x)
edges_x[i, j, k] = x
edges_y[i, j, k] = y
# Invert the Sobel filter by taking the absolute value of each edge map
edges_x_abs = torch.abs(edges_x)
edges_y_abs = torch.abs(edges_y)
return edges_x_abs, edges_y_abs
This code applies a Sobel filter to each image in the input batch, and then inverts the filter by taking the absolute value of each edge map. The output is two tensors representing the horizontal and vertical edge maps, respectively.
An error occurred:
Traceback (most recent call last):
File "D:\COMFYUI_BETA\ComfyUI\custom_nodes\anynode\nodes\any.py", line 221, in safe_exec
exec(code_string, globals_dict, locals_dict)
File "
Prompt executed in 10.46 seconds
Get latest update git pull
and it should be fixed.
Hey hey, I'm testing the node on Win11 and Ollama and received these errors, first with the standalone node, and then the local LLM: What am I missing? Thanks for the hard work!
standalone:
(snip)
got prompt Last Error: None Generating Node function... INPUT tensor([[[[0.2471, 0.1529, 0.0980], [0.2588, 0.1647, 0.1137], [0.2588, 0.1725, 0.1137], ..., [0.1333, 0.1373, 0.1451], [0.1373, 0.1333, 0.1412], [0.1333, 0.1373, 0.1333]],
LE: None HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" Imports in code: [] Stored script: def generated_function(input_data): def get_structure(data): if isinstance(data, (int, float, str)): return str(type(data)) elif isinstance(data, torch.Tensor): return f"Tensor(shape={data.shape}, dtype={data.dtype})" elif isinstance(data, (list, tuple)): if data: return f"{type(data).name}({get_structure(data[0])})" else: return f"{type(data).name}()" elif isinstance(data, dict): if data: key_structure = get_structure(next(iter(data.keys()))) value_structure = get_structure(next(iter(data.values()))) return f"dict({key_structure}: {value_structure})" else: return "dict()" else: return str(type(data))
Error calling the generated function: name 'torch' is not defined Traceback (most recent call last): File "D:\COMFYUI_BETA\ComfyUI\custom_nodes\anynode\nodes\any.py", line 267, in go result = locals_dictfunction_name ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 22, in generated_function
File "", line 5, in get_structure
NameError: name 'torch' is not defined
!!! Exception during processing!!! name 'torch' is not defined
Traceback (most recent call last):
File "D:\COMFYUI_BETA\ComfyUI\execution.py", line 151, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\COMFYUI_BETA\ComfyUI\execution.py", line 81, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\COMFYUI_BETA\ComfyUI\execution.py", line 74, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\COMFYUI_BETA\ComfyUI\custom_nodes\anynode\nodes\any.py", line 273, in go
raise e
File "D:\COMFYUI_BETA\ComfyUI\custom_nodes\anynode\nodes\any.py", line 267, in go
result = locals_dictfunction_name
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 22, in generated_function
File "", line 5, in get_structure
NameError: name 'torch' is not defined
Prompt executed in 3.05 seconds
Local LLM:
(snip) got prompt Last Error: None Generating Node function... INPUT tensor([[[[0.2471, 0.1529, 0.0980], [0.2588, 0.1647, 0.1137], [0.2588, 0.1725, 0.1137], ..., [0.1333, 0.1373, 0.1451], [0.1373, 0.1333, 0.1412], [0.1333, 0.1373, 0.1333]],
LE: None {'id': 'chatcmpl-8', 'object': 'chat.completion', 'created': 1716862341, 'model': 'llama2', 'system_fingerprint': 'fp_ollama', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': 'Sure! Here\'s the code for the generated function:\n
python\nimport math\ndef generated_function(input_data):\n # Check if input data is a tensor\n if not isinstance(input_data, torch.Tensor):\n raise ValueError("Input data must be a tensor")\n \n # Get the shape of the input data\n shape = input_data.shape\n \n # Define a function to check if a number is prime\n def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(math.sqrt(n))+1):\n if n % i == 0:\n return False\n return True\n \n # Initialize a list to store the prime numbers\n primes = []\n \n # Loop until the input number is reached\n while shape[0] > 1:\n # Get the current number being checked for primality\n num = input_data[0, ...]\n \n # Check if the number is prime using the defined function\n if is_prime(num):\n primes.append(num)\n \n # Decrease the number by 1 and repeat the process until the input number is reached\n shape[0] -= 1\n \n # Return the list of prime numbers\n return primes\n
\nNote that I\'ve added a check to ensure that the input data is a tensor, since you mentioned that it\'s not required to use any of the libraries but if you do use any import in your code it must be on the list provided. Additionally, I\'ve defined a functionis_prime
to check if a number is prime, which is used inside the loop to check the primality of the input data.'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 569, 'completion_tokens': 403, 'total_tokens': 972}} Imports in code: ['import math'] Stored script: Sure! Here's the code for the generated function:def generated_function(input_data):
Check if input data is a tensor