Skip to content

hill0106/fridge_linebot

Repository files navigation

🧊 Smart Fridge Manager - LINE Bot

A comprehensive LINE Bot application that helps users manage their refrigerator contents with AI-powered food recognition and expiration tracking.

🌟 Features

📱 LINE Bot Interface

  • Rich Menu Navigation: Easy-to-use interface with visual buttons
  • Interactive Messaging: Natural language processing for user commands
  • Flexible Message Types: Support for text, images, carousels, and LIFF web apps

🤖 AI-Powered Food Recognition

  • Azure Custom Vision: Automatic food classification from uploaded images
  • Smart Categorization: Recognizes 12+ food categories (蔬果, 海鮮, 肉類, etc.)
  • Image Processing: Handles multiple formats (PNG, JPG, JPEG, WebP)

📊 Comprehensive Food Management

  • Add Items: Manual entry or AI-assisted recognition
  • Edit Items: Update food details, quantities, and expiration dates
  • Delete Items: Safe removal with confirmation prompts
  • Smart Search: Find items by keywords, categories, or locations

📅 Expiration Tracking

  • Expiration Alerts: Daily reminders for expired and soon-to-expire items
  • Status Filtering: View items by expiration status (expired, fresh)
  • Time-based Queries: Filter by specific dates and time ranges

🗂️ Advanced Organization

  • Category Management: 12 food categories with visual icons
  • Storage Location: Track items in 冷藏 (refrigerator), 冷凍 (freezer), or 室溫 (room temperature)
  • Quantity Tracking: Monitor item quantities and usage

🏗️ Architecture

Backend Technologies

  • Flask: Web framework for API endpoints and LIFF integration
  • AWS DynamoDB: NoSQL database for food item storage
  • Azure Blob Storage: Cloud storage for food images
  • Azure Custom Vision: AI service for food classification

Frontend Technologies

  • LIFF (LINE Front-end Framework): Mobile-optimized web interface
  • Bootstrap: Responsive UI components
  • jQuery: Interactive form handling and date pickers

LINE Platform Integration

  • LINE Bot SDK: Official SDK for bot functionality
  • Rich Menu API: Visual menu interface
  • Webhook Handling: Real-time message processing
  • LIFF Integration: Seamless web app experience within LINE

📁 Project Structure

fridge_linebot/
├── application.py              # Main Flask application
├── line_chatbot_api.py         # LINE Bot API configuration
├── awsdb.py                    # DynamoDB database operations
├── requirements.txt            # Python dependencies
├── line_service/
│   ├── service.py             # LINE Bot message handlers
│   └── rich_menu.py           # Rich menu management
├── templates/                  # HTML templates for LIFF
│   ├── addItem.html           # Add item form
│   ├── editItem.html          # Edit item form
│   ├── all_item_info.html     # Item listing
│   └── recItem.html           # Recognition interface
└── static/
    ├── addItem.css            # Custom styling
    └── images/                # Static assets

🚀 Getting Started

Prerequisites

  • Python 3.7+
  • LINE Developer Account
  • AWS Account with DynamoDB access
  • Azure Account with Custom Vision and Blob Storage

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/fridge_linebot.git
    cd fridge_linebot
  2. Install dependencies

    pip install -r requirements.txt
  3. Configure environment variables

    # LINE Bot Configuration
    export LINE_CHANNEL_ACCESS_TOKEN="your_access_token"
    export LINE_CHANNEL_SECRET="your_channel_secret"
    
    # AWS Configuration
    export AWS_ACCESS_KEY_ID="your_aws_key"
    export AWS_SECRET_ACCESS_KEY="your_aws_secret"
    
    # Azure Configuration
    export AZURE_CUSTOM_VISION_KEY="your_custom_vision_key"
    export AZURE_STORAGE_CONNECTION_STRING="your_blob_connection"
  4. Set up database

    • Create DynamoDB table named MyFridge
    • Configure partition key: userid (String)
    • Configure sort key: id (String)
  5. Configure Azure services

    • Set up Custom Vision project for food classification
    • Create Blob Storage container for images
    • Update project IDs and endpoints in code
  6. Run the application

    python application.py

📱 Usage

LINE Bot Commands

  • 新增商品 - Add new food item
  • 顯示商品 - View food items with filtering options
  • 全部商品 - Show all items in carousel or LIFF interface
  • 依據時效 - Filter by expiration status
  • 依據類別 - Filter by food category
  • 依據位置 - Filter by storage location
  • 到期提醒 - Get expiration alerts

Food Categories

  • 🥕 蔬果 (Vegetables & Fruits)
  • 🐟 海鮮 (Seafood)
  • 🥩 肉類 (Meat)
  • 🍜 麵類 (Noodles & Pasta)
  • 🍚 飯類 (Rice)
  • 🥛 乳製品 (Dairy Products)
  • 🍳 蛋類 (Eggs)
  • 🍞 麵包 (Bread)
  • 🍰 甜點 (Desserts)
  • 🍗 炸物 (Fried Foods)
  • 🥣 湯類 (Soups)
  • ℹ️ 其他 (Other)

Storage Locations

  • 🧊 冷藏 (Refrigerator)
  • ❄️ 冷凍 (Freezer)
  • 🌡️ 室溫 (Room Temperature)

🔧 Configuration

LINE Bot Setup

  1. Create a new LINE Bot channel
  2. Configure webhook URL: https://yourdomain.com/callback
  3. Enable LIFF for web interface integration
  4. Upload rich menu image and configure menu areas

Database Schema

{
  "userid": "LINE user ID",
  "id": "Unique item UUID",
  "itemName": "Food item name",
  "itemDate": "Expiration date (YYYY-MM-DD)",
  "itemNum": "Quantity",
  "itemPlace": "Storage location",
  "itemType": "Food category",
  "itemImage": "Azure Blob Storage URL",
  "exp": "Timestamp for expiration tracking"
}

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

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

🙏 Acknowledgments

  • LINE Corporation for the LINE Bot SDK and platform
  • Microsoft Azure for Custom Vision and Blob Storage services
  • Amazon Web Services for DynamoDB infrastructure
  • Central Taiwan University (NCU) for academic support

📞 Support

For support and questions, please open an issue on GitHub or contact the development team.


Built with ❤️ for smarter food management