# dkg-2/pneumox-net architecture

> Architecture diagram of the GitHub repository dkg-2/pneumox-net, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dkg-2/pneumox-net
- Repository: https://github.com/dkg-2/pneumox-net

## Overview

##### Project type and purpose
- This is a lightweight ML-driven web application (“full‐stack” in the sense of front-end UI + back-end inference) for binary classification of chest X-rays (Pneumonia vs Normal).
- It uses Gradio to expose a user interface, TensorFlow/Keras (MobileNetV2) for inference, and standard Python libraries for image processing and visualization.

##### File structure
- Top-level files:
- app.py        → the Gradio application entry point (handles uploads, calls the model, returns results)
- model.h5      → pre-trained MobileNetV2 weights
- requirements.txt → Python dependencies (Gradio, TensorFlow, OpenCV/Pillow, Matplotlib, Seaborn, etc.)
- README.md     → project overview, tech stack, usage
- .gitattributes → Git configuration
- No separate “frontend” or “backend” directories; the code is consolidated in app.py.
- No database or external REST services; inference is local.

##### README for additional insights
- Deployment target: Hugging Face Spaces using Gradio.
- Core flow: user uploads X-ray → preprocessing (OpenCV/Pillow) → model inference (TensorFlow/Keras MobileNetV2) → postprocessing/visualization (Matplotlib/Seaborn) → display prediction.

a. Main components:
1) User Interface (Gradio front end in the browser)
2) Application Server (app.py):
– Preprocessing Module
– Inference Module (loads model.h5 into TensorFlow/Keras)
– Postprocessing & Visualization Module
3) Model Storage (model.h5 on disk)
4) External Dependencies (TensorFlow, OpenCV/Pillow, Matplotlib, Seaborn)
5) Hosting Environment (Hugging Face Spaces container)

b. Relationships & interactions:
- Browser ↔ Gradio UI
- Gradio UI → HTTP RPC to app.py
- app.py loads model.h5 at startup
- Preprocessing → Inference → Postprocessing pipeline
- app.py → returns results to Gradio UI → browser display

c. Architectural patterns / design principles:
- Single‐process service with clear modules (preprocess, infer, postprocess).
- Separation of concerns: UI vs ML logic.
- Lazy model load or load‐once at startup for performance.
- Stateless inference (no session management or DB).

d. Technologies/frameworks:
- Gradio (UI + API layer)
- TensorFlow/Keras (model inference)
- MobileNetV2 (transfer‐learning architecture)
- OpenCV/Pillow (image I/O & preprocessing)
- Matplotlib/Seaborn (visualization)
- Hugging Face Spaces (deployment)

## Diagram (Mermaid)

```mermaid
flowchart TB
    Browser["User Browser"]:::ui

    subgraph "Hugging Face Spaces Container" 
        direction TB
        UI["Gradio UI"]:::ui
        Pre["Preprocessing Module"]:::processing
        Infer["Inference Module"]:::processing
        Post["Postprocessing & Visualization"]:::processing
        Store(("model.h5")):::storage
        Deps["requirements.txt"]:::artifact
        Readme["README.md"]:::artifact
        Git[".gitattributes"]:::artifact
    end

    Browser -->|"interacts via web"| UI
    UI -->|"POST /predict (upload image)"| Pre
    Pre -->|"Tensor data"| Infer
    Infer -->|"Prediction results"| Post
    Post -->|"Visualization (PNG)"| UI
    UI -->|"renders results"| Browser
    Store -->|"loaded at startup"| Infer

    click UI "https://github.com/dkg-2/pneumox-net/blob/main/app.py"
    click Pre "https://github.com/dkg-2/pneumox-net/blob/main/app.py"
    click Infer "https://github.com/dkg-2/pneumox-net/blob/main/app.py"
    click Post "https://github.com/dkg-2/pneumox-net/blob/main/app.py"
    click Store "https://github.com/dkg-2/pneumox-net/blob/main/model.h5"
    click Deps "https://github.com/dkg-2/pneumox-net/blob/main/requirements.txt"
    click Readme "https://github.com/dkg-2/pneumox-net/blob/main/README.md"
    click Git "https://github.com/dkg-2/pneumox-net/blob/main/.gitattributes"

    classDef ui fill:#ADD8E6,stroke:#333;
    classDef processing fill:#98FB98,stroke:#333;
    classDef storage fill:#FFA500,stroke:#333;
    classDef artifact fill:#EEEEEE,stroke:#333;
    classDef hosting fill:#D3D3D3,stroke:#333;
```
