Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Interactive Chatbot</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .chat-container { | |
| height: calc(100vh - 120px); | |
| } | |
| .message { | |
| max-width: 80%; | |
| word-wrap: break-word; | |
| } | |
| .typing-indicator { | |
| display: flex; | |
| align-items: center; | |
| } | |
| .typing-dot { | |
| width: 8px; | |
| height: 8px; | |
| border-radius: 50%; | |
| background-color: #4b5563; | |
| margin: 0 2px; | |
| animation: typing 1.5s infinite ease-in-out; | |
| } | |
| .typing-dot:nth-child(1) { | |
| animation-delay: 0s; | |
| } | |
| .typing-dot:nth-child(2) { | |
| animation-delay: 0.3s; | |
| } | |
| .typing-dot:nth-child(3) { | |
| animation-delay: 0.6s; | |
| } | |
| @keyframes typing { | |
| 0%, 100% { | |
| transform: translateY(0); | |
| } | |
| 50% { | |
| transform: translateY(-5px); | |
| } | |
| } | |
| .chat-input { | |
| resize: none; | |
| } | |
| .chat-input:focus { | |
| outline: none; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100 font-sans"> | |
| <div class="max-w-4xl mx-auto p-4"> | |
| <div class="bg-white rounded-xl shadow-lg overflow-hidden"> | |
| <!-- Chat Header --> | |
| <div class="bg-indigo-600 text-white p-4 flex items-center justify-between"> | |
| <div class="flex items-center space-x-3"> | |
| <div class="w-10 h-10 rounded-full bg-indigo-500 flex items-center justify-center"> | |
| <i class="fas fa-robot text-xl"></i> | |
| </div> | |
| <div> | |
| <h2 class="font-bold text-lg">AI Assistant</h2> | |
| <p class="text-xs opacity-80">Online</p> | |
| </div> | |
| </div> | |
| <div class="flex space-x-3"> | |
| <button class="text-white hover:text-indigo-200 transition"> | |
| <i class="fas fa-ellipsis-v"></i> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Chat Messages --> | |
| <div class="chat-container p-4 overflow-y-auto bg-gray-50"> | |
| <div id="chat-messages" class="space-y-4"> | |
| <!-- Welcome message --> | |
| <div class="flex justify-start"> | |
| <div class="message bg-white p-3 rounded-lg rounded-tl-none shadow-sm"> | |
| <p>Hello! 👋 I'm your AI assistant. How can I help you today?</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Chat Input --> | |
| <div class="border-t border-gray-200 p-4 bg-white"> | |
| <div class="flex items-end space-x-2"> | |
| <div class="flex-1 relative"> | |
| <textarea | |
| id="chat-input" | |
| class="chat-input w-full border border-gray-300 rounded-lg p-3 pr-10 focus:border-indigo-500 transition" | |
| placeholder="Type your message here..." | |
| rows="1" | |
| ></textarea> | |
| <button id="send-button" class="absolute right-2 bottom-2 text-indigo-600 hover:text-indigo-800 transition"> | |
| <i class="fas fa-paper-plane"></i> | |
| </button> | |
| </div> | |
| <button id="mic-button" class="p-3 rounded-full bg-indigo-100 text-indigo-600 hover:bg-indigo-200 transition"> | |
| <i class="fas fa-microphone"></i> | |
| </button> | |
| </div> | |
| <div class="mt-2 text-xs text-gray-500 flex justify-between"> | |
| <span>AI Assistant may produce inaccurate information</span> | |
| <span id="char-count">0/500</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const chatMessages = document.getElementById('chat-messages'); | |
| const chatInput = document.getElementById('chat-input'); | |
| const sendButton = document.getElementById('send-button'); | |
| const micButton = document.getElementById('mic-button'); | |
| const charCount = document.getElementById('char-count'); | |
| // Auto-resize textarea | |
| chatInput.addEventListener('input', function() { | |
| this.style.height = 'auto'; | |
| this.style.height = (this.scrollHeight) + 'px'; | |
| // Update character count | |
| const currentLength = this.value.length; | |
| charCount.textContent = `${currentLength}/500`; | |
| if (currentLength > 500) { | |
| charCount.classList.add('text-red-500'); | |
| } else { | |
| charCount.classList.remove('text-red-500'); | |
| } | |
| }); | |
| // Send message on Enter (but allow Shift+Enter for new lines) | |
| chatInput.addEventListener('keydown', function(e) { | |
| if (e.key === 'Enter' && !e.shiftKey) { | |
| e.preventDefault(); | |
| sendMessage(); | |
| } | |
| }); | |
| // Send message on button click | |
| sendButton.addEventListener('click', sendMessage); | |
| // Mic button functionality | |
| micButton.addEventListener('click', function() { | |
| this.classList.toggle('bg-red-100'); | |
| this.classList.toggle('text-red-600'); | |
| const icon = this.querySelector('i'); | |
| if (icon.classList.contains('fa-microphone')) { | |
| icon.classList.remove('fa-microphone'); | |
| icon.classList.add('fa-microphone-slash'); | |
| // In a real app, you would start voice recognition here | |
| addMessage('user', '🎤 Voice input activated (demo)'); | |
| } else { | |
| icon.classList.remove('fa-microphone-slash'); | |
| icon.classList.add('fa-microphone'); | |
| // In a real app, you would stop voice recognition here | |
| } | |
| }); | |
| function sendMessage() { | |
| const message = chatInput.value.trim(); | |
| if (message === '') return; | |
| // Add user message | |
| addMessage('user', message); | |
| chatInput.value = ''; | |
| chatInput.style.height = 'auto'; | |
| charCount.textContent = '0/500'; | |
| // Show typing indicator | |
| showTypingIndicator(); | |
| // Simulate AI response after a delay | |
| setTimeout(() => { | |
| removeTypingIndicator(); | |
| // Simple response logic - in a real app, you would call an API | |
| const responses = [ | |
| "I understand what you're asking about. Let me think...", | |
| "That's an interesting question! Here's what I know...", | |
| "Thanks for your message. I can help with that.", | |
| "I'm processing your request. Please wait a moment...", | |
| "Let me check my knowledge base for that information." | |
| ]; | |
| const randomResponse = responses[Math.floor(Math.random() * responses.length)]; | |
| addMessage('bot', randomResponse); | |
| // Scroll to bottom | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| }, 1500); | |
| } | |
| function addMessage(sender, text) { | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.className = `flex ${sender === 'user' ? 'justify-end' : 'justify-start'}`; | |
| const messageContent = document.createElement('div'); | |
| messageContent.className = `message ${sender === 'user' ? 'bg-indigo-100 text-indigo-900 rounded-tr-none' : 'bg-white rounded-tl-none'} p-3 rounded-lg shadow-sm`; | |
| messageContent.innerHTML = `<p>${text}</p>`; | |
| messageDiv.appendChild(messageContent); | |
| chatMessages.appendChild(messageDiv); | |
| // Scroll to bottom | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| } | |
| function showTypingIndicator() { | |
| const typingDiv = document.createElement('div'); | |
| typingDiv.className = 'flex justify-start'; | |
| typingDiv.id = 'typing-indicator'; | |
| const typingContent = document.createElement('div'); | |
| typingContent.className = 'message bg-white p-3 rounded-lg rounded-tl-none shadow-sm typing-indicator'; | |
| typingContent.innerHTML = ` | |
| <div class="flex space-x-1 mr-2"> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| </div> | |
| <span class="text-gray-500 text-sm">AI is typing...</span> | |
| `; | |
| typingDiv.appendChild(typingContent); | |
| chatMessages.appendChild(typingDiv); | |
| // Scroll to bottom | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| } | |
| function removeTypingIndicator() { | |
| const typingIndicator = document.getElementById('typing-indicator'); | |
| if (typingIndicator) { | |
| typingIndicator.remove(); | |
| } | |
| } | |
| // Add some sample messages for demo | |
| setTimeout(() => { | |
| addMessage('bot', "I can answer questions, provide information, or just chat. What would you like to know?"); | |
| }, 1000); | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=gusbsuke/deepsite-sw" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |