# lyphucthanh1010/advance_dsp architecture

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

- Interactive diagram: https://gitdiagram.com/lyphucthanh1010/advance_dsp
- Repository: https://github.com/lyphucthanh1010/advance_dsp

## Overview

##### API and Web Server Layer
- The central entry point is the Flask application (app.py). This layer exposes endpoints such as "/predict" and "/predict_from_youtube".
- Routing and controller logic and how these endpoints call into internal modules.

##### Audio Preprocessing / Feature Extraction Layer
- Key modules here include:
– prepare.py and prepare_real.py: likely used for normalizing or pre-processing incoming audio (either local file or downloaded YouTube audio).
– segment.py and model_test.py: used to segment long audio files into portions for processing.
– get_chromaprint_func.py: extracts audio fingerprints (chromaprint) to generate features that will be fed to the model.

##### Model Inference Engine
- The model component is handled by model.py (and its test variants) and uses a pre-trained Keras model (referred to as model.pkl in the README and model.zip in the file tree).
- That the processed audio features are then sent to the model inference component, where the prediction of copyright violation is generated.

##### Data and Resource Storage
- The project contains two primary data directories:
– “dataset” which holds JSON files representing audio features for training or reference.
– “datasetreal” which is used for testing.
- Additionally, configuration files such as requirements.txt and scripts like fill_commit.sh provide supportive resources.

##### Utilities and Task Modules
- Files like repository.py and task.py are likely used for modularizing tasks such as data access and background processing.
- A module “repository” that encapsulates data read/write operations, showing it interacts with the preprocessing or model layers as needed.

##### External Integrations
- An endpoint for YouTube input is available (/predict_from_youtube), so show an external component (the YouTube service) that the API interacts with to fetch audio if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Interaction
    Client["Client Browser"]:::client
    Client -->|"HTTPRequest"| API["Flask API Controller (app.py)"]:::api
    API -->|"Renders"| Template["Web Template (templates/index.html)"]:::template
    API -->|"ReceivesFile"| Preprocess
    API -->|"ReceivesYouTubeURL"| YouTube["YouTube Service"]:::external

    %% Audio Processing Pipeline Subgraph
    subgraph "Audio Processing Pipeline"
        Preprocess_A["Preprocessing (prepare.py, prepare_real.py)"]:::processing
        Segmentation["Audio Segmentation (segment.py)"]:::processing
        Chromaprint["Chromaprint Extraction (get_chromaprint_func.py)"]:::processing
        Preprocess_A -->|"segments"| Segmentation
        Segmentation -->|"extracts"| Chromaprint
    end

    %% Model Inference Engine Subgraph
    subgraph "Model Inference Engine"
        ModelInf["Keras Model Inference (model.py, model_test.py)"]:::model
        ModelInf ---|"uses"| ModelRes["Pre-trained Model (model.zip)"]:::resource
    end

    %% Flow from Processing to Model Inference
    Chromaprint -->|"features"| ModelInf
    ModelInf -->|"prediction"| API

    %% Resources and Utilities Subgraph
    subgraph "Resources & Utilities"
        DataRef["Dataset Storage (dataset)"]:::storage
        DataTest["Testing Data (datasetreal)"]:::storage
        Utilities["Utilities & Tasks (repository.py, task.py)"]:::utility
        Config["Config & Scripts (fill_commit.sh, requirements.txt)"]:::config
    end

    %% Connections to Resources
    Chromaprint -->|"reads"| DataRef
    Chromaprint -->|"reads"| DataTest
    Preprocess_A -->|"calls"| Utilities

    %% Click Events
    click API "https://github.com/lyphucthanh1010/advance_dsp/blob/master/app.py"
    click Template "https://github.com/lyphucthanh1010/advance_dsp/blob/master/templates/index.html"
    click Preprocess_A "https://github.com/lyphucthanh1010/advance_dsp/blob/master/prepare.py"
    click Preprocess_A "https://github.com/lyphucthanh1010/advance_dsp/blob/master/prepare_real.py"
    click Segmentation "https://github.com/lyphucthanh1010/advance_dsp/blob/master/segment.py"
    click Chromaprint "https://github.com/lyphucthanh1010/advance_dsp/blob/master/get_chromaprint_func.py"
    click ModelInf "https://github.com/lyphucthanh1010/advance_dsp/blob/master/model.py"
    click ModelInf "https://github.com/lyphucthanh1010/advance_dsp/blob/master/model_test.py"
    click ModelRes "https://github.com/lyphucthanh1010/advance_dsp/blob/master/model.zip"
    click DataRef "https://github.com/lyphucthanh1010/advance_dsp/tree/master/dataset"
    click DataTest "https://github.com/lyphucthanh1010/advance_dsp/tree/master/datasetreal"
    click Utilities "https://github.com/lyphucthanh1010/advance_dsp/blob/master/repository.py"
    click Utilities "https://github.com/lyphucthanh1010/advance_dsp/blob/master/task.py"
    click Config "https://github.com/lyphucthanh1010/advance_dsp/blob/master/fill_commit.sh"
    click Config "https://github.com/lyphucthanh1010/advance_dsp/blob/master/requirements.txt"

    %% Styles
    classDef client fill:#b3cde0,stroke:#000,stroke-width:1px;
    classDef api fill:#fdae61,stroke:#000,stroke-width:1px;
    classDef template fill:#fee08b,stroke:#000,stroke-width:1px;
    classDef processing fill:#d9f0a3,stroke:#000,stroke-width:1px;
    classDef model fill:#66c2a5,stroke:#000,stroke-width:1px;
    classDef storage fill:#fc8d62,stroke:#000,stroke-width:1px;
    classDef resource fill:#8da0cb,stroke:#000,stroke-width:1px;
    classDef utility fill:#e78ac3,stroke:#000,stroke-width:1px;
    classDef config fill:#a6d854,stroke:#000,stroke-width:1px;
    classDef external fill:#cccccc,stroke:#000,stroke-width:1px;
```
