{"id":32862152,"url":"https://github.com/victorkiosh/temperature_anomaly_detection","last_synced_at":"2026-04-06T08:32:06.583Z","repository":{"id":321217638,"uuid":"1084925006","full_name":"Victorkiosh/temperature_anomaly_detection","owner":"Victorkiosh","description":"Real-time temperature anomaly detection with FastAPI, Streamlit, and Docker — simulating IoT sensor data for predictive monitoring.","archived":false,"fork":false,"pushed_at":"2025-10-28T13:58:52.000Z","size":5710,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-28T14:32:13.899Z","etag":null,"topics":["data-science","docker","fastapi","iot","machine-learning","mlops","model-deployment","python","real-time-analytics","sqlite","streamlit","tensorflow","timeseries"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Victorkiosh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T10:58:08.000Z","updated_at":"2025-10-28T13:58:56.000Z","dependencies_parsed_at":"2025-10-28T14:42:21.975Z","dependency_job_id":null,"html_url":"https://github.com/Victorkiosh/temperature_anomaly_detection","commit_stats":null,"previous_names":["victorkiosh/temperature_anomaly_detection"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Victorkiosh/temperature_anomaly_detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorkiosh%2Ftemperature_anomaly_detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorkiosh%2Ftemperature_anomaly_detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorkiosh%2Ftemperature_anomaly_detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorkiosh%2Ftemperature_anomaly_detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Victorkiosh","download_url":"https://codeload.github.com/Victorkiosh/temperature_anomaly_detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victorkiosh%2Ftemperature_anomaly_detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283424652,"owners_count":26833720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-08T02:00:06.281Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","docker","fastapi","iot","machine-learning","mlops","model-deployment","python","real-time-analytics","sqlite","streamlit","tensorflow","timeseries"],"created_at":"2025-11-08T22:01:29.278Z","updated_at":"2025-11-08T22:02:19.642Z","avatar_url":"https://github.com/Victorkiosh.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧊 Cold Storage Temperature Anomaly Detection System\n\n![Python](https://img.shields.io/badge/Python-3.10-blue?logo=python)\n![FastAPI](https://img.shields.io/badge/FastAPI-API%20Service-009688?logo=fastapi)\n![Streamlit](https://img.shields.io/badge/Streamlit-Dashboard-ff4b4b?logo=streamlit)\n![Docker](https://img.shields.io/badge/Docker-Containerized-2496ed?logo=docker)\n![SQLite](https://img.shields.io/badge/Database-SQLite-lightgrey?logo=sqlite)\n![Status](https://img.shields.io/badge/Status-Live-brightgreen)\n![License](https://img.shields.io/badge/License-MIT-yellow)\n\nThis project demonstrates a **complete end-to-end Machine Learning deployment pipeline** for real-time temperature anomaly detection in a cold storage environment.  \nIt combines **deep learning (LSTM)**, **statistical monitoring**, **operational rules**, and **real-time visualization** to simulate an intelligent cold storage monitoring system.\n\n---\n\n## 🌡️ Live Demos\n\n### 🔹 Streamlit Dashboard  \nA real-time Streamlit dashboard for monitoring and detecting temperature anomalies in cold storage facilities using hybrid threshold and ML models.\n\n[![Open in Streamlit](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://temperatureanomalydetection-gzwboeq5h9ytuysburuqpz.streamlit.app/)  \n🌐 **Dashboard:** [Launch Here](https://temperatureanomalydetection-gzwboeq5h9ytuysburuqpz.streamlit.app/)\n\n---\n\n### 🔹 FastAPI Backend  \nThe deployed API service handles model inference and integrates seamlessly with the Streamlit dashboard.\n\n[![FastAPI Docs](https://img.shields.io/badge/OpenAPI%20Docs-FastAPI-009688?logo=swagger)](https://temperature-anomaly-detection-1.onrender.com/docs)  \n🌐 **API Endpoint:** [Explore the FastAPI Service](https://temperature-anomaly-detection-1.onrender.com/docs)\n\n---\n\n\n## 🚀 Project Overview\n\n### 🎯 Objective\nTo detect abnormal temperature patterns in cold storage facilities and alert operators before a safety threshold is breached — ensuring **operational efficiency**, **food safety**, and **energy savings**.\n\n### 🧩 System Components\n\n| Module | Description |\n|--------|--------------|\n| **1. Data Simulation \u0026 Preprocessing** | Simulated realistic cold storage temperature data and structured it into a database. |\n| **2. LSTM Model Training** | Built an LSTM Autoencoder to learn normal temperature behavior and detect deviations. |\n| **3. Hybrid Detection Rule** | Combined AI-based anomaly prediction with operational threshold rules for robust alerts. |\n| **4. FastAPI Backend** | Exposed the trained model as a real-time REST API (`/predict`) for live inference. |\n| **5. SQLite Database** | Logged all readings and anomaly predictions for audit and visualization. |\n| **6. Stream Simulation** | Emulated a live data feed from IoT sensors using Python’s request loop. |\n| **7. Streamlit Dashboard** | Provided a real-time dashboard to visualize temperature fluctuations and alerts. |\n| **8. Docker Containerization** | (Optional) Bundled the app for portable and consistent deployment. |\n\n---\n\n## 🧠 Model Architecture\n\nThe system uses an **LSTM Autoencoder** trained on historical temperature data to reconstruct normal behavior.  \nA high reconstruction error indicates an **anomaly**, which is further validated through a **hybrid operational rule**.\n\n```\nNormal → Model reconstructs well → Low error\nAnomaly → Model fails to reconstruct → High error → Alert triggered\n```\n\n---\n\n## 🧩 Hybrid Rule Logic\n\n| Rule | Description |\n|------|--------------|\n| **LSTM anomaly** | Model detects unusual pattern based on reconstruction error. |\n| **Persistence** | Confirms if anomaly persists for `N` consecutive readings. |\n| **Bounds breach** | Checks if temperature is outside allowed range (e.g., -25°C to -18°C). |\n| **Hybrid alert** | Triggers alert if either persistence or bounds rule is True. |\n\n---\n\n## 🗂️ Folder Structure\n\n```text\ntemperature_anomaly_detection/\n│\n├── data/                        # Raw and processed temperature data\n├── notebooks/                   # Jupyter notebooks for training and exploration\n├── models/                      # Saved LSTM model and scaler\n│   ├── lstm_model.keras\n│   └── scaler.pkl\n│\n├── deployment/                  # Deployment pipeline\n│   ├── app.py                   # FastAPI app (model endpoint)\n│   ├── config.py                # Configuration variables\n│   ├── inference.py             # Core anomaly detection logic\n│   ├── simulate_stream.py       # Live temperature feed simulation\n│   ├── view_db.py               # Local DB visualizer\n│   ├── dashboard.py             # Streamlit dashboard\n│   ├── Dockerfile               # Container setup\n│   └── temperature_data.db      # SQLite database (auto-created)\n│\n├── requirements.txt\n└── README.md                    # You are here\n```\n\n---\n\n## ⚙️ How It Works\n\n1. **Start API**\n\n```bash\nuvicorn deployment.app:app --reload\n```\n\n2. **Simulate live temperature readings**\n\n```bash\npython deployment/simulate_stream.py\n```\n\n3. **View real-time dashboard**\n\n```bash\nstreamlit run deployment/dashboard.py\n```\n\n---\n\n## 🧭 System Workflow\n\n![Project Banner Placeholder](visuals/project_banner.png)\n\n---\n\n## 🐳 Docker Deployment (Optional)\n\nBuild and run the complete solution in a containerized environment:\n\n```bash\n# Build image\ndocker build -t coldstorage-monitor .\n\n# Run container\ndocker run -p 8000:8000 coldstorage-monitor\n```\n\n---\n\n## 📊 Example API Response\n\n`POST /predict`\n\nRequest:\n\n```json\n{\n  \"temperature\": -22.5\n}\n```\n\nResponse:\n\n```json\n{\n  \"temperature\": -22.5,\n  \"reconstruction_error\": 0.2358,\n  \"raw_anomaly\": true,\n  \"persistence_alert\": true,\n  \"bounds_breach\": false,\n  \"hybrid_alert\": true\n}\n```\n\n---\n\n## 🌐 Future Extensions\n\n* Multi-room \u0026 multi-sensor integration\n* Cloud database for persistent storage\n* Notification system (email/SMS alerts)\n* Auto model retraining on new data\n\n---\n\n## 🏁 Summary\n\nThis project showcases **end-to-end MLOps readiness** — from model training and hybrid logic to real-time inference and visualization —\na proof-of-concept for **AI-powered cold storage monitoring**.\n\n🔹 Real Data → 🔹 Smart Model → 🔹 Live Alerts → 🔹 Visual Insights\n\n---\n\n## 👨‍💻 Author\n\n**Victor Kioko**\n\nData Science \u0026 Analytics | Python | Power BI | SQL\n\n[LinkedIn](www.linkedin.com/in/mutuavictor)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorkiosh%2Ftemperature_anomaly_detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorkiosh%2Ftemperature_anomaly_detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorkiosh%2Ftemperature_anomaly_detection/lists"}