Skip to content

Commit e711d6d

Browse files
Merge branch 'main' into comfystream-mgmt-api
2 parents e2ea28e + 9ff4b39 commit e711d6d

File tree

14 files changed

+407
-66
lines changed

14 files changed

+407
-66
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"python.defaultInterpreterPath": "/workspace/miniconda3/envs/comfystream/bin/python",
1818
"python.venvPath": "/workspace/miniconda3/envs",
1919
"python.terminal.activateEnvInCurrentTerminal": false,
20-
"python.terminal.activateEnvironment": true,
20+
"python.terminal.activateEnvironment": false,
2121
"terminal.integrated.shellIntegration.enabled": true
2222
},
2323
"extensions": [

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ launch.json
2222
nodes/web/static/*
2323
.cursor/
2424
!nodes/web/static/.gitkeep
25+
26+
# opencv files
27+
opencv

configs/models.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ models:
1616
- url: "https://huggingface.co/aaronb/dreamshaper-8-dmd-1kstep/raw/main/config.json"
1717
path: "unet/dreamshaper-8-dmd-1kstep.json"
1818

19-
# Depth Anything ONNX model
19+
# Depth Anything V2 ONNX models
2020
depthanything-onnx:
2121
name: "DepthAnything ONNX"
2222
url: "https://huggingface.co/yuvraj108c/Depth-Anything-2-Onnx/resolve/main/depth_anything_v2_vitb.onnx?download=true"
2323
path: "tensorrt/depth-anything/depth_anything_vitl14.onnx"
24+
depth-anything-v2-large-onnx:
25+
name: "DepthAnything V2 Large ONNX"
26+
url: "https://huggingface.co/yuvraj108c/Depth-Anything-2-Onnx/resolve/main/depth_anything_v2_vitl.onnx?download=true"
27+
path: "tensorrt/depth-anything/depth_anything_v2_vitl.onnx"
2428

2529
# TAESD models
2630
taesd:
@@ -68,4 +72,4 @@ models:
6872
name: "ClipTextModel"
6973
url: "https://huggingface.co/Lykon/dreamshaper-8/resolve/main/text_encoder/model.fp16.safetensors"
7074
path: "text_encoders/CLIPText/model.fp16.safetensors"
71-
type: "text_encoder"
75+
type: "text_encoder"

configs/nodes.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ nodes:
1111

1212
comfyui-depthanything-tensorrt:
1313
name: "ComfyUI DepthAnything TensorRT"
14-
url: "https://github.com/yuvraj108c/ComfyUI-Depth-Anything-Tensorrt"
14+
url: "https://github.com/rickstaa/ComfyUI-Depth-Anything-Tensorrt"
15+
branch: "feature/add-export-trt-args"
1516
type: "tensorrt"
1617

1718
# Ryan's nodes
@@ -74,4 +75,4 @@ nodes:
7475
name: "ComfyUI Stream Pack"
7576
url: "https://github.com/livepeer/ComfyUI-Stream-Pack"
7677
branch: "main"
77-
type: "utility"
78+
type: "utility"

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ RUN bash -c "source $NVM_DIR/nvm.sh && \
2323
ENV NODE_PATH="$NVM_DIR/v$NODE_VERSION/lib/node_modules" \
2424
PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"
2525

26-
RUN conda init bash
2726

2827
# Create the supervisor configuration file for ComfyUI and ComfyStream
2928
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

docker/Dockerfile.base

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ RUN mkdir -p /workspace/comfystream && \
2727
wget "https://repo.anaconda.com/miniconda/Miniconda3-${CONDA_VERSION}-Linux-x86_64.sh" -O /tmp/miniconda.sh && \
2828
bash /tmp/miniconda.sh -b -p /workspace/miniconda3 && \
2929
eval "$(/workspace/miniconda3/bin/conda shell.bash hook)" && \
30-
conda create -n comfystream python="${PYTHON_VERSION}" -y && \
31-
rm /tmp/miniconda.sh && \
32-
conda run -n comfystream --no-capture-output pip install aiortc aiohttp requests tqdm pyyaml --root-user-action=ignore
30+
conda create -n comfystream python="${PYTHON_VERSION}" ffmpeg=6 -c conda-forge -y && \
31+
rm /tmp/miniconda.sh && echo 'export LD_LIBRARY_PATH=/workspace/miniconda3/envs/comfystream/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
3332

3433
# Clone ComfyUI
35-
ADD --link https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
34+
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
3635

3736
# Copy only files needed for setup
38-
COPY --link ./src/comfystream/scripts /workspace/comfystream/src/comfystream/scripts
39-
COPY --link ./configs /workspace/comfystream/configs
40-
41-
# Run setup_nodes (cached unless setup_nodes.py or nodes/ changes)
42-
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI
37+
COPY ./src/comfystream/scripts /workspace/comfystream/src/comfystream/scripts
38+
COPY ./configs /workspace/comfystream/configs
4339

4440
# Copy ComfyStream files into ComfyUI
4541
COPY . /workspace/comfystream
@@ -52,14 +48,24 @@ COPY ./test/example-512x512.png /workspace/ComfyUI/input
5248
RUN conda run -n comfystream --no-capture-output --cwd /workspace/ComfyUI pip install -r requirements.txt --root-user-action=ignore
5349

5450
# Install ComfyStream requirements
55-
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -r requirements.txt --root-user-action=ignore
56-
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install . --root-user-action=ignore
5751
RUN ln -s /workspace/comfystream /workspace/ComfyUI/custom_nodes/comfystream
52+
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -e . --root-user-action=ignore
5853
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python install.py --workspace /workspace/ComfyUI
54+
55+
# Run setup_nodes
56+
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI
57+
58+
# Install additional dependencies
5959
RUN conda run -n comfystream --no-capture-output pip install --upgrade tensorrt-cu12-bindings tensorrt-cu12-libs --root-user-action=ignore
6060

61+
# Setup opencv with CUDA support
62+
RUN conda run -n comfystream --no-capture-output bash /workspace/comfystream/docker/entrypoint.sh --opencv-cuda
63+
6164
# Configure no environment activation by default
6265
RUN conda config --set auto_activate_base false && \
6366
conda init bash
6467

68+
# Set comfystream environment as default
69+
RUN echo "conda activate comfystream" >> ~/.bashrc
70+
6571
WORKDIR /workspace/comfystream

docker/entrypoint.sh

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ show_help() {
2323
echo "Options:"
2424
echo " --download-models Download default models"
2525
echo " --build-engines Build TensorRT engines for default models"
26+
echo " --opencv-cuda Setup OpenCV with CUDA support"
2627
echo " --server Start the Comfystream server, UI and ComfyUI"
2728
echo " --help Show this help message"
2829
echo ""
@@ -49,7 +50,7 @@ if [ "$1" = "--build-engines" ]; then
4950
# Build Static Engine for Dreamshaper
5051
python src/comfystream/scripts/build_trt.py --model /workspace/ComfyUI/models/unet/dreamshaper-8-dmd-1kstep.safetensors --out-engine /workspace/ComfyUI/output/tensorrt/static-dreamshaper8_SD15_\$stat-b-1-h-512-w-512_00001_.engine
5152

52-
# Build Engine for DepthAnything2
53+
# Build Engine for Depth Anything V2
5354
if [ ! -f "$DEPTH_ANYTHING_DIR/depth_anything_vitl14-fp16.engine" ]; then
5455
if [ ! -d "$DEPTH_ANYTHING_DIR" ]; then
5556
mkdir -p "$DEPTH_ANYTHING_DIR"
@@ -59,9 +60,66 @@ if [ "$1" = "--build-engines" ]; then
5960
else
6061
echo "Engine for DepthAnything2 already exists, skipping..."
6162
fi
63+
64+
# Build Engine for Depth Anything2 (large)
65+
if [ ! -f "$DEPTH_ANYTHING_DIR/depth_anything_v2_vitl-fp16.engine" ]; then
66+
cd "$DEPTH_ANYTHING_DIR"
67+
python /workspace/ComfyUI/custom_nodes/ComfyUI-Depth-Anything-Tensorrt/export_trt.py --trt-path "${DEPTH_ANYTHING_DIR}/depth_anything_v2_vitl-fp16.engine" --onnx-path "${DEPTH_ANYTHING_DIR}/depth_anything_v2_vitl.onnx"
68+
else
69+
echo "Engine for DepthAnything2 (large) already exists, skipping..."
70+
fi
6271
shift
6372
fi
6473

74+
if [ "$1" = "--opencv-cuda" ]; then
75+
cd /workspace/comfystream
76+
conda activate comfystream
77+
78+
# Check if OpenCV CUDA build already exists
79+
if [ ! -f "/workspace/comfystream/opencv-cuda-release.tar.gz" ]; then
80+
# Download and extract OpenCV CUDA build
81+
DOWNLOAD_NAME="opencv-cuda-release.tar.gz"
82+
wget -q -O "$DOWNLOAD_NAME" https://github.com/JJassonn69/ComfyUI-Stream-Pack/releases/download/v1.0/opencv-cuda-release.tar.gz
83+
tar -xzf "$DOWNLOAD_NAME" -C /workspace/comfystream/
84+
rm "$DOWNLOAD_NAME"
85+
else
86+
echo "OpenCV CUDA build already exists, skipping download."
87+
fi
88+
89+
# Install required libraries
90+
apt-get update && apt-get install -y \
91+
libgflags-dev \
92+
libgoogle-glog-dev \
93+
libjpeg-dev \
94+
libavcodec-dev \
95+
libavformat-dev \
96+
libavutil-dev \
97+
libswscale-dev
98+
99+
# Remove existing cv2 package
100+
SITE_PACKAGES_DIR="/workspace/miniconda3/envs/comfystream/lib/python3.11/site-packages"
101+
rm -rf "${SITE_PACKAGES_DIR}/cv2"*
102+
103+
# Copy new cv2 package
104+
cp -r /workspace/comfystream/cv2 "${SITE_PACKAGES_DIR}/"
105+
106+
# Handle library dependencies
107+
CONDA_ENV_LIB="/workspace/miniconda3/envs/comfystream/lib"
108+
109+
# Remove existing libstdc++ and copy system one
110+
rm -f "${CONDA_ENV_LIB}/libstdc++.so"*
111+
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${CONDA_ENV_LIB}/"
112+
113+
# Copy OpenCV libraries
114+
cp /workspace/comfystream/opencv/build/lib/libopencv_* /usr/lib/x86_64-linux-gnu/
115+
116+
# remove the opencv-contrib and cv2 folders
117+
rm -rf /workspace/comfystream/opencv_contrib
118+
rm -rf /workspace/comfystream/cv2
119+
120+
echo "OpenCV CUDA installation completed"
121+
shift
122+
fi
65123

66124
if [ "$1" = "--server" ]; then
67125
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

server/app.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ async def on_startup(app: web.Application):
345345
patch_loop_datagram(app["media_ports"])
346346

347347
app["pipeline"] = Pipeline(
348-
cwd=app["workspace"], disable_cuda_malloc=True, gpu_only=True, preview_method='none'
348+
cwd=app["workspace"],
349+
disable_cuda_malloc=True,
350+
gpu_only=True,
351+
preview_method='none',
352+
comfyui_inference_log_level=app.get("comfui_inference_log_level", None),
349353
)
350354
app["pcs"] = set()
351355
app["video_tracks"] = {}
@@ -386,6 +390,18 @@ async def on_shutdown(app: web.Application):
386390
action="store_true",
387391
help="Include stream ID as a label in Prometheus metrics.",
388392
)
393+
parser.add_argument(
394+
"--comfyui-log-level",
395+
default=None,
396+
choices=logging._nameToLevel.keys(),
397+
help="Set the global logging level for ComfyUI",
398+
)
399+
parser.add_argument(
400+
"--comfyui-inference-log-level",
401+
default=None,
402+
choices=logging._nameToLevel.keys(),
403+
help="Set the logging level for ComfyUI inference",
404+
)
389405
args = parser.parse_args()
390406

391407
logging.basicConfig(
@@ -439,5 +455,11 @@ def force_print(*args, **kwargs):
439455
print(*args, **kwargs, flush=True)
440456
sys.stdout.flush()
441457

442-
458+
# Allow overriding of ComyfUI log levels.
459+
if args.comfyui_log_level:
460+
log_level = logging._nameToLevel.get(args.comfyui_log_level.upper())
461+
logging.getLogger("comfy").setLevel(log_level)
462+
if args.comfyui_inference_log_level:
463+
app["comfui_inference_log_level"] = args.comfyui_inference_log_level
464+
443465
web.run_app(app, host=args.host, port=int(args.port), print=force_print)

server/pipeline.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,27 @@
55

66
from typing import Any, Dict, Union, List
77
from comfystream.client import ComfyStreamClient
8+
from utils import temporary_log_level
89

910
WARMUP_RUNS = 5
1011

1112

1213
class Pipeline:
13-
def __init__(self, **kwargs):
14+
def __init__(self, comfyui_inference_log_level: int = None, **kwargs):
15+
"""Initialize the pipeline with the given configuration.
16+
Args:
17+
comfyui_inference_log_level: The logging level for ComfyUI inference.
18+
Defaults to None, using the global ComfyUI log level.
19+
**kwargs: Additional arguments to pass to the ComfyStreamClient
20+
"""
1421
self.client = ComfyStreamClient(**kwargs)
1522
self.video_incoming_frames = asyncio.Queue()
1623
self.audio_incoming_frames = asyncio.Queue()
1724

1825
self.processed_audio_buffer = np.array([], dtype=np.int16)
1926

27+
self._comfyui_inference_log_level = comfyui_inference_log_level
28+
2029
async def warm_video(self):
2130
dummy_frame = av.VideoFrame()
2231
dummy_frame.side_data.input = torch.randn(1, 512, 512, 3)
@@ -75,7 +84,8 @@ def audio_postprocess(self, output: Union[torch.Tensor, np.ndarray]) -> av.Audio
7584

7685
async def get_processed_video_frame(self):
7786
# TODO: make it generic to support purely generative video cases
78-
out_tensor = await self.client.get_video_output()
87+
async with temporary_log_level("comfy", self._comfyui_inference_log_level):
88+
out_tensor = await self.client.get_video_output()
7989
frame = await self.video_incoming_frames.get()
8090
while frame.side_data.skipped:
8191
frame = await self.video_incoming_frames.get()
@@ -90,7 +100,8 @@ async def get_processed_audio_frame(self):
90100
# TODO: make it generic to support purely generative audio cases and also add frame skipping
91101
frame = await self.audio_incoming_frames.get()
92102
if frame.samples > len(self.processed_audio_buffer):
93-
out_tensor = await self.client.get_audio_output()
103+
async with temporary_log_level("comfy", self._comfyui_inference_log_level):
104+
out_tensor = await self.client.get_audio_output()
94105
self.processed_audio_buffer = np.concatenate([self.processed_audio_buffer, out_tensor])
95106
out_data = self.processed_audio_buffer[:frame.samples]
96107
self.processed_audio_buffer = self.processed_audio_buffer[frame.samples:]
@@ -108,4 +119,4 @@ async def get_nodes_info(self) -> Dict[str, Any]:
108119
return nodes_info
109120

110121
async def cleanup(self):
111-
await self.client.cleanup()
122+
await self.client.cleanup()

server/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .utils import patch_loop_datagram, add_prefix_to_app_routes
1+
from .utils import patch_loop_datagram, add_prefix_to_app_routes, temporary_log_level
22
from .fps_meter import FPSMeter

0 commit comments

Comments
 (0)