# ai4bharat/indicf5 architecture

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

- Interactive diagram: https://gitdiagram.com/ai4bharat/indicf5
- Repository: https://github.com/ai4bharat/indicf5

## Overview

##### Project Type and Purpose
- IndicF5 is a Python-based **Text-to-Speech (TTS) library and toolkit** focused on Indian languages.
- It provides code for **training** new TTS models, **evaluating** them, and **running inference** (generating speech) via CLIs, a socket server, or a Gradio app.
- It is packaged for distribution through PyPI/GitHub and integrates with Hugging Face for model storage.

##### Main Components
- **Configurations**
- YAML files in `f5_tts/configs/` define hyperparameters for different model sizes.
- A “Config Loader” subcomponent reads these.
- **Data Preparation**
- Scripts under `train/datasets/` turn raw audio/text into CSVs for training.
- This is the “Dataset Preprocessor.”
- **Training Pipeline**
- `f5_tts/train/train.py` & `trainer.py` execute the training loop.
- Use “Trainer” to feed preprocessed data into the “Model.”
- **Model Library**
- Code under `f5_tts/model/` (modules, backbones, cfm.py, etc.) defines the network architecture.
- **Evaluation Pipeline**
- Under `f5_tts/eval/`, scripts compute metrics on test sets.
- Call this “Evaluator” or “Quality Checker.”
- **Inference Pipeline**
- CLI tools (`infer_cli.py`, `infer_cli_batch.py`), Gradio apps (`infer_gradio.py`), and `socket_server.py`.
- This is the “Inference Engine,” which loads a trained model and produces audio output.
- **External Services & Storage**
- Hugging Face Hub for model checkpoints.
- Local file system for datasets, prompts, and output audio.

##### How They Interact (Data Flow)
- Start at **Config Loader** → hands parameters to → **Dataset Preprocessor** → outputs training data to → **Trainer** → updates → **TTS Model** → saves weights to → **Checkpoint Storage**.
- **Evaluator** also pulls from **Checkpoint Storage** and **Dataset** → produces metrics/reports.
- For inference: **User Interface** (CLI / Gradio / Socket Server) → requests → **Inference Engine** → loads model from **Checkpoint Storage** + **Config** + **Reference Audio/Text** → outputs synthesized **Audio**.

##### Architectural Patterns & Design Principles
- **Modularity**: separate directories for configs, data prep, model, train, eval, infer.
- **Pipeline Pattern**: clear steps from raw data → training → evaluation → inference.
- **Plugin-style Backbones**: different model files under `model/backbones/` allow swapping architectures easily.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Configurations
    subgraph "Configurations"
        CF["Config Files"]:::storage
        CL["Config Loader"]:::compute
    end

    %% Data Preparation
    DP["Dataset Preprocessor"]:::compute

    %% Training Pipeline
    subgraph "Training"
        TCLI["Trainer CLI"]:::ui
        TCore["Trainer Core Logic"]:::compute
        FTCLI["Fine-tune CLI"]:::ui
        FTGR["Fine-tune Gradio"]:::ui
    end

    %% Model Library
    ML["TTS Model (Backbones + Modules)"]:::compute

    %% Storage
    subgraph "Storage"
        DS["Raw Dataset Storage"]:::storage
        CS["Checkpoint Storage"]:::storage
        HF["Hugging Face Hub"]:::external
    end

    %% Evaluation
    Eval["Evaluator (Quality Checker)"]:::compute

    %% Inference
    subgraph "Inference"
        subgraph "Interfaces"
            ICLI["Inference CLI"]:::ui
            ICLI_B["Inference CLI Batch"]:::ui
            IGR["Inference Gradio"]:::ui
            IGR_O["Inference Gradio Orig"]:::ui
            SOCK["Socket Server"]:::ui
        end
        subgraph "Utils & Batch"
            IBP["Batch & Utils"]:::compute
            EXCFG["Example Configs & Refs"]:::storage
        end
    end

    %% Utility Scripts
    US["Utility Scripts"]:::compute

    %% Data Flow
    CF -->|"load config"| CL
    CL -->|"params"| DP
    DP -->|"training data"| TCLI
    TCLI -->|"start training"| TCore
    TCore -->|"update weights"| ML
    ML -->|"save checkpoint"| CS
    DS -->|"raw data"| DP

    %% Evaluation Flow
    CS -->|"load model"| Eval
    DS -->|"test data"| Eval

    %% Inference Flow
    ICLI -->|"request inference"| IBP
    ICLI_B -->|"batch request"| IBP
    IGR -->|"web request"| IBP
    IGR_O -->|"orig web request"| IBP
    SOCK -->|"socket request"| IBP
    IBP -->|"load model & config"| ML
    IBP -->|"load checkpoint"| CS
    IBP -->|"load examples"| EXCFG
    IBP -->|"produce audio"| EXCFG

    %% Fine-tuning Flow
    FTCLI -->|"start finetuning"| TCore
    FTGR -->|"start finetuning"| TCore

    %% Utility Scripts Flow
    US -->|"analysis & metrics"| CS

    %% Click Events
    click CF "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/configs/"
    click CL "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/api.py"
    click DP "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/train/datasets/"
    click TCLI "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/train.py"
    click TCore "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/model/trainer.py"
    click ML "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/model/"
    click Eval "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/eval/"
    click ICLI "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/infer_cli.py"
    click ICLI_B "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/infer_cli_batch.py"
    click IGR "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/infer_gradio.py"
    click IGR_O "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/infer/infer_gradio_orig.py"
    click IBP "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/infer/"
    click SOCK "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/socket_server.py"
    click EXCFG "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/infer/examples/"
    click FTCLI "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/finetune_cli.py"
    click FTGR "https://github.com/ai4bharat/indicf5/blob/main/f5_tts/train/finetune_gradio.py"
    click US "https://github.com/ai4bharat/indicf5/tree/main/f5_tts/scripts/"

    %% Styling
    classDef storage fill:#bbdefb,stroke:#1e88e5,color:#0d47a1;
    classDef compute fill:#c8e6c9,stroke:#43a047,color:#1b5e20;
    classDef ui fill:#ffe0b2,stroke:#fb8c00,color:#e65100;
    classDef external fill:#eeeeee,stroke:#9e9e9e,color:#424242;
```
