1111from .interface import Pipeline
1212from comfystream .client import ComfyStreamClient
1313from trickle import VideoFrame , VideoOutput
14+ from utils import ComfyUtils
1415
1516import logging
1617
1718COMFY_UI_WORKSPACE_ENV = "COMFY_UI_WORKSPACE"
1819WARMUP_RUNS = 1
19- class ComfyUtils :
20- DEFAULT_WIDTH = 384
21- DEFAULT_HEIGHT = 704
22- @staticmethod
23- def get_default_workflow_json ():
24- _default_workflow_path = pathlib .Path (__file__ ).parent .absolute () / "comfyui_default_workflow.json"
25- with open (_default_workflow_path , 'r' ) as f :
26- return json .load (f )
27-
28- @staticmethod
29- def get_latent_image_dimensions (workflow : dict | None ) -> tuple [int , int ]:
30- """Get dimensions from the EmptyLatentImage node in the workflow.
31-
32- Args:
33- workflow: The workflow JSON dictionary
34-
35- Returns:
36- Tuple of (width, height) from the latent image. Returns default dimensions if not found or on error.
37- """
38-
39- if workflow is None :
40- return ComfyUtils .DEFAULT_WIDTH , ComfyUtils .DEFAULT_HEIGHT
41-
42- try :
43- for node_id , node in workflow .items ():
44- if node .get ("class_type" ) == "EmptyLatentImage" :
45- inputs = node .get ("inputs" , {})
46- width = inputs .get ("width" )
47- height = inputs .get ("height" )
48- if width is not None and height is not None :
49- return width , height
50- logging .warning ("Incomplete dimensions in latent image node" )
51- break
52- except Exception as e :
53- logging .warning (f"Failed to extract dimensions from workflow: { e } " )
54-
55- # Return defaults if dimensions not found or on any error
56- logging .info (f"Using default dimensions { ComfyUtils .DEFAULT_WIDTH } x{ ComfyUtils .DEFAULT_HEIGHT } " )
57- return ComfyUtils .DEFAULT_WIDTH , ComfyUtils .DEFAULT_HEIGHT
20+
21+ def get_default_workflow_json ():
22+ _default_workflow_path = pathlib .Path (__file__ ).parent .absolute () / "comfyui_default_workflow.json"
23+ with open (_default_workflow_path , 'r' ) as f :
24+ return json .load (f )
5825
5926# Get the default workflow json during startup
60- DEFAULT_WORKFLOW_JSON = ComfyUtils . get_default_workflow_json ()
27+ DEFAULT_WORKFLOW_JSON = get_default_workflow_json ()
6128
6229class ComfyUIParams (BaseModel ):
6330 class Config :
@@ -149,30 +116,4 @@ async def update_params(self, **params):
149116 async def stop (self ):
150117 logging .info ("Stopping ComfyUI pipeline" )
151118 await self .client .cleanup ()
152- logging .info ("ComfyUI pipeline stopped" )
153-
154- # async def get_latent_image_dimensions(self, workflow: dict) -> tuple[int, int] | None:
155- # """Get dimensions from the EmptyLatentImage node in the workflow.
156-
157- # Args:
158- # workflow: The workflow JSON dictionary
159-
160- # Returns:
161- # Tuple of (width, height) from the latent image. Returns default dimensions if not found or on error.
162- # """
163- # try:
164- # for node_id, node in workflow.items():
165- # if node.get("class_type") == "EmptyLatentImage":
166- # inputs = node.get("inputs", {})
167- # width = inputs.get("width")
168- # height = inputs.get("height")
169- # if width is not None and height is not None:
170- # return width, height
171- # logging.warning("Incomplete dimensions in latent image node")
172- # break
173- # except Exception as e:
174- # logging.warning(f"Failed to extract dimensions from workflow: {e}")
175-
176- # # Return defaults if dimensions not found or on any error
177- # logging.info(f"Using default dimensions {DEFAULT_WIDTH}x{DEFAULT_HEIGHT}")
178- # return DEFAULT_WIDTH, DEFAULT_HEIGHT
119+ logging .info ("ComfyUI pipeline stopped" )
0 commit comments