Skip to content

About

Multimodal desktop screen & webcam vision bridge connecting SillyTavern and MateEngine VRM avatars via Google Gemini APIs

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

AlphaVision Bridge

CI Tests Python Gemini API SillyTavern MateEngine License: AGPL-3.0

Multimodal desktop screen & webcam vision bridge connecting SillyTavern and MateEngine VRM avatars via Google Gemini APIs.

Quick Start · Architecture · Configuration · Privacy & Hardware


Overview

AlphaVision Bridge turns a desktop MateEngine VRM companion into a live-vision, screen-aware entity synchronized with SillyTavern. Rather than relying on stale window-title guesses, AlphaVision streams separate sharp screen (1600×900), webcam (640×480), and active-window/cursor ROI crops directly to Google Gemini via a persistent HTTP client—driving spontaneous desktop remarks on delta events and full multimodal conversation on demand.


Architecture

flowchart LR
    subgraph Input["Perception Layer (OpenCV + MediaPipe + MSS)"]
        CAM["Webcam 640x480\n(CLAHE Low-Light)"]
        SCR["Screen 1600x900\n+ Cursor ROI 768x512"]
        WIN["Win32 Window / Idle\n+ Pixel Delta Gate"]
    end

    subgraph Core["AlphaVision-Bridge (Python :5001)"]
        MEM["In-Memory JPEG Buffers\n(io.BytesIO, Zero Disk I/O)"]
        BRAIN["BrainEngine\nHysteresis + 90s Cooldown"]
        FAST["FastGeminiClient\nKeep-Alive TLS Pool"]
    end

    subgraph Cloud["Google Gemini API"]
        GEM["Gemini Multimodal API\n(User-Supplied API Key)"]
    end

    subgraph Clients["Avatar & Chat Endpoints"]
        ST["SillyTavern :8000\nChat History & Persona"]
        ME["MateEngine VRM :8787\nSpeech Bubbles & HUD"]
    end

    CAM --> MEM
    SCR --> MEM
    WIN --> BRAIN
    MEM --> BRAIN
    BRAIN --> FAST
    FAST --> GEM
    GEM --> FAST
    FAST <--> ST
    FAST --> ME
    ST <--> ME

    style Input fill:#0d1117,stroke:#00f0ff,color:#e6edf3
    style Core fill:#0d1117,stroke:#bc8cff,color:#e6edf3
    style Cloud fill:#0d1117,stroke:#ff2a6d,color:#e6edf3
    style Clients fill:#0d1117,stroke:#3fffa8,color:#e6edf3
Loading

Core Capabilities

  • Separate High-Detail Frames: Sends sharp desktop captures (1600×900), clean webcam frames (640×480 with automatic CLAHE low-light boost), and focused cursor/window ROI crops (768×512) as distinct multimodal parts—never crushed together in one downscaled thumbnail.
  • Pixel-Delta Attention Engine (engine/brain.py): Perceptual diff triggers react immediately to red terminal tracebacks, tab switches, or webcam movement while skipping API calls completely when the workspace is static.
  • Always-On Multimodal Chat (AnimeVision.py): OpenAI-compatible /v1/chat/completions bridge supporting both standard JSON and stream: true SSE responses with recent spontaneous remarks injected into short-term context.
  • Unity Runtime Bridge (unity_bridge_mod/): dnlib IL patcher adding dual-schema /api/chat support, live SPONTANEOUS REMARKS settings toggle sync inside MateEngine's GENERAL menu, and viewport-aware TextMeshPro scroll clipping.

Screenshots

SillyTavern Chat AlphaVision Terminal + MateEngine
SillyTavern Chat AlphaVision Terminal
Full Desktop View — MateEngine + Terminal Logs

MateEngine Desktop


Installation

Prerequisites

  • Windows 10 / 11 (Win32 DWM & DirectShow APIs for screen/webcam capture)
  • Python 3.10+
  • Google Gemini API Key (Google AI Studio)
  • SillyTavern & MateEngine (with unity_bridge_mod patch for desktop overlay)

3-Step Setup

# 1. Clone the repository & install pinned Python dependencies
git clone https://github.com/antrikshidk/AlphaVision-Bridge.git
cd AlphaVision-Bridge
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

# 2. Configure your local environment (copy templates)
Copy-Item .env.example .env
Copy-Item config.example.json config.json
# Edit .env and set GEMINI_API_KEY (plus optional MATEENGINE_DIR / SILLYTAVERN_DIR)

# 3. Run the bridge
python AnimeVision.py
Optional: SillyTavern Extension, Unity DLL Patch & One-Click Watchdog
  1. SillyTavern Extension & Server Plugin:
    • Copy extensions/Extension-MateEngine/ into SillyTavern/public/scripts/extensions/third-party/Extension-MateEngine/.
    • Copy extensions/mateengine-chat-plugin/ into SillyTavern/plugins/mateengine-chat-plugin/.
    • Point SillyTavern's OpenAI-compatible API endpoint to http://127.0.0.1:5001/v1.
  2. MateEngine DLL Patch:
    powershell -ExecutionPolicy Bypass -File .\unity_bridge_mod\patch_mateengine_dll.ps1 `
      -DnlibPath "C:\path\to\dnlib.dll" `
      -MateEngineDir "C:\path\to\MateEngine"
  3. Headless Watchdog Launch: Run start_alphavision.bat / launch_alphavision.bat to start SillyTavern, AlphaVision, and MateEngine together, or Stop_AlphaVision.bat to stop all services cleanly.

Configuration

Copy .env.example to .env (and optionally config.example.json to config.json). Both .env and config.json are gitignored so keys and local directory paths stay strictly on your machine.

Variable Default Purpose
GEMINI_API_KEY (required) Your personal Google AI Studio key
MODEL_NAME gemini-2.5-flash-lite Multimodal model for chat & brain engine
USER_NAME User Display name referenced in companion prompts
FLASK_PORT 5001 AlphaVision Flask HTTP bridge port
MATEENGINE_PORT 8787 MateEngine Unity local HTTP bridge port
SILLYTAVERN_PORT 8000 SillyTavern web client port
MATEENGINE_DIR (optional) MateEngine folder for supervisor.ps1 & patcher
SILLYTAVERN_DIR ../SillyTavern-Launcher/SillyTavern SillyTavern directory for supervisor.ps1

Hardware & Privacy

  • Zero Third-Party Telemetry: AlphaVision runs 100% locally on 127.0.0.1 (:5001, :8000, :8787). Captured screen regions and webcam frames are encoded purely in RAM (io.BytesIO, zero disk image writes) and sent exclusively to Google's Gemini endpoint under your own GEMINI_API_KEY.
  • Camera Fail-Safe: Works cleanly without a webcam attached (CameraWorker falls back to screen + Win32 window telemetry automatically).
  • Cursor-Safe Screen Capture: Suppresses Win32 CAPTUREBLT (mss.windows.CAPTUREBLT = 0) so DWM never flickers your hardware mouse cursor.

Verification

Run the offline unit test suite (mocks Gemini, webcam, and Unity sockets—no API key or hardware required):

$env:GEMINI_API_KEY = "offline-test-key"
.\.venv\Scripts\python.exe test_awareness.py

See CHANGELOG.md for release history and CONTRIBUTING.md for development guidelines.


Built by antrikshidk · Licensed under AGPL-3.0

About

Multimodal desktop screen & webcam vision bridge connecting SillyTavern and MateEngine VRM avatars via Google Gemini APIs

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages