Shared Gradio and CLI runtime for MatAnyone and MatAnyone 2 on Windows.
Project description
MatAnyone
Windows-friendly local runtime for MatAnyone and MatAnyone 2, with a shared core that powers both the Gradio WebUI and a reproducible CLI.
日本語 | Docs | PyPI | MatAnyone 2 | MatAnyone | Original Space
What This Repo Provides
- A shared runtime core in
matanyone2/demo_core.pyused by both the CLI and the Gradio app - A package entrypoint,
matanyone2-runtime, withcliandwebuisubcommands - Timestamped run folders under
results/<input-name>_<timestamp>/ - Debug artifacts for every run, including SAM previews, masks, frame snapshots, and
metadata.json - Windows-friendly setup with
uv, automatic checkpoint downloads, and ffmpeg discovery
Quick Start
Requirements:
- Windows 10 or Windows 11
- Python 3.10
uvgitffmpeg- NVIDIA GPU recommended for practical speed
Install the base tools with winget:
winget install astral-sh.uv
winget install Git.Git
winget install Gyan.FFmpeg
Install from PyPI if you just want to run the packaged runtime:
uv venv --python 3.10
uv pip install --python .\.venv\Scripts\python.exe --upgrade pip setuptools wheel
uv pip install --python .\.venv\Scripts\python.exe torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
uv pip install --python .\.venv\Scripts\python.exe matanyone2-runtime
PyPI package:
Install from source instead if you want to modify this repository locally:
uv venv --python 3.10
uv pip install --python .\.venv\Scripts\python.exe --upgrade pip setuptools wheel
uv pip install --python .\.venv\Scripts\python.exe torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
uv pip install --python .\.venv\Scripts\python.exe -e .
Installed entrypoints:
matanyone2-runtimematanyone-climatanyone-gradiopython -m matanyone2
Recommended unified entrypoint:
matanyone2-runtime webui ...matanyone2-runtime cli ...
Launch the WebUI:
uv run --python .\.venv\Scripts\python.exe matanyone2-runtime webui --device cuda --port 7860 --server_name 127.0.0.1
Run the shared CLI:
uv run --python .\.venv\Scripts\python.exe matanyone2-runtime cli --input .\media\bookcat.mp4 --device cpu --performance_profile fast --cpu_threads 8 --positive_point 280,180 --output_dir .\results
Then open http://127.0.0.1:7860 for the WebUI, or inspect the generated run folder for CLI outputs.
Run Output Layout
Every run creates a dedicated directory such as results/bookcat_1773163828_6577592/.
Typical contents:
- final outputs such as
*_foreground.mp4,*_alpha.mp4,*_mask.png, and*_sam_preview.png - debug artifacts such as
input_first_frame.png,input_selected_frame.png,sam_selected_preview.png, andsam_selected_mask.png - first and last matting snapshots such as
matting_output_first_*andmatting_output_last_* metadata.jsonwith the exact runtime configuration
This makes it easier to compare runs, reproduce experiments, and inspect intermediate state without launching the UI.
CLI and WebUI Share The Same Core
The Gradio app and the CLI both run through matanyone2/demo_core.py. Shared responsibilities include:
- runtime configuration and ffmpeg setup
- image and video loading
- SAM prompt handling
- matting orchestration
- final output writing
- debug artifact export
Thin entrypoints:
hugging_face/app.pyfor the WebUImatanyone2/cli.pyfor direct CLI executionmatanyone2/runtime.pyfor the package-friendlymatanyone2-runtimelauncherscripts/run_pipeline_check.pyas a compatibility wrapper around the CLI
Python API
The PyPI package now exposes an import-friendly API for host applications that want to call MatAnyone directly instead of shelling out to the CLI.
from matanyone2 import run_pipeline
result = run_pipeline(
input_path="bookcat.mp4",
device="cpu",
model="MatAnyone 2",
positive_points=["280,180"],
)
print(result["foreground_path"])
print(result["alpha_path"])
The returned dictionary includes:
run_output_dirdebug_dirforeground_pathalpha_pathmask_pathsam_preview_pathis_videofps
Reproducible Validation
To reproduce the historical bookcat-profile-exp style run more closely, pin the same prompt points and FPS settings:
uv run --python .\.venv\Scripts\python.exe matanyone2-runtime cli --input .\media\bookcat.mp4 --device cpu --performance_profile fast --cpu_threads 8 --sam_model_type vit_h --frame_limit 241 --video_target_fps 0 --output_fps 12 --positive_point 280,180 --negative_point 30,30 --negative_point 530,30 --model "MatAnyone 2" --output_dir .\results
This workflow is also useful for CI smoke checks, scripted regression checks, and local benchmarking.
By default, the CLI now writes video outputs at the loaded media's processing FPS so playback duration stays aligned with the processed frames. Use --output_fps only when you intentionally want to override that for benchmarking or comparison runs.
CI/CD
GitHub Actions now covers the main repository lifecycle:
Repo Checks: builds docs, compiles maintained Python sources, lints the maintained runtime files, builds the package, and verifies the packaged entrypointsDocs Pages: builds the VitePress site and deploys it to GitHub Pages on pushes tomainRelease Package: builds wheel and sdist artifacts onv*tags, attaches them to a GitHub Release with SHA256 checksums, and publishes them to PyPI
If you want to cut a release:
git tag v0.2.0
git push origin v0.2.0
That tag will trigger the package release workflow automatically.
To make PyPI publishing work, configure a trusted publisher for this repository on PyPI and bind it to the pypi GitHub Actions environment.
Published package:
Documentation
Full docs live at sunwood-ai-labs.github.io/MatAnyone2-Gradio-Windows and in docs/.
- Getting started:
docs/guide/getting-started.md - Usage guide:
docs/guide/usage.md - Performance notes:
docs/guide/performance.md - Architecture notes:
docs/guide/architecture.md - CI/CD guide:
docs/guide/ci-cd.md - Troubleshooting:
docs/guide/troubleshooting.md
To preview the docs site locally:
cd docs
npm install
npm run docs:dev
Repository Layout
| Path | Purpose |
|---|---|
hugging_face/app.py |
Gradio app entrypoint and UI wiring |
hugging_face/tools/ |
UI helper utilities used by the demo |
matanyone2/demo_core.py |
Shared runtime for WebUI and CLI |
matanyone2/cli.py |
Direct CLI entrypoint |
matanyone2/runtime.py |
Unified package entrypoint with cli and webui subcommands |
matanyone2/ |
Upstream model and inference implementation |
pretrained_models/ |
Auto-downloaded checkpoints, ignored by git |
results/ |
Generated outputs and debug artifacts, ignored by git |
media/ |
Repository branding and documentation assets |
Troubleshooting
- If ffmpeg is not detected, confirm
ffmpeg.exeis onPATHor installed viawinget - If CUDA startup fails, install a matching PyTorch build for your driver or switch to
--device cpu - If the first launch takes a while, checkpoints and sample media are being downloaded on demand
- If you want different host or port settings, use
--server_nameand--port
Attribution And License
This repository is a derivative adaptation of:
The included LICENSE is the upstream S-Lab License 1.0. Commercial use still requires permission from the original authors listed in that license file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matanyone2_runtime-0.2.0.tar.gz.
File metadata
- Download URL: matanyone2_runtime-0.2.0.tar.gz
- Upload date:
- Size: 72.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8f61de1adc3b7ea1a62b1864a773f5ca2c51d37d2f8ac5ac69d464f45f67e57
|
|
| MD5 |
052a4f84de59d98dd1a6a8db190aaf1b
|
|
| BLAKE2b-256 |
2f37bff2aa3b693b9ad35f8ec60558a5d2fdd3d2c404282f84ca7f3c6aea99e4
|
Provenance
The following attestation bundles were made for matanyone2_runtime-0.2.0.tar.gz:
Publisher:
release-package.yml on Sunwood-ai-labs/MatAnyone2-Gradio-Windows
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matanyone2_runtime-0.2.0.tar.gz -
Subject digest:
d8f61de1adc3b7ea1a62b1864a773f5ca2c51d37d2f8ac5ac69d464f45f67e57 - Sigstore transparency entry: 1082236646
- Sigstore integration time:
-
Permalink:
Sunwood-ai-labs/MatAnyone2-Gradio-Windows@d4161507834b69e34a3623f1170281f32ead2b25 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Sunwood-ai-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-package.yml@d4161507834b69e34a3623f1170281f32ead2b25 -
Trigger Event:
push
-
Statement type:
File details
Details for the file matanyone2_runtime-0.2.0-py3-none-any.whl.
File metadata
- Download URL: matanyone2_runtime-0.2.0-py3-none-any.whl
- Upload date:
- Size: 85.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
785cb9dbd4034f45f453e615ccfc3d81fc0622021400e6ebbf50bbfc2d527dab
|
|
| MD5 |
56dadd65c25e06b4628e17d3b07a5508
|
|
| BLAKE2b-256 |
9ae1e9296b4d5c1dfb66bf2ed594390ea2349b767d883d9bdb4566f2ebda08b2
|
Provenance
The following attestation bundles were made for matanyone2_runtime-0.2.0-py3-none-any.whl:
Publisher:
release-package.yml on Sunwood-ai-labs/MatAnyone2-Gradio-Windows
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matanyone2_runtime-0.2.0-py3-none-any.whl -
Subject digest:
785cb9dbd4034f45f453e615ccfc3d81fc0622021400e6ebbf50bbfc2d527dab - Sigstore transparency entry: 1082236711
- Sigstore integration time:
-
Permalink:
Sunwood-ai-labs/MatAnyone2-Gradio-Windows@d4161507834b69e34a3623f1170281f32ead2b25 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Sunwood-ai-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-package.yml@d4161507834b69e34a3623f1170281f32ead2b25 -
Trigger Event:
push
-
Statement type: