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