Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- 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
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|