1- from pathlib import Path
2- import os
3- import json
4- from git import Repo
5- import logging
6- import sys
71from aiohttp import web
82
93from api .nodes .nodes import list_nodes , install_node , delete_node
104from api .models .models import list_models , add_model , delete_model
115from api .settings .settings import set_twilio_account_info
126
7+ from comfy .nodes .package_typing import ExportedNodes
8+ from comfy .nodes .package import _comfy_nodes , import_all_nodes_in_workspace
9+ from comfy .cmd .execution import nodes
10+
11+ from api .nodes .nodes import force_import_all_nodes_in_workspace
12+ #use a different node import
13+ import_all_nodes_in_workspace = force_import_all_nodes_in_workspace
14+
1315def add_routes (app ):
1416 app .router .add_get ("/env/list_nodes" , nodes )
1517 app .router .add_post ("/env/install_nodes" , install_nodes )
@@ -19,9 +21,38 @@ def add_routes(app):
1921 app .router .add_post ("/env/add_models" , add_models )
2022 app .router .add_post ("/env/delete_models" , delete_models )
2123
24+ app .router .add_post ("/env/reload" , reload )
2225 app .router .add_post ("/env/set_account_info" , set_account_info )
2326
27+ async def reload (request ):
28+ '''
29+ Reload ComfyUI environment
2430
31+ '''
32+
33+ #reset embedded client
34+ from comfy .client .embedded_comfy_client import EmbeddedComfyClient
35+ from comfy .cli_args_types import Configuration
36+ await request .app ["pipeline" ].client .comfy_client .__aexit__ ()
37+
38+ #reset imports to clear imported nodes
39+ global _comfy_nodes
40+ if len (_comfy_nodes ) > 0 :
41+ import sys
42+ import importlib
43+ del sys .modules ['comfy.nodes.package' ]
44+ del sys .modules ['comfy.cmd.execution' ]
45+ globals ()['comfy.nodes.package' ] = importlib .import_module ('comfy.nodes.package' )
46+ globals ()['comfy.cmd.execution' ] = importlib .import_module ('comfy.cmd.execution' )
47+ #use a different node import
48+ import_all_nodes_in_workspace = force_import_all_nodes_in_workspace
49+ _comfy_nodes = import_all_nodes_in_workspace ()
50+
51+ #load new embedded client
52+ request .app ["pipeline" ].client .comfy_client = EmbeddedComfyClient (Configuration (cwd = request .app ["workspace" ], disable_cuda_malloc = True , gpu_only = True ))
53+
54+ return web .json_response ({"success" : True , "error" : None })
55+
2556async def nodes (request ):
2657 '''
2758 List all custom nodes in the workspace
@@ -87,6 +118,24 @@ async def install_nodes(request):
87118 for node in nodes :
88119 await install_node (node , workspace_dir )
89120 installed_nodes .append (node ['url' ])
121+
122+ #restart embedded client
123+ #request.app["pipeline"].client.set_prompt(request.app["pipeline"].client.prompt)
124+
125+ # reimport nodes to workspace
126+ #from comfy.cmd.execution import nodes
127+ #from comfy.nodes.package import import_all_nodes_in_workspace
128+ #update_nodes = import_all_nodes_in_workspace()
129+ #nodes.update(update_nodes)
130+
131+ #config = request.app["pipeline"].client.comfy_client._configuration
132+ #from comfy.client.embedded_comfy_client import EmbeddedComfyClient
133+ #request.app["pipeline"].client.comfy_client = EmbeddedComfyClient(config)
134+ #await request.app["pipeline"].warm()
135+
136+ #from pipeline import Pipeline
137+ #request.app["pipeline"] = Pipeline(cwd=request.app["workspace"], disable_cuda_malloc=True, gpu_only=True)
138+
90139 return web .json_response ({"success" : True , "error" : None , "installed_nodes" : installed_nodes })
91140 except Exception as e :
92141 return web .json_response ({"success" : False , "error" : str (e ), "installed_nodes" : installed_nodes }, status = 500 )
0 commit comments