Add optional SwarmUI service using Deck ComfyUI API
This commit is contained in:
+11
-1
@@ -5,6 +5,7 @@ from pathlib import Path, PurePosixPath
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import secrets
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
@@ -106,10 +107,14 @@ class VideoComfy:
|
||||
if link.is_symlink():link.unlink()
|
||||
link.symlink_to(source)
|
||||
node=work/'custom_nodes/deck_ltx';node.mkdir(parents=True,exist_ok=True);shutil.copyfile(Path(__file__).with_name('video_comfy_node.py'),node/'__init__.py')
|
||||
config={'deck':{'base_path':str(work),'custom_nodes':'custom_nodes',**{key:'models/'+key for key in paths}}};(work/'paths.json').write_text(json.dumps(config))
|
||||
swarm_nodes=self.root/'swarm-comfy-nodes'
|
||||
config={'deck':{'base_path':str(work),'custom_nodes':'custom_nodes',**{key:'models/'+key for key in paths}}};
|
||||
if swarm_nodes.is_dir():config['swarm']={'base_path':str(self.root),'custom_nodes':'swarm-comfy-nodes'}
|
||||
(work/'paths.json').write_text(json.dumps(config))
|
||||
for directory in ('input','output','temp','user'):(work/directory).mkdir(exist_ok=True)
|
||||
with socket.socket() as sock:sock.bind(('127.0.0.1',0));self.port=sock.getsockname()[1]
|
||||
python,comfy=self.runtime.paths();env=dict(os.environ,CUDA_VISIBLE_DEVICES=','.join(g[0].strip() for g in ordered))
|
||||
if (self.root/'swarm-python').is_dir():env['PYTHONPATH']=str(self.root/'swarm-python')+os.pathsep+env.get('PYTHONPATH','')
|
||||
args=[str(python),str(comfy/'main.py'),'--listen','127.0.0.1','--port',str(self.port),'--disable-auto-launch','--disable-metadata','--lowvram','--reserve-vram','1.5','--extra-model-paths-config',str(work/'paths.json')]
|
||||
for directory in ('input','output','temp','user'):args+=['--'+directory+'-directory',str(work/directory)]
|
||||
self.switch_phase='ComfyUI starten · Gewichte laden erst bei Anfrage';self.process=subprocess.Popen(args,env=env,cwd=comfy,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,start_new_session=True)
|
||||
@@ -130,6 +135,11 @@ class VideoComfy:
|
||||
try:process.wait(timeout=15)
|
||||
except subprocess.TimeoutExpired:os.killpg(process.pid,signal.SIGKILL);process.wait(timeout=10)
|
||||
self.process=None;self.port=None
|
||||
def service_authenticated(self,header):
|
||||
if self.scheduler.gpu_mode!='video' or not header.startswith('Bearer '):return False
|
||||
path=self.root/'comfy-client-token'
|
||||
try:return secrets.compare_digest(header[7:].encode(),path.read_bytes().strip())
|
||||
except OSError:return False
|
||||
def relay(self,handler):
|
||||
from video_comfy_proxy import relay
|
||||
if not self.port or not self.process or self.process.poll() is not None:raise ValueError('ComfyUI nicht bereit.')
|
||||
|
||||
Reference in New Issue
Block a user