acly / comfyui-tooling-nodes Goto Github PK
View Code? Open in Web Editor NEWNodes for using ComfyUI as a backend for external tools. Send and receive images directly without filesystem upload/download.
License: GNU General Public License v3.0
Nodes for using ComfyUI as a backend for external tools. Send and receive images directly without filesystem upload/download.
License: GNU General Public License v3.0
Hello,
I'm experiencing an issue with the Send Image (WebSocket) node where the output is unexpectedly in JSON format. According to the documentation, I was expecting a binary message followed by PNG data. However, my console debug output indicates the reception of JSON first, as follows: First few bytes of image data: b'{"prompt_i'. and Image data size: 87 bytes
Could you please clarify if this behavior is intentional or if I might be overlooking something in the implementation?
Thank you for your assistance.
ERROR:root:!!! Exception during processing !!!
ERROR:root:Traceback (most recent call last):
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\execution.py", line 151, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\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-aki-v1.1\ComfyUI-aki-v1.1\execution.py", line 74, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\custom_nodes\comfyui-tooling-nodes\nodes.py", line 20, in load_image
img = Image.open(BytesIO(imgdata))
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\python\lib\site-packages\PIL\Image.py", line 3298, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002AB9549C090>
Fault Traceback:
Not Available
Error occurred when executing ETN_LoadImageBase64:
cannot identify image file <_io.BytesIO object at 0x000002AB976583B0>
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\execution.py", line 151, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\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-aki-v1.1\ComfyUI-aki-v1.1\execution.py", line 74, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\custom_nodes\comfyui-tooling-nodes\nodes.py", line 20, in load_image
img = Image.open(BytesIO(imgdata))
File "D:\ComfyUI-aki-v1.1\ComfyUI-aki-v1.1\python\lib\site-packages\PIL\Image.py", line 3298, in open
raise UnidentifiedImageError(msg)
ๅ ณ้ญ
Very needed workflow about this.
Hi! Will be great to have option to send/recieve both PNG/JPEG. It might be some checkbox to switch parameter.
I'm trying to use the example provided in #2 but i don't get expected results,
def get_images(self):
prompt_id = self.queue_prompt()['prompt_id']
receiving_fin = False
while True:
out = self.ws.recv()
if isinstance(out, str):
message = json.loads(out)
print(message)
if message['type'] == 'executing':
if message['data']['node'] == '22':
receiving_fin = True
data = message['data']
if data['node'] is None and data['prompt_id'] == prompt_id:
break #Execution is done
elif receiving_fin == True:
if type(out) == bytes:
s = struct.calcsize(">II")
data = memoryview(out)
if len(data) > s:
event, format = struct.unpack_from(">II", data)
if event == 1 and format == 2: # 1=PREVIEW_IMAGE, 2=PNG, see ComfyUI server.py
im = Image.open(data)
im.show()
receiving_fin = False
The whole output from the WS looks like this:
{'type': 'status', 'data': {'status': {'exec_info': {'queue_remaining': 0}}, 'sid': '54cde4d6-e60b-40c5-8624-860ef07f2b0c'}}
{'type': 'status', 'data': {'status': {'exec_info': {'queue_remaining': 1}}}}
{'type': 'status', 'data': {'status': {'exec_info': {'queue_remaining': 1}}}}
{'type': 'execution_start', 'data': {'prompt_id': '45cb36fa-ff2e-4743-b279-35364f6ac710'}}
{'type': 'execution_cached', 'data': {'nodes': ['20', '6', '17', '19', '10', '7', '4'], 'prompt_id': '45cb36fa-ff2e-4743-b279-35364f6ac710'}}
{'type': 'executing', 'data': {'node': '3', 'prompt_id': '45cb36fa-ff2e-4743-b279-35364f6ac710'}}
{'type': 'progress', 'data': {'value': 1, 'max': 6}}
<class 'bytes'>
{'type': 'progress', 'data': {'value': 2, 'max': 6}}
<class 'bytes'>
{'type': 'progress', 'data': {'value': 3, 'max': 6}}
<class 'bytes'>
{'type': 'progress', 'data': {'value': 4, 'max': 6}}
<class 'bytes'>
{'type': 'progress', 'data': {'value': 5, 'max': 6}}
<class 'bytes'>
{'type': 'progress', 'data': {'value': 6, 'max': 6}}
<class 'bytes'>
{'type': 'executing', 'data': {'node': '8', 'prompt_id': '45cb36fa-ff2e-4743-b279-35364f6ac710'}}
{'type': 'executing', 'data': {'node': '22', 'prompt_id': '45cb36fa-ff2e-4743-b279-35364f6ac710'}}
Traceback (most recent call last):
File "C:\Users\blake\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 3240, in open
fp.seek(0)
AttributeError: 'memoryview' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Programming\comfyuiapi\main.py", line 36, in <module>
a.get_images()
File "C:\Programming\comfyuiapi\api.py", line 51, in get_images
im = Image.open(data)
File "C:\Users\blake\AppData\Local\Programs\Python\Python310\lib\site-packages\PIL\Image.py", line 3242, in open
fp = io.BytesIO(fp.read())
AttributeError: 'memoryview' object has no attribute 'read'
Greetings, thank you for your help with the previous problem.
I am able to send one image with Load Image node. valuable for me thank you.
I'm working on a project where I need to send two images input images with the "Load Image (Base64)" node .
Can this node handle two base64 images at once?
I'm receiving errors in comfy
File "D:\ComfyUI_windows_portable_nvidia_cu121_or_cpu\ComfyUI_windows_portable\python_embeded\Lib\site-packages\PIL\Image.py", line 3298, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x00000245B4F40770>
Prompt executed in 0.01 seconds
Thank you for your quick responses.
I am curious about how it's recommended to send the data for the image. I've been doing it like so:
with open("test_image.png", "rb") as image_file:
data = base64.b64encode(image_file.read())
load_image_b64["inputs"]["image"] = data.decode("iso-8859-1")
wf = json.dumps(customize_workflow(img))
This required a change in nodes.py:
def load_image(self, image):
img = Image.open(BytesIO(base64.b64decode(image.encode('iso-8859-1'))))
But it was the only way i could get the image info through a request because i couldnt encode the image with utf-8
Now, I have changed
with open("test_image.png", "rb") as image_file:
data = base64.b64encode(image_file.read())
to
img = Image.new("RGB", (512, 512))
data = base64.b64encode(img.tobytes())
I'm sure that this is absolutely the wrong way to do it. I am getting this error when running the new code
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001967A2E72E0>
First of all I'd like to thank you for this!
I am having problem with receiving the images via WebSocket with the Send Image node. The images are not being sent.
I am using the same client id in the /prompt request and the WebSocket connection so this should not be the issue.
The last message that I receive is:
{"type": "status", "data": {"status": {"exec_info": {"queue_remaining": 0}}}}
And nothing else.
Thanks!
I am running into a bizarre issue with these nodes and am not sure what's happening. If I try to run my workflow via API, it just instantly completes without error when I try to start with one of these nodes:
However, if I switch to a standard Load Image node, it works as expected and continues down the line, loading checkpoints and producing an image, etc. I am not sure why it instantly finishes and does not complete the flow if I start with the LoadImageBase64 node. Here is the flow:
I am including an entire json payload, ready to shoot of at Comfy which will reproduce the issue. I included the base64 image data in the payload: https://jpst.it/3DhLI
Hi! Can you provide code example for decoding image?
Hi i have setup node
const ws = new WebSocket('https://example.app/ws?clientId=b7f1429fac8bd2593e8');
ws.onopen = () => {
console.log("Connected to server")
}
ws.onerror = (error) => {
console.log(`Error:`, error)
}
ws.onmessage = (e) => {
console.log(e.data)
}
I am receiving updates
Connected to server
{"type": "status", "data": {"status": {"exec_info": {"queue_remaining": 0}}, "sid": "56da1da0b7f1429fac8bd2593e83f703"}}
{"type": "status", "data": {"status": {"exec_info": {"queue_remaining": 1}}}}
{"type": "status", "data": {"status": {"exec_info": {"queue_remaining": 1}}}}
{"type": "status", "data": {"status": {"exec_info": {"queue_remaining": 0}}}}
I am not able to get the images data here, how do i get it?
how i am doing it is, i have a frontend -> hits my backend -> connects on ws, and makes the prompts apis for comfynodes.
response from api
{
prompt_id: 'b2c65b71-02ff-4c62-ae13-70bcdf08f919',
number: 11,
node_errors: {}
}
can you help me with documentation here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.