Face-Expression-Analyzer / PROJECT_README.md
Antigravity AI
Initial deployment of FaceVision AI: Combined Next.js and FastAPI with Docker
954551b

FaceVision AI 🧠

A real-time facial expression recognition web app powered by MediaPipe Face Landmarker running fully in-browser (WASM), with a FastAPI backend for logging emotion data to a Neon PostgreSQL database.


Project Structure

FACE RECOGNIZATION/
β”œβ”€β”€ frontend/          # Next.js App Router + Tailwind CSS
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”œβ”€β”€ useFaceTracking.ts   # MediaPipe integration & emotion classification
β”‚   β”‚   β”‚   └── useEmotionLogger.ts  # 10s window logging to backend
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ EmotionDisplay.tsx
β”‚   β”‚   β”‚   └── StatsPanel.tsx
β”‚   β”‚   β”œβ”€β”€ FaceVisionApp.tsx        # Main client component
β”‚   β”‚   β”œβ”€β”€ page.tsx
β”‚   β”‚   └── globals.css
β”‚   └── .env.local                   # NEXT_PUBLIC_BACKEND_URL
β”‚
└── backend/           # FastAPI + SQLAlchemy
    β”œβ”€β”€ app/
    β”‚   β”œβ”€β”€ main.py       # FastAPI app, CORS, endpoints
    β”‚   β”œβ”€β”€ database.py   # SQLAlchemy engine + session
    β”‚   β”œβ”€β”€ models.py     # EmotionLog ORM model
    β”‚   └── schemas.py    # Pydantic schemas
    β”œβ”€β”€ requirements.txt
    β”œβ”€β”€ run.py            # Start with: python run.py
    └── .env.example      # Copy to .env and fill DATABASE_URL

Getting Started

1. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
venv\Scripts\activate          # Windows
# source venv/bin/activate     # macOS/Linux

# Install dependencies
pip install -r requirements.txt

# Configure database
copy .env.example .env
# Edit .env β†’ set DATABASE_URL to your Neon PostgreSQL connection string

# Start the server
python run.py
# β†’ http://localhost:8000
# β†’ Swagger UI: http://localhost:8000/docs

2. Frontend Setup

cd frontend

# Install dependencies (already done if you just cloned)
npm install

# Start development server
npm run dev
# β†’ http://localhost:3000

Environment Variables

Frontend (frontend/.env.local)

NEXT_PUBLIC_BACKEND_URL=http://localhost:8000

Backend (backend/.env)

DATABASE_URL=postgresql://user:password@your-neon-host.neon.tech/facerecog?sslmode=require

How It Works

  1. Camera – react-webcam accesses your device camera at up to 60 FPS.
  2. AI Model – MediaPipe Face Landmarker WASM model is downloaded from CDN and runs entirely in the browser.
  3. Classification – 8 key blendshapes are scored to classify: Happy, Sad, Angry, Surprised, Neutral.
  4. Smoothing – A 5-frame moving average prevents rapid flickering.
  5. Logging – Every 10 seconds, the mode emotion is POSTed to the backend without blocking the video loop.
  6. Database – FastAPI saves logs to Neon PostgreSQL via SQLAlchemy.

API Endpoints

Method Path Description
GET / Health check
POST /api/logs Log emotion entry
GET /api/logs List all logs
DELETE /api/logs Clear all logs

Interactive docs at: http://localhost:8000/docs