Archived
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
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}")
|
|
|
|
# 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_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
|
|
}, sid=None)
|
|
|
|
add_progress_hook(my_progress_callback)
|
|
|
|
# Register API routes
|
|
SetupRoutes(PromptServer.instance)
|
|
|
|
NODE_CLASS_MAPPINGS = {}
|
|
NODE_DISPLAY_NAME_MAPPINGS = {} |