Skip to content

swe-students-fall2025/4-containers-nov

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

107 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βœ‹ HandSense β€” Containerized Machine Learning + Web Dashboard System

ML Client CI Web App CI Lint-free

A fully containerized, three-service application that performs real-time hand gesture recognition using a MediaPipe + PyTorch machine-learning client, stores gesture events inside MongoDB, and visualizes them through a Flask-based web dashboard.

This project demonstrates how separate services communicate inside a Dockerized micro-service architecture.


πŸ‘₯ Teammates


🧱 System Overview

The system consists of three Dockerized services:

+------------------------+     +-----------------------+     +------------------------+
|   Machine Learning     |     |       MongoDB         |     |       Web App          |
|       Client           | --> |   handsense database  | --> |   Dashboard (Flask)    |
| (MediaPipe + PyTorch)  |     |     Gesture_events    |     |   Visualize gestures   |
+------------------------+     +-----------------------+     +------------------------+

πŸ”Ή Machine-Learning Client

Runs locally or inside Docker.
It uses a webcam β†’ detects hands using MediaPipe β†’ predicts gestures using a PyTorch MLP β†’ inserts events into handsense.gesture_events collection.

πŸ”Ή MongoDB

Stores gesture logs, statistics, and capture state toggles.

πŸ”Ή Web App

Reads gesture events from MongoDB and presents a dashboard showing:

  • Live latest gesture
  • Gesture distribution
  • Recent event timeline
  • Toggle capture control (/api/control)

After all services run, you can visit:

πŸ‘‰ http://localhost:5000


πŸ“ Project Structure

β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ instructions.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ machine-learning-client
β”‚   β”œβ”€β”€ data
β”‚   β”‚   β”œβ”€β”€ hagrid_keypoints_X.npy
β”‚   β”‚   └── hagrid_keypoints_y.npy
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ models
β”‚   β”‚   β”œβ”€β”€ gesture_mlp.pt
β”‚   β”‚   └── train_mlp.py
β”‚   β”œβ”€β”€ Pipfile
β”‚   β”œβ”€β”€ Pipfile.lock
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ extract_keypoints_from_hagrid.py
β”‚   β”‚   └── live_mediapipe_mlp.py
β”‚   └── tests
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ test_extract_keypoints_from_hagrid.py
β”‚       └── test_live_mediapipe_mlp.py
β”œβ”€β”€ README.md
└── web-app
    β”œβ”€β”€ app.py
    β”œβ”€β”€ Dockerfile
    β”œβ”€β”€ Pipfile
    β”œβ”€β”€ Pipfile.lock
    β”œβ”€β”€ readme.txt
    β”œβ”€β”€ static
    β”‚   β”œβ”€β”€ audios
    β”‚   β”‚   β”œβ”€β”€ among_us.mp3
    β”‚   β”‚   β”œβ”€β”€ android_beep.mp3
    β”‚   β”‚   β”œβ”€β”€ bom.mp3
    β”‚   β”‚   β”œβ”€β”€ error.mp3
    β”‚   β”‚   β”œβ”€β”€ playme.mp3
    β”‚   β”‚   β”œβ”€β”€ rick_roll.mp3
    β”‚   β”‚   β”œβ”€β”€ rizz.mp3
    β”‚   β”‚   β”œβ”€β”€ sponge_bob.mp3
    β”‚   β”‚   └── uwu.mp3
    β”‚   β”œβ”€β”€ hagrid_classes.json
    β”‚   β”œβ”€β”€ images
    β”‚   β”‚   β”œβ”€β”€ fist.png
    β”‚   β”‚   β”œβ”€β”€ like.png
    β”‚   β”‚   β”œβ”€β”€ ok.png
    β”‚   β”‚   β”œβ”€β”€ one.png
    β”‚   β”‚   β”œβ”€β”€ palm.png
    β”‚   β”‚   β”œβ”€β”€ stop.png
    β”‚   β”‚   β”œβ”€β”€ thinking.png
    β”‚   β”‚   β”œβ”€β”€ three.png
    β”‚   β”‚   └── two_up.png
    β”‚   β”œβ”€β”€ script.js
    β”‚   └── style.css
    β”œβ”€β”€ templates
    β”‚   └── index.html
    └── tests
        β”œβ”€β”€ __init__.py
        β”œβ”€β”€ conftest.py
        └── test_app.py

βš™οΈ 1. Environment Setup (Any Platform)

The recommended workflow uses pipenv for dependency management.

macOS / Linux / Windows (WSL)

Install pipenv

pip install pipenv

βš™οΈ 2. Running the System (Docker)

From project root:

docker compose up --build

This starts:

Service URL Purpose
web-app http://localhost:5000 Dashboard UI
mongodb localhost:27017 Database
ml-client headless, no UI Captures gestures + inserts into DB

To stop:

docker compose down

πŸ‘οΈ Running the ML Client With Webcam (macOS/Windows/Linux Host)

Since macOS Docker cannot access /dev/video0, we run the ML client on host machine:

cd machine-learning-client
pipenv install --dev
pipenv run python src/live_mediapipe_mlp.py

Features:

  • Live webcam feed
  • MediaPipe hand-tracking
  • PyTorch gesture inference
  • Inserts gesture records into handsense.gesture_events
  • Press q to quit

πŸ—„οΈ 3. MongoDB Configuration + Starter Data

The database name is:

handsense

Collections automatically created:

Collection Purpose
gesture_events ML client inserts gesture data
controls Stores capture toggle state

At first run the ML client ensures:

{
  "_id": "capture_control",
  "enabled": false
}

πŸ” 4. Environment Variables

Both ml-client and web-app use these:

Variable Description
MONGO_URI Mongo connection string (default: mongodb://mongodb:27017)
MONGO_DB_NAME Database name (default: handsense)
SECRET_KEY Flask sessions

See .env.example below.


πŸ“„ 5. .env.example (Required for TA Submission)

Place this file in project root:

# MongoDB configuration
MONGO_URI=mongodb://mongodb:27017
MONGO_DB_NAME=handsense

# Flask secret
SECRET_KEY=dev-secret

Then create an actual .env:

cp .env.example .env

πŸ” 6. Web App (Flask) β€” Running Locally

cd web-app
pipenv install --dev
pipenv run flask run --host=0.0.0.0 --port=5000

Navigate to:

πŸ‘‰ http://localhost:5000

Endpoints:

Route Description
/ Dashboard UI
/api/latest Latest gesture
/api/latest_full Latest gesture (detailed)
/api/control POST toggle capture
/api/control/status GET capture control

πŸ§ͺ 7. Testing + Linting + Coverage

Run ML Client Tests

cd machine-learning-client
pipenv run pytest --cov=src
pipenv run pylint src

Run Web App Tests

cd web-app
pipenv run pytest --cov=.
pipenv run pylint app.py

Coverage must be β‰₯ 80%.


🧰 8. Docker Compose

version: "3.9"

services:
  mongodb:
    image: mongo:6
    container_name: mongodb
    ports:
      - "27017:27017"
    volumes:
      - mongo-data:/data/db

  web-app:
    build:
      context: ./web-app
    container_name: web-app
    depends_on:
      - mongodb
    environment:
      MONGO_URI: "mongodb://mongodb:27017"
      MONGO_DB_NAME: "handsense"
      FLASK_APP: "app.py"
      FLASK_RUN_HOST: "0.0.0.0"
    ports:
      - "5000:5000"

  ml-client:
    build:
      context: ./machine-learning-client
    container_name: ml-client
    depends_on:
      - mongodb
    environment:
      MONGO_URI: "mongodb://mongodb:27017"
      MONGO_DB_NAME: "handsense"

volumes:
  mongo-data:

About

software-engineering-fall-2025-4-containers-containerized-app-exercise created by GitHub Classroom

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 74.7%
  • CSS 8.8%
  • HTML 6.9%
  • JavaScript 5.3%
  • Dockerfile 2.5%
  • Shell 1.8%