Spaces:
Running
Running
can you put an ai thats solely focuused on anything emergency and helping into the chatbot on the website?
Browse files- index.html +109 -55
index.html
CHANGED
|
@@ -221,31 +221,44 @@
|
|
| 221 |
waveSpeed: 0.75,
|
| 222 |
zoom: 0.8
|
| 223 |
});
|
| 224 |
-
|
| 225 |
-
// Chat functionality
|
| 226 |
const chatContainer = document.getElementById('chat-container');
|
| 227 |
const userInput = document.getElementById('user-input');
|
| 228 |
const sendBtn = document.getElementById('send-btn');
|
| 229 |
const emergencyBtn = document.getElementById('emergency-btn');
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
}
|
| 248 |
-
}
|
| 249 |
|
| 250 |
function addMessage(sender, message) {
|
| 251 |
const messageDiv = document.createElement('div');
|
|
@@ -262,58 +275,99 @@
|
|
| 262 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 263 |
}
|
| 264 |
|
| 265 |
-
|
| 266 |
-
input = input.toLowerCase();
|
| 267 |
-
|
| 268 |
-
for (const keyword in responses) {
|
| 269 |
-
if (input.includes(keyword)) {
|
| 270 |
-
return responses[keyword];
|
| 271 |
-
}
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
return responses['default'];
|
| 275 |
-
}
|
| 276 |
-
|
| 277 |
-
sendBtn.addEventListener('click', () => {
|
| 278 |
const message = userInput.value.trim();
|
| 279 |
if (message) {
|
| 280 |
addMessage('user', message);
|
| 281 |
userInput.value = '';
|
| 282 |
|
| 283 |
-
//
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
-
//
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
}, 500);
|
| 301 |
-
}, 1000);
|
| 302 |
}
|
| 303 |
});
|
| 304 |
-
|
| 305 |
-
userInput.addEventListener('keypress', (e) => {
|
| 306 |
if (e.key === 'Enter') {
|
| 307 |
sendBtn.click();
|
| 308 |
}
|
| 309 |
});
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
emergencyBtn.addEventListener('click', () => {
|
| 312 |
-
addMessage('assistant', '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
});
|
| 314 |
-
|
| 315 |
// Initialize feather icons
|
| 316 |
feather.replace();
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
</body>
|
| 319 |
</html>
|
|
|
|
| 221 |
waveSpeed: 0.75,
|
| 222 |
zoom: 0.8
|
| 223 |
});
|
| 224 |
+
// Chat functionality with AI integration
|
|
|
|
| 225 |
const chatContainer = document.getElementById('chat-container');
|
| 226 |
const userInput = document.getElementById('user-input');
|
| 227 |
const sendBtn = document.getElementById('send-btn');
|
| 228 |
const emergencyBtn = document.getElementById('emergency-btn');
|
| 229 |
|
| 230 |
+
// Emergency AI chatbot
|
| 231 |
+
async function getAIResponse(userMessage) {
|
| 232 |
+
try {
|
| 233 |
+
const response = await fetch('https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill', {
|
| 234 |
+
method: 'POST',
|
| 235 |
+
headers: {
|
| 236 |
+
'Authorization': 'Bearer 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',
|
| 237 |
+
'Content-Type': 'application/json'
|
| 238 |
+
},
|
| 239 |
+
body: JSON.stringify({
|
| 240 |
+
inputs: {
|
| 241 |
+
text: `You are an emergency response AI assistant. The user says: "${userMessage}". Provide concise emergency guidance, first aid steps, and safety instructions. Prioritize life-saving actions and official recommendations.`,
|
| 242 |
+
parameters: {
|
| 243 |
+
max_length: 200,
|
| 244 |
+
temperature: 0.7,
|
| 245 |
+
do_sample: true
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
})
|
| 249 |
+
});
|
| 250 |
+
|
| 251 |
+
if (!response.ok) {
|
| 252 |
+
throw new Error('AI service unavailable');
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
const data = await response.json();
|
| 256 |
+
return data.generated_text || "I can't provide specific medical advice. Please call emergency services immediately if this is a life-threatening situation.";
|
| 257 |
+
} catch (error) {
|
| 258 |
+
console.error('AI Error:', error);
|
| 259 |
+
return "Emergency response AI is currently unavailable. For immediate help, please call 911 or your local emergency number.";
|
| 260 |
}
|
| 261 |
+
}
|
| 262 |
|
| 263 |
function addMessage(sender, message) {
|
| 264 |
const messageDiv = document.createElement('div');
|
|
|
|
| 275 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 276 |
}
|
| 277 |
|
| 278 |
+
sendBtn.addEventListener('click', async () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
const message = userInput.value.trim();
|
| 280 |
if (message) {
|
| 281 |
addMessage('user', message);
|
| 282 |
userInput.value = '';
|
| 283 |
|
| 284 |
+
// Show typing indicator
|
| 285 |
+
const typingIndicator = document.createElement('div');
|
| 286 |
+
typingIndicator.classList.add('mb-4', 'max-w-xs', 'rounded-lg', 'p-4', 'bg-red-100', 'mr-auto');
|
| 287 |
+
typingIndicator.innerHTML = '<p class="text-gray-500">Emergency AI is responding...</p>';
|
| 288 |
+
chatContainer.appendChild(typingIndicator);
|
| 289 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 290 |
+
|
| 291 |
+
try {
|
| 292 |
+
const aiResponse = await getAIResponse(message);
|
| 293 |
+
chatContainer.removeChild(typingIndicator);
|
| 294 |
+
addMessage('assistant', aiResponse);
|
| 295 |
|
| 296 |
+
// Always remind to call 911 if serious
|
| 297 |
+
if (message.toLowerCase().includes('emergency') ||
|
| 298 |
+
message.toLowerCase().includes('help') ||
|
| 299 |
+
message.toLowerCase().includes('911')) {
|
| 300 |
+
setTimeout(() => {
|
| 301 |
+
addMessage('assistant', '⚠️ If this is a life-threatening emergency, please call 911 immediately while waiting for further instructions.');
|
| 302 |
+
}, 500);
|
| 303 |
+
}
|
| 304 |
+
} catch (error) {
|
| 305 |
+
chatContainer.removeChild(typingIndicator);
|
| 306 |
+
addMessage('assistant', "I'm having trouble connecting to the emergency AI. Please call 911 if you need immediate help.");
|
| 307 |
+
}
|
|
|
|
|
|
|
| 308 |
}
|
| 309 |
});
|
| 310 |
+
userInput.addEventListener('keypress', async (e) => {
|
|
|
|
| 311 |
if (e.key === 'Enter') {
|
| 312 |
sendBtn.click();
|
| 313 |
}
|
| 314 |
});
|
| 315 |
|
| 316 |
+
// Emergency protocols database
|
| 317 |
+
const emergencyProtocols = {
|
| 318 |
+
"medical": [
|
| 319 |
+
"Call 911 immediately for life-threatening conditions",
|
| 320 |
+
"Check ABCs (Airway, Breathing, Circulation)",
|
| 321 |
+
"Perform CPR if trained and needed",
|
| 322 |
+
"Stop any bleeding with direct pressure",
|
| 323 |
+
"Do not move injured person unless in danger"
|
| 324 |
+
],
|
| 325 |
+
"fire": [
|
| 326 |
+
"Get out immediately and call 911",
|
| 327 |
+
"Stay low to avoid smoke inhalation",
|
| 328 |
+
"Test doors for heat before opening",
|
| 329 |
+
"Use stairs, never elevators",
|
| 330 |
+
"Stop-drop-roll if clothes catch fire"
|
| 331 |
+
],
|
| 332 |
+
"natural disaster": [
|
| 333 |
+
"Follow official evacuation orders",
|
| 334 |
+
"Move to higher ground for floods",
|
| 335 |
+
"Take cover under sturdy furniture for earthquakes",
|
| 336 |
+
"Go to interior room for tornadoes",
|
| 337 |
+
"Have emergency supplies ready"
|
| 338 |
+
]
|
| 339 |
+
};
|
| 340 |
emergencyBtn.addEventListener('click', () => {
|
| 341 |
+
addMessage('assistant', '🚨 EMERGENCY PROTOCOL ACTIVATED 🚨');
|
| 342 |
+
setTimeout(() => {
|
| 343 |
+
addMessage('assistant', '1. Call 911 immediately if you can');
|
| 344 |
+
setTimeout(() => {
|
| 345 |
+
addMessage('assistant', '2. Your location is being determined (enable location services)');
|
| 346 |
+
setTimeout(() => {
|
| 347 |
+
addMessage('assistant', '3. Stay on the line with emergency services');
|
| 348 |
+
setTimeout(() => {
|
| 349 |
+
addMessage('assistant', '4. Follow all instructions from dispatcher');
|
| 350 |
+
setTimeout(() => {
|
| 351 |
+
addMessage('assistant', '5. Help is on the way - stay calm and safe');
|
| 352 |
+
}, 1000);
|
| 353 |
+
}, 1000);
|
| 354 |
+
}, 1000);
|
| 355 |
+
}, 1000);
|
| 356 |
+
}, 500);
|
| 357 |
});
|
|
|
|
| 358 |
// Initialize feather icons
|
| 359 |
feather.replace();
|
| 360 |
+
|
| 361 |
+
// Add disclaimer
|
| 362 |
+
setTimeout(() => {
|
| 363 |
+
const disclaimer = document.createElement('div');
|
| 364 |
+
disclaimer.classList.add('mt-4', 'p-4', 'bg-yellow-100', 'rounded-lg', 'text-sm', 'text-gray-700');
|
| 365 |
+
disclaimer.innerHTML = `
|
| 366 |
+
<p><strong>Important:</strong> This AI assistant provides general emergency guidance only and is not a substitute for professional medical help. Always call 911 for life-threatening emergencies.</p>
|
| 367 |
+
`;
|
| 368 |
+
chatContainer.appendChild(disclaimer);
|
| 369 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 370 |
+
}, 3000);
|
| 371 |
+
</script>
|
| 372 |
</body>
|
| 373 |
</html>
|