Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
},
"runArgs": [
"--gpus=all"
],
],
// Features to add to the dev container. More info: https://containers.dev/features.
// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/workspace/miniconda3/envs/comfystream/bin/python",
"python.venvPath": "/workspace/miniconda3/envs",
"python.defaultInterpreterPath": "/workspace/.venv/bin/python",
"python.venvPath": "/workspace",
"python.terminal.activateEnvInCurrentTerminal": false,
"python.terminal.activateEnvironment": false,
"terminal.integrated.shellIntegration.enabled": true
"terminal.integrated.shellIntegration.enabled": true,
"python.analysis.autoImportCompletions": true
},
"extensions": [
"ms-python.python",
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd /workspace/comfystream

# Install Comfystream in editable mode.
echo -e "\e[32mInstalling Comfystream in editable mode...\e[0m"
/workspace/miniconda3/envs/comfystream/bin/python3 -m pip install -e . --root-user-action=ignore > /dev/null
python -m pip install -e . --root-user-action=ignore > /dev/null

# Install npm packages if needed
if [ ! -d "/workspace/comfystream/ui/node_modules" ]; then
Expand Down
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.venv/
.github/
.dockerignore
ui/node_modules
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"--disable-cuda-malloc",
"--front-end-version", "Comfy-Org/[email protected]"
],
"python": "/workspace/miniconda3/envs/comfystream/bin/python",
"python": "${command:python.interpreterPath}",
"justMyCode": true
},
{
Expand Down
4 changes: 2 additions & 2 deletions configs/nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ nodes:
# Core TensorRT nodes
comfyui-tensorrt:
name: "ComfyUI TensorRT"
url: "https://github.com/yondonfu/ComfyUI_TensorRT.git"
branch: "quantization_with_controlnet_fixes"
url: "https://github.com/eliteprox/ComfyUI_TensorRT.git"
branch: "patch-1"
type: "tensorrt"
dependencies:
- "tensorrt==10.12.0.36"
Expand Down
10 changes: 8 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ ARG BASE_IMAGE=livepeer/comfyui-base:latest

FROM ${BASE_IMAGE}

ENV PATH="/workspace/miniconda3/bin:${PATH}" \
# Ensure Bash is the default shell (inherited from base)
SHELL ["/bin/bash", "-c"]

ENV PATH="/workspace/.venv/bin:/root/.local/bin:${PATH}" \
NVM_DIR=/root/.nvm \
NODE_VERSION=18.18.0
NODE_VERSION=18.18.0 \
VIRTUAL_ENV="/workspace/.venv" \
PYTHONPATH="/workspace/.venv/lib/python${PYTHON_VERSION}/site-packages" \
SHELL="/bin/bash"

RUN echo "Using base image: ${BASE_IMAGE}" && \
apt update && \
Expand Down
77 changes: 41 additions & 36 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
ARG BASE_IMAGE=nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04 \
CONDA_VERSION=latest \
PYTHON_VERSION=3.12

FROM "${BASE_IMAGE}"

ARG CONDA_VERSION \
PYTHON_VERSION
ARG PYTHON_VERSION

# Set Bash as the default shell
SHELL ["/bin/bash", "-c"]

ENV DEBIAN_FRONTEND=noninteractive \
CONDA_VERSION="${CONDA_VERSION}" \
PATH="/workspace/miniconda3/bin:${PATH}" \
PYTHON_VERSION="${PYTHON_VERSION}"
PYTHON_VERSION="${PYTHON_VERSION}" \
SHELL="/bin/bash" \
UV_PYTHON="${PYTHON_VERSION}" \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
PATH="/workspace/.venv/bin:/root/.local/bin:/usr/local/bin:${PATH}" \
VIRTUAL_ENV="/workspace/.venv" \
PYTHONPATH="/workspace/.venv/lib/python${PYTHON_VERSION}/site-packages"

# System dependencies
RUN apt update && apt install -yqq --no-install-recommends \
git \
wget \
curl \
nano \
socat \
libsndfile1 \
Expand All @@ -27,6 +34,11 @@ RUN apt update && apt install -yqq --no-install-recommends \
swig \
libprotobuf-dev \
protobuf-compiler \
ffmpeg \
python3 \
python3-pip \
python3-venv \
curl \
&& rm -rf /var/lib/apt/lists/*

#enable opengl support with nvidia gpu
Expand All @@ -38,59 +50,52 @@ RUN printf '%s\n' \
' }' \
'}' > /usr/share/glvnd/egl_vendor.d/10_nvidia.json

# Conda setup
# Install uv package manager
RUN curl -LsSf https://astral.sh/uv/install.sh | sh

# Install Python and setup virtual environment using uv
RUN mkdir -p /workspace/comfystream && \
wget "https://repo.anaconda.com/miniconda/Miniconda3-${CONDA_VERSION}-Linux-x86_64.sh" -O /tmp/miniconda.sh && \
bash /tmp/miniconda.sh -b -p /workspace/miniconda3 && \
eval "$(/workspace/miniconda3/bin/conda shell.bash hook)" && \
/workspace/miniconda3/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
/workspace/miniconda3/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
conda create -n comfystream python="${PYTHON_VERSION}" ffmpeg=6 -c conda-forge -y && \
rm /tmp/miniconda.sh && echo 'export LD_LIBRARY_PATH=/workspace/miniconda3/envs/comfystream/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
uv python install "${PYTHON_VERSION}" && \
cd /workspace && \
uv venv .venv --python="${PYTHON_VERSION}"

RUN conda run -n comfystream --no-capture-output pip install --upgrade pip && \
conda run -n comfystream --no-capture-output pip install wheel
# Ensure pip exists inside the venv for tools that shell out to `python -m pip`
RUN /workspace/.venv/bin/python -m ensurepip --upgrade && \
/workspace/.venv/bin/python -m pip install -U pip setuptools wheel && \
/workspace/.venv/bin/python -m pip --version

# Install comfy-cli using uv
RUN uv pip install comfy-cli

# Copy only files needed for setup
COPY ./src/comfystream/scripts /workspace/comfystream/src/comfystream/scripts
COPY ./configs /workspace/comfystream/configs

# Clone ComfyUI
RUN git clone --branch v0.3.56 --depth 1 https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
RUN mkdir -p /workspace

# Install ComfyUI using comfy-cli
RUN comfy --skip-prompt --workspace /workspace/ComfyUI install --skip-torch-or-directml --nvidia

# Copy ComfyStream files into ComfyUI
COPY . /workspace/comfystream

RUN conda run -n comfystream --cwd /workspace/comfystream --no-capture-output pip install -r ./src/comfystream/scripts/constraints.txt
RUN cd /workspace/comfystream && uv pip install -r ./src/comfystream/scripts/overrides.txt

# Copy comfystream and example workflows to ComfyUI
COPY ./workflows/comfyui/* /workspace/ComfyUI/user/default/workflows/
COPY ./test/example-512x512.png /workspace/ComfyUI/input

# Install ComfyUI requirements
RUN conda run -n comfystream --no-capture-output --cwd /workspace/ComfyUI pip install -r requirements.txt --root-user-action=ignore

# Install ComfyStream requirements
RUN ln -s /workspace/comfystream /workspace/ComfyUI/custom_nodes/comfystream
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -e . --root-user-action=ignore
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python install.py --workspace /workspace/ComfyUI
RUN cd /workspace/comfystream && uv pip install -e .
RUN cd /workspace/comfystream && python install.py --workspace /workspace/ComfyUI

# Accept a build-arg that lets CI force-invalidate setup_nodes.py
ARG CACHEBUST=static
ENV CACHEBUST=${CACHEBUST}

# Run setup_nodes
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI

RUN conda run -n comfystream --no-capture-output pip install "numpy<2.0.0"

RUN conda run -n comfystream --no-capture-output pip install --no-cache-dir xformers==0.0.30 --no-deps

# Configure no environment activation by default
RUN conda config --set auto_activate_base false && \
conda init bash

# Set comfystream environment as default
RUN echo "conda activate comfystream" >> ~/.bashrc
# Ensure bash is used by default for interactive shells
ENV BASH_ENV=/root/.bashrc

WORKDIR /workspace/comfystream
26 changes: 11 additions & 15 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

set -e
eval "$(conda shell.bash hook)"

# Add help command to show usage
show_help() {
Expand Down Expand Up @@ -76,8 +75,7 @@ fi

if [ "$1" = "--download-models" ]; then
cd /workspace/comfystream
conda activate comfystream
python src/comfystream/scripts/setup_models.py --workspace /workspace/ComfyUI
python -m comfystream.scripts.setup_models --workspace /workspace/ComfyUI
shift
fi

Expand All @@ -89,7 +87,6 @@ FASTERLIVEPORTRAIT_DIR="/workspace/ComfyUI/models/liveportrait_onnx"

if [ "$1" = "--build-engines" ]; then
cd /workspace/comfystream
conda activate comfystream

# Build Static Engine for Dreamshaper - Square (512x512)
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 --width 512 --height 512
Expand Down Expand Up @@ -152,8 +149,7 @@ fi

if [ "$1" = "--opencv-cuda" ]; then
cd /workspace/comfystream
conda activate comfystream


# Check if OpenCV CUDA build already exists
if [ ! -f "/workspace/comfystream/opencv-cuda-release.tar.gz" ]; then
# Download and extract OpenCV CUDA build
Expand All @@ -176,18 +172,18 @@ if [ "$1" = "--opencv-cuda" ]; then
libswscale-dev

# Remove existing cv2 package
SITE_PACKAGES_DIR="/workspace/miniconda3/envs/comfystream/lib/python3.12/site-packages"
SITE_PACKAGES_DIR="$(uv python dir --bin)/lib/python3.12/site-packages"
rm -rf "${SITE_PACKAGES_DIR}/cv2"*

# Copy new cv2 package
cp -r /workspace/comfystream/cv2 "${SITE_PACKAGES_DIR}/"

# Handle library dependencies
CONDA_ENV_LIB="/workspace/miniconda3/envs/comfystream/lib"
UV_ENV_LIB="$(uv python dir --bin)/lib"

# Remove existing libstdc++ and copy system one
rm -f "${CONDA_ENV_LIB}/libstdc++.so"*
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${CONDA_ENV_LIB}/"
rm -f "${UV_ENV_LIB}/libstdc++.so"*
cp /usr/lib/x86_64-linux-gnu/libstdc++.so* "${UV_ENV_LIB}/"

# Copy OpenCV libraries
cp /workspace/comfystream/opencv/build/lib/libopencv_* /usr/lib/x86_64-linux-gnu/
Expand All @@ -207,20 +203,20 @@ if [ "$START_COMFYUI" = true ] || [ "$START_API" = true ] || [ "$START_UI" = tru
# Start supervisord in background
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf &
sleep 2 # Give supervisord time to start

# Start requested services
if [ "$START_COMFYUI" = true ]; then
supervisorctl -c /etc/supervisor/supervisord.conf start comfyui
fi

if [ "$START_API" = true ]; then
supervisorctl -c /etc/supervisor/supervisord.conf start comfystream-api
fi

if [ "$START_UI" = true ]; then
supervisorctl -c /etc/supervisor/supervisord.conf start comfystream-ui
fi

# Keep the script running
tail -f /var/log/supervisord.log
fi
Expand Down
4 changes: 2 additions & 2 deletions docker/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loglevel=info
pidfile=/var/run/supervisord.pid

[program:comfyui]
command=bash -c "source /workspace/miniconda3/bin/activate comfystream && python main.py --listen --disable-cuda-malloc --front-end-version Comfy-Org/[email protected]"
command=bash -c "python main.py --listen --disable-cuda-malloc --front-end-version Comfy-Org/[email protected]"
directory=/workspace/ComfyUI
autostart=false
autorestart=true
Expand All @@ -19,7 +19,7 @@ stdout_logfile_maxbytes=0
loglevel=debug

[program:comfystream-api]
command=bash -c "source /workspace/miniconda3/bin/activate comfystream && python app.py --workspace=/workspace/ComfyUI --media-ports=5678,5679,5680 --host=0.0.0.0 --port=8889 --log-level=DEBUG"
command=bash -c "python app.py --workspace=/workspace/ComfyUI --media-ports=5678,5679,5680 --host=0.0.0.0 --port=8889 --log-level=DEBUG"
directory=/workspace/comfystream/server
autostart=false
autorestart=true
Expand Down
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def download_and_extract_ui_files(version: str):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Install custom node requirements")
parser.add_argument(
"--workspace", default=os.environ.get('COMFY_UI_WORKSPACE', None), required=False, help="Set Comfy workspace"
"--workspace", default=os.environ.get('COMFYUI_WORKSPACE', None), required=False, help="Set Comfy workspace"
)
args = parser.parse_args()

Expand Down
19 changes: 6 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ build-backend = "setuptools.build_meta"
name = "comfystream"
description = "Build Live AI Video with ComfyUI"
version = "0.1.5"
license = { file = "LICENSE" }
dependencies = [
"asyncio",
"pytrickle @ git+https://github.com/livepeer/pytrickle.git@de37bea74679fa5db46b656a83c9b7240fc597b6",
"comfyui @ git+https://github.com/hiddenswitch/ComfyUI.git@58622c7e91cb5cc2bca985d713db55e5681ff316",
"aiortc",
"aiohttp",
"aiohttp_cors",
"toml",
"twilio",
"prometheus_client",
"librosa"
]
license = "MIT"
dynamic = ["dependencies"]

[project.optional-dependencies]
dev = ["pytest", "pytest-cov"]

[project.scripts]
setup-nodes = "comfystream.scripts.setup_nodes:setup_nodes"
setup-models = "comfystream.scripts.setup_models:setup_models"

[project.urls]
Repository = "https://github.com/yondonfu/comfystream"

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
asyncio
pytrickle @ git+https://github.com/livepeer/pytrickle.git@de37bea74679fa5db46b656a83c9b7240fc597b6
comfyui @ git+https://github.com/hiddenswitch/ComfyUI.git@58622c7e91cb5cc2bca985d713db55e5681ff316
comfyui @ git+https://github.com/hiddenswitch/ComfyUI.git@3de77f6e24901fa0c423f1e298a8be9f89f312cc
aiortc
aiohttp
aiohttp_cors
Expand Down
2 changes: 1 addition & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ bcrypt
rich
# Profiler
psutil
pynvml
nvidia-ml-py
8 changes: 6 additions & 2 deletions src/comfystream/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class Pipeline:
postprocessing, and queue management.
"""

def __init__(self, width: int = 512, height: int = 512,
comfyui_inference_log_level: Optional[int] = None, **kwargs):
def __init__(self,
width: int = 512,
height: int = 512,
comfyui_inference_log_level: Optional[int] = None,
blacklist_nodes: List[str] = ["ComfyUI-Manager"],
**kwargs):
"""Initialize the pipeline with the given configuration.

Args:
Expand Down
4 changes: 0 additions & 4 deletions src/comfystream/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from . import utils
from utils import get_config_path, load_model_config
from .setup_nodes import run_setup_nodes
from .setup_models import run_setup_models

"""Setup scripts for ComfyUI streaming server"""

3 changes: 1 addition & 2 deletions src/comfystream/scripts/build_trt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import time
import argparse

# Reccomended running from comfystream conda environment
# Recommended running from the workspace directory (uv venv auto-activated)
# in devcontainer from the workspace/ directory, or comfystream/ if you've checked out the repo
# $> conda activate comfystream
# $> python src/comfystream/scripts/build_trt.py --model /ComfyUI/models/checkpoints/SD1.5/dreamshaper-8.safetensors --out-engine /ComfyUI/output/tensorrt/static-dreamshaper8_SD15_$stat-b-1-h-512-w-512_00001_.engine

# Paths path explicitly to use the downloaded comfyUI installation on root
Expand Down
Loading