HTTP API for ComfyUI workflow submission with: - POST /api/webhook endpoint for workflow submission - Real-time progress events via callback URL - Automatic output collection (no re-encoding) - Input/Output nodes for webhook data access
31 lines
859 B
Python
31 lines
859 B
Python
"""Shared helper functions."""
|
|
|
|
import asyncio
|
|
import concurrent.futures
|
|
|
|
|
|
def format_size(size_bytes: int) -> str:
|
|
"""Format bytes as human readable."""
|
|
if size_bytes is None:
|
|
return "unknown"
|
|
if size_bytes < 1024:
|
|
return f"{size_bytes} bytes"
|
|
elif size_bytes < 1024 * 1024:
|
|
return f"{size_bytes / 1024:.1f} KB"
|
|
else:
|
|
return f"{size_bytes / (1024 * 1024):.1f} MB"
|
|
|
|
|
|
def run_async(coro):
|
|
"""Run an async coroutine in sync context."""
|
|
try:
|
|
loop = asyncio.get_event_loop()
|
|
if loop.is_running():
|
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
future = executor.submit(asyncio.run, coro)
|
|
return future.result()
|
|
else:
|
|
return loop.run_until_complete(coro)
|
|
except RuntimeError:
|
|
return asyncio.run(coro)
|