Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +5 -28
static/script.js
CHANGED
@@ -28,10 +28,7 @@ function sendMessage() {
|
|
28 |
addMessage('user', message);
|
29 |
conversation.push({ role: 'user', message: message });
|
30 |
userInput.value = '';
|
31 |
-
|
32 |
-
setTimeout(() => {
|
33 |
-
handleResponse(message);
|
34 |
-
}, 500);
|
35 |
} else {
|
36 |
console.warn('Empty message!');
|
37 |
}
|
@@ -48,27 +45,9 @@ function handleResponse(userInput) {
|
|
48 |
{ text: 'Vegetarian', class: 'green' },
|
49 |
{ text: 'Non-Vegetarian', class: 'red' }
|
50 |
];
|
51 |
-
} else if (lastMessage.includes('vegetarian')) {
|
52 |
-
botResponse =
|
53 |
-
|
54 |
-
{ text: 'Vegan', class: '' },
|
55 |
-
{ text: 'Gluten-Free', class: '' },
|
56 |
-
{ text: 'Vegetarian', class: '' },
|
57 |
-
{ text: 'Low Carb', class: '' },
|
58 |
-
{ text: 'Dairy-Free', class: '' },
|
59 |
-
{ text: 'Keto', class: '' },
|
60 |
-
{ text: 'Halal', class: '' }
|
61 |
-
];
|
62 |
-
} else if (lastMessage.includes('non-vegetarian')) {
|
63 |
-
botResponse = 'Great choice! 🍽️ We have some amazing non-vegetarian options! What\'s your dietary preference?';
|
64 |
-
options = [
|
65 |
-
{ text: 'Low Carb', class: '' },
|
66 |
-
{ text: 'Dairy-Free', class: '' },
|
67 |
-
{ text: 'Keto', class: '' },
|
68 |
-
{ text: 'Halal', class: '' }
|
69 |
-
];
|
70 |
-
} else if (lastMessage.includes('low carb') || lastMessage.includes('dairy-free') || lastMessage.includes('keto') || lastMessage.includes('halal') || lastMessage.includes('gluten-free') || lastMessage.includes('vegan') || lastMessage.includes('vegetarian')) {
|
71 |
-
fetchIngredients(lastMessage);
|
72 |
return; // Exit early to handle ingredients fetch
|
73 |
}
|
74 |
|
@@ -109,7 +88,6 @@ function displayIngredientsList(ingredients) {
|
|
109 |
return;
|
110 |
}
|
111 |
|
112 |
-
// Create or update ingredients list
|
113 |
let ingredientsList = document.querySelector('.ingredients-list');
|
114 |
if (!ingredientsList) {
|
115 |
ingredientsList = document.createElement('div');
|
@@ -123,7 +101,7 @@ function displayIngredientsList(ingredients) {
|
|
123 |
const item = document.createElement('div');
|
124 |
item.className = 'ingredient-item';
|
125 |
const img = document.createElement('img');
|
126 |
-
img.src = ingredient.image_url || 'https://via.placeholder.com/80';
|
127 |
img.alt = ingredient.name;
|
128 |
const name = document.createElement('div');
|
129 |
name.textContent = ingredient.name;
|
@@ -152,7 +130,6 @@ function displaySelectedIngredients() {
|
|
152 |
return;
|
153 |
}
|
154 |
|
155 |
-
// Create or update selected ingredients area
|
156 |
let selectedArea = document.querySelector('.selected-ingredients');
|
157 |
if (!selectedArea) {
|
158 |
selectedArea = document.createElement('div');
|
|
|
28 |
addMessage('user', message);
|
29 |
conversation.push({ role: 'user', message: message });
|
30 |
userInput.value = '';
|
31 |
+
setTimeout(() => handleResponse(message), 500);
|
|
|
|
|
|
|
32 |
} else {
|
33 |
console.warn('Empty message!');
|
34 |
}
|
|
|
45 |
{ text: 'Vegetarian', class: 'green' },
|
46 |
{ text: 'Non-Vegetarian', class: 'red' }
|
47 |
];
|
48 |
+
} else if (lastMessage.includes('vegetarian') || lastMessage.includes('non-vegetarian')) {
|
49 |
+
botResponse = `Great choice! 🍽️ These are the available ingredients for ${lastMessage}:`;
|
50 |
+
fetchIngredients(lastMessage.toLowerCase()); // Pass the preference directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
return; // Exit early to handle ingredients fetch
|
52 |
}
|
53 |
|
|
|
88 |
return;
|
89 |
}
|
90 |
|
|
|
91 |
let ingredientsList = document.querySelector('.ingredients-list');
|
92 |
if (!ingredientsList) {
|
93 |
ingredientsList = document.createElement('div');
|
|
|
101 |
const item = document.createElement('div');
|
102 |
item.className = 'ingredient-item';
|
103 |
const img = document.createElement('img');
|
104 |
+
img.src = ingredient.image_url || 'https://via.placeholder.com/80';
|
105 |
img.alt = ingredient.name;
|
106 |
const name = document.createElement('div');
|
107 |
name.textContent = ingredient.name;
|
|
|
130 |
return;
|
131 |
}
|
132 |
|
|
|
133 |
let selectedArea = document.querySelector('.selected-ingredients');
|
134 |
if (!selectedArea) {
|
135 |
selectedArea = document.createElement('div');
|