Skip to content

One-click character swap for videos: an open-source, local Higgsfield Genjutsu alternative built on ComfyUI and MiniMax H3, with FLUX.3 Klein relighting.

Add security headers, run the launcher on a production build, and fix README details (#15)

mixbag63d0d0fe325c
diff --git a/README.md b/README.md
index 4794eac..7391dd3 100644
--- a/README.md
+++ b/README.md
@@ -55,13 +55,13 @@ Before uploading a job, Openjutsu checks the selected workflow against ComfyUI's
## Run it locally
-On Windows, double-click `start_openjutsu.bat` (ComfyUI must be running, or started while it waits). The first run installs `comfy-api-proxy` into `.venv-proxy` and the node packages; then it opens the proxy and the app in two windows and the page in your browser. Close those two windows to stop Openjutsu. The manual steps:
+On Windows, double-click `start_openjutsu.bat` (ComfyUI must be running, or started while it waits). The first run installs `comfy-api-proxy` 0.1.6 into `.venv-proxy` and the node packages. Each run builds the app, then opens the proxy and the app (`npm start`, the production server) in two windows and the page in your browser. Close those two windows to stop Openjutsu. The manual steps:
1. Start ComfyUI on `127.0.0.1:8188`. On Windows, set `AIOHTTP_NOSENDFILE=1` first (PowerShell: `$env:AIOHTTP_NOSENDFILE = "1"`). Without it, the first partial-file request (the video player sends one when you seek) can stall ComfyUI's `/view`, and every later file download hangs until ComfyUI restarts.
2. Install and start the proxy, which serves the Comfy API v2 on `127.0.0.1:8189`. Raise the upload cap for longer videos (the default is 100 MB):
```sh
- pip install comfy-api-proxy
+ pip install comfy-api-proxy==0.1.6
comfy-api-proxy run --max-upload-mb 500
```
@@ -72,9 +72,12 @@ On Windows, double-click `start_openjutsu.bat` (ComfyUI must be running, or star
cd openjutsu
cp .env.example .env.local
npm ci
- npm run dev
+ npm run build
+ npm start
```
+ While changing the code, `npm run dev` runs the development server instead.
+
4. Open <http://127.0.0.1:3000>.
`.env.local` sets `COMFY_BASE_URL=http://127.0.0.1:8189`. Leave `COMFY_API_KEY` empty for a local proxy. The base model and LoRA pickers read ComfyUI's model lists from `COMFYUI_URL` (default `http://127.0.0.1:8188`); without it they become text fields.
@@ -117,7 +120,7 @@ Each clip, SAM 3.1 tracks everyone at 1008 px (its own working size), and H3 Peo
`lib/model.ts` then sets the Swap Plan's steps and the H3 Diffusion Model file, and replaces the DMAD LoRA node with the chosen LoRAs in a chain (or links the model straight through when there are none). Advanced mode does the same.
-`lib/comfy.ts` binds the uploaded video to `VHS_LoadVideo` and the photo to the `LoadImage` node, then submits with the SDK. `/api/jobs/[id]/events` streams `job.events()` to the page as server-sent events. Node ids are turned into node titles and clip numbers there: each clip after the first is a graph expansion whose node ids carry a prefix per clip (`58`, `64.0.0.58`, `64.0.0.Recurse.0.0.58`). The final MP4 is the output of the Final Video node (`MiniMaxH3ChainAssemble`, node `65`).
+`lib/comfy.ts` binds the uploaded video to `VHS_LoadVideo` and the photo to the `LoadImage` node, then submits with the SDK. `/api/jobs/[id]/events` reads the job's raw event stream (the SDK's low-level `getJobEvents`) and forwards it to the page as server-sent events. Node ids are turned into node titles and clip numbers there: each clip after the first is a graph expansion of the loop, whose node ids carry a prefix per clip (`64`, `66.0.0.64`, `66.0.0.Recurse.0.0.64` for Save Clip in clips 1–3). The final MP4 is the output of the Final Video node (`MiniMaxH3ChainAssemble`, node `67`).
`workflows/mask.api.json` is the mask check: the same SAM, People Mask and grow settings over the whole video, with the mask tinted over the frames next to the mannequin, saved as an MP4.
@@ -165,4 +168,4 @@ Notes:
## License
-MIT, see [`LICENSE`](LICENSE). Model licences are separate.
+MIT, see [`LICENSE`](LICENSE). Model licences are separate. Fix faces depends on InsightFace `buffalo_l`, which is licensed for non-commercial research only, and on the Ultralytics YOLO weights from Bingsu/adetailer, which are AGPL-3.0.
diff --git a/lib/color.ts b/lib/color.ts
index 45d8106..367280e 100644
--- a/lib/color.ts
+++ b/lib/color.ts
@@ -1,4 +1,4 @@
-// Fix colours: post-processing for a finished video. Image Detail Contrast (F:\AI\comfyui-image-detail-contrast) softens
+// Fix colours: post-processing for a finished video. Image Detail Contrast (comfyui-image-detail-contrast) softens
// H3's crunchy fine detail, then Orion4D's DCTL Tone Mapper grades the frames: by default H3 soft, a lighter take on
// zuanfilm's H3 preset that softens contrast and highlights without washing out the blacks. workflows/color.api.json is
// hand-written; each request sets the values and drops a step that is turned off. Nodes are found by title.
diff --git a/next.config.ts b/next.config.ts
index cb651cd..f78fc2b 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -1,5 +1,21 @@
import type { NextConfig } from "next";
-const nextConfig: NextConfig = {};
+// Next reads this config before it starts telemetry, so this turns telemetry off for every npm script on any OS
+// (a `NEXT_TELEMETRY_DISABLED=1 next ...` script prefix would fail in Windows cmd).
+process.env.NEXT_TELEMETRY_DISABLED ??= "1";
+
+// No full CSP: Next's inline scripts and the page's blob: video previews would need one written around them.
+const securityHeaders = [
+ { key: "X-Frame-Options", value: "DENY" },
+ { key: "Content-Security-Policy", value: "frame-ancestors 'none'" },
+ { key: "X-Content-Type-Options", value: "nosniff" },
+ { key: "Referrer-Policy", value: "same-origin" },
+];
+
+const nextConfig: NextConfig = {
+ async headers() {
+ return [{ source: "/:path*", headers: securityHeaders }];
+ },
+};
export default nextConfig;
diff --git a/start_openjutsu.bat b/start_openjutsu.bat
index d1c5ff5..19a5945 100644
--- a/start_openjutsu.bat
+++ b/start_openjutsu.bat
@@ -2,18 +2,25 @@
setlocal
title Openjutsu
cd /d "%~dp0"
+set NEXT_TELEMETRY_DISABLED=1
+rem The comfy-api-proxy version the app is written for. pip skips the install when it is already there.
+set PROXY_VERSION=0.1.6
-if not exist ".venv-proxy\Scripts\comfy-api-proxy.exe" (
+if not exist ".venv-proxy\Scripts\python.exe" (
echo Installing comfy-api-proxy...
python -m venv .venv-proxy || goto :fail
- ".venv-proxy\Scripts\python.exe" -m pip install comfy-api-proxy || goto :fail
)
+".venv-proxy\Scripts\python.exe" -m pip install -q --disable-pip-version-check comfy-api-proxy==%PROXY_VERSION% || goto :fail
if not exist "node_modules" (
echo Installing the app...
call npm ci || goto :fail
)
if not exist ".env.local" copy ".env.example" ".env.local" >nul
+rem Build every time, so the app always matches the code (a rebuild takes a few seconds).
+echo Building the app...
+call npm run build || goto :fail
+
curl -s -o nul -m 3 http://127.0.0.1:8188/queue
if errorlevel 1 echo Waiting for ComfyUI on 127.0.0.1:8188. Start it now.
:comfy
@@ -24,7 +31,7 @@ if errorlevel 1 (
)
start "Openjutsu proxy" ".venv-proxy\Scripts\comfy-api-proxy.exe" run --max-upload-mb 500
-start "Openjutsu app" cmd /c npm run dev
+start "Openjutsu app" cmd /c npm start
echo Starting Openjutsu...
:app
diff --git a/workflows/advanced.api.json b/workflows/advanced.api.json
index ed5c433..f56c092 100644
--- a/workflows/advanced.api.json
+++ b/workflows/advanced.api.json
@@ -1,7 +1,7 @@
{
"2": {
"inputs": {
- "image": "apt_vest_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -46,7 +46,7 @@
},
"5": {
"inputs": {
- "image": "apt_kurta_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -181,7 +181,7 @@
},
"14": {
"inputs": {
- "video": "apt_rose_16s.mkv",
+ "video": "",
"force_rate": 24,
"custom_width": 0,
"custom_height": 0,
diff --git a/workflows/advanced_maxq.api.json b/workflows/advanced_maxq.api.json
index 8514a1b..bb0cca2 100644
--- a/workflows/advanced_maxq.api.json
+++ b/workflows/advanced_maxq.api.json
@@ -1,7 +1,7 @@
{
"2": {
"inputs": {
- "image": "apt_vest_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -46,7 +46,7 @@
},
"5": {
"inputs": {
- "image": "apt_kurta_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -91,7 +91,7 @@
},
"8": {
"inputs": {
- "video": "apt_rose_16s.mkv",
+ "video": "",
"force_rate": 24,
"custom_width": 0,
"custom_height": 0,
diff --git a/workflows/control.api.json b/workflows/control.api.json
index 3709850..c4f7328 100644
--- a/workflows/control.api.json
+++ b/workflows/control.api.json
@@ -1,7 +1,7 @@
{
"2": {
"inputs": {
- "image": "apt_vest_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -52,7 +52,7 @@
},
"5": {
"inputs": {
- "video": "spiderman_jeangrey_apt.mp4",
+ "video": "",
"force_rate": 24,
"custom_width": 0,
"custom_height": 0,
diff --git a/workflows/montage.api.json b/workflows/montage.api.json
index 746732b..1ca2d55 100644
--- a/workflows/montage.api.json
+++ b/workflows/montage.api.json
@@ -1,11 +1,11 @@
{
- "2": {"inputs": {"image": "apt_vest_reference.png"}, "class_type": "LoadImage", "_meta": {"title": "Picture 1"}},
+ "2": {"inputs": {"image": ""}, "class_type": "LoadImage", "_meta": {"title": "Picture 1"}},
"3": {"inputs": {"upscale_method": "area", "largest_size": 768, "image": ["2", 0]}, "class_type": "ImageScaleToMaxDimension", "_meta": {"title": "Shrink for the describer"}},
"4": {"inputs": {"prompt": "Describe the person in this picture for a casting sheet, in one sentence of about 40 words: apparent age and gender, hair, facial hair, skin tone, build, and their complete outfit including footwear. No preamble, no background.", "max_length": 120, "sampling_mode": "off", "thinking": false, "use_default_template": true, "mtp": "auto", "clip": ["16", 0], "image": ["3", 0]}, "class_type": "TextGenerate", "_meta": {"title": "Describe picture 1"}},
- "5": {"inputs": {"image": "apt_kurta_reference.png"}, "class_type": "LoadImage", "_meta": {"title": "Picture 2"}},
+ "5": {"inputs": {"image": ""}, "class_type": "LoadImage", "_meta": {"title": "Picture 2"}},
"6": {"inputs": {"upscale_method": "area", "largest_size": 768, "image": ["5", 0]}, "class_type": "ImageScaleToMaxDimension", "_meta": {"title": "Shrink for the describer"}},
"7": {"inputs": {"prompt": "Describe the person in this picture for a casting sheet, in one sentence of about 40 words: apparent age and gender, hair, facial hair, skin tone, build, and their complete outfit including footwear. No preamble, no background.", "max_length": 120, "sampling_mode": "off", "thinking": false, "use_default_template": true, "mtp": "auto", "clip": ["16", 0], "image": ["6", 0]}, "class_type": "TextGenerate", "_meta": {"title": "Describe picture 2"}},
- "8": {"inputs": {"video": "apt_rose_16s.mkv", "force_rate": 24, "custom_width": 0, "custom_height": 0, "frame_load_cap": 0, "skip_first_frames": 0, "select_every_nth": 1, "format": "None"}, "class_type": "VHS_LoadVideo", "_meta": {"title": "Source video (people get replaced)"}},
+ "8": {"inputs": {"video": "", "force_rate": 24, "custom_width": 0, "custom_height": 0, "frame_load_cap": 0, "skip_first_frames": 0, "select_every_nth": 1, "format": "None"}, "class_type": "VHS_LoadVideo", "_meta": {"title": "Source video (people get replaced)"}},
"9": {"inputs": {"start_index": 0, "duration": 2048, "audio": ["8", 2]}, "class_type": "TrimAudioDuration", "_meta": {"title": "Soundtrack (whole video)"}},
"14": {"class_type": "H3MontagePlan", "_meta": {"title": "Swap Plan (roles, seed, size)"}, "inputs": {"clip_seconds": 6, "overlap_frames": 39, "resolution": "736p", "steps": 6, "seed": 0, "roles": "", "no_lip_sync": ["97", 0], "source_frames": ["8", 0], "picture_1": ["2", 0], "picture_2": ["5", 0], "picture_3": ["103", 0], "picture_4": ["106", 0], "picture_1_text": ["4", 0], "picture_2_text": ["7", 0], "picture_3_text": ["105", 0], "picture_4_text": ["108", 0], "track_data": ["121", 0], "labels": ["125", 0]}},
"16": {"inputs": {"clip_name": "qwen3vl_8b_int8_convrot.safetensors", "type": "stable_diffusion", "device": "default"}, "class_type": "CLIPLoader", "_meta": {"title": "Describer: Qwen3-VL 8B"}},
diff --git a/workflows/object.api.json b/workflows/object.api.json
index c659c02..8ff85ef 100644
--- a/workflows/object.api.json
+++ b/workflows/object.api.json
@@ -1,7 +1,7 @@
{
"2": {
"inputs": {
- "image": "apt_vest_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -52,7 +52,7 @@
},
"5": {
"inputs": {
- "video": "spiderman_jeangrey_apt.mp4",
+ "video": "",
"force_rate": 24,
"custom_width": 0,
"custom_height": 0,
diff --git a/workflows/simple.api.json b/workflows/simple.api.json
index 4103da7..c4061d0 100644
--- a/workflows/simple.api.json
+++ b/workflows/simple.api.json
@@ -1,7 +1,7 @@
{
"2": {
"inputs": {
- "image": "apt_vest_reference.png"
+ "image": ""
},
"class_type": "LoadImage",
"_meta": {
@@ -46,7 +46,7 @@
},
"5": {
"inputs": {
- "video": "spiderman_jeangrey_apt.mp4",
+ "video": "",
"force_rate": 24,
"custom_width": 0,
"custom_height": 0,