Skip to content

Ricepaste/coffeegrindsize

 
 

Repository files navigation

☕ Coffee Grind AI Analyzer

Python FastAPI Docker YOLOv8

An industrial-grade Deep Learning solution for Coffee Particle Size Distribution (PSD) analysis. This project transforms a traditional OpenCV-based tool into a modern, containerized AI service capable of high-precision grind size measurement using YOLOv8 segmentation.


🚀 Highlights

  • AI Inference Engine: Integrates YOLOv8-segmentation for precise particle detection and size calculation.
  • Microservices Architecture: Separate containers for API (FastAPI), Task Queue (Celery), and In-memory Store (Redis).
  • Asynchronous Processing: Handles heavy AI inference tasks in the background to ensure a smooth UI experience.
  • Manual Calibration Tool: Built-in canvas-based scaling tool in React to convert pixels to real-world millimeters (mm).
  • Dockerized Environment: Fully containerized deployment with optimized CPU-only PyTorch builds.

🛠️ Technical Architecture

Architecture Overview

Note

The diagram above shows the full microservices flow. If your viewer doesn't render the Mermaid code below, please refer to the image.

graph LR
    A[React Frontend] -->|Upload + Calibration| B[FastAPI API]
    B -->|Dispatch Task| C[Redis Queue]
    C -->|Fetch Task| D[Celery AI Worker]
    D -->|YOLOv8 Prediction| D
    D -->|Calc PSD| D
    D -->|Store Result| C
    B ---|Poll Result| C
Loading

📦 Project Structure

  • api/: Backend core logic.
    • main.py: RESTful API endpoints.
    • worker.py: AI inference and PSD calculation logic.
  • frontend/: Modern React + Vite + Tailwind CSS dashboard.
  • synthetic_data/: Scripts and utilities for generating AI training data.
  • Dockerfile & docker-compose.yml: Container orchestration.

⚙️ Quick Start (Docker)

Ensure you have Docker Desktop installed.

  1. Clone and Build:

    docker-compose up --build -d
  2. Access the Services:


🎨 Frontend Setup (Manual)

If you wish to run or develop the frontend separately without Docker:

  1. Prerequisites: Node.js installed.
  2. Install Dependencies:
    cd frontend
    npm install
  3. Run Development Server:
    npm run dev
  4. Access: http://localhost:5173

Important

Manual frontend requires the Backend (Docker) to be running on http://localhost:8000.


📸 Usage & Calibration

To get accurate results, follow these steps:

  1. Upload: Select a top-down clear photo of your coffee grounds. Place a reference object (like a coin) next to them.
  2. Calibrate:
    • Click and drag a line over the reference object (e.g., the diameter of a NT$10 coin).
    • Enter the real-world length (e.g., 26 mm for a 10-dollar coin).
  3. Analyze: Click "Run AI Analysis".
  4. Result: The AI will identify all particles and calculate their average diameter in millimeters.

🧹 Maintenance

The system includes an automatic cleanup mechanism:

  • Uploaded images are automatically deleted from the server immediately after AI analysis is complete to prevent storage accumulation.

👨‍💻 Author

Ricepaste/coffeegrindsize (Modernized Version) Enhanced with Deep Learning and Microservices for Future Resume Enhancement.

About

Detects the individual coffee grounds in a white-background picture to determine particle size distribution

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 99.7%
  • JavaScript 0.2%
  • Shell 0.1%
  • PowerShell 0.0%
  • Xonsh 0.0%
  • Dockerfile 0.0%