EdgeCart: Predictive Waste Intelligence System

Sometimes sustainability isn't about doing something grand—it's about starting small. We're tackling food waste, one produce shelf at a time.


The Problem

Every year, 40% of food in America goes to waste—that's $408 billion worth of perfectly edible food thrown into landfills (USDA, 2023).

Meanwhile:

  • Grocery stores lose billions on expired produce they can't sell
  • Customers miss deals on perfectly good food nearing peak ripeness
  • Our planet suffers from unnecessary methane emissions and wasted resources

The current approach to preventing waste?

Random discounts.

Generic clearance sales.

Hoping someone—anyone—buys it.

It doesn't work.

Why? Because discounts are either:

  • Too late (applied when food is already unsellable)
  • Too broad (blasting everyone with irrelevant spam notifications)
  • Too random (no connection between what's discounted and who actually wants it)

The result? Stores throw away inventory that could have been sold. Customers never see deals on items they actually buy. And 133 billion pounds of food ends up in landfills annually—wasting the water, energy, and labor used to produce it.

The stakes are enormous.

Food waste isn't just an economic problem—it's an environmental crisis. When organic matter decomposes in landfills, it produces methane, a greenhouse gas 25 times more potent than carbon dioxide. Meanwhile, 10% of global greenhouse gas emissions come from food that's never eaten (Project Drawdown, 2020).

We don't have a food scarcity problem. We have a food intelligence problem.

That's where EdgeCart comes in.


The Solution

EdgeCart is the world's first predictive waste intelligence system that connects real-time produce decay detection with actual customer purchasing behavior. Using Markov Chain analysis, we project our solution causing a 19.5% reduction in emissions from grocery store food waste and ~180 million tons globally.

Imagine this scenario:

9:00 AM - A camera spots bananas on the shelf at Store X.
12:00 PM - AI detects browning spots: freshness drops to 70%.
12:01 PM - System calculates a 35% discount to move inventory.
12:02 PM - AI identifies Sarah, who buys bananas every Tuesday, prefers ripe ones, and shops at Store X.
12:03 PM - Sarah's phone buzzes: "Your favorite bananas now 35% off at Store X—perfect ripeness for banana bread tonight!"
2:30 PM - Sarah visits the store, buys the bananas, saves $2.50.
Result - Store recovers revenue on inventory that would've expired. Sarah saves money on groceries she was going to buy anyway. Zero waste.

Here's what makes it revolutionary:

EdgeCart Admin Video Stream

1. Real-Time Visual Intelligence

Cameras monitor produce shelves 24/7, using:

  • YOLO object detection to identify what's on the shelf
  • ResNet freshness scoring (0-100 scale based on visual decay)
  • Google Gemini Robotics (gemini-robotics-er-1.5-preview) for precise blemish detection and quality assessment

Our AI watches bananas brown, tomatoes soften, and lettuce wilt—creating a live decay map of inventory with predictive expiration timestamps.

Blemish Detection

2. Deep Customer Intelligence (Knot API)

Customers connect their bank accounts through Knot API, revealing:

  • Complete purchase history across ALL grocery stores
  • What they buy, how often, at what price points
  • Shopping patterns, preferences, and price sensitivity

The system learns: "Sarah buys organic avocados 2x per week, always spends $3-4 each" and "Marcus bought strawberries 5 times last month, only when under $5."

Dashboard

3. AI-Powered Smart Matching (xAI Grok)

When produce hits the "risk zone" (70% freshness, 12 hours until spoilage):

  1. AI calculates dynamic discounts (lower freshness = deeper discount)
  2. System identifies customers who actually buy that specific item
  3. xAI Grok analyzes match quality across multiple dimensions:

    • Purchase Pattern Analysis - When are they due for their next shopping trip?
    • Timing Relevance - Weekend bulk buyer vs. weekday shopper?
    • Value Perception - Does the discount exceed their usual threshold?
    • Behavioral Triggers - Seasonal preferences, health choices, new varieties?
    • Urgency Factors - Limited quantity, time sensitivity, expiration proximity?
  4. Sends targeted notifications ONLY to high-priority matches (80+ score)

No spam. No random deals. Only relevant offers for groceries you were already going to buy.

Analytics Dashboard

4. Predictive Analytics for Stores

Store dashboard provides actionable insights:

  • "Based on current decay rates and customer buying patterns, reduce next banana order by 30%"
  • "Your avocado customers also shop at Whole Foods—stock more organic to compete"
  • "50 customers notified about strawberries but only 10 bought—discount wasn't deep enough"

Impact Carbon

5. Zero-Waste Fallback

For items that won't sell even with targeted discounts:

  • System auto-schedules food bank donations 12 hours before critical decay
  • Customers who referred food banks earn "waste warrior" points
  • Community impact tracking shows pounds of food saved

6. Natural Language Interface (xAI Grok)

Everything is queryable:

  • Stores ask: "Which products have the worst sell-through rate at 60% freshness?"
  • Customers ask: "How much could I save monthly based on my shopping patterns?"
  • Instant AI-powered insights with full context

How We Built It

Backend (Python)

  • Flask - REST API & WebSocket server for real-time updates
  • OpenCV + YOLOv8 - Real-time object detection and tracking
  • PyTorch + ResNet18 - Custom-trained freshness classification model achieving 90% accuracy on fresh/rotten produce dataset through transfer learning
  • Google Gemini (gemini-robotics-er-1.5-preview) - High-precision blemish segmentation and quality assessment
  • Knot API - Customer purchase data integration across multiple merchants
  • xAI Grok - Natural language recommendation engine with multi-dimensional analysis
  • SQLite - Database for inventory, customers, and recommendations

Frontend (React + TypeScript)

  • React - Modern component-based UI with responsive design
  • WebSocket Client - Real-time inventory and notification updates
  • Framer Motion - Smooth animations and transitions
  • Custom Terminal UI - Cyberpunk-inspired admin dashboard

AI/ML Pipeline

  1. YOLO detects produce → crops objects → passes to next stage
  2. ResNet scores freshness (0-100) → triggers discount calculation
  3. Gemini Robotics detects blemishes → adjusts quality assessment
  4. Grok matches customers → generates personalized recommendations with reasoning

The Technical Challenge:
Building a system that processes video frames in real-time, evaluates freshness with computer vision, matches thousands of customer profiles against hundreds of inventory items, and generates contextually-aware AI recommendations—all within 2-3 seconds from detection to notification.


Challenges We Ran Into

1. Real-Time Computer Vision at Scale
Processing video feeds from multiple cameras while running YOLO + ResNet + Gemini sequentially threatened to bottleneck the system. We optimized by batching detections, caching non-changing frames, and running models asynchronously.

2. Knot API Integration Complexity
Fetching and syncing purchase history across multiple merchants required careful rate limiting and data normalization. We built a robust caching layer and fallback system with demo users for development.

3. AI Recommendation Quality vs. Cost
xAI Grok API calls are expensive. We implemented intelligent rate limiting (10s between calls), batch processing, and priority scoring to only generate recommendations for high-value matches (80+ priority score).

4. Dynamic Discount Calculation
Balancing "deep enough to move inventory" with "not too deep to hurt margins" required iterative testing. We settled on a formula: discount = (100 - freshness_score) * 0.6 with minimum 20% threshold.

5. WebSocket State Management
Keeping admin dashboard and customer portals synchronized across real-time inventory changes, freshness updates, and new recommendations required careful event design and conflict resolution.

6. Freshness Model Training
Limited datasets for produce decay across multiple fruit types. We augmented existing datasets with synthetic aging transformations and transfer learning from ImageNet.


Accomplishments That We're Proud Of

Created the first end-to-end waste prevention system that connects visual decay detection with actual consumer behavior

Integrated 4 different AI systems (YOLO, ResNet, Gemini Robotics, Grok) into a cohesive real-time pipeline

Trained a custom ResNet18 freshness classifier locally achieving 90% accuracy on produce decay detection across multiple fruit types

Achieved sub-3-second latency from produce detection to customer notification

Built a working Knot API integration that successfully syncs multi-merchant purchase history

Developed AI reasoning engine that explains why each recommendation was made (transparency in AI decisions)

Designed beautiful dual-interface system (admin dashboard + customer portal) with real-time WebSocket updates

Created demo system with realistic data that showcases the full customer journey from detection to purchase

Proved the concept works - Our system identified 15 "at-risk" inventory items and successfully matched them to 8 customers with 90+ priority scores during testing


What We Learned

Computer vision is powerful, but context is everything.
A banana at 65% freshness means different things to different customers. Some want perfectly ripe fruit for immediate eating. Others want slightly underripe for meal prep. The AI needs to understand intent, not just state.

Real-time doesn't mean instantaneous.
We learned that 2-3 seconds from detection to notification is actually better than instantaneous. It gives the system time to calculate optimal discounts, match multiple customers, and batch API calls—resulting in higher quality recommendations.

Training our own freshness model was essential. Pre-trained models couldn't distinguish subtle decay patterns in produce. By collecting our own dataset and fine-tuning ResNet18 locally, we achieved 90% accuracy—high enough for production use while keeping the model lightweight for real-time inference.

The hardest part isn't the ML—it's the integration.
Getting YOLO, ResNet, Gemini Robotics, Grok, Knot API, WebSockets, and a React frontend to work together seamlessly required more debugging than any individual model. Systems engineering beats algorithm optimization every time.

Customers want transparency in AI decisions.
When we added the "AI Reasoning" section showing why xAI Grok recommended a deal, trust increased dramatically. People want to understand the logic, not just see a black box discount.

On the technical side:
We mastered real-time video processing pipelines, transfer learning for custom datasets, multi-API orchestration under rate limits, and WebSocket state synchronization across distributed clients.

Most importantly:
We proved that waste prevention doesn't require behavior change—it requires intelligence at the edge of the supply chain. When you match the right product (visual AI) with the right customer (purchase data) at the right time (predictive expiry), waste disappears naturally.


The Vision:
A world where no edible food goes to waste because the supply chain is intelligent enough to match every item with someone who wants it, at a price that makes economic sense, before it spoils.

The Impact

By the numbers: Using an Absorbing Markov Chain (AMC) to approximate the lifetimes and end states of each of the items in our inventory, we predict that adoption of EdgeCart would result in:

  • 19.5% reduction in emissions by 83.7 million tons of CO2
  • ~180 million tons less food waste annually

EdgeCart: Intelligence at the edge of the supply chain.

Because the best way to prevent waste isn't to change behavior—it's to make the system smarter.

Team Picture

Made at HackPrinceton 2025

Built With

Share this project:

Updates