This repository has been archived on 2026-10-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
imagelab_v3_extension/__init__.py
T

49 lines
1.8 KiB
Python

from server import PromptServer
from .progress import add_progress_hook
from .routes import SetupRoutes
from .workflows import *
from io import BytesIO
import json
# Custom binary event types (use high numbers to avoid conflicts)
IMAGELAB_PROGRESS_EVENT = 100
IMAGELAB_PREVIEW_EVENT = 101
# Your custom progress callback
def my_progress_callback(value, total, preview_image, prompt_id, node_id):
# Send progress data as binary JSON
progress_data = {
'value': value,
'total': total,
'prompt_id': prompt_id,
'node_id': node_id,
'progress_percent': round((value / total * 100), 2) if total > 0 else 0
}
progress_bytes = json.dumps(progress_data).encode('utf-8')
PromptServer.instance.send_sync(IMAGELAB_PROGRESS_EVENT, progress_bytes, sid=None)
# Send preview image separately if available
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:
image_format = preview_image[0] # 'JPEG' or 'PNG'
pil_image = preview_image[1]
# Convert PIL image to bytes
buffer = BytesIO()
pil_image.save(buffer, format=image_format, quality=95 if image_format == 'JPEG' else None)
image_bytes = buffer.getvalue()
# Send as binary message with integer event type
PromptServer.instance.send_sync(IMAGELAB_PREVIEW_EVENT, image_bytes, sid=None)
except Exception as e:
print(f"[ImageLab] Error sending preview image: {e}")
add_progress_hook(my_progress_callback)
# Register API routes
SetupRoutes(PromptServer.instance)
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}