File size: 10,728 Bytes
0469d65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/usr/bin/env python3
"""
Create distributable package for SafetyMaster Pro
Creates a ZIP file with all necessary components for easy sharing
"""

import os
import shutil
import zipfile
from pathlib import Path
import datetime

def create_distribution_package():
    """Create a complete distribution package."""
    print("๐Ÿ“ฆ Creating SafetyMaster Pro Distribution Package")
    print("=" * 50)
    
    # Create distribution folder
    timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
    dist_name = f"SafetyMasterPro_v1.0_{timestamp}"
    dist_folder = f"{dist_name}"
    
    if os.path.exists(dist_folder):
        shutil.rmtree(dist_folder)
    
    os.makedirs(dist_folder)
    print(f"๐Ÿ“ Created distribution folder: {dist_folder}")
    
    # Files to include in distribution
    files_to_copy = [
        'web_interface.py',
        'safety_detector.py',
        'camera_manager.py',
        'config.py',
        'requirements.txt',
        'README.md',
        'high_fps_test.py',
        'test_improved_detection.py',
        'test_camera.py',
    ]
    
    # Copy Python files
    print("๐Ÿ“„ Copying Python files...")
    for file in files_to_copy:
        if os.path.exists(file):
            shutil.copy2(file, dist_folder)
            print(f"   โœ… {file}")
        else:
            print(f"   โš ๏ธ  {file} not found")
    
    # Copy model files
    print("๐Ÿค– Copying AI model files...")
    model_files = list(Path('.').glob('*.pt'))
    for model_file in model_files:
        shutil.copy2(model_file, dist_folder)
        print(f"   โœ… {model_file.name}")
    
    # Copy templates folder
    if os.path.exists('templates'):
        print("๐ŸŽจ Copying templates...")
        shutil.copytree('templates', os.path.join(dist_folder, 'templates'))
        print("   โœ… templates/ folder")
    
    # Copy test files
    test_files = [
        'test_websocket.html',
        'demo.py',
        'demo_simple.py',
    ]
    
    print("๐Ÿงช Copying test files...")
    for file in test_files:
        if os.path.exists(file):
            shutil.copy2(file, dist_folder)
            print(f"   โœ… {file}")
    
    # Create startup scripts
    create_startup_scripts(dist_folder)
    
    # Create user guide
    create_user_guide(dist_folder)
    
    # Create ZIP package
    zip_filename = f"{dist_name}.zip"
    print(f"๐Ÿ—œ๏ธ  Creating ZIP package: {zip_filename}")
    
    with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
        for root, dirs, files in os.walk(dist_folder):
            for file in files:
                file_path = os.path.join(root, file)
                arc_name = os.path.relpath(file_path, dist_folder)
                zipf.write(file_path, arc_name)
    
    # Get package size
    zip_size = os.path.getsize(zip_filename) / (1024 * 1024)  # MB
    
    print(f"\n๐ŸŽ‰ Package created successfully!")
    print(f"๐Ÿ“ฆ Package: {zip_filename}")
    print(f"๐Ÿ“ Size: {zip_size:.1f} MB")
    print(f"๐Ÿ“ Folder: {dist_folder}/")
    
    return zip_filename, dist_folder

def create_startup_scripts(dist_folder):
    """Create easy startup scripts for users."""
    print("๐Ÿš€ Creating startup scripts...")
    
    # Windows batch script
    windows_script = '''@echo off
title SafetyMaster Pro
echo.
echo  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—
echo  โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•šโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•”โ•
echo  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—     โ–ˆโ–ˆโ•‘    โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• 
echo  โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•”โ•โ•โ•     โ–ˆโ–ˆโ•‘     โ•šโ–ˆโ–ˆโ•”โ•  
echo  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•‘      โ–ˆโ–ˆโ•‘   
echo  โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•     โ•šโ•โ•โ•โ•โ•โ•โ•   โ•šโ•โ•      โ•šโ•โ•   
echo.
echo                    MASTER PRO v1.0
echo           Real-time AI Safety Equipment Detection
echo.
echo Checking Python installation...
python --version >nul 2>&1
if errorlevel 1 (
    echo โŒ ERROR: Python is not installed or not in PATH
    echo Please install Python 3.8+ from https://python.org
    echo.
    pause
    exit /b 1
)

echo โœ… Python found!
echo.
echo Installing dependencies (first time only)...
pip install -r requirements.txt >nul 2>&1

echo.
echo ๐Ÿš€ Starting SafetyMaster Pro...
echo ๐ŸŒ Web interface will open at: http://localhost:8080
echo ๐Ÿ“น Make sure your camera is connected
echo.
echo Press Ctrl+C to stop the application
echo.

python web_interface.py
pause
'''
    
    # Unix shell script
    unix_script = '''#!/bin/bash
clear
echo
echo "  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—"
echo "  โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•šโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•”โ•"
echo "  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—     โ–ˆโ–ˆโ•‘    โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• "
echo "  โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•”โ•โ•โ•     โ–ˆโ–ˆโ•‘     โ•šโ–ˆโ–ˆโ•”โ•  "
echo "  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•‘      โ–ˆโ–ˆโ•‘   "
echo "  โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•     โ•šโ•โ•โ•โ•โ•โ•โ•   โ•šโ•โ•      โ•šโ•โ•   "
echo
echo "                    MASTER PRO v1.0"
echo "           Real-time AI Safety Equipment Detection"
echo

echo "Checking Python installation..."
if ! command -v python3 &> /dev/null; then
    echo "โŒ ERROR: Python 3 is not installed"
    echo "Please install Python 3.8+ from your package manager"
    exit 1
fi

echo "โœ… Python found!"
echo
echo "Installing dependencies (first time only)..."
pip3 install -r requirements.txt > /dev/null 2>&1

echo
echo "๐Ÿš€ Starting SafetyMaster Pro..."
echo "๐ŸŒ Web interface will open at: http://localhost:8080"
echo "๐Ÿ“น Make sure your camera is connected"
echo
echo "Press Ctrl+C to stop the application"
echo

python3 web_interface.py
'''
    
    # Write scripts
    with open(os.path.join(dist_folder, 'START_SafetyMaster.bat'), 'w') as f:
        f.write(windows_script)
    
    with open(os.path.join(dist_folder, 'START_SafetyMaster.sh'), 'w') as f:
        f.write(unix_script)
    
    # Make shell script executable
    os.chmod(os.path.join(dist_folder, 'START_SafetyMaster.sh'), 0o755)
    
    print("   โœ… START_SafetyMaster.bat (Windows)")
    print("   โœ… START_SafetyMaster.sh (Unix/Linux/Mac)")

def create_user_guide(dist_folder):
    """Create a comprehensive user guide."""
    print("๐Ÿ“– Creating user guide...")
    
    user_guide = '''# SafetyMaster Pro v1.0 - User Guide

## ๐Ÿš€ Quick Start

### Windows Users:
1. Double-click `START_SafetyMaster.bat`
2. Wait for installation to complete
3. Open your web browser to: http://localhost:8080

### Mac/Linux Users:
1. Open terminal in this folder
2. Run: `./START_SafetyMaster.sh`
3. Open your web browser to: http://localhost:8080

## ๐Ÿ“‹ Requirements

- **Python 3.8+** (Download from https://python.org)
- **Webcam or USB camera**
- **Internet connection** (for first-time model download)
- **4GB RAM minimum** (8GB recommended)

## ๐ŸŽฏ Features

- **Real-time PPE Detection**: Hard hats, safety vests, face masks
- **High-Performance**: Optimized for 30+ FPS
- **Web Interface**: Modern, responsive dashboard
- **Violation Alerts**: Real-time safety compliance monitoring
- **Multi-Platform**: Windows, Mac, Linux support

## ๐Ÿ”ง Manual Installation

If the automatic scripts don't work:

```bash
# Install dependencies
pip install -r requirements.txt

# Run the application
python web_interface.py
```

## ๐ŸŽฎ Controls

- **Start Monitoring**: Click "Start Monitoring" in the web interface
- **Stop Monitoring**: Click "Stop Monitoring"
- **Fullscreen**: Click the fullscreen button for immersive view
- **Settings**: Adjust camera source and detection settings

## ๐ŸŽจ Interface Features

- **Live Video Feed**: Real-time camera with AI detection overlays
- **Statistics Panel**: People count, compliance rate, violations
- **Violation Log**: Real-time alerts with timestamps
- **FPS Counter**: Performance monitoring
- **Responsive Design**: Works on desktop, tablet, mobile

## ๐Ÿ” Detection Classes

The AI model detects:
- โœ… **Hard Hat** (Green boxes when worn)
- โœ… **Safety Vest** (Yellow boxes when worn)  
- โœ… **Face Mask** (Blue boxes when worn)
- โŒ **Violations** (Red person boxes when equipment missing)

## โšก Performance Tips

- **Close other applications** for better performance
- **Use good lighting** for better detection accuracy
- **Position camera** to clearly see people and equipment
- **Stable internet** for model downloads

## ๐Ÿ› Troubleshooting

### Camera Issues:
- Check camera permissions
- Try different camera source (0, 1, 2...)
- Restart the application

### Performance Issues:
- Close other applications
- Lower camera resolution
- Check system requirements

### Installation Issues:
- Update Python to latest version
- Run as administrator (Windows)
- Check internet connection

## ๐Ÿ“ž Support

For technical support or questions:
- Check the README.md file
- Review error messages in the console
- Ensure all requirements are met

## ๐Ÿ”’ Privacy

- All processing is done locally on your computer
- No data is sent to external servers
- Camera feed stays on your device

---

**SafetyMaster Pro v1.0** - Professional AI-powered safety monitoring
'''
    
    with open(os.path.join(dist_folder, 'USER_GUIDE.md'), 'w') as f:
        f.write(user_guide)
    
    print("   โœ… USER_GUIDE.md")

def main():
    """Main packaging process."""
    try:
        zip_file, dist_folder = create_distribution_package()
        
        print(f"\n๐Ÿ“‹ Distribution Package Summary:")
        print(f"   ๐Ÿ“ฆ ZIP File: {zip_file}")
        print(f"   ๐Ÿ“ Folder: {dist_folder}/")
        print(f"   ๐Ÿš€ Startup: START_SafetyMaster.bat/.sh")
        print(f"   ๐Ÿ“– Guide: USER_GUIDE.md")
        
        print(f"\nโœ… Ready to share!")
        print(f"   Users can simply:")
        print(f"   1. Extract the ZIP file")
        print(f"   2. Run the startup script")
        print(f"   3. Open http://localhost:8080")
        
    except Exception as e:
        print(f"โŒ Error creating package: {e}")

if __name__ == "__main__":
    main()