File size: 4,947 Bytes
7ca901a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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()