Yaswanth56 commited on
Commit
7e92e60
Β·
verified Β·
1 Parent(s): 3e009ae

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +13 -44
static/script.js CHANGED
@@ -1,48 +1,17 @@
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  function sendMessage() {
2
  const input = document.getElementById('user-input').value;
3
+ if (input) {
4
+ const userMessage = document.createElement('div');
5
+ userMessage.classList.add('chat-message', 'user');
6
+ userMessage.innerHTML = `<p>${input}</p>`;
7
+ document.getElementById('chatbot').appendChild(userMessage);
8
+ document.getElementById('user-input').value = '';
9
+
10
+ // Placeholder for Gradio Bot response (Add API call later)
11
+ const botMessage = document.createElement('div');
12
+ botMessage.classList.add('chat-message', 'bot');
13
+ botMessage.innerHTML = `<p>Bot is processing: ${input}...</p>`;
14
+ document.getElementById('chatbot').appendChild(botMessage);
15
+ document.getElementById('chatbot').scrollTop = document.getElementById('chatbot').scrollHeight;
16
  }
17
  }