Spaces:
Runtime error
Runtime error
Testimony Adekoya
commited on
Commit
Β·
2999575
1
Parent(s):
19f420a
Pushing the code for huggingface deployment again
Browse files
README.md
CHANGED
|
@@ -1,31 +1,127 @@
|
|
| 1 |
---
|
| 2 |
-
title: Drive Paddy
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
tags:
|
| 9 |
-
- streamlit
|
| 10 |
pinned: false
|
| 11 |
-
short_description: Drive Paddy is a drowsiness detection buddy for drivers, utilizing OpenCV and a fine-tuned CNN model to monitor driver alertness.
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
* **Deep Learning Model:** Fine-tuned Convolutional Neural Network (CNN)
|
| 29 |
-
* **Application Framework:** Streamlit (as indicated by project metadata `tags`)
|
| 30 |
-
* **Containerization:** Docker (as indicated by project metadata `sdk`)
|
| 31 |
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Drive Paddy - Drowsiness Detection
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
app_file: drive_paddy/main.py
|
|
|
|
|
|
|
| 8 |
pinned: false
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
+
<div align="center">
|
| 12 |
+
<img src="https://em-content.zobj.net/source/samsung/380/automobile_1f697.png" alt="Car Emoji" width="100"/>
|
| 13 |
+
<h1>Drive Paddy</h1>
|
| 14 |
+
<p><strong>Your AI-Powered Drowsiness Detection Assistant</strong></p>
|
| 15 |
+
|
| 16 |
+
<p>
|
| 17 |
+
<a href="#"><img alt="License" src="https://img.shields.io/badge/License-MIT-yellow.svg"/></a>
|
| 18 |
+
<a href="#"><img alt="Python" src="https://img.shields.io/badge/Python-3.9+-blue.svg"/></a>
|
| 19 |
+
<a href="#"><img alt="Streamlit" src="https://img.shields.io/badge/Streamlit-1.35.0-red.svg"/></a>
|
| 20 |
+
</p>
|
| 21 |
|
| 22 |
+
<p>A real-time system to enhance driver safety by detecting signs of drowsiness using advanced computer vision and deep learning techniques.</p>
|
| 23 |
|
| 24 |
+
<!-- *A GIF of the application running would be highly effective here.*
|
| 25 |
+
|
| 26 |
+
**[GIF of Drive Paddy in Action]** -->
|
| 27 |
+
</div>
|
| 28 |
|
| 29 |
+
---
|
| 30 |
+
|
| 31 |
+
## π Features
|
| 32 |
+
|
| 33 |
+
Drive Paddy employs a sophisticated, multi-faceted approach to ensure robust and reliable drowsiness detection.
|
| 34 |
+
|
| 35 |
+
- **Hybrid Detection Strategy**: Combines traditional computer vision techniques with deep learning for superior accuracy.
|
| 36 |
+
- **Multi-Signal Analysis**:
|
| 37 |
+
- **π Eye Closure Detection**: Measures Eye Aspect Ratio (EAR) to detect prolonged blinks and microsleeps.
|
| 38 |
+
- **π₯± Yawn Detection**: Measures Mouth Aspect Ratio (MAR) to identify driver fatigue.
|
| 39 |
+
- **π΄ Head Pose Estimation**: Tracks head pitch and yaw to detect nodding off or inattentiveness.
|
| 40 |
+
- **π§ Deep Learning Inference**: Utilizes a pre-trained `EfficientNet-B7` model for an additional layer of analysis.
|
| 41 |
+
- **Dynamic AI-Powered Alerts**: Leverages the Gemini API and gTTS for clear, context-aware voice alerts that are played directly in the user's browser.
|
| 42 |
+
- **Low-Light Warning**: Automatically detects poor lighting conditions that could affect detection accuracy and notifies the user.
|
| 43 |
+
- **Web-Based Interface**: Built with Streamlit for a user-friendly and accessible experience.
|
| 44 |
+
- **Configurable**: All detection thresholds and model weights can be easily tuned via a central `config.yaml` file.
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## π οΈ How It Works
|
| 49 |
+
|
| 50 |
+
The system processes a live video feed from the user's webcam and calculates a weighted "drowsiness score" based on the configured detection strategy.
|
| 51 |
+
|
| 52 |
+
1. **Video Processing**: The `streamlit-webrtc` component captures the camera feed.
|
| 53 |
+
2. **Concurrent Detection**: The `HybridProcessor` runs two pipelines in parallel for maximum efficiency:
|
| 54 |
+
- **Geometric Analysis (`geometric.py`)**: Uses `MediaPipe` to detect facial landmarks and calculate EAR, MAR, and head position in real-time.
|
| 55 |
+
- **Deep Learning Inference (`cnn_model.py`)**: Uses a `dlib` face detector and a `PyTorch` model to classify the driver's state. This is run on a set interval to optimize performance.
|
| 56 |
+
3. **Scoring & Alerting**: The results are weighted and combined. If the score exceeds a set threshold, an alert is triggered.
|
| 57 |
+
4. **AI Voice Generation**: The `GeminiAlertSystem` sends a prompt to the Gemini API, generates a unique voice message using `gTTS`, and sends the audio data to the browser for playback.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## π Setup and Installation
|
| 62 |
+
|
| 63 |
+
Follow these steps to set up and run Drive Paddy on your local machine.
|
| 64 |
+
|
| 65 |
+
### 1. Clone the Repository
|
| 66 |
+
|
| 67 |
+
```bash
|
| 68 |
+
git clone https://github.com/<dev-tyta>/drive-paddy.git
|
| 69 |
+
cd drive-paddy
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### 2. Set Up a Virtual Environment (Recommended)
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
python -m venv venv
|
| 76 |
+
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### 3. Install Dependencies
|
| 80 |
+
|
| 81 |
+
Install all required Python packages from the `requirements.txt` file.
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
pip install -r requirements.txt
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### 4. Download the CNN Model
|
| 88 |
+
|
| 89 |
+
Run the provided script to download the pre-trained model from Hugging Face Hub.
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
python download_model.py
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### 5. Configure Environment Variables
|
| 96 |
+
|
| 97 |
+
Create a `.env` file by copying the example file.
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
cp .env.example .env
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
Now, open the `.env` file and add your Gemini API key:
|
| 104 |
+
|
| 105 |
+
```
|
| 106 |
+
GEMINI_API_KEY="YOUR_GEMINI_API_KEY_GOES_HERE"
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
## βοΈ Configuration
|
| 112 |
+
|
| 113 |
+
The application's behavior can be fine-tuned via the `config.yaml` file. You can adjust detection thresholds, change the detection strategy (`geometric`, `cnn_model`, or `hybrid`), and modify the weights for the hybrid scoring system without touching the source code.
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## βΆοΈ Usage
|
| 118 |
+
|
| 119 |
+
To run the application, execute the following command from the root directory of the project:
|
| 120 |
|
| 121 |
+
```bash
|
| 122 |
+
streamlit run drive_paddy/main.py
|
| 123 |
+
```
|
| 124 |
|
| 125 |
+
Open your web browser and navigate to the local URL provided by Streamlit (usually `http://localhost:8501`).
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
---
|