#!/usr/bin/env python3 """ Startup script for Smart Farm Photo Keyword Tagging AI Web UI """ import os import sys import subprocess import time import webbrowser from pathlib import Path def check_dependencies(): """Check if required dependencies are installed""" print("šŸ” Checking dependencies...") required_packages = ['fastapi', 'uvicorn', 'python-multipart'] missing_packages = [] for package in required_packages: try: __import__(package.replace('-', '_')) print(f" āœ… {package}") except ImportError: missing_packages.append(package) print(f" āŒ {package}") if missing_packages: print(f"\nšŸ“¦ Installing missing packages: {', '.join(missing_packages)}") try: subprocess.check_call([ sys.executable, "-m", "pip", "install" ] + missing_packages) print("āœ… Dependencies installed successfully!") except subprocess.CalledProcessError as e: print(f"āŒ Failed to install dependencies: {e}") return False return True def start_server(): """Start the FastAPI server""" print("\nšŸš€ Starting Smart Farm AI Web UI...") print("=" * 50) # Change to project directory project_dir = Path(__file__).parent os.chdir(project_dir) # Start the server try: import uvicorn print("🌐 Server starting at: http://localhost:8000") print("šŸ“š API Documentation: http://localhost:8000/docs") print("šŸ“‹ Alternative Docs: http://localhost:8000/redoc") print("\nā¹ļø Press Ctrl+C to stop the server") print("=" * 50) # Open browser after a short delay def open_browser(): time.sleep(2) try: webbrowser.open("http://localhost:8000") print("🌐 Opened web browser automatically") except: print("🌐 Please open http://localhost:8000 in your browser") import threading browser_thread = threading.Thread(target=open_browser) browser_thread.daemon = True browser_thread.start() # Start the server uvicorn.run( "src.api.main:app", host="0.0.0.0", port=8000, reload=False, log_level="info" ) except KeyboardInterrupt: print("\n\nšŸ›‘ Server stopped by user") except Exception as e: print(f"\nāŒ Error starting server: {e}") print("\nTroubleshooting:") print("1. Make sure you're in the project directory") print("2. Check that all dependencies are installed: pip install -r requirements.txt") print("3. Verify Python version is 3.8+") def main(): """Main function""" print("🚜 Smart Farm Photo Keyword Tagging AI") print("🌐 Professional Web Interface") print("=" * 50) # Check dependencies if not check_dependencies(): print("\nāŒ Dependency check failed. Please install requirements manually:") print("pip install fastapi uvicorn python-multipart") return # Start server start_server() if __name__ == "__main__": main()