rahul-02 commited on
Commit
12b0bb5
·
verified ·
1 Parent(s): aa09738

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +82 -219
templates/index.html CHANGED
@@ -3,243 +3,106 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Nexus AI | Research OS</title>
7
- <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;600;700&display=swap" rel="stylesheet">
8
  <style>
9
- :root {
10
- --bg-dark: #020617;
11
- --sidebar-bg: #0f172a;
12
- --accent: #38bdf8;
13
- --accent-glow: rgba(56, 189, 248, 0.3);
14
- --border: rgba(255, 255, 255, 0.08);
15
- --text-main: #f8fafc;
16
- --text-dim: #94a3b8;
17
- }
18
-
19
- * { margin: 0; padding: 0; box-sizing: border-box; }
20
-
21
- body {
22
- font-family: 'Plus Jakarta Sans', sans-serif;
23
- background-color: var(--bg-dark);
24
- color: var(--text-main);
25
- height: 100vh;
26
- display: flex;
27
- overflow: hidden;
28
- }
29
-
30
- /* Sidebar Navigation */
31
- aside {
32
- width: 260px;
33
- background: var(--sidebar-bg);
34
- border-right: 1px solid var(--border);
35
- display: flex;
36
- flex-direction: column;
37
- padding: 24px;
38
- }
39
-
40
- .logo {
41
- font-size: 1.5rem;
42
- font-weight: 700;
43
- color: var(--accent);
44
- margin-bottom: 40px;
45
- letter-spacing: -1px;
46
- }
47
-
48
- .nav-item {
49
- padding: 12px 16px;
50
- border-radius: 12px;
51
- color: var(--text-dim);
52
- text-decoration: none;
53
- margin-bottom: 8px;
54
- font-weight: 500;
55
- transition: 0.2s;
56
- }
57
-
58
- .nav-item.active { background: rgba(255,255,255,0.05); color: white; }
59
-
60
- /* Main Canvas */
61
- main { flex: 1; display: flex; flex-direction: column; position: relative; }
62
-
63
- header {
64
- padding: 20px 40px;
65
- border-bottom: 1px solid var(--border);
66
- display: flex;
67
- justify-content: space-between;
68
- align-items: center;
69
- }
70
-
71
- .status-pill {
72
- background: rgba(34, 197, 94, 0.1);
73
- color: #4ade80;
74
- padding: 4px 12px;
75
- border-radius: 100px;
76
- font-size: 0.75rem;
77
- border: 1px solid rgba(34, 197, 94, 0.2);
78
- }
79
-
80
- #chat-window {
81
- flex: 1;
82
- overflow-y: auto;
83
- padding: 40px;
84
- display: flex;
85
- flex-direction: column;
86
- gap: 24px;
87
- }
88
-
89
- .message {
90
- max-width: 75%;
91
- padding: 20px;
92
- border-radius: 20px;
93
- line-height: 1.6;
94
- font-size: 0.95rem;
95
- animation: slideUp 0.4s ease-out;
96
- }
97
-
98
- @keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
99
-
100
- .user-msg {
101
- align-self: flex-end;
102
- background: var(--accent);
103
- color: #000;
104
- border-bottom-right-radius: 4px;
105
- box-shadow: 0 10px 20px -10px var(--accent-glow);
106
- }
107
-
108
- .ai-msg {
109
- align-self: flex-start;
110
- background: rgba(255,255,255,0.03);
111
- border: 1px solid var(--border);
112
- border-bottom-left-radius: 4px;
113
- }
114
-
115
- .typing { color: var(--text-dim); font-size: 0.85rem; font-style: italic; }
116
-
117
- /* Input Deck */
118
- .input-area {
119
- padding: 30px 40px;
120
- background: linear-gradient(to top, var(--bg-dark), transparent);
121
- }
122
-
123
- .input-box {
124
- max-width: 900px;
125
- margin: 0 auto;
126
- background: rgba(255, 255, 255, 0.05);
127
- border: 1px solid var(--border);
128
- border-radius: 16px;
129
- padding: 8px;
130
- display: flex;
131
- gap: 10px;
132
- }
133
-
134
- input {
135
- flex: 1;
136
- background: transparent;
137
- border: none;
138
- color: white;
139
- padding: 12px;
140
- outline: none;
141
- font-size: 1rem;
142
- }
143
-
144
- button {
145
- background: var(--accent);
146
- color: #000;
147
- border: none;
148
- padding: 10px 24px;
149
- border-radius: 10px;
150
- font-weight: 700;
151
- cursor: pointer;
152
- transition: 0.2s;
153
- }
154
-
155
- button:hover { transform: translateY(-1px); box-shadow: 0 5px 15px var(--accent-glow); }
156
- button:disabled { background: #334155; color: #94a3b8; cursor: not-allowed; }
157
  </style>
158
  </head>
159
  <body>
160
 
161
- <aside>
162
- <div class="logo">Nexus AI</div>
163
- <a href="#" class="nav-item active">Dashboard</a>
164
- <a href="#" class="nav-item">Research Vault</a>
165
- <a href="#" class="nav-item">API Keys</a>
166
- <div style="margin-top: auto; padding-top: 20px; border-top: 1px solid var(--border);">
167
- <p style="font-size: 0.75rem; color: var(--text-dim);">SYSTEM STATUS</p>
168
- <p style="font-size: 0.85rem; margin-top: 4px;">Llama 3.2 3B Instruct</p>
169
- </div>
170
- </aside>
171
-
172
- <main>
173
- <header>
174
- <div>
175
- <h1 style="font-size: 1.1rem; font-weight: 700;">Research Assistant</h1>
176
- <p style="font-size: 0.8rem; color: var(--text-dim);">Real-time web search enabled</p>
177
  </div>
178
- <div class="status-pill">● Online</div>
179
- </header>
180
-
181
- <div id="chat-window">
182
- <div class="message ai-msg">Welcome to Nexus. Type a research query to begin.</div>
183
  </div>
 
184
 
185
- <div class="input-area">
186
- <div class="input-box">
187
- <input type="text" id="user-input" placeholder="What would you like to research today?" autocomplete="off">
188
- <button id="send-btn">Generate</button>
189
- </div>
190
  </div>
191
- </main>
192
 
193
  <script>
194
- const chatWindow = document.getElementById('chat-window');
195
- const userInput = document.getElementById('user-input');
196
- const sendBtn = document.getElementById('send-btn');
197
-
198
- function appendMessage(text, isUser) {
199
- const msgDiv = document.createElement('div');
200
- msgDiv.className = `message ${isUser ? 'user-msg' : 'ai-msg'}`;
201
- msgDiv.innerText = text;
202
- chatWindow.appendChild(msgDiv);
203
- chatWindow.scrollTop = chatWindow.scrollHeight;
204
- }
205
-
206
- async function handleSend() {
207
- const query = userInput.value.trim();
208
- if (!query) return;
209
-
210
- appendMessage(query, true);
211
- userInput.value = '';
212
-
213
- sendBtn.disabled = true;
214
- const typing = document.createElement('div');
215
- typing.className = 'typing';
216
- typing.innerText = 'Nexus AI is thinking...';
217
- chatWindow.appendChild(typing);
218
-
 
 
 
219
  try {
220
- // IMPORTANT: window.location.origin ensures absolute routing on HF Spaces
221
- const response = await fetch(`${window.location.origin}/ask`, {
222
  method: 'POST',
223
- headers: { 'Content-Type': 'application/json' },
224
- body: JSON.stringify({ query: query })
225
  });
226
-
227
- if (!response.ok) throw new Error(`Server Error: ${response.status}`);
228
 
229
- const data = await response.json();
230
- chatWindow.removeChild(typing);
231
- appendMessage(data.answer, false);
232
- } catch (err) {
233
- if (chatWindow.contains(typing)) chatWindow.removeChild(typing);
234
- appendMessage(`Connection Error: ${err.message}. Please check Space logs.`, false);
235
- } finally {
236
- sendBtn.disabled = false;
237
- chatWindow.scrollTop = chatWindow.scrollHeight;
238
  }
239
  }
240
 
241
- sendBtn.addEventListener('click', handleSend);
242
- userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleSend(); });
 
 
 
 
 
 
 
 
 
 
243
  </script>
244
  </body>
245
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Nexus AI ChatBot</title>
 
7
  <style>
8
+ body { font-family: 'Segoe UI', Roboto, sans-serif; background: #212121; color: #ececf1; margin: 0; display: flex; flex-direction: column; height: 100vh; }
9
+
10
+ /* Chat Area */
11
+ #chat-window { flex: 1; overflow-y: auto; display: flex; flex-direction: column; padding: 20px 0; }
12
+ .row { width: 100%; display: flex; justify-content: center; padding: 25px 0; border-bottom: 1px solid #3d3d3d; }
13
+ .user-row { background: #2f2f2f; }
14
+ .message-content { max-width: 800px; width: 90%; display: flex; gap: 20px; line-height: 1.6; font-size: 16px; }
15
+ .avatar { width: 30px; height: 30px; border-radius: 2px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: bold; color: white; }
16
+ .ai-avatar { background: #19c37d; }
17
+ .user-avatar { background: #5436da; }
18
+
19
+ /* Input Bar */
20
+ #input-area { padding: 40px 20px; background: linear-gradient(transparent, #212121 50%); position: sticky; bottom: 0; display: flex; justify-content: center; }
21
+ .input-container { max-width: 800px; width: 100%; position: relative; }
22
+ input { width: 100%; padding: 14px 45px 14px 16px; background: #40414f; border: 1px solid #565869; border-radius: 8px; color: white; font-size: 16px; outline: none; box-sizing: border-box; }
23
+ button { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: transparent; border: none; color: #acacbe; cursor: pointer; font-size: 20px; }
24
+
25
+ /* Loading dots */
26
+ .typing { font-style: italic; color: #9a9a9a; font-size: 14px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  </style>
28
  </head>
29
  <body>
30
 
31
+ <div id="chat-window">
32
+ <div class="row">
33
+ <div class="message-content">
34
+ <div class="avatar ai-avatar">AI</div>
35
+ <div class="text">Hello! I am Nexus AI. Ask me anything that you want to know.</div>
 
 
 
 
 
 
 
 
 
 
 
36
  </div>
 
 
 
 
 
37
  </div>
38
+ </div>
39
 
40
+ <div id="input-area">
41
+ <div class="input-container">
42
+ <input type="text" id="userInput" placeholder="Send a message..." onkeypress="if(event.key==='Enter') sendMessage()">
43
+ <button onclick="sendMessage()">➤</button>
 
44
  </div>
45
+ </div>
46
 
47
  <script>
48
+ async function sendMessage() {
49
+ const input = document.getElementById('userInput');
50
+ const chat = document.getElementById('chat-window');
51
+ const query = input.value.trim();
52
+ if(!query) return;
53
+
54
+ // 1. Add User Message
55
+ chat.innerHTML += `
56
+ <div class="row user-row">
57
+ <div class="message-content">
58
+ <div class="avatar user-avatar">U</div>
59
+ <div class="text">${query}</div>
60
+ </div>
61
+ </div>`;
62
+ input.value = '';
63
+
64
+ // 2. Add AI Placeholder (Loading)
65
+ const aiId = "ai-" + Date.now();
66
+ chat.innerHTML += `
67
+ <div class="row">
68
+ <div class="message-content">
69
+ <div class="avatar ai-avatar">AI</div>
70
+ <div class="text typing" id="${aiId}">Thinking...</div>
71
+ </div>
72
+ </div>`;
73
+ chat.scrollTop = chat.scrollHeight;
74
+
75
+ // 3. Fetch Answer
76
  try {
77
+ const res = await fetch('/ask', {
 
78
  method: 'POST',
79
+ headers: {'Content-Type': 'application/json'},
80
+ body: JSON.stringify({query: query})
81
  });
82
+ const data = await res.json();
 
83
 
84
+ // 4. Type the Answer
85
+ const aiDiv = document.getElementById(aiId);
86
+ aiDiv.classList.remove('typing');
87
+ aiDiv.innerText = '';
88
+ typeWriter(aiDiv, data.answer);
89
+ } catch (e) {
90
+ document.getElementById(aiId).innerText = "Error: Could not connect to the AI.";
 
 
91
  }
92
  }
93
 
94
+ function typeWriter(element, text) {
95
+ let i = 0;
96
+ function type() {
97
+ if (i < text.length) {
98
+ element.innerHTML += text.charAt(i);
99
+ i++;
100
+ setTimeout(type, 15); // Adjust speed here
101
+ document.getElementById('chat-window').scrollTop = document.getElementById('chat-window').scrollHeight;
102
+ }
103
+ }
104
+ type();
105
+ }
106
  </script>
107
  </body>
108
  </html>