Spaces:
Running
Running
add an Ai assistant for the chat box and also change the colors
Browse files- index.html +112 -60
index.html
CHANGED
|
@@ -391,16 +391,20 @@ const contactMethods = [
|
|
| 391 |
</div>
|
| 392 |
);
|
| 393 |
}
|
| 394 |
-
|
| 395 |
// Chat Page
|
| 396 |
function ChatPage({ goToPage }) {
|
| 397 |
const [messages, setMessages] = useState([
|
| 398 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
]);
|
| 400 |
-
const [newMessage, setNewMessage] = useState('');
|
| 401 |
const [isTyping, setIsTyping] = useState(false);
|
| 402 |
-
|
| 403 |
-
|
| 404 |
// Initialize animation for chat bubbles
|
| 405 |
gsap.from(".message", {
|
| 406 |
opacity: 0,
|
|
@@ -411,21 +415,20 @@ const [newMessage, setNewMessage] = useState('');
|
|
| 411 |
});
|
| 412 |
|
| 413 |
// Initialize Vanta.js background
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
feather.replace();
|
| 429 |
}, []);
|
| 430 |
|
| 431 |
const handleSendMessage = () => {
|
|
@@ -436,18 +439,38 @@ const [newMessage, setNewMessage] = useState('');
|
|
| 436 |
setMessages([...messages, userMsg]);
|
| 437 |
setNewMessage('');
|
| 438 |
setIsTyping(true);
|
| 439 |
-
//
|
| 440 |
setTimeout(() => {
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
setIsTyping(false);
|
| 452 |
}, 1500);
|
| 453 |
};
|
|
@@ -459,11 +482,17 @@ const randomResponse = botResponses[Math.floor(Math.random() * botResponses.leng
|
|
| 459 |
<div className="max-w-3xl mx-auto bg-white bg-opacity-90 rounded-xl shadow-xl overflow-hidden">
|
| 460 |
{/* Chat Header */}
|
| 461 |
<div className="bg-green-600 text-white p-4 flex items-center">
|
| 462 |
-
<div className="w-10 h-10 rounded-full bg-
|
| 463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
</div>
|
| 465 |
-
<div>
|
| 466 |
-
<h2 className="font-bold">Dr. AI - Health Assistant</h2>
|
| 467 |
<p className="text-xs opacity-80">
|
| 468 |
{isTyping ? 'Typing...' : 'Online'}
|
| 469 |
</p>
|
|
@@ -484,9 +513,15 @@ const randomResponse = botResponses[Math.floor(Math.random() * botResponses.leng
|
|
| 484 |
key={msg.id}
|
| 485 |
className={`message flex ${msg.sender === 'user' ? 'justify-end' : 'justify-start'}`}
|
| 486 |
>
|
| 487 |
-
<div
|
| 488 |
-
|
| 489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
<p>{msg.text}</p>
|
| 491 |
</div>
|
| 492 |
</div>
|
|
@@ -523,18 +558,31 @@ const randomResponse = botResponses[Math.floor(Math.random() * botResponses.leng
|
|
| 523 |
<i data-feather="send"></i>
|
| 524 |
</button>
|
| 525 |
</div>
|
| 526 |
-
|
| 527 |
-
|
|
|
|
| 528 |
Symptoms
|
| 529 |
</button>
|
| 530 |
-
<button className="text-xs bg-
|
| 531 |
Medications
|
| 532 |
</button>
|
| 533 |
-
<button className="text-xs bg-
|
| 534 |
Wellness
|
| 535 |
</button>
|
| 536 |
-
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
</div>
|
|
|
|
| 538 |
</div>
|
| 539 |
|
| 540 |
<div className="mt-8 grid grid-cols-2 md:grid-cols-4 gap-4 max-w-3xl mx-auto">
|
|
@@ -545,9 +593,9 @@ const randomResponse = botResponses[Math.floor(Math.random() * botResponses.leng
|
|
| 545 |
document.querySelector('input').focus();
|
| 546 |
}}
|
| 547 |
>
|
| 548 |
-
<div className="w-12 h-12 bg-
|
| 549 |
-
<i data-feather="alert-triangle" className="text-
|
| 550 |
-
|
| 551 |
<span className="text-sm font-medium">Symptoms</span>
|
| 552 |
</button>
|
| 553 |
<button
|
|
@@ -557,9 +605,9 @@ const randomResponse = botResponses[Math.floor(Math.random() * botResponses.leng
|
|
| 557 |
document.querySelector('input').focus();
|
| 558 |
}}
|
| 559 |
>
|
| 560 |
-
<div className="w-12 h-12 bg-
|
| 561 |
-
<i data-feather="package" className="text-
|
| 562 |
-
|
| 563 |
<span className="text-sm font-medium">Medications</span>
|
| 564 |
</button>
|
| 565 |
<button
|
|
@@ -569,20 +617,24 @@ const randomResponse = botResponses[Math.floor(Math.random() * botResponses.leng
|
|
| 569 |
document.querySelector('input').focus();
|
| 570 |
}}
|
| 571 |
>
|
| 572 |
-
<div className="w-12 h-12 bg-
|
| 573 |
-
<i data-feather="moon" className="text-
|
| 574 |
-
|
| 575 |
<span className="text-sm font-medium">Sleep Help</span>
|
| 576 |
</button>
|
| 577 |
-
<button
|
| 578 |
className="bg-white bg-opacity-90 hover:bg-opacity-100 rounded-lg p-4 shadow-md flex flex-col items-center transition-all hover:shadow-lg"
|
| 579 |
-
onClick={() =>
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
</div>
|
| 587 |
</div>
|
| 588 |
</div>
|
|
|
|
| 391 |
</div>
|
| 392 |
);
|
| 393 |
}
|
|
|
|
| 394 |
// Chat Page
|
| 395 |
function ChatPage({ goToPage }) {
|
| 396 |
const [messages, setMessages] = useState([
|
| 397 |
+
{
|
| 398 |
+
id: 1,
|
| 399 |
+
text: "Hello! I'm Dr. AI, your personal health assistant. What health concerns can I help with today?",
|
| 400 |
+
sender: 'bot',
|
| 401 |
+
isAI: true
|
| 402 |
+
}
|
| 403 |
]);
|
| 404 |
+
const [newMessage, setNewMessage] = useState('');
|
| 405 |
const [isTyping, setIsTyping] = useState(false);
|
| 406 |
+
const [aiMode, setAiMode] = useState(true);
|
| 407 |
+
useEffect(() => {
|
| 408 |
// Initialize animation for chat bubbles
|
| 409 |
gsap.from(".message", {
|
| 410 |
opacity: 0,
|
|
|
|
| 415 |
});
|
| 416 |
|
| 417 |
// Initialize Vanta.js background
|
| 418 |
+
VANTA.GLOBE({
|
| 419 |
+
el: "#chat-background",
|
| 420 |
+
mouseControls: true,
|
| 421 |
+
touchControls: true,
|
| 422 |
+
gyroControls: false,
|
| 423 |
+
minHeight: 200.00,
|
| 424 |
+
minWidth: 200.00,
|
| 425 |
+
scale: 1.00,
|
| 426 |
+
scaleMobile: 1.00,
|
| 427 |
+
color: aiMode ? 0x7c3aed : 0x3b82f6,
|
| 428 |
+
backgroundColor: 0xf8fafc,
|
| 429 |
+
size: 0.8
|
| 430 |
+
});
|
| 431 |
+
feather.replace();
|
|
|
|
| 432 |
}, []);
|
| 433 |
|
| 434 |
const handleSendMessage = () => {
|
|
|
|
| 439 |
setMessages([...messages, userMsg]);
|
| 440 |
setNewMessage('');
|
| 441 |
setIsTyping(true);
|
| 442 |
+
// AI response generation
|
| 443 |
setTimeout(() => {
|
| 444 |
+
let response;
|
| 445 |
+
if (aiMode) {
|
| 446 |
+
// Enhanced AI responses
|
| 447 |
+
const responses = {
|
| 448 |
+
symptoms: "Based on your symptoms, I'm analyzing possible conditions. Please provide more details like duration and severity.",
|
| 449 |
+
medications: "I can check for drug interactions. Please list all medications including dosage.",
|
| 450 |
+
wellness: "For better wellness, I recommend a balanced diet, regular exercise and 7-9 hours of sleep. Would you like a personalized plan?"
|
| 451 |
+
};
|
| 452 |
+
|
| 453 |
+
if (newMessage.toLowerCase().includes('symptom') || newMessage.toLowerCase().includes('pain')) {
|
| 454 |
+
response = responses.symptoms;
|
| 455 |
+
} else if (newMessage.toLowerCase().includes('medication') || newMessage.toLowerCase().includes('pill')) {
|
| 456 |
+
response = responses.medications;
|
| 457 |
+
} else if (newMessage.toLowerCase().includes('wellness') || newMessage.toLowerCase().includes('health')) {
|
| 458 |
+
response = responses.wellness;
|
| 459 |
+
} else {
|
| 460 |
+
response = "I'm analyzing your query with my medical knowledge base. Please provide any additional details that might help.";
|
| 461 |
+
}
|
| 462 |
+
} else {
|
| 463 |
+
// Standard support responses
|
| 464 |
+
response = "Thank you for your message. A support representative will respond shortly.";
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
const botMsg = {
|
| 468 |
+
id: messages.length + 2,
|
| 469 |
+
text: response,
|
| 470 |
+
sender: 'bot',
|
| 471 |
+
isAI: aiMode
|
| 472 |
+
};
|
| 473 |
+
setMessages(prev => [...prev, botMsg]);
|
| 474 |
setIsTyping(false);
|
| 475 |
}, 1500);
|
| 476 |
};
|
|
|
|
| 482 |
<div className="max-w-3xl mx-auto bg-white bg-opacity-90 rounded-xl shadow-xl overflow-hidden">
|
| 483 |
{/* Chat Header */}
|
| 484 |
<div className="bg-green-600 text-white p-4 flex items-center">
|
| 485 |
+
<div className="w-10 h-10 rounded-full bg-indigo-500 flex items-center justify-center mr-3">
|
| 486 |
+
<i data-feather={aiMode ? "cpu" : "headphones"} className="text-white"></i>
|
| 487 |
+
</div>
|
| 488 |
+
<div>
|
| 489 |
+
<h2 className="font-bold">Dr. AI - Health Assistant</h2>
|
| 490 |
+
<div className="flex items-center">
|
| 491 |
+
<div className={`w-2 h-2 rounded-full mr-1 ${aiMode ? 'bg-green-400' : 'bg-gray-400'}`}></div>
|
| 492 |
+
<span className="text-xs opacity-80">
|
| 493 |
+
{aiMode ? 'AI Mode' : 'Support Mode'}
|
| 494 |
+
</span>
|
| 495 |
</div>
|
|
|
|
|
|
|
| 496 |
<p className="text-xs opacity-80">
|
| 497 |
{isTyping ? 'Typing...' : 'Online'}
|
| 498 |
</p>
|
|
|
|
| 513 |
key={msg.id}
|
| 514 |
className={`message flex ${msg.sender === 'user' ? 'justify-end' : 'justify-start'}`}
|
| 515 |
>
|
| 516 |
+
<div
|
| 517 |
+
className={`max-w-xs md:max-w-md rounded-lg p-3 ${
|
| 518 |
+
msg.sender === 'user'
|
| 519 |
+
? 'bg-indigo-100 text-gray-800 rounded-br-none'
|
| 520 |
+
: msg.isAI
|
| 521 |
+
? 'bg-purple-100 text-gray-800 rounded-bl-none'
|
| 522 |
+
: 'bg-blue-100 text-gray-800 rounded-bl-none'
|
| 523 |
+
}`}
|
| 524 |
+
>
|
| 525 |
<p>{msg.text}</p>
|
| 526 |
</div>
|
| 527 |
</div>
|
|
|
|
| 558 |
<i data-feather="send"></i>
|
| 559 |
</button>
|
| 560 |
</div>
|
| 561 |
+
<div className="mt-2 flex justify-between items-center">
|
| 562 |
+
<div className="flex space-x-2">
|
| 563 |
+
<button className="text-xs bg-indigo-100 text-indigo-800 px-2 py-1 rounded-full">
|
| 564 |
Symptoms
|
| 565 |
</button>
|
| 566 |
+
<button className="text-xs bg-indigo-100 text-indigo-800 px-2 py-1 rounded-full">
|
| 567 |
Medications
|
| 568 |
</button>
|
| 569 |
+
<button className="text-xs bg-indigo-100 text-indigo-800 px-2 py-1 rounded-full">
|
| 570 |
Wellness
|
| 571 |
</button>
|
| 572 |
+
</div>
|
| 573 |
+
<button
|
| 574 |
+
onClick={() => setAiMode(!aiMode)}
|
| 575 |
+
className="text-xs flex items-center px-2 py-1 rounded-full transition-colors"
|
| 576 |
+
style={{
|
| 577 |
+
backgroundColor: aiMode ? 'rgba(99, 102, 241, 0.1)' : 'rgba(156, 163, 175, 0.1)',
|
| 578 |
+
color: aiMode ? 'rgb(99, 102, 241)' : 'rgb(156, 163, 175)'
|
| 579 |
+
}}
|
| 580 |
+
>
|
| 581 |
+
<i data-feather={aiMode ? "cpu" : "user"} className="w-3 h-3 mr-1"></i>
|
| 582 |
+
{aiMode ? 'AI Mode' : 'Support'}
|
| 583 |
+
</button>
|
| 584 |
</div>
|
| 585 |
+
</div>
|
| 586 |
</div>
|
| 587 |
|
| 588 |
<div className="mt-8 grid grid-cols-2 md:grid-cols-4 gap-4 max-w-3xl mx-auto">
|
|
|
|
| 593 |
document.querySelector('input').focus();
|
| 594 |
}}
|
| 595 |
>
|
| 596 |
+
<div className="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-2">
|
| 597 |
+
<i data-feather="alert-triangle" className="text-indigo-500"></i>
|
| 598 |
+
</div>
|
| 599 |
<span className="text-sm font-medium">Symptoms</span>
|
| 600 |
</button>
|
| 601 |
<button
|
|
|
|
| 605 |
document.querySelector('input').focus();
|
| 606 |
}}
|
| 607 |
>
|
| 608 |
+
<div className="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mb-2">
|
| 609 |
+
<i data-feather="package" className="text-purple-500"></i>
|
| 610 |
+
</div>
|
| 611 |
<span className="text-sm font-medium">Medications</span>
|
| 612 |
</button>
|
| 613 |
<button
|
|
|
|
| 617 |
document.querySelector('input').focus();
|
| 618 |
}}
|
| 619 |
>
|
| 620 |
+
<div className="w-12 h-12 bg-pink-100 rounded-full flex items-center justify-center mb-2">
|
| 621 |
+
<i data-feather="moon" className="text-pink-500"></i>
|
| 622 |
+
</div>
|
| 623 |
<span className="text-sm font-medium">Sleep Help</span>
|
| 624 |
</button>
|
| 625 |
+
<button
|
| 626 |
className="bg-white bg-opacity-90 hover:bg-opacity-100 rounded-lg p-4 shadow-md flex flex-col items-center transition-all hover:shadow-lg"
|
| 627 |
+
onClick={() => {
|
| 628 |
+
setAiMode(false);
|
| 629 |
+
setNewMessage("I need to speak with a human support representative.");
|
| 630 |
+
document.querySelector('input').focus();
|
| 631 |
+
}}
|
| 632 |
+
>
|
| 633 |
+
<div className="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-2">
|
| 634 |
+
<i data-feather="help-circle" className="text-indigo-500"></i>
|
| 635 |
+
</div>
|
| 636 |
+
<span className="text-sm font-medium">Human Support</span>
|
| 637 |
+
</button>
|
| 638 |
</div>
|
| 639 |
</div>
|
| 640 |
</div>
|