Spaces:
Sleeping
Sleeping
Download frontend/index.html from YADUUG/NPS-ChatAgentBot: direct link, hf CLI and curl.
- Browser
- Download file 19.7 kB
-
https://huggingface.co/spaces/YADUUG/NPS-ChatAgentBot/resolve/main/frontend/index.html
- Command line
-
hf download hf://spaces/YADUUG/NPS-ChatAgentBot/frontend/index.html
-
curl -L -o index.html https://huggingface.co/spaces/YADUUG/NPS-ChatAgentBot/resolve/main/frontend/index.html
19.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>NPS Informational Assistant</title> | |
| <link rel="icon" | |
| href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🏛️</text></svg>"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css"> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'); | |
| :root { | |
| --primary: linear-gradient(135deg, #1e3c72, #2a5298); | |
| --secondary: #e67e22; | |
| --background: #0f172a; | |
| --surface: #1e293b; | |
| --surface-light: #334155; | |
| --text: #f8fafc; | |
| --text-muted: #94a3b8; | |
| --assistant-bg: linear-gradient(135deg, #334155, #475569); | |
| --user-bg: linear-gradient(135deg, #1e3c72, #2a5298); | |
| --border: #333344; | |
| --accent: #60a5fa; | |
| --success: #10b981; | |
| --error: #ef4444; | |
| --glass-bg: rgba(26, 26, 36, 0.7); | |
| --glass-border: rgba(255, 255, 255, 0.1); | |
| } | |
| * { | |
| box-sizing: border-box; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| html { | |
| scroll-behavior: smooth; | |
| } | |
| body { | |
| font-family: 'Inter', sans-serif; | |
| background: var(--background); | |
| background-image: | |
| radial-gradient(circle at 15% 25%, rgba(30, 60, 114, 0.15) 0%, transparent 40%), | |
| radial-gradient(circle at 85% 75%, rgba(230, 126, 34, 0.08) 0%, transparent 40%); | |
| color: var(--text); | |
| min-height: 100vh; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| padding: 10px; | |
| } | |
| .container { | |
| width: 100%; | |
| max-width: 900px; | |
| height: calc(100vh - 40px); | |
| max-height: 850px; | |
| background: var(--glass-bg); | |
| backdrop-filter: blur(25px); | |
| border: 1px solid var(--glass-border); | |
| border-radius: 24px; | |
| box-shadow: 0 32px 64px rgba(0, 0, 0, 0.4); | |
| display: flex; | |
| flex-direction: column; | |
| overflow: hidden; | |
| position: relative; | |
| animation: fadeIn 0.5s ease-out; | |
| } | |
| @keyframes fadeIn { | |
| from { | |
| opacity: 0; | |
| transform: scale(0.95); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: scale(1); | |
| } | |
| } | |
| header { | |
| background: var(--primary); | |
| padding: 20px 24px; | |
| text-align: center; | |
| position: relative; | |
| overflow: hidden; | |
| flex-shrink: 0; | |
| } | |
| header h1 { | |
| font-size: 1.6rem; | |
| font-weight: 700; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 12px; | |
| } | |
| .status-indicator { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 8px; | |
| margin-top: 8px; | |
| font-size: 0.85rem; | |
| opacity: 0.9; | |
| } | |
| .status-dot { | |
| width: 8px; | |
| height: 8px; | |
| border-radius: 50%; | |
| background: var(--success); | |
| animation: pulse 2s infinite cubic-bezier(0.4, 0, 0.6, 1); | |
| } | |
| @keyframes pulse { | |
| 50% { | |
| opacity: 0.6; | |
| transform: scale(0.9); | |
| } | |
| } | |
| /* Toggle Switch */ | |
| .mode-toggle-container { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 12px; | |
| margin-top: 16px; | |
| } | |
| .mode-label { | |
| font-size: 0.9rem; | |
| color: rgba(255, 255, 255, 0.8); | |
| font-weight: 500; | |
| } | |
| .language-select { | |
| background: rgba(255, 255, 255, 0.1); | |
| border: 1px solid rgba(255, 255, 255, 0.2); | |
| color: white; | |
| padding: 5px 10px; | |
| border-radius: 15px; | |
| outline: none; | |
| font-family: 'Inter', sans-serif; | |
| font-size: 0.9rem; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| } | |
| .language-select:hover { | |
| background: rgba(255, 255, 255, 0.2); | |
| } | |
| .language-select option { | |
| background: var(--surface); | |
| color: var(--text); | |
| } | |
| .switch { | |
| position: relative; | |
| display: inline-block; | |
| width: 50px; | |
| height: 26px; | |
| } | |
| .switch input { | |
| opacity: 0; | |
| width: 0; | |
| height: 0; | |
| } | |
| .slider { | |
| position: absolute; | |
| cursor: pointer; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background-color: rgba(255, 255, 255, 0.2); | |
| -webkit-transition: .4s; | |
| transition: .4s; | |
| border-radius: 34px; | |
| } | |
| .slider:before { | |
| position: absolute; | |
| content: ""; | |
| height: 20px; | |
| width: 20px; | |
| left: 3px; | |
| bottom: 3px; | |
| background-color: white; | |
| -webkit-transition: .4s; | |
| transition: .4s; | |
| border-radius: 50%; | |
| } | |
| input:checked+.slider { | |
| background-color: var(--accent); | |
| } | |
| input:focus+.slider { | |
| box-shadow: 0 0 1px var(--accent); | |
| } | |
| input:checked+.slider:before { | |
| -webkit-transform: translateX(24px); | |
| -ms-transform: translateX(24px); | |
| transform: translateX(24px); | |
| } | |
| .chat-container { | |
| flex: 1; | |
| display: flex; | |
| flex-direction: column; | |
| background: var(--surface); | |
| position: relative; | |
| min-height: 0; | |
| } | |
| #chat-box { | |
| flex: 1; | |
| overflow-y: auto; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 10px; | |
| padding: 24px; | |
| padding-bottom: 120px; | |
| } | |
| #chat-box::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| #chat-box::-webkit-scrollbar-track { | |
| background: transparent; | |
| } | |
| #chat-box::-webkit-scrollbar-thumb { | |
| background: var(--border); | |
| border-radius: 3px; | |
| } | |
| #chat-box::-webkit-scrollbar-thumb:hover { | |
| background: var(--accent); | |
| } | |
| .message-wrapper { | |
| display: flex; | |
| gap: 12px; | |
| max-width: 85%; | |
| animation: slideIn 0.4s ease-out; | |
| } | |
| @keyframes slideIn { | |
| from { | |
| opacity: 0; | |
| transform: translateY(15px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| .user-message-wrapper { | |
| align-self: flex-end; | |
| flex-direction: row-reverse; | |
| } | |
| .assistant-message-wrapper { | |
| align-self: flex-start; | |
| } | |
| .assistant-avatar { | |
| width: 40px; | |
| height: 40px; | |
| border-radius: 50%; | |
| background: var(--accent); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| flex-shrink: 0; | |
| font-size: 1.5rem; | |
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); | |
| } | |
| .message { | |
| padding: 14px 20px; | |
| border-radius: 20px; | |
| line-height: 1.6; | |
| position: relative; | |
| box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15); | |
| } | |
| .assistant-message { | |
| background: var(--assistant-bg); | |
| border-bottom-left-radius: 8px; | |
| } | |
| .user-message { | |
| background: var(--user-bg); | |
| border-bottom-right-radius: 8px; | |
| color: white; | |
| } | |
| .message-content :is(h1, h2, h3) { | |
| margin-bottom: 12px; | |
| color: var(--accent); | |
| border-bottom: 1px solid var(--border); | |
| padding-bottom: 8px; | |
| } | |
| .message-content :is(ul, ol) { | |
| margin-left: 20px; | |
| margin-bottom: 12px; | |
| } | |
| .message-content li { | |
| margin-bottom: 6px; | |
| } | |
| .message-content p { | |
| margin-bottom: 12px; | |
| } | |
| .message-content p:last-child { | |
| margin-bottom: 0; | |
| } | |
| .message-content code { | |
| background: rgba(0, 0, 0, 0.3); | |
| padding: 3px 6px; | |
| border-radius: 4px; | |
| font-size: 0.9em; | |
| font-family: 'Courier New', Courier, monospace; | |
| } | |
| .message-content pre { | |
| background: rgba(0, 0, 0, 0.4); | |
| padding: 16px; | |
| border-radius: 8px; | |
| overflow-x: auto; | |
| margin: 12px 0; | |
| border-left: 4px solid var(--accent); | |
| } | |
| .message-content blockquote { | |
| border-left: 4px solid var(--accent); | |
| padding-left: 16px; | |
| margin: 12px 0; | |
| font-style: italic; | |
| opacity: 0.9; | |
| } | |
| .loading-message .message-content { | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| } | |
| .typing-indicator { | |
| display: flex; | |
| gap: 5px; | |
| } | |
| .typing-dot { | |
| width: 8px; | |
| height: 8px; | |
| border-radius: 50%; | |
| background: var(--accent); | |
| animation: typing 1.4s infinite ease-in-out; | |
| } | |
| .typing-dot:nth-child(2) { | |
| animation-delay: 0.2s; | |
| } | |
| .typing-dot:nth-child(3) { | |
| animation-delay: 0.4s; | |
| } | |
| @keyframes typing { | |
| 0%, | |
| 80%, | |
| 100% { | |
| transform: scale(0); | |
| } | |
| 40% { | |
| transform: scale(1.0); | |
| } | |
| } | |
| .input-section { | |
| position: absolute; | |
| bottom: 0; | |
| left: 0; | |
| right: 0; | |
| background: linear-gradient(to top, rgba(26, 26, 36, 1), rgba(26, 26, 36, 0.8)); | |
| padding: 24px; | |
| padding-top: 16px; | |
| border-top: 1px solid var(--border); | |
| backdrop-filter: blur(10px); | |
| } | |
| .input-container { | |
| background: var(--surface-light); | |
| border-radius: 24px; | |
| padding: 6px; | |
| border: 1px solid var(--border); | |
| transition: all 0.3s ease; | |
| } | |
| .input-container:focus-within { | |
| border-color: var(--accent); | |
| box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25); | |
| } | |
| .input-form { | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| #user-input { | |
| flex: 1; | |
| background: transparent; | |
| border: none; | |
| padding: 12px 16px; | |
| color: var(--text); | |
| font-size: 1rem; | |
| outline: none; | |
| resize: none; | |
| min-height: 24px; | |
| max-height: 120px; | |
| } | |
| #user-input::placeholder { | |
| color: var(--text-muted); | |
| } | |
| .send-button { | |
| background: var(--primary); | |
| border: none; | |
| border-radius: 18px; | |
| width: 48px; | |
| height: 48px; | |
| color: white; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| flex-shrink: 0; | |
| } | |
| .send-button:hover:not(:disabled) { | |
| transform: scale(1.05); | |
| box-shadow: 0 8px 25px rgba(0, 90, 156, 0.4); | |
| } | |
| .send-button:disabled { | |
| opacity: 0.6; | |
| cursor: not-allowed; | |
| } | |
| .send-icon { | |
| width: 20px; | |
| height: 20px; | |
| transition: transform 0.3s ease; | |
| } | |
| .send-button:hover:not(:disabled) .send-icon { | |
| transform: rotate(45deg) scale(1.1); | |
| } | |
| footer { | |
| padding: 12px 24px; | |
| text-align: center; | |
| font-size: 0.8rem; | |
| color: var(--text-muted); | |
| border-top: 1px solid var(--border); | |
| background: var(--surface); | |
| flex-shrink: 0; | |
| } | |
| .error-message { | |
| background: linear-gradient(135deg, #b91c1c, #ef4444); | |
| border-color: #fca5a5; | |
| } | |
| @media (max-width: 768px) { | |
| body { | |
| padding: 0; | |
| } | |
| .container { | |
| height: 100vh; | |
| max-height: 100vh; | |
| border-radius: 0; | |
| box-shadow: none; | |
| border: none; | |
| } | |
| header h1 { | |
| font-size: 1.3rem; | |
| } | |
| #chat-box { | |
| padding: 16px; | |
| padding-bottom: 120px; | |
| } | |
| .message-wrapper { | |
| max-width: 90%; | |
| } | |
| .assistant-avatar { | |
| width: 32px; | |
| height: 32px; | |
| font-size: 1.2rem; | |
| } | |
| .message { | |
| padding: 12px 16px; | |
| } | |
| .input-section { | |
| padding: 12px; | |
| } | |
| .input-container { | |
| border-radius: 20px; | |
| } | |
| .send-button { | |
| width: 44px; | |
| height: 44px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <header> | |
| <h1>🏛️ NPS Informational Assistant</h1> | |
| <div class="status-indicator"> | |
| <div class="status-dot"></div> | |
| <span>Online and ready to help</span> | |
| </div> | |
| <div class="mode-toggle-container"> | |
| <select id="language-select" class="language-select"> | |
| <option value="English">English</option> | |
| <option value="Hindi">Hindi (हिंदी)</option> | |
| <option value="Bengali">Bengali (বাংলা)</option> | |
| <option value="Telugu">Telugu (తెలుగు)</option> | |
| <option value="Marathi">Marathi (मराठी)</option> | |
| <option value="Tamil">Tamil (தமிழ்)</option> | |
| <option value="Urdu">Urdu (اردو)</option> | |
| <option value="Gujarati">Gujarati (ગુજરાતી)</option> | |
| <option value="Kannada">Kannada (ಕನ್ನಡ)</option> | |
| <option value="Malayalam">Malayalam (മലയാളം)</option> | |
| <option value="Odia">Odia (ଓଡ଼ିଆ)</option> | |
| <option value="Punjabi">Punjabi (ਪੰਜਾਬੀ)</option> | |
| <option value="Assamese">Assamese (অসমীয়া)</option> | |
| </select> | |
| <span class="mode-label">Chat</span> | |
| <label class="switch"> | |
| <input type="checkbox" id="mode-toggle"> | |
| <span class="slider"></span> | |
| </label> | |
| <span class="mode-label">Agent</span> | |
| </div> | |
| </header> | |
| <main class="chat-container"> | |
| <div id="chat-box"> | |
| </div> | |
| <div class="input-section"> | |
| <div class="input-container"> | |
| <form class="input-form" id="question-form"> | |
| <textarea id="user-input" placeholder="Ask anything about NPS..." rows="1" autocomplete="off" | |
| required></textarea> | |
| <button type="submit" class="send-button" id="send-btn" aria-label="Send message"> | |
| <svg class="send-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" | |
| stroke-linecap="round" stroke-linejoin="round"> | |
| <path d="M22 2L11 13" /> | |
| <path d="M22 2L15 22L11 13L2 9L22 2Z" /> | |
| </svg> | |
| </button> | |
| </form> | |
| </div> | |
| </div> | |
| </main> | |
| <footer> | |
| <p>Powered by AI | <a href="/admin.html" style="color: var(--text-muted);">Admin</a></p> | |
| </footer> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', () => { | |
| // Configuration for marked library | |
| if (typeof marked !== 'undefined') { | |
| marked.setOptions({ | |
| breaks: true, | |
| gfm: true, | |
| highlight: function (code, lang) { | |
| if (typeof Prism !== 'undefined' && Prism.languages[lang]) { | |
| return Prism.highlight(code, Prism.languages[lang], lang); | |
| } | |
| return code; | |
| } | |
| }); | |
| } | |
| const API_BASE_URL = ''; // Keep empty to use the same origin | |
| const chatBox = document.getElementById('chat-box'); | |
| const questionForm = document.getElementById('question-form'); | |
| const userInput = document.getElementById('user-input'); | |
| const sendBtn = document.getElementById('send-btn'); | |
| const modeToggle = document.getElementById('mode-toggle'); | |
| const languageSelect = document.getElementById('language-select'); | |
| userInput.addEventListener('input', function () { | |
| this.style.height = 'auto'; | |
| this.style.height = Math.min(this.scrollHeight, 120) + 'px'; | |
| }); | |
| userInput.addEventListener('keydown', function (e) { | |
| if (e.key === 'Enter' && !e.shiftKey) { | |
| e.preventDefault(); | |
| sendBtn.click(); | |
| } | |
| }); | |
| const addMessage = (content, sender, isError = false) => { | |
| const wrapper = document.createElement('div'); | |
| wrapper.classList.add('message-wrapper', `${sender}-message-wrapper`); | |
| let messageHTML = ''; | |
| if (sender === 'assistant') { | |
| messageHTML += `<div class="assistant-avatar">🏛️</div>`; | |
| } | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.classList.add('message', `${sender}-message`); | |
| if (isError) { | |
| messageDiv.classList.add('error-message'); | |
| } | |
| const contentDiv = document.createElement('div'); | |
| contentDiv.classList.add('message-content'); | |
| // Safely handle marked parsing | |
| if (sender === 'assistant' && typeof marked !== 'undefined') { | |
| contentDiv.innerHTML = marked.parse(content); | |
| } else { | |
| contentDiv.textContent = content; | |
| } | |
| messageDiv.appendChild(contentDiv); | |
| wrapper.innerHTML = messageHTML; | |
| wrapper.appendChild(messageDiv); | |
| chatBox.appendChild(wrapper); | |
| chatBox.scrollTop = chatBox.scrollHeight; | |
| }; | |
| const showLoadingIndicator = () => { | |
| const wrapper = document.createElement('div'); | |
| wrapper.classList.add('message-wrapper', 'assistant-message-wrapper'); | |
| wrapper.id = 'loading-indicator'; | |
| wrapper.innerHTML = ` | |
| <div class="assistant-avatar">🏛️</div> | |
| <div class="message assistant-message loading-message"> | |
| <div class="message-content"> | |
| <div class="typing-indicator"> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| <div class="typing-dot"></div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| chatBox.appendChild(wrapper); | |
| chatBox.scrollTop = chatBox.scrollHeight; | |
| }; | |
| const handleQuestionSubmit = async (event) => { | |
| event.preventDefault(); | |
| const question = userInput.value.trim(); | |
| if (!question) return; | |
| const mode = modeToggle.checked ? 'agent' : 'chat'; | |
| const language = languageSelect.value; | |
| addMessage(question, 'user'); | |
| userInput.value = ''; | |
| userInput.style.height = 'auto'; | |
| sendBtn.disabled = true; | |
| showLoadingIndicator(); | |
| const loadingIndicator = document.getElementById('loading-indicator'); | |
| try { | |
| const response = await fetch(`${API_BASE_URL}/ask`, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ question: question, mode: mode, language: language }), | |
| }); | |
| if (!response.ok) { | |
| const errorData = await response.json(); | |
| throw new Error(errorData.detail || 'An unknown server error occurred.'); | |
| } | |
| const data = await response.json(); | |
| addMessage(data.answer, 'assistant'); | |
| } catch (error) { | |
| console.error('Error:', error); | |
| const errorMessage = `**Connection Error**\n\nI'm having trouble connecting to my knowledge base. Please try again in a moment.\n\n*(Error: ${error.message})*`; | |
| addMessage(errorMessage, 'assistant', true); | |
| } finally { | |
| if (loadingIndicator) { | |
| loadingIndicator.remove(); | |
| } | |
| sendBtn.disabled = false; | |
| userInput.focus(); | |
| } | |
| }; | |
| const displayWelcomeMessage = () => { | |
| const welcomeText = `👋 Hello! I'm your NPS Assistant. I can help with questions about:\n\n- **Registration & Account Opening**\n- **Contributions & Tax Benefits**\n- **Investment Choices & Asset Classes**\n- **Exit, Withdrawal & Annuity**\n\n## 📋 Chat Guidelines\n\n✅ **Do's:**\n- Ask specifically about NPS rules and regulations\n- Inquire about processes for different sectors (Govt, Corporate, All Citizens)\n\n❌ **Don'ts:**\n- Share personal financial details (PRAN, Passwords)\n\nHow can I assist you with your National Pension System queries today?`; | |
| addMessage(welcomeText, 'assistant'); | |
| }; | |
| questionForm.addEventListener('submit', handleQuestionSubmit); | |
| displayWelcomeMessage(); | |
| userInput.focus(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |