Skip to content

TheSigmaSociety/PlatePredictProdBackend

Repository files navigation

PlatePredict Backend API

A Node.js backend service that analyzes food waste using Google's Gemini AI and manages student ration data.

📋 Overview

PlatePredict is a solution designed to monitor and reduce food waste in school cafeterias. The system analyzes images of leftover food on plates, assigns a waste score, and adjusts student ration allocations accordingly to promote more responsible consumption habits.

🚀 Features

  • AI-Powered Waste Analysis: Uses Google's Gemini AI to analyze food waste from plate images
  • Student Management: Track individual student waste patterns and ration allocations
  • RESTful API: Simple API endpoints for integration with frontend applications
  • MongoDB Integration: Persistent storage for student data and waste history

🛠️ Tech Stack

  • Node.js - JavaScript runtime
  • Express - Web framework
  • MongoDB - Database
  • Google Gemini AI - Image analysis
  • Docker - Containerization

📦 Installation

Prerequisites

  • Node.js (v16+)
  • MongoDB connection string
  • Google Gemini AI API key

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd platePredit-js-backend
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory:

    MONGO_URI=your_mongodb_connection_string
    GENAI_API_KEY=your_google_gemini_ai_key
    PORT=5000
    
  4. Start the server:

    npm start

Using Docker

  1. Build and run using Docker Compose:

    docker-compose up -d
  2. Or build and push using the provided script:

    ./build.cmd

🔌 API Endpoints

Add a new student entry

  • POST /add_entry
  • Body: { "student_id": "string" }
  • Response: { "message": "entry added successfully" }

Record waste for a student

  • POST /add_waste
  • Body: { "student_id": "string", "image": "base64_encoded_image" }
  • Response: { "message": "waste updated successfully" }

Get all student entries

  • GET /get_all_entries
  • Response: Array of student records

Get a specific student entry

  • GET /get_entry?student_id=123
  • Query Parameter: student_id
  • Response: Student record object

🧪 How It Works

  1. Student Registration: A new student is registered with a unique ID
  2. Waste Recording: After a meal, a photo of the student's plate is submitted
  3. AI Analysis: The Gemini AI analyzes the image and assigns a waste score (0-10)
  4. Ration Adjustment:
    • Low waste scores (0-1) increase rations
    • High waste scores (4+) decrease rations

🔒 Environment Variables

Variable Description
MONGO_URI MongoDB connection string
GENAI_API_KEY Google Gemini AI API key
PORT Port to run the server (default: 5000)

🐳 Deployment

The application is containerized with Docker and can be deployed to any platform that supports Docker containers.

👥 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published