# jagratadeb/pneumonia-detector architecture

> Architecture diagram of the GitHub repository jagratadeb/pneumonia-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jagratadeb/pneumonia-detector
- Repository: https://github.com/jagratadeb/pneumonia-detector

## Overview

Pneumonia Detector is a Streamlit application for classifying chest X-rays as Normal or Viral Pneumonia. Users upload one or more images; the app validates and decodes them, runs ResNet-18, KNN, and SVM inference, averages their two-class probabilities, and presents predictions, confidence, charts, and downloadable batch results. The README documents the major capabilities; the sampled app.py excerpts show validation, classical-model preprocessing, inference calls, and result rendering, but do not expose every internal implementation detail.

Main entry points: [`app.py`](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py) (Upload and UI), [`ResNet18/resnet18_state_dict.pth`](https://github.com/jagratadeb/pneumonia-detector/blob/main/ResNet18/resnet18_state_dict.pth) (ResNet-18 model), [`KNN/knn_model_latest.pkl`](https://github.com/jagratadeb/pneumonia-detector/blob/main/KNN/knn_model_latest.pkl) (KNN bundle), [`SVM/svm_rbf_latest.pkl`](https://github.com/jagratadeb/pneumonia-detector/blob/main/SVM/svm_rbf_latest.pkl) (SVM bundle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Upload interface"]
  node_streamlit["Upload and UI<br/>[app.py]"]
end

subgraph group_inference["Inference workflow"]
  node_validation["Image validation<br/>[app.py]"]
  node_preprocess["Image preprocessing<br/>[app.py]"]
  node_ensemble["Probability ensemble<br/>[app.py]"]
end

subgraph group_models["Classifier models"]
  node_resnet["ResNet-18 model"]
  node_knn["KNN bundle"]
  node_svm["SVM bundle<br/>[svm_rbf_latest.pkl]"]
end

subgraph group_results["Prediction results"]
  node_presentation["Prediction display<br/>[app.py]"]
  node_chart["Confidence chart<br/>[app.py]"]
  node_batch["Batch summary CSV<br/>[app.py]"]
  node_history["Session history<br/>[app.py]"]
end

node_user(("Image uploader"))

node_user -->|"uploads images"| node_streamlit
node_streamlit -->|"validates uploads"| node_validation
node_validation -->|"decodes images"| node_preprocess
node_preprocess -->|"prepares input"| node_resnet
node_preprocess -->|"prepares features"| node_knn
node_preprocess -->|"prepares features"| node_svm
node_streamlit -->|"loads and runs"| node_resnet
node_streamlit -->|"loads and runs"| node_knn
node_streamlit -->|"loads and runs"| node_svm
node_streamlit -->|"combines scores"| node_ensemble
node_ensemble -->|"selects prediction"| node_presentation
node_presentation -->|"shows confidence"| node_chart
node_presentation -->|"exports summary"| node_batch
node_presentation -->|"updates session"| node_history

click node_streamlit "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_validation "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_preprocess "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_resnet "https://github.com/jagratadeb/pneumonia-detector/blob/main/ResNet18/resnet18_state_dict.pth"
click node_knn "https://github.com/jagratadeb/pneumonia-detector/blob/main/KNN/knn_model_latest.pkl"
click node_svm "https://github.com/jagratadeb/pneumonia-detector/blob/main/SVM/svm_rbf_latest.pkl"
click node_ensemble "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_presentation "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_chart "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_batch "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"
click node_history "https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_streamlit toneBlue
class node_validation,node_preprocess,node_ensemble toneAmber
class node_resnet,node_knn,node_svm toneMint
class node_presentation,node_chart,node_batch,node_history toneRose
class node_user toneIndigo
```

## Components

### Upload interface

- [Upload and UI](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`

### Inference workflow

- [Image validation](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`
- [Image preprocessing](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`
- [Probability ensemble](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`

### Classifier models

- [ResNet-18 model](https://github.com/jagratadeb/pneumonia-detector/blob/main/ResNet18/resnet18_state_dict.pth): `ResNet18/resnet18_state_dict.pth`
- [KNN bundle](https://github.com/jagratadeb/pneumonia-detector/blob/main/KNN/knn_model_latest.pkl): `KNN/knn_model_latest.pkl`
- [SVM bundle](https://github.com/jagratadeb/pneumonia-detector/blob/main/SVM/svm_rbf_latest.pkl): `SVM/svm_rbf_latest.pkl`

### Prediction results

- [Prediction display](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`
- [Confidence chart](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`
- [Batch summary CSV](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`
- [Session history](https://github.com/jagratadeb/pneumonia-detector/blob/main/app.py): `app.py`

### Other components

- **Image uploader**

## Connections

- Image uploader → Upload and UI: uploads images (evidence: `README.md`)
- Upload and UI → Image validation: validates uploads (evidence: `README.md`)
- Image validation → Image preprocessing: decodes images (evidence: `app.py`)
- Image preprocessing → ResNet-18 model: prepares input (evidence: `README.md`)
- Image preprocessing → KNN bundle: prepares features (evidence: `app.py`)
- Image preprocessing → SVM bundle: prepares features (evidence: `app.py`)
- Upload and UI → ResNet-18 model: loads and runs (evidence: `README.md`)
- Upload and UI → KNN bundle: loads and runs (evidence: `README.md`)
- Upload and UI → SVM bundle: loads and runs (evidence: `README.md`)
- Upload and UI → Probability ensemble: combines scores (evidence: `README.md`)
- Probability ensemble → Prediction display: selects prediction (evidence: `app.py`)
- Prediction display → Confidence chart: shows confidence (evidence: `app.py`)
- Prediction display → Batch summary CSV: exports summary (evidence: `README.md`)
- Prediction display → Session history: updates session (evidence: `app.py`)
