Archived
added realtime progress image previews support
This commit is contained in:
1 parent
7c8768ac1f
commit
43ebd851ad
1 file changed
+20
-2
+20
-2
@@ -2,16 +2,34 @@ from server import PromptServer
|
||||
from .progress import add_progress_hook
|
||||
from .routes import SetupRoutes
|
||||
from .workflows import *
|
||||
import base64
|
||||
from io import BytesIO
|
||||
|
||||
# Your custom progress callback
|
||||
def my_progress_callback(value, total, preview_image, prompt_id, node_id):
|
||||
print(f"Progress: {value}/{total}, Prompt: {prompt_id}, Node: {node_id}, Preview: {preview_image}")
|
||||
# print(f"Progress: {value}/{total}, Prompt: {prompt_id}, Node: {node_id}, Preview: {preview_image}")
|
||||
|
||||
# Convert preview image to base64 if available
|
||||
preview_base64 = None
|
||||
if preview_image is not None:
|
||||
try:
|
||||
# preview_image is a tuple: (format, PIL.Image, max_size)
|
||||
if isinstance(preview_image, tuple) and len(preview_image) >= 2:
|
||||
pil_image = preview_image[1] # Extract the PIL Image
|
||||
else:
|
||||
pil_image = preview_image
|
||||
|
||||
buffer = BytesIO()
|
||||
pil_image.save(buffer, format='JPEG', quality=80, optimize=True)
|
||||
preview_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
||||
except Exception as e:
|
||||
print(f"[ImageLab] Error encoding preview image: {e}")
|
||||
|
||||
# Broadcast to ALL WebSocket clients using ComfyUI's system (sid=None means broadcast to all)
|
||||
PromptServer.instance.send_sync("imagelab_progress", {
|
||||
'value': value,
|
||||
'total': total,
|
||||
# 'preview_image': preview_image,
|
||||
'preview_image': preview_base64, # base64 encoded JPEG or None
|
||||
'prompt_id': prompt_id,
|
||||
'node_id': node_id,
|
||||
'progress_percent': round((value / total * 100), 2) if total > 0 else 0
|
||||
|
||||
Reference in new issue
Block a user