Yaswanth56 commited on
Commit
1ceb38a
Β·
verified Β·
1 Parent(s): 3c16630

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +44 -4
static/script.js CHANGED
@@ -1,8 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  function sendMessage() {
2
  const input = document.getElementById('user-input').value;
3
- if (input) {
4
- // Send message to Flask server (This would be integrated with Gradio's response mechanism)
5
- // Placeholder for now
6
- alert('Message sent: ' + input);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  }
 
 
8
  }
 
1
+ let chatHistory = []; // Keep track of chat history
2
+
3
+ // Function to append new message to the chat
4
+ function appendMessage(message, sender) {
5
+ const chatbotDiv = document.getElementById('chatbot');
6
+ const messageDiv = document.createElement('div');
7
+ messageDiv.classList.add('chat-message', `${sender}-message`);
8
+ messageDiv.innerHTML = message;
9
+ chatHistory.push({ sender, message });
10
+ chatbotDiv.appendChild(messageDiv);
11
+ chatbotDiv.scrollTop = chatbotDiv.scrollHeight; // Scroll to bottom
12
+ }
13
+
14
+ // Function to send user message
15
  function sendMessage() {
16
  const input = document.getElementById('user-input').value;
17
+ if (input.trim()) {
18
+ appendMessage(`You: ${input} 🎀`, 'user');
19
+ document.getElementById('user-input').value = ''; // Clear input field
20
+
21
+ // Simulate bot response
22
+ setTimeout(() => botReply(input), 1000);
23
+ }
24
+ }
25
+
26
+ // Function to simulate the chatbot's reply
27
+ function botReply(userInput) {
28
+ let response = "";
29
+
30
+ // Fun, interactive bot responses with emojis
31
+ if (/yes|yeah/i.test(userInput)) {
32
+ response = "Yay! πŸ₯³ Let's start customizing your meal! 🍽️";
33
+ } else if (/vegetarian/i.test(userInput)) {
34
+ response = "Yum, vegetarian food is so tasty! πŸ₯¦πŸ… What do you want as your main ingredient? πŸ†";
35
+ } else if (/non-vegetarian/i.test(userInput)) {
36
+ response = "Mmmm... Non-veg food incoming! πŸ—πŸŸ What type of meat are you feeling today? πŸ₯©";
37
+ } else if (/chicken/i.test(userInput)) {
38
+ response = "Nice choice! πŸ— You can go for a spicy chicken curry or grilled chicken! πŸ˜‹";
39
+ } else if (/fish/i.test(userInput)) {
40
+ response = "Fish it is! 🐟 Grilled salmon or spicy fish curry? 🐠";
41
+ } else if (/cart/i.test(userInput)) {
42
+ response = "You got it! πŸ›’ Your cart is ready to go!";
43
+ } else {
44
+ response = "Hmm... I'm not sure about that. Can you ask something else? πŸ€”";
45
  }
46
+
47
+ appendMessage(response, 'bot');
48
  }