An end-to-end ML/DL + MLOps project for detecting anomalies in battery behavior using LSTM Autoencoders.
This project demonstrates how to go from model training β API service β Streamlit UI β CI/CD deployment on AWS EC2 π
- π§ LSTM Autoencoder for anomaly detection on battery cycles
- π Preprocessing pipeline (scaling + sequence creation)
- β‘ REST API using FastAPI
- π¨ Interactive Streamlit UI
- π³ Dockerized setup for portability
- π Automated CI/CD with GitHub Actions β builds & deploys to AWS EC2
- π Secrets managed via GitHub Secrets (secure deployment)
Battery-Anamoly-Detector/
βββ app/
β βββ fastapi_app.py # FastAPI backend (model inference API)
β βββ streamlit_app.py # Streamlit frontend (UI)
β
βββ src/
β βββ model.py # LSTM Autoencoder definition
β βββ train.py # Training pipeline
β βββ utils.py # Helper functions
β βββ config.py # Configs (sequence length, paths, features, etc.)
β
βββ artifacts/
β βββ best_model.pth # Saved trained model
β βββ scaler.pkl # Pre-fitted scaler
β
βββ Dockerfile # Docker build for API + Streamlit
βββ requirements.txt # Dependencies
βββ .github/workflows/cd.yml # CI/CD pipeline
βββ README.md # Project documentation
1οΈβ£ Training
- Run
train.pyto train the model on battery data. - Saves
best_model.pth&scaler.pklinartifacts/.
2οΈβ£ API Service (FastAPI)
- Exposes endpoints for anomaly detection.
- Example:
http://<EC2-IP>:8000/docs
3οΈβ£ Streamlit UI
- Interactive frontend for predictions.
- Example:
http://<EC2-IP>:8501
4οΈβ£ Dockerization
- Single container runs both FastAPI & Streamlit.
- Lightweight & portable deployment.
5οΈβ£ CI/CD Deployment
- On
pushto GitHub:- ποΈ Build Docker image on GitHub runner
- π¦ Push image β DockerHub
- βοΈ Connect to AWS EC2 & deploy container
- π Stops old container & runs latest image
DOCKERHUB_USERNAMEβ your DokcerHUB usernameDOCKERHUB_TOKENβ your login token , generated from DockerHubEC2_HOSTβ your instance IPEC2_USERβ usuallyubuntuor else the Cloud OS you choosedEC2_KEYβ your private SSH/RSA key for connecting this github to cloud machine
- FastAPI β
http://<EC2-IP>:8000/docs - Streamlit β
http://<EC2-IP>:8501
- Python π
- PyTorch π₯
- FastAPI β‘
- Streamlit π¨
- Docker π³
- GitHub Actions π€
- AWS EC2 βοΈ
Pull requests are welcome! π
For major changes, open an issue first to discuss what youβd like to change.
MIT License Β© 2025 Milan Kumar Singh