-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_web.py
More file actions
142 lines (123 loc) · 4.44 KB
/
start_web.py
File metadata and controls
142 lines (123 loc) · 4.44 KB
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
#!/usr/bin/env python3
"""
DeepDrone Web Interface Launcher
Starts both the FastAPI backend and serves the React frontend
"""
import os
import sys
import subprocess
import time
import webbrowser
from pathlib import Path
def check_dependencies():
"""Check if required dependencies are installed"""
try:
import fastapi
import uvicorn
print("✅ Backend dependencies found")
except ImportError as e:
print(f"❌ Missing backend dependencies: {e}")
print("Please run: pip install -r requirements.txt")
return False
return True
def check_frontend():
"""Check if frontend is built"""
frontend_build = Path("frontend/build")
if frontend_build.exists():
print("✅ Frontend build found")
return True
else:
print("⚠️ Frontend not built")
return False
def check_npm():
"""Check if npm is available"""
try:
subprocess.run(["npm", "--version"], capture_output=True, check=True, shell=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
def build_frontend():
"""Build the React frontend"""
print("🔨 Building frontend...")
frontend_dir = Path("frontend")
if not frontend_dir.exists():
print("❌ Frontend directory not found")
return False
# Check if npm is available
if not check_npm():
print("❌ npm not found in PATH")
print("💡 Please ensure Node.js and npm are installed and available in your PATH")
print("💡 You may need to restart your terminal or activate the correct environment")
print("💡 Alternatively, you can manually build the frontend:")
print(" cd frontend")
print(" npm install")
print(" npm run build")
return False
# Check if node_modules exists
node_modules = frontend_dir / "node_modules"
if not node_modules.exists():
print("📦 Installing frontend dependencies...")
try:
subprocess.run(["npm", "install"], cwd=frontend_dir, check=True, shell=True)
except subprocess.CalledProcessError:
print("❌ Failed to install frontend dependencies")
print("Please make sure Node.js and npm are installed")
return False
except FileNotFoundError:
print("❌ npm command not found")
print("Please make sure Node.js and npm are installed and in your PATH")
return False
# Build the frontend
try:
subprocess.run(["npm", "run", "build"], cwd=frontend_dir, check=True, shell=True)
print("✅ Frontend built successfully")
return True
except subprocess.CalledProcessError:
print("❌ Failed to build frontend")
return False
except FileNotFoundError:
print("❌ npm command not found")
print("Please make sure Node.js and npm are installed and in your PATH")
return False
def start_server():
"""Start the FastAPI server"""
print("🚀 Starting DeepDrone Web Server...")
print("📡 Server will be available at: http://localhost:8000")
print("🎮 Web interface will open automatically")
print("\nPress Ctrl+C to stop the server\n")
# Wait a moment then open browser
def open_browser():
time.sleep(2)
webbrowser.open("http://localhost:8000")
import threading
browser_thread = threading.Thread(target=open_browser)
browser_thread.daemon = True
browser_thread.start()
# Start the server
try:
import uvicorn
uvicorn.run("web_api:app", host="0.0.0.0", port=8000, reload=True)
except KeyboardInterrupt:
print("\n🛑 Server stopped")
except Exception as e:
print(f"❌ Server error: {e}")
def main():
"""Main launcher function"""
print("🚁 DeepDrone Web Interface Launcher")
print("=" * 40)
# Check backend dependencies
if not check_dependencies():
sys.exit(1)
# Check and build frontend if needed
if not check_frontend():
print("🔨 Frontend needs to be built")
if input("Build frontend now? (y/n): ").lower().startswith('y'):
if not build_frontend():
print("❌ Cannot start without frontend")
sys.exit(1)
else:
print("⚠️ Starting without frontend (API only)")
# Start the server
start_server()
if __name__ == "__main__":
main()