Blhasn-Sehli/Drowsy
Real-time drowsiness detection system using AI, FastAPI backend, and React Native mobile app
Drowsy โ Drowsiness & Emotion Detection App
Real-time drowsiness and emotion detection system using a phone camera, a FastAPI backend, and a React Native (Expo) mobile app with Firebase integration.
๐ง Prerequisites
| Tool | Version | Install |
|---|---|---|
| Python | 3.11.x | https://www.python.org/downloads/release/python-3119/ (check "Add to PATH") |
| Node.js | 18+ | https://nodejs.org/ |
| Expo Go | Latest | Install on your phone from App Store / Google Play |
| DroidCam | Latest | App on phone + PC client from https://www.dev47apps.com/ |
Your phone and PC must be connected to the same WiFi network.
๐ Step-by-Step Setup
1. Clone the repo
git clone https://github.com/Blhasn-Sehli/Drowsy.git
cd Drowsy2. Find your PC's local IP address
You'll need this IP for both the backend camera and the frontend API connection.
Windows:
ipconfig
Look for Wireless LAN adapter WiFi โ IPv4 Address (e.g. 192.168.1.XX)
macOS / Linux:
ifconfig | grep "inet "
Write down your IP, you'll use it in steps 4 and 5 below.
3. Setup Firebase credentials
Backend (Back/)
You need a firebaseKey.json file in the Back/ folder. Ask the project owner to send it to you, or create your own:
- Go to Firebase Console โ Project Settings โ Service Accounts
- Click "Generate new private key"
- Save the file as
Back/firebaseKey.json
A template is provided at Back/firebaseKey.example.json for reference.
Frontend (front/)
Create a file front/.env with your Firebase config:
EXPO_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
EXPO_PUBLIC_FIREBASE_DATABASE_URL=https://your_project-default-rtdb.firebaseio.com
EXPO_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.firebasestorage.app
EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
EXPO_PUBLIC_FIREBASE_APP_ID=your_app_idAsk the project owner for the real values, or get them from Firebase Console โ Project Settings โ General โ Your apps.
4. Configure the camera source (Backend)
Edit Back/config.py and set your phone's DroidCam IP:
CAMERA_INDEX: str = "http://YOUR_PHONE_IP:4747/video"Example: if DroidCam shows 192.168.1.50, set:
CAMERA_INDEX: str = "http://192.168.1.50:4747/video"Or use "0" to use your PC's built-in webcam.
5. โ ๏ธ Configure the API URL (Frontend) โ IMPORTANT
Edit front/services/api.ts and change the IP to your PC's IP (from step 2):
const API_BASE_URL = 'http://YOUR_PC_IP:8000';Example: if your PC's IP is 192.168.1.25:
const API_BASE_URL = 'http://192.168.1.25:8000';This is the most common issue! The app won't connect if this IP doesn't match your PC.
6. Start the Backend
cd BackWindows: Double-click setup.bat (first time only), then run.bat
Or manually:
python -m venv venv
source venv/Scripts/activate # Windows
# source venv/bin/activate # macOS/Linux
pip install -r requirements.txt
python main.pyYou should see:
โ
Server: http://0.0.0.0:8000
โ
Continuous detection started
Test it: open http://localhost:8000/health in your browser.
7. Start the Frontend
cd front
npm install
npm startThen scan the QR code with Expo Go on your phone.
๐ Quick Checklist
- Python 3.11 installed
- Node.js 18+ installed
- Phone and PC on the same WiFi
-
Back/firebaseKey.jsonexists with real credentials -
front/.envexists with Firebase config -
Back/config.pyโ camera IP matches your phone's DroidCam IP -
front/services/api.tsโ API URL matches your PC's WiFi IP - Backend running (
python main.py) - Frontend running (
npm start)
โ Troubleshooting
| Problem | Fix |
|---|---|
| Frontend can't connect to backend | Make sure the IP in front/services/api.ts matches your PC's WiFi IP (ipconfig) |
| Camera not working | Check Back/config.py โ DroidCam IP must be correct, and phone + PC on same WiFi |
| Firebase errors | Make sure Back/firebaseKey.json and front/.env have real credentials |
python not found |
Reinstall Python 3.11 with "Add to PATH" checked |
| Port 8000 in use | Kill the process using it, or change the port in Back/main.py |
| Expo app can't connect | Make sure your phone is on the same WiFi as your PC |
๐ Project Structure
Drowsy/
โโโ Back/ # Python FastAPI backend
โ โโโ main.py # Server entry point
โ โโโ detector.py # Drowsiness detection (EAR/MAR)
โ โโโ emotion_detector.py# Emotion detection (DeepFace)
โ โโโ firebase_service.py# Firebase integration
โ โโโ config.py # Camera URL & thresholds โ EDIT THIS
โ โโโ firebaseKey.json # Firebase credentials (not in git)
โ โโโ requirements.txt # Python dependencies
โ
โโโ front/ # React Native (Expo) app
โ โโโ app/ # Screens (tabs)
โ โโโ components/ # UI components
โ โโโ services/
โ โ โโโ api.ts # Backend API connection โ EDIT THIS
โ โ โโโ firebase.ts # Firebase realtime listener
โ โโโ hooks/ # Custom React hooks
โ โโโ .env # Firebase config (not in git)
โ โโโ package.json
โ
โโโ README.md # โ You are here