- ComfyUI custom nodes: BridgeInput (11 types) + BridgeOutput
- AnyType wildcard for universal output capture
- Custom server route: GET /comfybridge/results/{prompt_id}
- Python async client (ComfyBridge) + sync wrapper (ComfyBridgeSync)
- Workflow JSON parser and patcher (deepcopy, original unchanged)
- WebSocket completion detection
- BridgeResult container with PIL/bytes helpers
- Examples: basic_text_to_image.py, agent_loop.py
- Unit tests for workflow parser and client
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""ComfyBridgeSync — asyncio가 없는 환경을 위한 동기 래퍼."""
|
|
|
|
import asyncio
|
|
from collections.abc import Callable
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from .bridge import ComfyBridge
|
|
from .result import BridgeResult
|
|
|
|
|
|
class ComfyBridgeSync:
|
|
"""
|
|
ComfyBridge의 동기 래퍼.
|
|
|
|
사용 예시::
|
|
|
|
bridge = ComfyBridgeSync(host="localhost", port=8188)
|
|
result = bridge.run("workflow_api.json", inputs={"prompt": "a cat"})
|
|
image = result.as_pil("output_image")
|
|
image.show()
|
|
"""
|
|
|
|
def __init__(self, host: str = "localhost", port: int = 8188, timeout: float = 300.0):
|
|
self._bridge = ComfyBridge(host=host, port=port, timeout=timeout)
|
|
|
|
def run(
|
|
self,
|
|
workflow: str | dict | Path,
|
|
inputs: dict[str, Any] | None = None,
|
|
progress_callback: Callable[[float], None] | None = None,
|
|
) -> BridgeResult:
|
|
return asyncio.run(self._bridge.run(workflow, inputs, progress_callback))
|
|
|
|
def upload_image(self, image: bytes | str | Path, filename: str = "input.png") -> str:
|
|
return asyncio.run(self._bridge.upload_image(image, filename))
|