A Flask web app that detects pneumonia from chest X-ray images using TensorFlow/Keras. Upload an image in the browser to receive a prediction and confidence score.
- Upload X-ray images (PNG, JPG, JPEG, BMP, WEBP)
- Two model entry points (grayscale and RGB)
- Simple, responsive UI with clear results and warnings
- Python
- Flask
- TensorFlow/Keras
- NumPy
- Pillow
app/
factory.py
templates/
mainpage.html
static/
utils/
main.py
mainDense.py
model/
requirements.txt
- Create and activate a virtual environment
- Windows (PowerShell)
python -m venv .venv .\.venv\Scripts\activate - macOS/Linux
python -m venv .venv source .venv/bin/activate
- Windows (PowerShell)
- Install dependencies
pip install -r requirements.txt
- Grayscale model (default)
python main.py - DenseNet RGB model
python mainDense.py
Open http://127.0.0.1:5000 in your browser.
The app is created via create_app in app/factory.py:
model_path: path to a Keras.h5modelinput_mode:grayscaleorrgbcompile_model: set toTrueif your model requires compilation
Prediction logic:
- A score is produced by the model
Normalif score >= 0.5, otherwisePneumonia
main.pyusesmodel/pneumoniadetection2.h5(grayscale)mainDense.pyusesmodel/pneumoniadetection_densenet.h5(RGB)
If the model files are not present, add them under the model/ directory. If the files are large (e.g., >100 MB), use Git LFS to store them.
Uploaded files are saved to app/static/uploads. This folder is safe to clear.
This project is for educational and demonstration purposes only. It is not a medical device and should not be used for clinical diagnosis. Always consult a qualified healthcare professional.
No automated tests yet.
Add a license before publishing (MIT, Apache-2.0, etc.).