#!/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()