PRC142004 commited on
Commit
88d056c
·
verified ·
1 Parent(s): eb224f7

Update templates/chatbot.html

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