Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Real-time Fleet Resource Optimization Simulator Launcher | |
| Simple launcher script for the comprehensive fleet optimization system | |
| """ | |
| import sys | |
| import os | |
| import subprocess | |
| import time | |
| from pathlib import Path | |
| def check_dependencies(): | |
| """Check if required dependencies are installed""" | |
| required_packages = [ | |
| 'pandas', 'numpy', 'plotly', 'gradio', 'requests', | |
| 'google-generativeai', 'aiohttp' | |
| ] | |
| missing_packages = [] | |
| for package in required_packages: | |
| try: | |
| __import__(package.replace('-', '_')) | |
| except ImportError: | |
| missing_packages.append(package) | |
| if missing_packages: | |
| print("โ Missing required packages:") | |
| for package in missing_packages: | |
| print(f" - {package}") | |
| print("\n๐ฆ Install missing packages with:") | |
| print(" pip install -r requirements.txt") | |
| return False | |
| print("โ All required packages are installed") | |
| return True | |
| def test_api_connections(): | |
| """Test API connections""" | |
| print("๐ Testing API connections...") | |
| try: | |
| from realtime_api_client import test_api_connections | |
| test_api_connections() | |
| print("โ API connections successful") | |
| return True | |
| except Exception as e: | |
| print(f"โ ๏ธ API connection issues: {e}") | |
| print(" The simulator will continue with simulated data") | |
| return False | |
| def launch_demo(): | |
| """Launch the comprehensive demo interface""" | |
| print("๐ Launching Real-time Fleet Optimization Demo...") | |
| try: | |
| from demo_realtime_simulator import main | |
| main() | |
| except KeyboardInterrupt: | |
| print("\n๐ Demo stopped by user") | |
| except Exception as e: | |
| print(f"โ Error launching demo: {e}") | |
| return False | |
| return True | |
| def launch_optimizer(): | |
| """Launch the real-time optimizer only""" | |
| print("๐ Launching Real-time Fleet Optimizer...") | |
| try: | |
| from realtime_fleet_optimizer import create_realtime_fleet_interface | |
| demo = create_realtime_fleet_interface() | |
| demo.launch(share=True, server_name="0.0.0.0", server_port=7860) | |
| except KeyboardInterrupt: | |
| print("\n๐ Optimizer stopped by user") | |
| except Exception as e: | |
| print(f"โ Error launching optimizer: {e}") | |
| return False | |
| return True | |
| def show_menu(): | |
| """Show the main menu""" | |
| print("\n" + "="*60) | |
| print("๐ Real-time Fleet Resource Optimization Simulator") | |
| print("="*60) | |
| print("Choose an option:") | |
| print("1. ๐ฎ Launch Full Demo Interface (Recommended)") | |
| print("2. ๐ Launch Real-time Optimizer Only") | |
| print("3. ๐ Test API Connections") | |
| print("4. ๐ View Analytics Dashboard") | |
| print("5. โ Show Help") | |
| print("6. ๐ช Exit") | |
| print("="*60) | |
| def show_help(): | |
| """Show help information""" | |
| print("\n๐ Help Information") | |
| print("-" * 40) | |
| print("๐ฎ Full Demo Interface:") | |
| print(" - Comprehensive demo with multiple scenarios") | |
| print(" - Rush hour, weather impact, AI optimization demos") | |
| print(" - Interactive testing and validation") | |
| print(" - Access at: http://localhost:7860") | |
| print() | |
| print("๐ Real-time Optimizer:") | |
| print(" - Core fleet optimization system") | |
| print(" - Live dashboard with real-time data") | |
| print(" - AI-powered vehicle allocation") | |
| print(" - Access at: http://localhost:7860") | |
| print() | |
| print("๐ API Connections:") | |
| print(" - Test Google Maps, OpenWeather, and Gemini APIs") | |
| print(" - Verify API keys and connectivity") | |
| print(" - Check rate limiting and caching") | |
| print() | |
| print("๐ Analytics Dashboard:") | |
| print(" - Performance metrics and trends") | |
| print(" - Historical data analysis") | |
| print(" - Export capabilities") | |
| print() | |
| print("๐ง Configuration:") | |
| print(" - API keys are pre-configured") | |
| print(" - Fleet size: 50 vehicles (configurable)") | |
| print(" - Update interval: 30 seconds") | |
| print(" - AI optimization: Enabled by default") | |
| def main(): | |
| """Main launcher function""" | |
| print("๐ Real-time Fleet Resource Optimization Simulator") | |
| print("Initializing...") | |
| # Check dependencies | |
| if not check_dependencies(): | |
| sys.exit(1) | |
| # Test API connections | |
| api_status = test_api_connections() | |
| while True: | |
| show_menu() | |
| try: | |
| choice = input("\nEnter your choice (1-6): ").strip() | |
| if choice == '1': | |
| launch_demo() | |
| elif choice == '2': | |
| launch_optimizer() | |
| elif choice == '3': | |
| test_api_connections() | |
| elif choice == '4': | |
| print("๐ Analytics Dashboard") | |
| print(" Run the demo or optimizer to collect analytics data") | |
| print(" Analytics are automatically collected during simulation") | |
| elif choice == '5': | |
| show_help() | |
| elif choice == '6': | |
| print("๐ Goodbye!") | |
| break | |
| else: | |
| print("โ Invalid choice. Please enter 1-6.") | |
| except KeyboardInterrupt: | |
| print("\n๐ Goodbye!") | |
| break | |
| except Exception as e: | |
| print(f"โ Error: {e}") | |
| input("\nPress Enter to continue...") | |
| if __name__ == "__main__": | |
| main() | |