Skip to content

cursed027/Battery-Anamoly-Detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”‹ Battery Anomaly Detector

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 πŸš€


✨ Features

  • 🧠 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)

πŸ—οΈ Project Structure

  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

βš™οΈ Workflow

1️⃣ Training

  • Run train.py to train the model on battery data.
  • Saves best_model.pth & scaler.pkl in artifacts/.

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 push to GitHub:
    • πŸ—οΈ Build Docker image on GitHub runner
    • πŸ“¦ Push image β†’ DockerHub
    • ☁️ Connect to AWS EC2 & deploy container
    • πŸ”„ Stops old container & runs latest image

πŸš€ Deployment

πŸ”‘ GitHub Secrets Required

  • DOCKERHUB_USERNAME β†’ your DokcerHUB username
  • DOCKERHUB_TOKEN β†’ your login token , generated from DockerHub
  • EC2_HOST β†’ your instance IP
  • EC2_USER β†’ usually ubuntu or else the Cloud OS you choosed
  • EC2_KEY β†’ your private SSH/RSA key for connecting this github to cloud machine

🌍 Access After Deployment

  • FastAPI β†’ http://<EC2-IP>:8000/docs
  • Streamlit β†’ http://<EC2-IP>:8501

πŸ“ˆ Tech Stack

  • Python 🐍
  • PyTorch πŸ”₯
  • FastAPI ⚑
  • Streamlit 🎨
  • Docker 🐳
  • GitHub Actions πŸ€–
  • AWS EC2 ☁️

🀝 Contributions

Pull requests are welcome! πŸŽ‰
For major changes, open an issue first to discuss what you’d like to change.


πŸ“œ License

MIT License Β© 2025 Milan Kumar Singh

About

Battery-Anamoly-Detector πŸ”‹πŸͺ«πŸ”–

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published