Spaces:
Sleeping
Sleeping
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 | |
| ```bash | |
| 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 | |
| ```bash | |
| 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` | |