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