Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| DroneAgent - Advanced Flight Management System. | |
| """ | |
| import os | |
| import asyncio | |
| import uvicorn | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from dotenv import load_dotenv | |
| from src.api.routes import router | |
| from src.core.websocket_server import start_websocket_server | |
| load_dotenv() | |
| async def lifespan(app: FastAPI): | |
| """Application lifespan manager.""" | |
| # Startup | |
| print("🚀 Starting DroneAgent with Flight Management System") | |
| # Start WebSocket server for real-time notifications | |
| asyncio.create_task(start_websocket_server()) | |
| print("✅ All background services started") | |
| yield | |
| # Shutdown | |
| print("🛑 Shutting down DroneAgent services") | |
| # Initialize FastAPI with lifespan | |
| app = FastAPI( | |
| title="DroneAgent", | |
| description="Advanced AI-powered drone mission planner with real-time flight management", | |
| version="3.0.0", | |
| lifespan=lifespan | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routes | |
| app.include_router(router) | |
| async def root(): | |
| """API information.""" | |
| return { | |
| "name": "DroneAgent", | |
| "version": "3.0.0", | |
| "status": "operational", | |
| "features": [ | |
| "🧠 Gemini-first AI mission planning", | |
| "📡 Real-time telemetry processing", | |
| "🎯 Intelligent flight management", | |
| "📱 WebSocket notifications", | |
| "⏸️ Dynamic mission control", | |
| "🛡️ AI-powered safety checks", | |
| "🗺️ QGroundControl compatibility" | |
| ], | |
| "endpoints": { | |
| "chat": "POST /chat - Conversational AI for mission planning", | |
| "flight_confirm": "POST /flight/confirm - Confirm and start tracking a flight", | |
| "flight_pause": "POST /flight/pause - Pause active flight mission", | |
| "flight_cancel": "POST /flight/cancel - Cancel active flight mission", | |
| "flight_update": "POST /flight/update - Update mission waypoints during flight", | |
| "flight_status": "GET /flight/status/{drone_id} - Get intelligent flight status", | |
| "flight_missions": "GET /flight/missions - Get all active missions", | |
| "flight_telemetry": "POST /flight/telemetry - Real-time telemetry updates", | |
| "drone_status": "GET /drone/status - Monitor current drone status", | |
| "websocket": "ws://localhost:8001 - Real-time flight notifications" | |
| }, | |
| "websocket_notifications": [ | |
| "flight_confirmed - Mission tracking started", | |
| "waypoint_completed - Waypoint reached with AI analysis", | |
| "flight_paused - Mission paused with timeout", | |
| "mission_updated - Dynamic route changes", | |
| "emergency - Critical conditions detected", | |
| "mission_completed - All waypoints reached" | |
| ], | |
| "examples": [ | |
| "Go straight 100m from 16.047, 108.206", | |
| "Survey mission at 16.047, 108.206", | |
| "Patrol route at 16.047, 108.206 at 80m altitude", | |
| "Photography flight at 16.047, 108.206" | |
| ] | |
| } | |
| if __name__ == "__main__": | |
| port = int(os.environ.get('PORT', 8000)) | |
| uvicorn.run(app, host="0.0.0.0", port=port, reload=False) | |