# warmshao/fasterliveportrait architecture

> Architecture diagram of the GitHub repository warmshao/fasterliveportrait, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/warmshao/fasterliveportrait
- Repository: https://github.com/warmshao/fasterliveportrait

## Overview

##### Project Type and Purpose
- Project Type: This is a full-stack multimedia processing application that provides real-time portrait animation driven by various modalities (audio, video, text) and supports deployment as a web-based UI and an API.
- Purpose: It takes a static source image and driving input (video, audio, or even text) to produce animated portraits in real time. The project leverages deep learning models (including modules like JoyVASA, XPose, Kokoro and others) using different inference backends (TensorRT and ONNX Runtime).

##### File Structure
- Top-Level Files and Directories:
– Main entry points: api.py (for API deployment), run.py (command-line interface for testing/inference), and webui.py (Gradio-based web front-end).
– Configuration: “configs” folder provides YAML files for different inference setups.
– Models: “src/models” contains multiple submodules (JoyVASA, XPose, Kokoro, etc.) with further subdivisions for specific functionalities (such as pre-processing, inference, transformers, and custom CUDA operations).
– Pipelines: “src/pipelines” combines models and utilities into cohesive workflows (such as live portrait, audio-driven animation, etc.).
– Utilities: “src/utils” for common pre-, post-, and intermediate processing utilities.
– Assets and Scripts: “assets” for examples and documentation, “scripts” for conversion tasks (onnx2trt) and starting API/sample inference.
– Tests: “tests” containing unit tests for API, pipelines, and models.
– DockerfileAPI and various bat/sh and update scripts indicate multi-environment support (Docker, Windows, macOS).

##### README for Additional Insights
- The README provides detailed instructions for:
– Running inference with TensorRT or ONNX.
– Using the Gradio web UI.
– Deploying the API.
– Model conversion and environment setup.
- It emphasizes real-time performance (e.g., achieving 30+ FPS) and demonstrates the system’s support for multiple drive modes (audio, video, text, animal mode, etc.).

A. Input Interfaces:
- User Interfaces: Represent three separate access points.
- Command-line/Script (via run.py and camera.bat)
- Web UI (via webui.py and Gradio components)
- API endpoints (via api.py)
- External Input Devices: Cameras, uploaded videos/images, audio files.

B. Core Processing and Inference Pipeline:
- Pre-processing Module: Indicate components that handle image/video capture, cropping, and formatting (likely part of src/utils).
- Model Loader and Inference Engine:
- JoyVASA Module (audio-driven animations)
- XPose Module (pose extraction and enhancements)
- Kokoro Module (text-driven video/image generation)
- Which backend is used based on config (TensorRT or ONNX Runtime) – reference the “configs” folder.
- Post-processing Module:
- Modules that recompose the final animated portrait (e.g., stitching, paste_back function, etc. found in src/models and src/pipelines).

C. Supporting Components:
- Configuration Manager: Represent the “configs” directory where YAML files define inference parameters and pipeline behaviors.
- Utility Functions: Represent “src/utils” – these handle common tasks such as logging, image transformations, and general helper functions.
- Model Conversion and Deployment Tools:
- “scripts” components (e.g., onnx2trt.py, batch conversion scripts) that convert models.
- Docker components (Dockerfile/API) to denote containerized deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Interfaces Subgraph
    subgraph "Input Interfaces"
        subgraph "Command-Line Interface"
            runpy["run.py"]:::interface
            camera["camera.bat"]:::interface
        end
        subgraph "Web UI Interface"
            webui["webui.py"]:::interface
            gradio["assets/gradio"]:::interface
        end
        subgraph "API Endpoint"
            api["api.py"]:::interface
        end
        ext["External Input Devices\n(Camera,Video,Audio)"]:::external
    end

    %% Core Processing Pipeline Subgraph
    subgraph "Core Processing Pipeline"
        preproc["Pre-processing Module\n(src/utils)"]:::processing
        subgraph "Model Inference Modules"
            joyvasa["JoyVASA Module\n(src/models/JoyVASA)"]:::processing
            xpose["XPose Module\n(src/models/XPose)"]:::processing
            kokoro["Kokoro Module\n(src/models/kokoro)"]:::processing
        end
        unified["Unified Inference Workflow\n(src/pipelines)"]:::processing
        postproc["Post-processing Module\n(src/models/stitching_model.py & src/pipelines)"]:::processing
    end

    %% Supporting Components Subgraph
    subgraph "Supporting Components"
        config["Configuration Manager\n(configs)"]:::support
        util["Utility Functions\n(src/utils)"]:::support
        conversion["Model Conversion & Deployment Tools\n(scripts)"]:::support
        docker["Containerized Deployment\n(DockerfileAPI)"]:::support
    end

    %% Data Flow Connections from Input Interfaces to Core Pipeline
    runpy --> preproc
    camera --> preproc
    webui --> preproc
    gradio --> preproc
    api --> preproc
    ext --> preproc

    %% Data Flow within Core Processing Pipeline
    preproc --> joyvasa
    preproc --> xpose
    preproc --> kokoro
    joyvasa --> unified
    xpose --> unified
    kokoro --> unified
    unified --> postproc

    %% Supporting Components linking to Core Pipeline
    config --> preproc
    util --> preproc
    conversion --> unified
    docker --> unified

    %% Click Events for Input Interfaces
    click runpy "https://github.com/warmshao/fasterliveportrait/blob/master/run.py"
    click camera "https://github.com/warmshao/fasterliveportrait/blob/master/camera.bat"
    click webui "https://github.com/warmshao/fasterliveportrait/blob/master/webui.py"
    click gradio "https://github.com/warmshao/fasterliveportrait/tree/master/assets/gradio"
    click api "https://github.com/warmshao/fasterliveportrait/blob/master/api.py"
    
    %% Click Events for Core Processing Pipeline
    click preproc "https://github.com/warmshao/fasterliveportrait/tree/master/src/utils"
    click joyvasa "https://github.com/warmshao/fasterliveportrait/tree/master/src/models/JoyVASA"
    click xpose "https://github.com/warmshao/fasterliveportrait/tree/master/src/models/XPose"
    click kokoro "https://github.com/warmshao/fasterliveportrait/tree/master/src/models/kokoro"
    click unified "https://github.com/warmshao/fasterliveportrait/tree/master/src/pipelines"
    click postproc "https://github.com/warmshao/fasterliveportrait/blob/master/src/models/stitching_model.py"

    %% Click Events for Supporting Components
    click config "https://github.com/warmshao/fasterliveportrait/tree/master/configs"
    click util "https://github.com/warmshao/fasterliveportrait/tree/master/src/utils"
    click conversion "https://github.com/warmshao/fasterliveportrait/tree/master/scripts"
    click docker "https://github.com/warmshao/fasterliveportrait/tree/master/DockerfileAPI"

    %% Styles
    classDef interface fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef external fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef processing fill:#a1c4fd,stroke:#333,stroke-width:2px;
    classDef support fill:#b9f6ca,stroke:#333,stroke-width:2px;
```
