Sujith2121's picture
Create app.py
f818817 verified
# app.py
import streamlit as st
st.set_page_config(
page_title="Driver Drowsiness Detection Dashboard",
layout="wide",
initial_sidebar_state="expanded"
)
st.title("πŸ‘οΈ Driver Drowsiness Detection Dashboard")
st.markdown("""
Welcome to the **Driver Drowsiness Detection Dashboard**, a real-time monitoring system designed to enhance road safety by detecting signs of fatigue and alerting drivers before it's too late.
This dashboard is powered by a FastAPI backend and a Streamlit frontend, and includes:
- **Live webcam-based drowsiness detection**
- **Real-time logging of events like eye closure and yawning**
- **Visual analytics including pie charts and tabular history**
- **Backend integration for scalable deployment and data tracking**
---
### πŸš— Why Drowsiness Detection Matters
Driver fatigue is a leading cause of road accidents. This tool uses facial landmarks to monitor eye aspect ratio (EAR) and mouth aspect ratio (MAR) to detect signs of drowsiness and yawning. When thresholds are crossed, alerts are triggered and events are logged.
---
### 🧭 How to Use This Dashboard
Use the sidebar to navigate between the following pages:
- **Drowsiness Detection**: Activate your webcam and run the detection algorithm locally. Events are automatically sent to the backend.
- **Stats Pie Chart**: View a breakdown of detected events (e.g., yawns, eye closures, no face).
- **Event History Table**: Explore a timestamped log of all detection events in tabular format.
---
### πŸ› οΈ Backend Integration
All detection events are sent to a FastAPI backend hosted on Hugging Face Spaces:
`https://sujith2121-drowsiness-detection-backend.hf.space`
Endpoints include:
- `POST /detect` β€” log a new detection event
- `GET /events` β€” retrieve all logged events
- `GET /stats` β€” get summary statistics for visualization
---
### πŸ“¦ Technologies Used
- **Streamlit** for frontend UI
- **FastAPI** for backend API
- **MediaPipe** for facial landmark detection
- **OpenCV** for webcam access and frame processing
- **Plotly** for interactive charts
- **Hugging Face Spaces** for deployment
---
### πŸ‘¨β€πŸ’» Developer Notes
This project is modular and scalable. You can easily extend it to include:
- SMS/email alerts
- Cloud-based logging
- Multi-user dashboards
- Integration with vehicle systems
""")