File size: 3,183 Bytes
e65b3b4
f7db860
e65b3b4
 
 
e8a0692
e65b3b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7db860
e65b3b4
 
f7db860
e65b3b4
f7db860
e65b3b4
 
 
 
f7db860
e65b3b4
 
 
 
f7db860
e65b3b4
 
 
 
deefd7f
e65b3b4
 
 
 
f7db860
e65b3b4
 
f7db860
e65b3b4
f7db860
e65b3b4
f7db860
e65b3b4
 
 
 
f7db860
e65b3b4
 
 
f7db860
e65b3b4
 
 
 
 
 
 
 
72cf232
f7db860
e65b3b4
 
 
 
deefd7f
 
e65b3b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# main.py
import os
import sys
from gradio_interface import GradioWebRTCInterface
from dotenv import load_dotenv

load_dotenv()

def check_opencv_installation():
    """Check if OpenCV is properly installed with required cascades"""
    try:
        import cv2
        
        # Check for required cascade files
        cascade_files = [
            'haarcascade_frontalface_default.xml',
            'haarcascade_eye.xml',
            'haarcascade_smile.xml'
        ]
        
        missing_cascades = []
        for cascade in cascade_files:
            cascade_path = cv2.data.haarcascades + cascade
            if not os.path.exists(cascade_path):
                missing_cascades.append(cascade)
        
        if missing_cascades:
            print(f"❌ Missing OpenCV cascade files: {missing_cascades}")
            print("πŸ’‘ Please reinstall OpenCV: pip install opencv-python")
            return False
        
        print("βœ… OpenCV and required cascade files found!")
        return True
        
    except ImportError:
        print("❌ OpenCV not found. Please install: pip install opencv-python")
        return False

def check_optional_dependencies():
    """Check for optional dependencies and provide info"""
    optional_deps = {
        'mediapipe': 'Enhanced facial landmark detection',
        'google.generativeai': 'AI-powered voice alerts',
        'scipy': 'Advanced mathematical computations'
    }
    
    available = []
    missing = []
    
    for dep, description in optional_deps.items():
        try:
            __import__(dep)
            available.append(f"βœ… {dep} - {description}")
        except ImportError:
            missing.append(f"βšͺ {dep} - {description}")
    
    if available:
        print("πŸ“¦ Available optional features:")
        for item in available:
            print(f"   {item}")
    
    if missing:
        print("πŸ“¦ Optional features (install for enhanced functionality):")
        for item in missing:
            print(f"   {item}")

def main():
    """Main entry point"""
    print("πŸš— Starting AI Driver Drowsiness Detection System...")
    print("πŸ”§ Using OpenCV-based detection (no external model downloads required)")
    
    if not check_opencv_installation():
        sys.exit(1)
    
    check_optional_dependencies()
    
    print("\nπŸš€ All core requirements satisfied!")
    
    # Create and launch interface
    try:
        interface_manager = GradioWebRTCInterface()
        demo = interface_manager.create_interface()
        
        print("🌐 Launching Gradio interface...")
        print("πŸ“± The interface will be available in your browser")
        print("πŸ”— A public link will be generated for sharing")
        
        demo.launch(
            server_name="0.0.0.0",
            server_port=7860,
            share=True,
            show_error=True,
            enable_queue=True,
            max_threads=10,
            favicon_path=None
        )
        
    except Exception as e:
        print(f"❌ Error launching interface: {e}")
        print("πŸ’‘ Try running: pip install --upgrade gradio")
        sys.exit(1)

if __name__ == "__main__":
    main()