# paragshah97/pixads-ai architecture

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

- Interactive diagram: https://gitdiagram.com/paragshah97/pixads-ai
- Repository: https://github.com/paragshah97/pixads-ai

## Overview

##### Main Components
- Frontend/UI: Represented by the Streamlit application that kicks off with master.py. This component handles user authentication (as seen in the README login credentials) and image upload.
- Model Inference Engine: Encompasses model_structure.py to define/create the models and the use of pre-trained weights from model_weights. Include sub-components for:
▪ Resnet
▪ Densenet (weights: densenet_final_project_75.pth)
▪ VGG13
▪ Alexnet (as mentioned in the README)
- Prediction Aggregation: Component for combining outputs from these models, represented by overall_pred.py, which selects the most confident prediction.

##### Relationships and Data Flow
- The user interacts with the Streamlit UI (master.py) to log in and upload images.
- The uploaded image moves into the preprocessing pipeline (using libraries such as Pillow and OpenCV).
- The preprocessed image is then sent into the model inference engine (with models defined in model_structure.py and weights loaded from model_weights).
- Each model makes a prediction and sends its output to overall_pred.py, which aggregates the results.
- The results (predicted class and advertisement) are then displayed back to the user via the Streamlit UI.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear division between the UI layer (Streamlit) and the backend processing (model inference, prediction aggregation, advertisement selection).
- Modular Design: Each Python file (master.py, model_structure.py, overall_pred.py, advertisments.py) represents a modular component of the application.
- Extensibility: The architecture has natural extension points like adding more models or new advertisement selection strategies, which is important for a lab-style or real-world application.

##### Relevant Technologies, Frameworks, and Libraries
- Streamlit: For building the web-based application interface.
- PyTorch: For deep learning model implementation and inference.
- TorchVision: The likely source of the deep learning models.
- Pillow & OpenCV: For image processing.
- Pre-trained model weights: Stored in the model_weights directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    subgraph "User Interaction"
        User("User"):::user
        UI["Streamlit Frontend (master.py)"]:::ui
    end

    %% Image Processing Layer
    subgraph "Image Processing"
        Preproc["Image Upload & Preprocessing"]:::preprocessing
    end

    %% Model Inference Engine
    subgraph "Model Inference Engine"
        ModelDef["Model Definition (model_structure.py)"]:::backend
        Resnet["Resnet Model"]:::model
        Densenet["Densenet Model"]:::model
        VGG13["VGG13 Model"]:::model
        Alexnet["Alexnet Model"]:::model
    end

    %% Prediction Aggregation & Advertisement
    subgraph "Aggregation & Advertisement"
        Aggregation["Prediction Aggregation (overall_pred.py)"]:::backend
        Ads["Advertisement Selection (advertisments.py)"]:::backend
        AdsMedia["Advertisement Media (ads_imgs)"]:::storage
    end

    %% Data Flow
    User -->|"interacts"| UI
    UI -->|"uploads-image"| Preproc
    Preproc -->|"sends-image"| ModelDef

    ModelDef -->|"runs-inference"| Resnet
    ModelDef -->|"runs-inference"| Densenet
    ModelDef -->|"runs-inference"| VGG13
    ModelDef -->|"runs-inference"| Alexnet

    Resnet -->|"outputs"| Aggregation
    Densenet -->|"outputs"| Aggregation
    VGG13 -->|"outputs"| Aggregation
    Alexnet -->|"outputs"| Aggregation

    Aggregation -->|"selects"| Ads
    Ads -->|"retrieves-ad"| AdsMedia
    Ads -->|"displays"| UI

    %% Click Events
    click UI "https://github.com/paragshah97/pixads-ai/blob/main/master.py"
    click ModelDef "https://github.com/paragshah97/pixads-ai/blob/main/model_structure.py"
    click Resnet "https://github.com/paragshah97/pixads-ai/blob/main/model_weights/rnet_model_accuracy_82.29809406279995.pth"
    click Densenet "https://github.com/paragshah97/pixads-ai/blob/main/model_weights/densenet_final_project_75.pth"
    click Aggregation "https://github.com/paragshah97/pixads-ai/blob/main/overall_pred.py"
    click Ads "https://github.com/paragshah97/pixads-ai/blob/main/advertisments.py"
    click AdsMedia "https://github.com/paragshah97/pixads-ai/tree/main/ads_imgs"

    %% Styles
    classDef user fill:#f4d03f,stroke:#333,stroke-width:2px;
    classDef ui fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef preprocessing fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef backend fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef model fill:#f5cba7,stroke:#333,stroke-width:2px;
    classDef storage fill:#d0ece7,stroke:#333,stroke-width:2px;
```
