Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"python.defaultInterpreterPath": "/workspace/miniconda3/envs/comfystream/bin/python",
"python.venvPath": "/workspace/miniconda3/envs",
"python.terminal.activateEnvInCurrentTerminal": false,
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvironment": false,
"terminal.integrated.shellIntegration.enabled": true
},
"extensions": [
Expand Down
17 changes: 15 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[.gitignore]
insert_final_newline = unset

[*.py]
indent_size = 4

[workflows/comfy*/*.json]
insert_final_newline = unset

[Dockerfile*]
indent_style = tab
indent_size = 8
indent_size = 4

[*.{md,txt,mkdn}]
indent_size = 4
indent_size = unset
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .github/codeql-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paths-ignore:
- "docker/"
14 changes: 4 additions & 10 deletions .github/workflows/comfyui-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ name: Build and push comfyui-base docker image

on:
pull_request:
paths:
- docker/Dockerfile.base
- src/comfystream/scripts/
- configs/
- .github/workflows/comfyui-base.yaml
paths-ignore:
- "ui/*"
branches:
- main
push:
paths:
- docker/Dockerfile.base
- src/comfystream/scripts/
- configs/
- .github/workflows/comfyui-base.yaml
paths-ignore:
- "ui/*"
branches:
- main
tags:
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Test project

on:
pull_request:
branches:
- "main"
push:
branches:
- "main"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
codeql:
name: Perform CodeQL analysis
if: ${{ github.repository == 'livepeer/comfystream' }}
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: typescript,javascript,python
config-file: ./.github/codeql-config.yaml

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3


editorconfig:
name: Run editorconfig checker
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Install editorconfig-checker
uses: editorconfig-checker/action-editorconfig-checker@main

- name: Run editorconfig checker against the repo
if: false
# disabled editorconfig lint rule for now
run: editorconfig-checker --format github-actions

test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install '.[dev]'

- name: Run tests
run: pytest --cov --verbose --showlocals

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CI_CODECOV_TOKEN }}
name: ${{ github.event.repository.name }}
7 changes: 6 additions & 1 deletion configs/nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@ nodes:
comfyui-stream-pack:
name: "ComfyUI Stream Pack"
url: "https://github.com/livepeer/ComfyUI-Stream-Pack"
branch: "expose_feature_bank_to_comfyui"
branch: "main"
type: "utility"

comfyui-super-resolution:
name: "ComfyUI Super Resolution"
url: "https://github.com/ryanontheinside/ComfyUI_SuperResolution.git"
type: "utility"
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ RUN bash -c "source $NVM_DIR/nvm.sh && \
ENV NODE_PATH="$NVM_DIR/v$NODE_VERSION/lib/node_modules" \
PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"

RUN conda init bash

# Create the supervisor configuration file for ComfyUI and ComfyStream
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
Expand Down
25 changes: 14 additions & 11 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ 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)" && \
conda create -n comfystream python="${PYTHON_VERSION}" -y && \
rm /tmp/miniconda.sh && \
conda run -n comfystream --no-capture-output pip install aiortc aiohttp requests tqdm pyyaml --root-user-action=ignore
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

# Clone ComfyUI
ADD --link https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /workspace/ComfyUI

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

# Run setup_nodes (cached unless setup_nodes.py or nodes/ changes)
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI
COPY ./src/comfystream/scripts /workspace/comfystream/src/comfystream/scripts
COPY ./configs /workspace/comfystream/configs

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

# Install ComfyStream requirements
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install -r requirements.txt --root-user-action=ignore
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream pip install . --root-user-action=ignore
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 setup_nodes
RUN conda run -n comfystream --no-capture-output --cwd /workspace/comfystream python src/comfystream/scripts/setup_nodes.py --workspace /workspace/ComfyUI

# Install additional dependencies
RUN conda run -n comfystream --no-capture-output pip install --upgrade tensorrt-cu12-bindings tensorrt-cu12-libs --root-user-action=ignore

# 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

WORKDIR /workspace/comfystream
41 changes: 41 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ show_help() {
echo "Options:"
echo " --download-models Download default models"
echo " --build-engines Build TensorRT engines for default models"
echo " --opencv-cuda Setup OpenCV with CUDA support"
echo " --server Start the Comfystream server, UI and ComfyUI"
echo " --help Show this help message"
echo ""
Expand Down Expand Up @@ -62,6 +63,46 @@ if [ "$1" = "--build-engines" ]; then
shift
fi

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

# Download and extract OpenCV CUDA build
DOWNLOAD_NAME="opencv-cuda-latest.tar.gz"
wget -O "$DOWNLOAD_NAME" https://github.com/JJassonn69/ComfyUI_SuperResolution/releases/download/v1/opencv-cuda.tar.gz
tar -xzf "$DOWNLOAD_NAME" -C /workspace/comfystream/
rm "$DOWNLOAD_NAME"

# Install required libraries
apt-get update && apt-get install -y \
libgflags-dev \
libgoogle-glog-dev \
libjpeg-dev \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev

# Remove existing cv2 package
SITE_PACKAGES_DIR="/workspace/miniconda3/envs/comfystream/lib/python3.11/site-packages"
rm -rf "${SITE_PACKAGES_DIR}/cv2"*

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

# Handle library dependencies
CONDA_ENV_LIB="/workspace/miniconda3/envs/comfystream/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}/"

# Copy OpenCV libraries
cp /workspace/comfystream/opencv-cuda/opencv/build/lib/libopencv_* /usr/lib/x86_64-linux-gnu/

echo "OpenCV CUDA installation completed"
shift
fi

if [ "$1" = "--server" ]; then
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
Expand Down
15 changes: 0 additions & 15 deletions nodes/web/js/comfystream_ui_preview_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,10 @@ app.registerExtension({
});
});

// Update iframe size
this.updateIframeSize();

return result;
};

// Override the resize method to allow both expanding and shrinking
nodeType.prototype.onResize = function(size) {
// Update the size
this.size[0] = size[0];
this.size[1] = size[1];

// Update the iframe size
this.updateIframeSize();

// Force canvas update
this.setDirtyCanvas(true, true);
};

// Add a helper method to update iframe size
nodeType.prototype.updateIframeSize = function() {
if (this.iframeWidget) {
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "comfystream"
description = "Build Live AI Video with ComfyUI"
version = "0.0.4"
version = "0.0.5"
license = { file = "LICENSE" }
dependencies = [
"asyncio",
Expand All @@ -15,10 +15,11 @@ dependencies = [
"toml",
"twilio",
"prometheus_client",
"librosa"
]

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

[project.urls]
repository = "https://github.com/yondonfu/comfystream"
Expand All @@ -33,4 +34,4 @@ package-dir = {"" = "src"}
packages = {find = {where = ["src", "nodes"]}}

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
dependencies = {file = ["requirements.txt"]}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ aiohttp
toml
twilio
prometheus_client
librosa
25 changes: 24 additions & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ async def on_startup(app: web.Application):
patch_loop_datagram(app["media_ports"])

app["pipeline"] = Pipeline(
cwd=app["workspace"], disable_cuda_malloc=True, gpu_only=True, preview_method='none'
cwd=app["workspace"],
disable_cuda_malloc=True,
gpu_only=True,
preview_method='none',
comfyui_inference_log_level=app.get("comfui_inference_log_level", None),
)
app["pcs"] = set()
app["video_tracks"] = {}
Expand Down Expand Up @@ -386,6 +390,18 @@ async def on_shutdown(app: web.Application):
action="store_true",
help="Include stream ID as a label in Prometheus metrics.",
)
parser.add_argument(
"--comfyui-log-level",
default=None,
choices=logging._nameToLevel.keys(),
help="Set the global logging level for ComfyUI",
)
parser.add_argument(
"--comfyui-inference-log-level",
default=None,
choices=logging._nameToLevel.keys(),
help="Set the logging level for ComfyUI inference",
)
args = parser.parse_args()

logging.basicConfig(
Expand Down Expand Up @@ -435,4 +451,11 @@ def force_print(*args, **kwargs):
print(*args, **kwargs, flush=True)
sys.stdout.flush()

# Allow overriding of ComyfUI log levels.
if args.comfyui_log_level:
log_level = logging._nameToLevel.get(args.comfyui_log_level.upper())
logging.getLogger("comfy").setLevel(log_level)
if args.comfyui_inference_log_level:
app["comfui_inference_log_level"] = args.comfyui_inference_log_level

web.run_app(app, host=args.host, port=int(args.port), print=force_print)
Loading