Update static/script.js
Browse files- static/script.js +55 -54
static/script.js
CHANGED
|
@@ -1,71 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
};
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
const
|
| 13 |
-
|
| 14 |
-
addMessage(userInput, 'user-message');
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
});
|
| 19 |
|
| 20 |
-
|
| 21 |
-
const messageDiv = document.createElement('div');
|
| 22 |
-
messageDiv.classList.add('message', className);
|
| 23 |
-
messageDiv.innerText = message;
|
| 24 |
-
document.getElementById("chat-box").appendChild(messageDiv);
|
| 25 |
-
scrollToBottom();
|
| 26 |
}
|
| 27 |
|
| 28 |
-
function
|
| 29 |
-
const
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
-
function
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
function getChatbotReply(userInput) {
|
| 40 |
-
// Simulating a basic conversation
|
| 41 |
-
if (userInput.toLowerCase().includes('hello') || userInput.toLowerCase().includes('hi')) {
|
| 42 |
-
return "Hello! How can I help you today?";
|
| 43 |
-
} else if (userInput.toLowerCase().includes('menu')) {
|
| 44 |
-
return "Sure! What type of food are you looking for? Vegan, Vegetarian, Non-Vegetarian, or Spicy?";
|
| 45 |
} else {
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
}
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
-
function
|
| 51 |
-
let
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
} else if (userInput.toLowerCase().includes('non-vegetarian')) {
|
| 58 |
-
userPreference = 'non_vegetarian';
|
| 59 |
-
} else if (userInput.toLowerCase().includes('spicy')) {
|
| 60 |
-
userPreference = 'spicy';
|
| 61 |
-
}
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
menuDiv.innerHTML = `<strong>Recommended Dishes:</strong><br>${suggestedItems.join(', ')}`;
|
| 68 |
-
} else {
|
| 69 |
-
menuDiv.innerHTML = "Sorry, I couldn't find any suggestions for that. Please specify your preference.";
|
| 70 |
-
}
|
| 71 |
}
|
|
|
|
| 1 |
+
const dishes = {
|
| 2 |
+
"rice": ["Biryani", "Fried Rice", "Pulao"],
|
| 3 |
+
"milk": ["Kheer", "Milkshake", "Payasam"],
|
| 4 |
+
"chicken": ["Chicken Curry", "Grilled Chicken", "Chicken Salad"],
|
| 5 |
+
"paneer": ["Paneer Butter Masala", "Paneer Tikka", "Palak Paneer"],
|
| 6 |
+
"potatoes": ["Aloo Gobi", "Aloo Tikki", "Mashed Potatoes"],
|
| 7 |
};
|
| 8 |
|
| 9 |
+
function sendMessage() {
|
| 10 |
+
const userInput = document.getElementById('user-input').value.toLowerCase();
|
| 11 |
+
if (userInput.trim() === "") return;
|
| 12 |
+
|
| 13 |
+
displayMessage(userInput, 'user');
|
| 14 |
|
| 15 |
+
const ingredients = userInput.split(' ').map(ingredient => ingredient.trim());
|
| 16 |
+
const suggestedDishes = getDishSuggestions(ingredients);
|
|
|
|
| 17 |
|
| 18 |
+
setTimeout(() => {
|
| 19 |
+
displayBotMessage(suggestedDishes);
|
| 20 |
+
}, 1000);
|
| 21 |
|
| 22 |
+
document.getElementById('user-input').value = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
+
function displayMessage(message, sender) {
|
| 26 |
+
const messageElement = document.createElement('div');
|
| 27 |
+
messageElement.classList.add('message', sender === 'bot' ? 'bot-message' : 'user-message');
|
| 28 |
+
messageElement.textContent = message;
|
| 29 |
+
document.getElementById('chatbox-body').appendChild(messageElement);
|
| 30 |
+
document.getElementById('chatbox-body').scrollTop = document.getElementById('chatbox-body').scrollHeight;
|
| 31 |
}
|
| 32 |
|
| 33 |
+
function displayBotMessage(dishes) {
|
| 34 |
+
let botMessage = 'Here are some dishes I suggest based on the ingredients you provided:\n\n';
|
| 35 |
+
if (dishes.length === 0) {
|
| 36 |
+
botMessage += 'Sorry, I couldn\'t find any dishes for the given ingredients.';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
} else {
|
| 38 |
+
dishes.forEach(dish => {
|
| 39 |
+
botMessage += `- ${dish}\n`;
|
| 40 |
+
});
|
| 41 |
}
|
| 42 |
+
|
| 43 |
+
displayMessage(botMessage, 'bot');
|
| 44 |
+
displayFoodItems(dishes);
|
| 45 |
}
|
| 46 |
|
| 47 |
+
function getDishSuggestions(ingredients) {
|
| 48 |
+
let suggestedDishes = [];
|
| 49 |
+
ingredients.forEach(ingredient => {
|
| 50 |
+
if (dishes[ingredient]) {
|
| 51 |
+
suggestedDishes = [...suggestedDishes, ...dishes[ingredient]];
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
return [...new Set(suggestedDishes)]; // Remove duplicates
|
| 55 |
+
}
|
| 56 |
|
| 57 |
+
function displayFoodItems(dishes) {
|
| 58 |
+
const foodItemsContainer = document.getElementById('food-items');
|
| 59 |
+
foodItemsContainer.innerHTML = ''; // Clear previous items
|
| 60 |
+
foodItemsContainer.style.display = dishes.length > 0 ? 'block' : 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
dishes.forEach(dish => {
|
| 63 |
+
const dishElement = document.createElement('div');
|
| 64 |
+
dishElement.textContent = dish;
|
| 65 |
+
dishElement.onclick = () => showFoodDescription(dish);
|
| 66 |
+
foodItemsContainer.appendChild(dishElement);
|
| 67 |
+
});
|
| 68 |
+
}
|
| 69 |
|
| 70 |
+
function showFoodDescription(dish) {
|
| 71 |
+
alert(`You selected: ${dish}\nHere is a brief description of ${dish}: ...`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|