Spaces:
Sleeping
Sleeping
File size: 12,429 Bytes
8579cdc | 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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🚁 DroneAgent Chatbot</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.chat-container {
width: 90%;
max-width: 800px;
height: 80vh;
background: white;
border-radius: 20px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-header {
background: linear-gradient(135deg, #4CAF50, #45a049);
color: white;
padding: 20px;
text-align: center;
font-size: 1.2em;
font-weight: bold;
}
.chat-messages {
flex: 1;
padding: 20px;
overflow-y: auto;
background: #f8f9fa;
}
.message {
margin-bottom: 15px;
padding: 12px 16px;
border-radius: 18px;
max-width: 80%;
word-wrap: break-word;
white-space: pre-wrap;
}
.user-message {
background: #007bff;
color: white;
margin-left: auto;
text-align: right;
}
.bot-message {
background: #e9ecef;
color: #333;
margin-right: auto;
}
.chat-input-container {
padding: 20px;
background: white;
border-top: 1px solid #dee2e6;
display: flex;
gap: 10px;
}
.chat-input {
flex: 1;
padding: 12px 16px;
border: 2px solid #dee2e6;
border-radius: 25px;
outline: none;
font-size: 14px;
transition: border-color 0.3s;
}
.chat-input:focus {
border-color: #007bff;
}
.send-button {
padding: 12px 24px;
background: #007bff;
color: white;
border: none;
border-radius: 25px;
cursor: pointer;
font-weight: bold;
transition: background 0.3s;
}
.send-button:hover {
background: #0056b3;
}
.send-button:disabled {
background: #6c757d;
cursor: not-allowed;
}
.examples {
margin-bottom: 20px;
padding: 15px;
background: #fff3cd;
border-radius: 10px;
border-left: 4px solid #ffc107;
}
.examples h3 {
margin-bottom: 10px;
color: #856404;
}
.example-button {
display: inline-block;
margin: 5px;
padding: 8px 12px;
background: #fff;
border: 1px solid #ffc107;
border-radius: 15px;
cursor: pointer;
font-size: 12px;
transition: all 0.3s;
}
.example-button:hover {
background: #ffc107;
color: white;
}
.loading {
text-align: center;
color: #6c757d;
font-style: italic;
padding: 10px;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
🚁 DroneAgent - AI Mission Planner
</div>
<div class="chat-messages" id="chatMessages">
<div class="examples">
<h3>🎯 Try these examples:</h3>
<div class="example-button" onclick="sendExample('Go straight 100m from 16.047, 108.206')">
Go straight 100m from 16.047, 108.206
</div>
<div class="example-button" onclick="sendExample('Survey mission at 16.047, 108.206')">
Survey mission at 16.047, 108.206
</div>
<div class="example-button" onclick="sendExample('Patrol route at 16.047, 108.206 at 80m altitude')">
Patrol route at 16.047, 108.206 at 80m altitude
</div>
<div class="example-button" onclick="sendExample('Photography flight at 16.047, 108.206')">
Photography flight at 16.047, 108.206
</div>
<div class="example-button" onclick="sendExample('Hi, I want to take photos of my building')">
Hi, I want to take photos of my building
</div>
</div>
</div>
<div class="chat-input-container">
<input type="text" class="chat-input" id="chatInput" placeholder="Type your message... (e.g., 'Survey mission at 16.047, 108.206')" onkeypress="handleKeyPress(event)">
<button class="send-button" id="sendButton" onclick="sendMessage()">Send</button>
<button class="send-button" style="background: #28a745;" onclick="getLatestMission()">📁 Latest</button>
<button class="send-button" style="background: #17a2b8;" onclick="getDroneStatus()">🚁 Drone</button>
</div>
</div>
<script>
const chatMessages = document.getElementById('chatMessages');
const chatInput = document.getElementById('chatInput');
const sendButton = document.getElementById('sendButton');
// Add welcome message
addBotMessage("👋 Hi! I'm DroneBot, your friendly AI assistant for drone mission planning!\n\n🚁 I can help you create professional drone missions. Try one of the examples above or ask me anything about drone missions!");
function handleKeyPress(event) {
if (event.key === 'Enter') {
sendMessage();
}
}
function sendExample(text) {
chatInput.value = text;
sendMessage();
}
async function sendMessage() {
const message = chatInput.value.trim();
if (!message) return;
// Add user message
addUserMessage(message);
chatInput.value = '';
// Disable input
sendButton.disabled = true;
chatInput.disabled = true;
// Add loading message
const loadingElement = addLoadingMessage();
try {
const response = await fetch('http://localhost:8000/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: message })
});
const data = await response.json();
// Remove loading message
loadingElement.remove();
// Add bot response
let botResponse = data.ai_response || 'Sorry, I had trouble processing that request.';
// Add comprehensive status information
if (data.mission_file) {
botResponse += `\n\n📁 Mission file: ${data.mission_file}`;
}
addBotMessage(botResponse);
} catch (error) {
loadingElement.remove();
addBotMessage('❌ Error: Could not connect to DroneAgent server. Make sure the server is running on http://localhost:8000');
}
// Re-enable input
sendButton.disabled = false;
chatInput.disabled = false;
chatInput.focus();
}
function addUserMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.className = 'message user-message';
messageDiv.textContent = message;
chatMessages.appendChild(messageDiv);
scrollToBottom();
}
function addBotMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.className = 'message bot-message';
messageDiv.textContent = message;
chatMessages.appendChild(messageDiv);
scrollToBottom();
}
function addLoadingMessage() {
const loadingDiv = document.createElement('div');
loadingDiv.className = 'loading';
loadingDiv.textContent = '🤖 DroneBot is thinking...';
chatMessages.appendChild(loadingDiv);
scrollToBottom();
return loadingDiv;
}
async function getLatestMission() {
try {
const loadingElement = addLoadingMessage();
const response = await fetch('http://localhost:8000/api/latest-mission');
const data = await response.json();
loadingElement.remove();
if (data.status === 'success') {
let message = `📁 **Latest Mission Retrieved**\n\n`;
message += `**File:** ${data.filename}\n`;
message += `**Created:** ${new Date(data.created_at).toLocaleString()}\n`;
message += `**Size:** ${data.file_size} bytes\n\n`;
message += `✅ Mission plan ready for QGroundControl!`;
addBotMessage(message);
} else {
addBotMessage(`📁 ${data.message}`);
}
} catch (error) {
addBotMessage('❌ Error retrieving latest mission. Make sure the server is running.');
}
}
async function getDroneStatus() {
try {
const loadingElement = addLoadingMessage();
const response = await fetch('http://localhost:8000/drone/status');
const data = await response.json();
loadingElement.remove();
if (data.status === 'success') {
const status = data.drone_status;
const rec = data.mission_recommendations;
let message = `🚁 **Drone Status**\n\n`;
message += `🔋 Battery: ${status.batteryRemaining}% (${status.voltage.toFixed(1)}V)\n`;
message += `📡 GPS: ${status.satelite} satellites\n`;
message += `📍 Location: ${status.latitude.toFixed(4)}, ${status.longitude.toFixed(4)}\n`;
message += `🛩️ Mode: ${status.mode} | Altitude: ${status.altitude.toFixed(0)}m\n\n`;
message += `**Mission Recommendations:**\n`;
message += `• Optimal Altitude: ${rec.optimal_altitude}\n`;
message += `• Max Distance: ${rec.max_mission_distance}\n`;
message += `• Flight Time: ${rec.estimated_flight_time}\n`;
message += `• Ready: ${rec.ready_for_mission ? '✅ Yes' : '❌ No'}`;
addBotMessage(message);
} else {
addBotMessage('❌ Could not retrieve drone status.');
}
} catch (error) {
addBotMessage('❌ Error retrieving drone status. Make sure the server is running.');
}
}
function scrollToBottom() {
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Focus input on load
chatInput.focus();
</script>
</body>
</html>
|