A deep learning project to detect Pneumonia from chest X-ray images using a Convolutional Neural Network (CNN).
This project has:
- Frontend (HTML, CSS, JS) → inside the
frontendfolder for remote access. - Backend API (Flask) → for predictions.
- Streamlit Deployment → a standalone web app for easy usage without dealing with CORS issues.
-
Streamlit Deployment: https://czgk8ceahwswtw2wmd97x3.streamlit.app
(Click to open the deployed app and try it live) -
Frontend + Backend Setup:
- Frontend folder:
/frontend - Backend served on:
https://pneumonia-x-ray-detector-cnn.onrender.com
- Frontend folder:
The dataset used is from Kaggle:
Chest X-Ray Images (Pneumonia)
dataset/ │ ├── train/ │ ├── NORMAL/ │ └── PNEUMONIA/ │ ├── test/ │ ├── NORMAL/ │ └── PNEUMONIA/ │ └── val/ ├── NORMAL/ └── PNEUMONIA/
- NORMAL → X-rays without pneumonia.
- PNEUMONIA → includes bacterial and viral pneumonia images.
We used a custom CNN with 5 convolutional layers.
The model was trained using TensorFlow and Keras.
| Layer Type | Filters / Units | Activation | Notes |
|---|---|---|---|
| Conv2D | 32 | ReLU | Input shape (150, 150, 1) |
| MaxPooling2D | 2x2 | - | Downsampling |
| Conv2D | 64 | ReLU | + Dropout (0.1) |
| MaxPooling2D | 2x2 | - | Downsampling |
| Conv2D | 64 | ReLU | - |
| MaxPooling2D | 2x2 | - | Downsampling |
| Conv2D | 128 | ReLU | + Dropout (0.2) |
| MaxPooling2D | 2x2 | - | Downsampling |
| Conv2D | 256 | ReLU | + Dropout (0.2) |
| MaxPooling2D | 2x2 | - | Final pooling |
| Flatten | - | - | Flatten output |
| Dense | 128 | ReLU | Fully connected |
| Dropout | 0.2 | - | Prevent overfitting |
| Dense (Output) | 1 | Sigmoid | Binary classification |
The model was trained for 12 epochs with data augmentation applied to prevent overfitting.
| Metric | Value |
|---|---|
| Accuracy | 92.46% |
| Loss | 0.27 |
- Input: User uploads a chest X-ray image.
- Preprocessing:
- Image is converted to grayscale.
- Resized to 150x150 pixels.
- Normalized to the range
[0, 1].
- Prediction: The trained CNN model classifies the image as:
NORMALPNEUMONIA
- Output: Displays the prediction and confidence score.
-
Frontend (HTML/CSS/JS)
- Simple interface for uploading chest X-ray images.
- Sends the image to the backend API for prediction.
-
Backend (Flask)
- Handles requests from the frontend.
- Runs the trained CNN model (
pneumonia_model.h5).
-
Streamlit App
- Standalone web app combining frontend and backend.
- Deployed on Streamlit Cloud for easy sharing.
- Backend: Render (
Flask+Gunicorn) - Frontend: Vercel (Static HTML, CSS, JS)
- Host: Streamlit Community Cloud
- Link: https://your-app-name.streamlit.app
Below are placeholders for four images. Replace them with actual screenshots later.
| Sample image(normal) | Sample image(pneumonia) | Training vs Validation | Data Distribution |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
- Python (TensorFlow, Keras, NumPy, Pillow)
- Flask (Backend API)
- Streamlit (Final Deployment)
- HTML, CSS, JS (Frontend UI)
- Render (Backend hosting)
- Vercel (Frontend hosting)
- Clone the repo:
git clone https://github.com/<your-username>/Pneumonia-X-ray-Detector-CNN.git
- Navigate into the project folder:
cd Pneumonia-X-ray-Detector-CNN - Install dependencies:
pip install -r requirements.txt
- Run the Streamlit app:
streamlit run streamlit_app.py
Building solutions in deep learning and computer vision with a focus on real-world applications.



