An AI-powered ecological solution for reducing food waste through computer vision and thermal degradation modeling.
The AI Food Spoilage Estimator is a comprehensive software solution designed to tackle the global issue of food waste. By combining Computer Vision (CV) for food identification with Predictive Analytics (Machine Learning) for shelf life estimation, the system provides users with actionable insights into when their food items will become unsafe for consumption.
The system doesn't just "guess"; it utilizes established food science principles, including the Q10 Temperature Coefficient and USDA FoodKeeper averages, to provide scientifically grounded predictions tailored to specific storage environments (Refrigerated, Room Temperature, or Frozen).
- Global Food Waste: Approximately 1.3 billion tons of food are wasted annually, with a significant portion occurring at the consumer level due to confusion over "Use By" vs. "Best Before" dates.
- Storage Complexity: Most consumers do not understand how small fluctuations in temperature (e.g., a fridge door being left open) or high humidity can drastically accelerate microbial growth and chemical degradation.
- Gap in Technology: While smart fridges exist, they are expensive. There is a lack of accessible, software-first tools that can instantly analyze a food item and provide a remaining shelf life estimate based on real-time environmental data.
- Instant Identification: Automate the classification of food items using state-of-the-art Deep Learning models.
- Environmental Modeling: Account for temperature and humidity variables to provide a dynamic (not static) shelf life prediction.
- Science-Driven Insights: Implement the Q10 temperature coefficient to model biological decay accurately.
- Accessibility: Deliver the solution via a lightweight web interface accessible on both desktop and mobile devices.
- Sustainability: Promote "Zero Hunger" (SDG 2) and "Responsible Consumption" (SDG 12) by preventing avoidable food spoilage.
- Hybrid AI Classification: Uses both Food-101 and ImageNet models for maximum accuracy.
- 15 Food Categories: Apple, Banana, Bread, Milk, Pasta, Pizza, Burger, Sushi, Meat, Fish, Egg, Vegetable, Fruit, Rice, Cake.
- Dynamic Shelf Life Prediction: RandomForest model predicts remaining days based on temperature, humidity, and storage type.
- Science-Based: Calculations based on USDA FoodKeeper data and Q10 temperature coefficients.
- Interactive Dashboard: Modern Glassmorphism UI for easy data input and visualization.
- Docker Ready: One-command deployment with
docker-compose up.
- Backend: Python, Flask (Production API), Streamlit (Dashboard)
- AI/Vision: Hugging Face Inference API (
Food-101&EfficientNet-B0) - ML/Analytics: Scikit-Learn (RandomForestRegressor), Pandas, NumPy
- Frontend: HTML5, CSS3 (Glassmorphism), JavaScript
- Deployment: Docker, Docker Compose, Python-dotenv
The system uses a weighted ensemble/hybrid approach:
- Primary: Queries
Kaludi/food-category-classification-v2.0(Food-101 model) - Best for prepared dishes. - Fallback: If confidence is low, queries
google/efficientnet-b0(ImageNet) - Best for raw ingredients. - Result: Returns the highest-confidence match from either model.
Food degradation is a temperature-dependent chemical and biological process. The system implements the Q10 Temperature Coefficient:
- Logic: For many food items, the rate of spoilage increases by ~2.5x (Q10 factor) for every 10ยฐC increase in temperature.
- Reference: We use 4ยฐC (Standard Fridge Temp) as our baseline.
Microbial growth is accelerated by moisture. Our model applies a penalty/bonus factor where every 10% increase in humidity above 55% reduces the remaining shelf life by approximately 10%.
| Category | Typical Fridge Life | Example Items | Scientific Logic |
|---|---|---|---|
| Apple | 21 days | Whole apples, apple pie | High fiber, low oxidation rate |
| Banana | 5 days | Fresh bananas | High Ethylene production |
| Bread | 7 days | Loaves, toast, bagels | Moisture loss & retrogradation |
| Milk | 7 days | Dairy products | Bacterial lactic acid production |
| Pasta | 4 days | Spaghetti, lasagna, ramen | High water activity |
| Pizza | 4 days | Leftover pizza | Fat oxidation & microbial risk |
| Burger | 3 days | Hamburgers, hot dogs | Processed meat degradation |
| Sushi | 1 day | Sushi, sashimi | Raw fish; high bacterial risk |
| Meat | 4 days | Steak, pork, chicken | Protein degradation |
| Fish | 2 days | Salmon, tuna, seafood | Rapid enzymatic breakdown |
| Egg | 28 days | Eggs, omelettes | Natural protective shell coating |
| Vegetable | 7 days | Salads, fresh veggies | Respiration & transpiration |
| Fruit | 5 days | Berries, cut fruit | Cell wall breakdown |
| Rice | 5 days | Cooked rice, risotto | Bacillus cereus risk |
| Cake | 5 days | Cakes, desserts | High sugar stability |
-
Clone the repo and create
.env:git clone https://github.com/yourusername/AI-Food-Spoilage-Estimator.git cd AI-Food-Spoilage-Estimator cp .env.example .env # Edit .env and add your Hugging Face token
-
Run with Docker:
docker-compose up --build
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variable:
# Windows PowerShell $env:HUGGINGFACE_API_TOKEN = "hf_your_token_here" # Linux/Mac export HUGGINGFACE_API_TOKEN="hf_your_token_here"
-
Run the apps:
- Flask (Main UI):
python app_flask.py - Streamlit (Metrics):
streamlit run app.py
- Flask (Main UI):
| Variable | Required | Description |
|---|---|---|
HUGGINGFACE_API_TOKEN |
Yes | Get free at huggingface.co/settings/tokens |
food-spoilage-estimator/
โโโ app_flask.py # Production-ready Flask server
โโโ app.py # Interactive Streamlit dashboard
โโโ config.py # Centralized configuration (Constants, Mappings)
โโโ Dockerfile # Container definition
โโโ docker-compose.yml # Multi-container orchestration
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment template
โโโ models/
โ โโโ classifier.py # Hybrid AI Vision logic (Hugging Face)
โ โโโ shelf_life_predictor.py # RandomForest ML Model
โโโ utils/
โ โโโ data_loader.py # Research-based dataset generator
โโโ templates/
โ โโโ index.html # Modern Glassmorphism UI
โโโ data/ # Generated training data (gitignored)
- IoT Integration: Connect with real-time temperature/humidity sensors.
- Mobile App: Develop a Flutter cross-platform mobile application.
- Barcode Scanning: Fetch brand-specific data via OpenFoodFacts.
- Multi-Item Detection: Enable YOLOv8 for detecting multiple items in one fridge scan.
Created for educational and research purposes in AI-driven sustainability.
- Food-101: Bossard et al., "Food-101 โ Mining Discriminative Components", ECCV 2014
- Q10 Coefficient: Labuza, T.P. (1982). "Shelf Life Dating of Foods"
- USDA: FoodKeeper Application Data (2024)
MIT License - Free for educational and commercial use.
Tip
Pro Tip for PPT: When presenting, highlight the Q10 Coefficient โ it's the "Secret Sauce" that differentiates this project from simple image labelers by adding a layer of genuine food science.