Spaces:
Runtime error
Runtime error
Update templates/chatbot.html
Browse files- templates/chatbot.html +366 -364
templates/chatbot.html
CHANGED
|
@@ -1,365 +1,367 @@
|
|
| 1 |
-
{% extends "base.html" %}
|
| 2 |
-
|
| 3 |
-
{% block content %}
|
| 4 |
-
<div class="container">
|
| 5 |
-
<h1 class="page-title text-center mb-4">Find the Right Scheme for You</h1>
|
| 6 |
-
|
| 7 |
-
<div class="row justify-content-center">
|
| 8 |
-
<div class="col-lg-8">
|
| 9 |
-
<div class="card shadow-sm">
|
| 10 |
-
<div class="card-body">
|
| 11 |
-
<div id="chat-container">
|
| 12 |
-
<div id="chat-messages" class="mb-4">
|
| 13 |
-
<div class="chat-message bot">
|
| 14 |
-
<div class="message-content">
|
| 15 |
-
Hello! I can help you find the perfect agricultural scheme for your needs. Let's
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
<
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
<div
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
<
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
</div>
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
{%
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
{ value: '
|
| 59 |
-
{ value: '
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
{ value: '
|
| 70 |
-
{ value: '
|
| 71 |
-
{ value: '
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
{ value: '
|
| 82 |
-
{ value: '
|
| 83 |
-
{ value: '
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
{ value: '
|
| 94 |
-
{ value: '
|
| 95 |
-
{ value: '
|
| 96 |
-
{ value: '
|
| 97 |
-
{ value: '
|
| 98 |
-
{ value: '
|
| 99 |
-
{ value: '
|
| 100 |
-
{ value: '
|
| 101 |
-
{ value: '
|
| 102 |
-
{ value: '
|
| 103 |
-
{ value: '
|
| 104 |
-
{ value: '
|
| 105 |
-
{ value: '
|
| 106 |
-
{ value: '
|
| 107 |
-
{ value: '
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
{ value: '
|
| 118 |
-
{ value: '
|
| 119 |
-
{ value: '
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
const
|
| 132 |
-
const
|
| 133 |
-
const
|
| 134 |
-
const
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
<
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
questionHTML += `<div class="
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
<
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
questionHTML += `<
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
messageDiv
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
<
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
<
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
<
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
<
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
<
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
<
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
| 365 |
{% endblock %}
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="container">
|
| 5 |
+
<h1 class="page-title text-center mb-4">Find the Right Scheme for You</h1>
|
| 6 |
+
|
| 7 |
+
<div class="row justify-content-center">
|
| 8 |
+
<div class="col-lg-8">
|
| 9 |
+
<div class="card shadow-sm">
|
| 10 |
+
<div class="card-body">
|
| 11 |
+
<div id="chat-container">
|
| 12 |
+
<div id="chat-messages" class="mb-4">
|
| 13 |
+
<div class="chat-message bot">
|
| 14 |
+
<div class="message-content">
|
| 15 |
+
Hello! I can help you find the perfect agricultural scheme for your needs. Let's
|
| 16 |
+
start with a few questions.
|
| 17 |
+
</div>
|
| 18 |
+
</div>
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<div id="question-container" class="mb-3">
|
| 22 |
+
<!-- Current question will be displayed here -->
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
<div id="user-input" class="d-flex">
|
| 26 |
+
<input type="text" id="user-response" class="form-control me-2"
|
| 27 |
+
placeholder="Type your answer..." disabled>
|
| 28 |
+
<button id="send-button" class="btn btn-primary" disabled>Send</button>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<div id="recommendations-container" class="mt-4" style="display: none;">
|
| 33 |
+
<h3 class="section-title">Recommended Schemes</h3>
|
| 34 |
+
<div id="schemes-list" class="mt-3">
|
| 35 |
+
<!-- Recommended schemes will be displayed here -->
|
| 36 |
+
</div>
|
| 37 |
+
<div class="mt-4 text-center">
|
| 38 |
+
<a href="/chatbot" class="btn btn-outline-primary me-2">Start Over</a>
|
| 39 |
+
<a href="/" class="btn btn-primary">View All Schemes</a>
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
{% endblock %}
|
| 48 |
+
|
| 49 |
+
{% block extra_scripts %}
|
| 50 |
+
<script>
|
| 51 |
+
// Chat flow and questions
|
| 52 |
+
const chatFlow = [
|
| 53 |
+
{
|
| 54 |
+
id: 'farmer_type',
|
| 55 |
+
question: 'What type of farmer are you?',
|
| 56 |
+
type: 'options',
|
| 57 |
+
options: [
|
| 58 |
+
{ value: 'small', label: 'Small or Marginal Farmer' },
|
| 59 |
+
{ value: 'tenant', label: 'Tenant Farmer or Sharecropper' },
|
| 60 |
+
{ value: 'all', label: 'Landholding Farmer' },
|
| 61 |
+
{ value: 'fpo', label: 'Part of a Farmer Producer Organization (FPO)' }
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
id: 'interests',
|
| 66 |
+
question: 'What aspects of farming are you interested in? (Select all that apply)',
|
| 67 |
+
type: 'checkbox',
|
| 68 |
+
options: [
|
| 69 |
+
{ value: 'organic', label: 'Organic Farming' },
|
| 70 |
+
{ value: 'irrigation', label: 'Irrigation & Water Management' },
|
| 71 |
+
{ value: 'infrastructure', label: 'Farm Infrastructure' },
|
| 72 |
+
{ value: 'soil', label: 'Soil Health Management' },
|
| 73 |
+
{ value: 'market', label: 'Market Access & Selling Produce' }
|
| 74 |
+
]
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
id: 'financial_needs',
|
| 78 |
+
question: 'What type of financial support are you looking for? (Select all that apply)',
|
| 79 |
+
type: 'checkbox',
|
| 80 |
+
options: [
|
| 81 |
+
{ value: 'credit', label: 'Loans & Credit' },
|
| 82 |
+
{ value: 'subsidy', label: 'Equipment/Input Subsidies' },
|
| 83 |
+
{ value: 'insurance', label: 'Crop Insurance' },
|
| 84 |
+
{ value: 'income', label: 'Direct Income Support' },
|
| 85 |
+
{ value: 'training', label: 'Training & Education' }
|
| 86 |
+
]
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
id: 'region',
|
| 90 |
+
question: 'Which state are you from?',
|
| 91 |
+
type: 'select',
|
| 92 |
+
options: [
|
| 93 |
+
{ value: 'all', label: 'All India (National Scheme)' },
|
| 94 |
+
{ value: 'andhra', label: 'Andhra Pradesh' },
|
| 95 |
+
{ value: 'assam', label: 'Assam' },
|
| 96 |
+
{ value: 'bihar', label: 'Bihar' },
|
| 97 |
+
{ value: 'gujarat', label: 'Gujarat' },
|
| 98 |
+
{ value: 'haryana', label: 'Haryana' },
|
| 99 |
+
{ value: 'karnataka', label: 'Karnataka' },
|
| 100 |
+
{ value: 'kerala', label: 'Kerala' },
|
| 101 |
+
{ value: 'madhya', label: 'Madhya Pradesh' },
|
| 102 |
+
{ value: 'maharashtra', label: 'Maharashtra' },
|
| 103 |
+
{ value: 'punjab', label: 'Punjab' },
|
| 104 |
+
{ value: 'rajasthan', label: 'Rajasthan' },
|
| 105 |
+
{ value: 'tamil', label: 'Tamil Nadu' },
|
| 106 |
+
{ value: 'telangana', label: 'Telangana' },
|
| 107 |
+
{ value: 'uttar', label: 'Uttar Pradesh' },
|
| 108 |
+
{ value: 'west', label: 'West Bengal' },
|
| 109 |
+
{ value: 'other', label: 'Other' }
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
id: 'land_area',
|
| 114 |
+
question: 'How much land do you cultivate (in acres)?',
|
| 115 |
+
type: 'select',
|
| 116 |
+
options: [
|
| 117 |
+
{ value: 'less_than_1', label: 'Less than 1 acre' },
|
| 118 |
+
{ value: '1_to_2', label: '1-2 acres' },
|
| 119 |
+
{ value: '2_to_5', label: '2-5 acres' },
|
| 120 |
+
{ value: '5_to_10', label: '5-10 acres' },
|
| 121 |
+
{ value: 'more_than_10', label: 'More than 10 acres' }
|
| 122 |
+
]
|
| 123 |
+
}
|
| 124 |
+
];
|
| 125 |
+
|
| 126 |
+
// Store answers
|
| 127 |
+
let userAnswers = {};
|
| 128 |
+
let currentQuestionIndex = 0;
|
| 129 |
+
|
| 130 |
+
// DOM elements
|
| 131 |
+
const questionContainer = document.getElementById('question-container');
|
| 132 |
+
const chatMessages = document.getElementById('chat-messages');
|
| 133 |
+
const userResponseInput = document.getElementById('user-response');
|
| 134 |
+
const sendButton = document.getElementById('send-button');
|
| 135 |
+
const recommendationsContainer = document.getElementById('recommendations-container');
|
| 136 |
+
const schemesList = document.getElementById('schemes-list');
|
| 137 |
+
|
| 138 |
+
// Start the conversation
|
| 139 |
+
document.addEventListener('DOMContentLoaded', function () {
|
| 140 |
+
displayQuestion(chatFlow[currentQuestionIndex]);
|
| 141 |
+
});
|
| 142 |
+
|
| 143 |
+
// Display a new question
|
| 144 |
+
function displayQuestion(questionObj) {
|
| 145 |
+
questionContainer.innerHTML = '';
|
| 146 |
+
let questionHTML = `<p class="mb-3">${questionObj.question}</p>`;
|
| 147 |
+
|
| 148 |
+
if (questionObj.type === 'options') {
|
| 149 |
+
questionHTML += `<div class="options-container">`;
|
| 150 |
+
questionObj.options.forEach(option => {
|
| 151 |
+
questionHTML += `
|
| 152 |
+
<div class="form-check mb-2">
|
| 153 |
+
<input class="form-check-input" type="radio" name="${questionObj.id}" id="${option.value}" value="${option.value}">
|
| 154 |
+
<label class="form-check-label" for="${option.value}">
|
| 155 |
+
${option.label}
|
| 156 |
+
</label>
|
| 157 |
+
</div>
|
| 158 |
+
`;
|
| 159 |
+
});
|
| 160 |
+
questionHTML += `</div><button class="btn btn-primary mt-2" onclick="submitAnswer()">Next</button>`;
|
| 161 |
+
} else if (questionObj.type === 'checkbox') {
|
| 162 |
+
questionHTML += `<div class="options-container">`;
|
| 163 |
+
questionObj.options.forEach(option => {
|
| 164 |
+
questionHTML += `
|
| 165 |
+
<div class="form-check mb-2">
|
| 166 |
+
<input class="form-check-input" type="checkbox" name="${questionObj.id}" id="${option.value}" value="${option.value}">
|
| 167 |
+
<label class="form-check-label" for="${option.value}">
|
| 168 |
+
${option.label}
|
| 169 |
+
</label>
|
| 170 |
+
</div>
|
| 171 |
+
`;
|
| 172 |
+
});
|
| 173 |
+
questionHTML += `</div><button class="btn btn-primary mt-2" onclick="submitAnswer()">Next</button>`;
|
| 174 |
+
} else if (questionObj.type === 'select') {
|
| 175 |
+
questionHTML += `<select class="form-select" id="${questionObj.id}">`;
|
| 176 |
+
questionHTML += `<option value="" selected disabled>Please select...</option>`;
|
| 177 |
+
questionObj.options.forEach(option => {
|
| 178 |
+
questionHTML += `<option value="${option.value}">${option.label}</option>`;
|
| 179 |
+
});
|
| 180 |
+
questionHTML += `</select><button class="btn btn-primary mt-2" onclick="submitAnswer()">Next</button>`;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
questionContainer.innerHTML = questionHTML;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
// Submit answer and move to next question
|
| 187 |
+
function submitAnswer() {
|
| 188 |
+
const currentQuestion = chatFlow[currentQuestionIndex];
|
| 189 |
+
|
| 190 |
+
// Get user's answer
|
| 191 |
+
let answer;
|
| 192 |
+
|
| 193 |
+
if (currentQuestion.type === 'options') {
|
| 194 |
+
const selectedOption = document.querySelector(`input[name="${currentQuestion.id}"]:checked`);
|
| 195 |
+
if (!selectedOption) return; // Require an answer
|
| 196 |
+
answer = selectedOption.value;
|
| 197 |
+
|
| 198 |
+
// Add user message
|
| 199 |
+
const selectedLabel = currentQuestion.options.find(opt => opt.value === answer).label;
|
| 200 |
+
addMessage('user', selectedLabel);
|
| 201 |
+
|
| 202 |
+
} else if (currentQuestion.type === 'checkbox') {
|
| 203 |
+
const selectedOptions = document.querySelectorAll(`input[name="${currentQuestion.id}"]:checked`);
|
| 204 |
+
if (selectedOptions.length === 0) return; // Require at least one selection
|
| 205 |
+
|
| 206 |
+
answer = Array.from(selectedOptions).map(opt => opt.value);
|
| 207 |
+
|
| 208 |
+
// Add user message
|
| 209 |
+
const selectedLabels = Array.from(selectedOptions).map(opt => {
|
| 210 |
+
const option = currentQuestion.options.find(o => o.value === opt.value);
|
| 211 |
+
return option ? option.label : '';
|
| 212 |
+
}).join(', ');
|
| 213 |
+
addMessage('user', selectedLabels);
|
| 214 |
+
|
| 215 |
+
} else if (currentQuestion.type === 'select') {
|
| 216 |
+
const selectElement = document.getElementById(currentQuestion.id);
|
| 217 |
+
if (!selectElement.value) return; // Require a selection
|
| 218 |
+
answer = selectElement.value;
|
| 219 |
+
|
| 220 |
+
// Add user message
|
| 221 |
+
const selectedLabel = currentQuestion.options.find(opt => opt.value === answer).label;
|
| 222 |
+
addMessage('user', selectedLabel);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// Store the answer
|
| 226 |
+
userAnswers[currentQuestion.id] = answer;
|
| 227 |
+
|
| 228 |
+
// Move to next question or finish
|
| 229 |
+
currentQuestionIndex++;
|
| 230 |
+
if (currentQuestionIndex < chatFlow.length) {
|
| 231 |
+
// Display next question
|
| 232 |
+
displayQuestion(chatFlow[currentQuestionIndex]);
|
| 233 |
+
} else {
|
| 234 |
+
// Finish conversation and show recommendations
|
| 235 |
+
finishConversation();
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// Add a message to the chat
|
| 240 |
+
function addMessage(sender, content) {
|
| 241 |
+
const messageDiv = document.createElement('div');
|
| 242 |
+
messageDiv.className = `chat-message ${sender}`;
|
| 243 |
+
messageDiv.innerHTML = `
|
| 244 |
+
<div class="message-content">
|
| 245 |
+
${content}
|
| 246 |
+
</div>
|
| 247 |
+
`;
|
| 248 |
+
chatMessages.appendChild(messageDiv);
|
| 249 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
// Finish conversation and get recommendations
|
| 253 |
+
function finishConversation() {
|
| 254 |
+
// Display loading message
|
| 255 |
+
questionContainer.innerHTML = `
|
| 256 |
+
<div class="text-center">
|
| 257 |
+
<div class="spinner-border text-primary" role="status">
|
| 258 |
+
<span class="visually-hidden">Loading...</span>
|
| 259 |
+
</div>
|
| 260 |
+
<p class="mt-2">Analyzing your needs to find the best schemes...</p>
|
| 261 |
+
</div>
|
| 262 |
+
`;
|
| 263 |
+
|
| 264 |
+
// Add final bot message
|
| 265 |
+
addMessage('bot', "Thanks for answering all the questions. Let me find the best schemes for you based on your needs.");
|
| 266 |
+
|
| 267 |
+
// Make API call to get recommendations
|
| 268 |
+
fetch('/api/recommend', {
|
| 269 |
+
method: 'POST',
|
| 270 |
+
headers: {
|
| 271 |
+
'Content-Type': 'application/json',
|
| 272 |
+
},
|
| 273 |
+
body: JSON.stringify({ answers: userAnswers }),
|
| 274 |
+
})
|
| 275 |
+
.then(response => response.json())
|
| 276 |
+
.then(data => {
|
| 277 |
+
// Hide question area
|
| 278 |
+
questionContainer.style.display = 'none';
|
| 279 |
+
document.getElementById('user-input').style.display = 'none';
|
| 280 |
+
|
| 281 |
+
// Display recommendations
|
| 282 |
+
displayRecommendations(data.schemes);
|
| 283 |
+
})
|
| 284 |
+
.catch(error => {
|
| 285 |
+
console.error('Error:', error);
|
| 286 |
+
questionContainer.innerHTML = `
|
| 287 |
+
<div class="alert alert-danger">
|
| 288 |
+
Sorry, there was an error finding recommendations. Please try again.
|
| 289 |
+
</div>
|
| 290 |
+
<button class="btn btn-primary" onclick="location.reload()">Restart</button>
|
| 291 |
+
`;
|
| 292 |
+
});
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
// Display scheme recommendations
|
| 296 |
+
function displayRecommendations(recommendations) {
|
| 297 |
+
if (recommendations.length === 0) {
|
| 298 |
+
schemesList.innerHTML = `
|
| 299 |
+
<div class="alert alert-info">
|
| 300 |
+
No schemes match your specific criteria. Try broadening your requirements or view all available schemes.
|
| 301 |
+
</div>
|
| 302 |
+
`;
|
| 303 |
+
} else {
|
| 304 |
+
let schemesHTML = '';
|
| 305 |
+
recommendations.forEach(scheme => {
|
| 306 |
+
schemesHTML += `
|
| 307 |
+
<div class="card mb-3">
|
| 308 |
+
<div class="card-body">
|
| 309 |
+
<h5 class="card-title text-success">${scheme.name}</h5>
|
| 310 |
+
<p class="card-text">${scheme.introduction}</p>
|
| 311 |
+
<a href="/scheme/${scheme.id}" class="btn btn-outline-success">View Details</a>
|
| 312 |
+
</div>
|
| 313 |
+
</div>
|
| 314 |
+
`;
|
| 315 |
+
});
|
| 316 |
+
schemesList.innerHTML = schemesHTML;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// Show recommendations container
|
| 320 |
+
recommendationsContainer.style.display = 'block';
|
| 321 |
+
}
|
| 322 |
+
</script>
|
| 323 |
+
|
| 324 |
+
<style>
|
| 325 |
+
.chat-message {
|
| 326 |
+
margin-bottom: 15px;
|
| 327 |
+
display: flex;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
.chat-message.user {
|
| 331 |
+
justify-content: flex-end;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
.message-content {
|
| 335 |
+
padding: 10px 15px;
|
| 336 |
+
border-radius: 15px;
|
| 337 |
+
max-width: 80%;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.chat-message.bot .message-content {
|
| 341 |
+
background-color: #f0f0f0;
|
| 342 |
+
border-top-left-radius: 5px;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
.chat-message.user .message-content {
|
| 346 |
+
background-color: var(--primary);
|
| 347 |
+
color: white;
|
| 348 |
+
border-top-right-radius: 5px;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
#chat-messages {
|
| 352 |
+
max-height: 300px;
|
| 353 |
+
overflow-y: auto;
|
| 354 |
+
padding: 15px;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
#question-container {
|
| 358 |
+
background-color: #f8f9fa;
|
| 359 |
+
padding: 15px;
|
| 360 |
+
border-radius: 10px;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
.options-container {
|
| 364 |
+
margin-top: 10px;
|
| 365 |
+
}
|
| 366 |
+
</style>
|
| 367 |
{% endblock %}
|