#!/usr/bin/env python3 """ Launch script for the Agricultural Analysis Tool Simple launcher with menu options for different modes. """ import sys import os import subprocess import warnings warnings.filterwarnings('ignore') def print_banner(): """Print the application banner.""" print("🚜" + "="*70) print(" AGRICULTURAL ANALYSIS TOOL - STATION DE KERGUΓ‰HENNEC") print(" Hackathon CRA - RΓ©duction des herbicides") print("="*73) print() def check_dependencies(): """Check if all required dependencies are installed.""" print("πŸ”§ Checking dependencies...") try: import pandas, numpy, matplotlib, seaborn, sklearn, gradio, plotly from data_loader import AgriculturalDataLoader from analysis_tools import AgriculturalAnalyzer print("βœ… All dependencies are installed") return True except ImportError as e: print(f"❌ Missing dependency: {e}") print("Please run: pip install -r requirements.txt") return False def test_data_loading(): """Test if data can be loaded successfully.""" print("πŸ“Š Testing data loading...") try: from data_loader import AgriculturalDataLoader loader = AgriculturalDataLoader() df = loader.load_all_files() print(f"βœ… Successfully loaded {len(df):,} records") return True except Exception as e: print(f"❌ Data loading failed: {e}") return False def launch_gradio(): """Launch the Gradio interface.""" print("πŸš€ Launching Gradio interface...") print("πŸ“± The app will open in your web browser") print("🌐 Access at: http://localhost:7860") print("⏹️ Press Ctrl+C to stop the server") print() try: from gradio_app import create_gradio_app app = create_gradio_app() app.launch( server_name="0.0.0.0", server_port=7860, share=False, debug=False, quiet=False ) except KeyboardInterrupt: print("\nπŸ›‘ Server stopped by user") except Exception as e: print(f"❌ Failed to launch Gradio: {e}") def launch_mcp_server(): """Launch the MCP server.""" print("πŸ€– Launching MCP Server...") print("πŸ“‘ Server will run in Model Context Protocol mode") print("⏹️ Press Ctrl+C to stop the server") print() try: subprocess.run([sys.executable, "mcp_server.py"]) except KeyboardInterrupt: print("\nπŸ›‘ MCP Server stopped by user") except Exception as e: print(f"❌ Failed to launch MCP server: {e}") def run_demo(): """Run the demonstration.""" print("🎬 Running comprehensive demo...") print() try: subprocess.run([sys.executable, "demo.py"]) except Exception as e: print(f"❌ Demo failed: {e}") def show_menu(): """Show the main menu.""" print("πŸ“‹ Choose an option:") print() print("1. 🌐 Launch Gradio Web Interface (Recommended)") print("2. πŸ€– Launch MCP Server") print("3. 🎬 Run Demo") print("4. πŸ”§ Check System Status") print("5. ❌ Exit") print() def main(): """Main launcher function.""" print_banner() # Check dependencies first if not check_dependencies(): return # Test data loading if not test_data_loading(): return print("🎯 System ready!") print() while True: show_menu() try: choice = input("Enter your choice (1-5): ").strip() if choice == "1": print() launch_gradio() print() elif choice == "2": print() launch_mcp_server() print() elif choice == "3": print() run_demo() print() input("Press Enter to continue...") print() elif choice == "4": print() print("πŸ” System Status Check:") check_dependencies() test_data_loading() print() input("Press Enter to continue...") print() elif choice == "5": print() print("πŸ‘‹ Goodbye! Thank you for using the Agricultural Analysis Tool") break else: print("❌ Invalid choice. Please enter a number between 1-5.") print() except KeyboardInterrupt: print("\n\nπŸ‘‹ Goodbye! Thank you for using the Agricultural Analysis Tool") break except Exception as e: print(f"❌ Error: {e}") print() if __name__ == "__main__": main()