lks-ai / anynode

A Node for ComfyUI that does what you ask it to do

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error calling the generated function: name 'torch' is not defined

gabrie opened this issue · comments

Keep getting this, no matter which model to use in Ollama

Write the Code

LLM COMMENTS:

Imports in code: ['import torchvision.transforms as transforms']
Stored script:
def generated_function(input_data_1=None, input_data_2=None):
def apply_transforms(image):
# Apply all three tweaks to image
hue = torch.randint(0, 360, (1,))
saturation = torch.randint(-100, 100, (1,))
lightness = torch.randint(-50, 50, (1,))
transforms_list = [transforms.ColorJitter(hue=hue),
transforms.ColorJitter(saturation=saturation),
transforms.ColorJitter(brightness=lightness)]
for transform in transforms_list:
image = transform(image)
return image

if input_data_2 is not None:
    # If input_data_2 is provided, apply the transforms to it
    output_data = apply_transforms(input_data_2)
else:
    # Otherwise, apply the transforms to input_data_1
    output_data = apply_transforms(input_data_1)

return output_data

Error calling the generated function: name 'torch' is not defined
Traceback (most recent call last):
File "D:\ComfyUI\custom_nodes\anynode\nodes\any.py", line 391, in go
result = locals_dict[function_name](any, input_data_2=any2)
File "", line 19, in generated_function_21900ac62c88401fa67acabf7dee08c6
File "", line 4, in apply_transforms
NameError: name 'torch' is not defined
!!! Exception during processing!!! name 'torch' is not defined
Traceback (most recent call last):
File "D:\ComfyUI\execution.py", line 151, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File "D:\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\execution.py", line 74, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File "D:\ComfyUI\custom_nodes\anynode\nodes\any.py", line 398, in go
raise e
File "D:\ComfyUI\custom_nodes\anynode\nodes\any.py", line 391, in go
result = locals_dict[function_name](any, input_data_2=any2)
File "", line 19, in generated_function_21900ac62c88401fa67acabf7dee08c6
File "", line 4, in apply_transforms
NameError: name 'torch' is not defined

Prompt executed in 15.60 seconds

Tell it specifically in the prompt on it's own line remember to import torch ... sometimes smaller LLMs don't really follow the initial instruction or understand what to do with that error, so you can try to reinforce it.