Spaces:
Running
Running
Update index.html (#2)
Browse files- Update index.html (a2b7f75eff5c97a9f22b84ad5a0488e6a4eed205)
Co-authored-by: Aditya Adaki <[email protected]>
- index.html +130 -0
index.html
CHANGED
|
@@ -5,6 +5,78 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
<title>Farmers Training</title>
|
| 7 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
/* Global Styles */
|
| 9 |
* {
|
| 10 |
margin: 0;
|
|
@@ -229,10 +301,24 @@
|
|
| 229 |
</div>
|
| 230 |
</main>
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
<script>
|
| 233 |
const searchInput = document.querySelector('.search-container input[type="text"]');
|
| 234 |
const cards = document.querySelectorAll('.card');
|
|
|
|
|
|
|
| 235 |
|
|
|
|
| 236 |
searchInput.addEventListener('input', function() {
|
| 237 |
const searchTerm = searchInput.value.toLowerCase();
|
| 238 |
cards.forEach(card => {
|
|
@@ -245,6 +331,50 @@
|
|
| 245 |
}
|
| 246 |
});
|
| 247 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
</script>
|
| 249 |
|
| 250 |
</body>
|
|
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
<title>Farmers Training</title>
|
| 7 |
<style>
|
| 8 |
+
/* Chat Interface Styles */
|
| 9 |
+
.chat-container {
|
| 10 |
+
position: fixed;
|
| 11 |
+
bottom: 20px;
|
| 12 |
+
right: 20px;
|
| 13 |
+
width: 300px;
|
| 14 |
+
height: 400px;
|
| 15 |
+
background: white;
|
| 16 |
+
border-radius: 10px;
|
| 17 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
| 18 |
+
display: flex;
|
| 19 |
+
flex-direction: column;
|
| 20 |
+
overflow: hidden;
|
| 21 |
+
z-index: 1000;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.chat-header {
|
| 25 |
+
background: #2e7d32;
|
| 26 |
+
color: white;
|
| 27 |
+
padding: 10px;
|
| 28 |
+
font-weight: bold;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.chat-messages {
|
| 32 |
+
flex-grow: 1;
|
| 33 |
+
overflow-y: auto;
|
| 34 |
+
padding: 10px;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.chat-message {
|
| 38 |
+
margin-bottom: 10px;
|
| 39 |
+
padding: 8px 12px;
|
| 40 |
+
border-radius: 15px;
|
| 41 |
+
max-width: 80%;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.user-message {
|
| 45 |
+
background: #e3f2fd;
|
| 46 |
+
margin-left: auto;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.bot-message {
|
| 50 |
+
background: #f5f5f5;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.chat-input {
|
| 54 |
+
display: flex;
|
| 55 |
+
padding: 10px;
|
| 56 |
+
border-top: 1px solid #eee;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.chat-input input {
|
| 60 |
+
flex-grow: 1;
|
| 61 |
+
padding: 8px;
|
| 62 |
+
border: 1px solid #ddd;
|
| 63 |
+
border-radius: 20px;
|
| 64 |
+
margin-right: 8px;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.chat-input button {
|
| 68 |
+
background: #2e7d32;
|
| 69 |
+
color: white;
|
| 70 |
+
border: none;
|
| 71 |
+
padding: 8px 15px;
|
| 72 |
+
border-radius: 20px;
|
| 73 |
+
cursor: pointer;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.chat-input button:hover {
|
| 77 |
+
background: #1b5e20;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
/* Global Styles */
|
| 81 |
* {
|
| 82 |
margin: 0;
|
|
|
|
| 301 |
</div>
|
| 302 |
</main>
|
| 303 |
|
| 304 |
+
<!-- Chat Interface -->
|
| 305 |
+
<div class="chat-container">
|
| 306 |
+
<div class="chat-header">Farming Assistant</div>
|
| 307 |
+
<div class="chat-messages" id="chatMessages"></div>
|
| 308 |
+
<div class="chat-input">
|
| 309 |
+
<input type="text" placeholder="Ask about farming..." id="chatInput">
|
| 310 |
+
<button onclick="sendMessage()">Send</button>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
|
| 314 |
+
<script src="chatbot.js"></script>
|
| 315 |
<script>
|
| 316 |
const searchInput = document.querySelector('.search-container input[type="text"]');
|
| 317 |
const cards = document.querySelectorAll('.card');
|
| 318 |
+
const chatInput = document.getElementById('chatInput');
|
| 319 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 320 |
|
| 321 |
+
// Search functionality
|
| 322 |
searchInput.addEventListener('input', function() {
|
| 323 |
const searchTerm = searchInput.value.toLowerCase();
|
| 324 |
cards.forEach(card => {
|
|
|
|
| 331 |
}
|
| 332 |
});
|
| 333 |
});
|
| 334 |
+
|
| 335 |
+
// Chat functionality
|
| 336 |
+
function addMessage(message, isUser) {
|
| 337 |
+
const messageDiv = document.createElement('div');
|
| 338 |
+
messageDiv.className = `chat-message ${isUser ? 'user-message' : 'bot-message'}`;
|
| 339 |
+
messageDiv.textContent = message;
|
| 340 |
+
chatMessages.appendChild(messageDiv);
|
| 341 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
function displayRecommendations(recommendations) {
|
| 345 |
+
recommendations.forEach(video => {
|
| 346 |
+
const messageDiv = document.createElement('div');
|
| 347 |
+
messageDiv.className = 'chat-message bot-message';
|
| 348 |
+
messageDiv.innerHTML = `<strong><a href="${video.url}" target="_blank">${video.title}</a></strong><br>${video.description}`;
|
| 349 |
+
chatMessages.appendChild(messageDiv);
|
| 350 |
+
});
|
| 351 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
function sendMessage() {
|
| 355 |
+
const message = chatInput.value.trim();
|
| 356 |
+
if (message) {
|
| 357 |
+
addMessage(message, true);
|
| 358 |
+
chatbot.addToHistory(message, true);
|
| 359 |
+
|
| 360 |
+
const response = chatbot.processInput(message);
|
| 361 |
+
addMessage(response.message, false);
|
| 362 |
+
chatbot.addToHistory(response.message, false);
|
| 363 |
+
|
| 364 |
+
if (response.recommendations.length > 0) {
|
| 365 |
+
displayRecommendations(response.recommendations);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
chatInput.value = '';
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
// Handle Enter key
|
| 373 |
+
chatInput.addEventListener('keypress', function(e) {
|
| 374 |
+
if (e.key === 'Enter') {
|
| 375 |
+
sendMessage();
|
| 376 |
+
}
|
| 377 |
+
});
|
| 378 |
</script>
|
| 379 |
|
| 380 |
</body>
|