ashutoshneemval commited on
Commit
d84f05e
·
1 Parent(s): e4e1bf1

feat: Add interactive frontend dashboard served at root endpoint

Browse files
Files changed (2) hide show
  1. backend/main.py +10 -6
  2. backend/templates/index.html +1242 -0
backend/main.py CHANGED
@@ -1,7 +1,9 @@
1
  import logging
 
2
  import uvicorn
3
  from fastapi import FastAPI
4
  from fastapi.middleware.cors import CORSMiddleware
 
5
  from config import settings
6
  from database.connection import engine, Base
7
  from auth.routes import router as auth_router
@@ -46,13 +48,15 @@ app.include_router(auth_router)
46
  app.include_router(rag_router)
47
  app.include_router(ai_router)
48
 
49
- @app.get("/")
50
  def read_root():
51
- return {
52
- "status": "online",
53
- "app_name": settings.APP_NAME,
54
- "api_docs": "/docs"
55
- }
 
 
56
 
57
  if __name__ == "__main__":
58
  uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=settings.DEBUG)
 
1
  import logging
2
+ import os
3
  import uvicorn
4
  from fastapi import FastAPI
5
  from fastapi.middleware.cors import CORSMiddleware
6
+ from fastapi.responses import HTMLResponse
7
  from config import settings
8
  from database.connection import engine, Base
9
  from auth.routes import router as auth_router
 
48
  app.include_router(rag_router)
49
  app.include_router(ai_router)
50
 
51
+ @app.get("/", response_class=HTMLResponse)
52
  def read_root():
53
+ # Serve index.html dynamically
54
+ filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates", "index.html")
55
+ if not os.path.exists(filepath):
56
+ return HTMLResponse("<h1>LexAI is online! Web Interface template is missing.</h1>")
57
+
58
+ with open(filepath, "r", encoding="utf-8") as f:
59
+ return HTMLResponse(content=f.read())
60
 
61
  if __name__ == "__main__":
62
  uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=settings.DEBUG)
backend/templates/index.html ADDED
@@ -0,0 +1,1242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>LexAI - CLAT Preparation Ecosystem</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=DM+Sans:wght@400;500;700&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet">
8
+ <style>
9
+ :root {
10
+ --bg-dark: #090d16;
11
+ --bg-card: rgba(22, 30, 49, 0.7);
12
+ --border-glow: rgba(99, 102, 241, 0.25);
13
+ --accent-primary: #6366f1; /* Indigo */
14
+ --accent-glow: #818cf8;
15
+ --accent-gold: #f5a623; /* Gold */
16
+ --text-main: #f3f4f6;
17
+ --text-muted: #9ca3af;
18
+ --glass-bg: rgba(15, 23, 42, 0.4);
19
+ --glass-border: rgba(255, 255, 255, 0.08);
20
+ --success: #10b981;
21
+ --error: #ef4444;
22
+ }
23
+
24
+ * {
25
+ margin: 0;
26
+ padding: 0;
27
+ box-sizing: border-box;
28
+ font-family: 'DM Sans', sans-serif;
29
+ }
30
+
31
+ body {
32
+ background-color: var(--bg-dark);
33
+ color: var(--text-main);
34
+ height: 100vh;
35
+ overflow: hidden;
36
+ display: flex;
37
+ justify-content: center;
38
+ align-items: center;
39
+ background-image:
40
+ radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
41
+ radial-gradient(circle at 90% 80%, rgba(245, 166, 35, 0.05) 0%, transparent 40%);
42
+ }
43
+
44
+ /* Loading / Auth Overlay */
45
+ #auth-overlay {
46
+ position: fixed;
47
+ top: 0;
48
+ left: 0;
49
+ width: 100%;
50
+ height: 100%;
51
+ background: rgba(9, 13, 22, 0.95);
52
+ backdrop-filter: blur(10px);
53
+ z-index: 1000;
54
+ display: flex;
55
+ justify-content: center;
56
+ align-items: center;
57
+ transition: all 0.5s ease;
58
+ }
59
+
60
+ .auth-card {
61
+ background: var(--bg-card);
62
+ border: 1px solid var(--glass-border);
63
+ border-radius: 20px;
64
+ padding: 40px;
65
+ width: 100%;
66
+ max-width: 440px;
67
+ box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 40px rgba(99, 102, 241, 0.1);
68
+ backdrop-filter: blur(20px);
69
+ }
70
+
71
+ .auth-title {
72
+ font-family: 'Outfit', sans-serif;
73
+ font-size: 32px;
74
+ font-weight: 800;
75
+ text-align: center;
76
+ margin-bottom: 8px;
77
+ background: linear-gradient(135deg, #fff 0%, var(--accent-primary) 100%);
78
+ -webkit-background-clip: text;
79
+ -webkit-text-fill-color: transparent;
80
+ }
81
+
82
+ .auth-subtitle {
83
+ color: var(--text-muted);
84
+ font-size: 14px;
85
+ text-align: center;
86
+ margin-bottom: 30px;
87
+ }
88
+
89
+ .form-group {
90
+ margin-bottom: 20px;
91
+ }
92
+
93
+ .form-group label {
94
+ display: block;
95
+ font-size: 13px;
96
+ color: var(--text-muted);
97
+ margin-bottom: 8px;
98
+ font-weight: 500;
99
+ }
100
+
101
+ .form-input {
102
+ width: 100%;
103
+ padding: 12px 16px;
104
+ background: rgba(9, 13, 22, 0.6);
105
+ border: 1px solid var(--glass-border);
106
+ border-radius: 10px;
107
+ color: white;
108
+ font-size: 15px;
109
+ outline: none;
110
+ transition: all 0.3s;
111
+ }
112
+
113
+ .form-input:focus {
114
+ border-color: var(--accent-primary);
115
+ box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
116
+ }
117
+
118
+ .auth-btn {
119
+ width: 100%;
120
+ padding: 14px;
121
+ background: linear-gradient(135deg, var(--accent-primary) 0%, #4f46e5 100%);
122
+ border: none;
123
+ border-radius: 10px;
124
+ color: white;
125
+ font-size: 16px;
126
+ font-weight: 600;
127
+ cursor: pointer;
128
+ transition: all 0.3s;
129
+ margin-top: 10px;
130
+ box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
131
+ }
132
+
133
+ .auth-btn:hover {
134
+ transform: translateY(-2px);
135
+ box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
136
+ }
137
+
138
+ .auth-toggle-link {
139
+ text-align: center;
140
+ font-size: 13.5px;
141
+ color: var(--text-muted);
142
+ margin-top: 20px;
143
+ }
144
+
145
+ .auth-toggle-link span {
146
+ color: var(--accent-primary);
147
+ cursor: pointer;
148
+ font-weight: 600;
149
+ }
150
+
151
+ .auth-toggle-link span:hover {
152
+ text-decoration: underline;
153
+ }
154
+
155
+ .alert-message {
156
+ padding: 10px 14px;
157
+ border-radius: 8px;
158
+ font-size: 13px;
159
+ margin-bottom: 20px;
160
+ display: none;
161
+ }
162
+
163
+ .alert-error {
164
+ background: rgba(239, 68, 68, 0.15);
165
+ color: #fca5a5;
166
+ border: 1px solid rgba(239, 68, 68, 0.3);
167
+ }
168
+
169
+ .alert-success {
170
+ background: rgba(16, 185, 129, 0.15);
171
+ color: #a7f3d0;
172
+ border: 1px solid rgba(16, 185, 129, 0.3);
173
+ }
174
+
175
+ /* Main Ecosystem Layout */
176
+ #app-container {
177
+ width: 96vw;
178
+ height: 94vh;
179
+ background: rgba(10, 15, 30, 0.6);
180
+ backdrop-filter: blur(30px);
181
+ border: 1px solid var(--glass-border);
182
+ border-radius: 24px;
183
+ display: flex;
184
+ overflow: hidden;
185
+ box-shadow: 0 50px 100px rgba(0, 0, 0, 0.6);
186
+ }
187
+
188
+ /* Sidebar */
189
+ .sidebar {
190
+ width: 320px;
191
+ border-right: 1px solid var(--glass-border);
192
+ background: rgba(13, 20, 38, 0.5);
193
+ display: flex;
194
+ flex-direction: column;
195
+ padding: 24px;
196
+ }
197
+
198
+ .logo-section {
199
+ display: flex;
200
+ align-items: center;
201
+ gap: 12px;
202
+ margin-bottom: 30px;
203
+ }
204
+
205
+ .logo-icon {
206
+ width: 38px;
207
+ height: 38px;
208
+ background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-gold) 100%);
209
+ border-radius: 10px;
210
+ display: flex;
211
+ justify-content: center;
212
+ align-items: center;
213
+ font-size: 20px;
214
+ color: white;
215
+ box-shadow: 0 0 15px rgba(99, 102, 241, 0.3);
216
+ }
217
+
218
+ .logo-text {
219
+ font-family: 'Outfit', sans-serif;
220
+ font-size: 24px;
221
+ font-weight: 800;
222
+ letter-spacing: 0.5px;
223
+ }
224
+
225
+ .logo-text span {
226
+ color: var(--accent-gold);
227
+ }
228
+
229
+ /* PDF Uploader Card */
230
+ .upload-section {
231
+ background: rgba(255, 255, 255, 0.02);
232
+ border: 2px dashed rgba(255, 255, 255, 0.1);
233
+ border-radius: 16px;
234
+ padding: 20px;
235
+ text-align: center;
236
+ cursor: pointer;
237
+ transition: all 0.3s;
238
+ margin-bottom: 24px;
239
+ position: relative;
240
+ }
241
+
242
+ .upload-section:hover {
243
+ border-color: var(--accent-primary);
244
+ background: rgba(99, 102, 241, 0.03);
245
+ }
246
+
247
+ .upload-icon {
248
+ font-size: 28px;
249
+ color: var(--accent-primary);
250
+ margin-bottom: 8px;
251
+ }
252
+
253
+ .upload-title {
254
+ font-size: 14px;
255
+ font-weight: 600;
256
+ margin-bottom: 4px;
257
+ }
258
+
259
+ .upload-desc {
260
+ font-size: 11px;
261
+ color: var(--text-muted);
262
+ }
263
+
264
+ #file-input {
265
+ position: absolute;
266
+ top: 0;
267
+ left: 0;
268
+ width: 100%;
269
+ height: 100%;
270
+ opacity: 0;
271
+ cursor: pointer;
272
+ }
273
+
274
+ /* Document Manager */
275
+ .doc-section {
276
+ flex: 1;
277
+ display: flex;
278
+ flex-direction: column;
279
+ min-height: 0;
280
+ }
281
+
282
+ .section-header {
283
+ display: flex;
284
+ justify-content: space-between;
285
+ align-items: center;
286
+ margin-bottom: 12px;
287
+ }
288
+
289
+ .section-title {
290
+ font-family: 'Outfit', sans-serif;
291
+ font-size: 14px;
292
+ font-weight: 600;
293
+ text-transform: uppercase;
294
+ letter-spacing: 1px;
295
+ color: var(--text-muted);
296
+ }
297
+
298
+ .reload-btn {
299
+ background: none;
300
+ border: none;
301
+ color: var(--accent-primary);
302
+ cursor: pointer;
303
+ font-size: 12px;
304
+ font-weight: 600;
305
+ }
306
+
307
+ .reload-btn:hover {
308
+ text-decoration: underline;
309
+ }
310
+
311
+ .doc-list {
312
+ flex: 1;
313
+ overflow-y: auto;
314
+ display: flex;
315
+ flex-direction: column;
316
+ gap: 10px;
317
+ padding-right: 4px;
318
+ }
319
+
320
+ .doc-list::-webkit-scrollbar {
321
+ width: 4px;
322
+ }
323
+
324
+ .doc-list::-webkit-scrollbar-thumb {
325
+ background: rgba(255, 255, 255, 0.1);
326
+ border-radius: 2px;
327
+ }
328
+
329
+ .doc-item {
330
+ background: rgba(255, 255, 255, 0.03);
331
+ border: 1px solid var(--glass-border);
332
+ border-radius: 12px;
333
+ padding: 12px;
334
+ display: flex;
335
+ align-items: center;
336
+ gap: 12px;
337
+ transition: all 0.2s;
338
+ }
339
+
340
+ .doc-item:hover {
341
+ background: rgba(255, 255, 255, 0.05);
342
+ border-color: rgba(99, 102, 241, 0.3);
343
+ }
344
+
345
+ .doc-item-icon {
346
+ font-size: 20px;
347
+ color: var(--accent-gold);
348
+ }
349
+
350
+ .doc-item-info {
351
+ flex: 1;
352
+ min-width: 0;
353
+ }
354
+
355
+ .doc-item-name {
356
+ font-size: 13.5px;
357
+ font-weight: 500;
358
+ white-space: nowrap;
359
+ overflow: hidden;
360
+ text-overflow: ellipsis;
361
+ }
362
+
363
+ .doc-item-meta {
364
+ font-size: 10.5px;
365
+ color: var(--text-muted);
366
+ margin-top: 2px;
367
+ }
368
+
369
+ .user-panel {
370
+ border-top: 1px solid var(--glass-border);
371
+ padding-top: 20px;
372
+ margin-top: 20px;
373
+ display: flex;
374
+ align-items: center;
375
+ justify-content: space-between;
376
+ }
377
+
378
+ .user-info {
379
+ display: flex;
380
+ align-items: center;
381
+ gap: 10px;
382
+ min-width: 0;
383
+ }
384
+
385
+ .user-avatar {
386
+ width: 36px;
387
+ height: 36px;
388
+ border-radius: 50%;
389
+ background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-gold) 100%);
390
+ display: flex;
391
+ justify-content: center;
392
+ align-items: center;
393
+ font-weight: 700;
394
+ color: white;
395
+ font-size: 14px;
396
+ }
397
+
398
+ .user-email {
399
+ font-size: 13px;
400
+ font-weight: 500;
401
+ white-space: nowrap;
402
+ overflow: hidden;
403
+ text-overflow: ellipsis;
404
+ max-width: 160px;
405
+ }
406
+
407
+ .logout-btn {
408
+ background: none;
409
+ border: none;
410
+ color: var(--error);
411
+ font-size: 18px;
412
+ cursor: pointer;
413
+ padding: 4px;
414
+ border-radius: 6px;
415
+ transition: background 0.2s;
416
+ }
417
+
418
+ .logout-btn:hover {
419
+ background: rgba(239, 68, 68, 0.15);
420
+ }
421
+
422
+ /* Chat Panel */
423
+ .chat-panel {
424
+ flex: 1;
425
+ display: flex;
426
+ flex-direction: column;
427
+ background: rgba(9, 13, 22, 0.2);
428
+ }
429
+
430
+ .chat-header {
431
+ padding: 20px 30px;
432
+ border-bottom: 1px solid var(--glass-border);
433
+ display: flex;
434
+ justify-content: space-between;
435
+ align-items: center;
436
+ background: rgba(13, 20, 38, 0.3);
437
+ }
438
+
439
+ .chat-header-info h2 {
440
+ font-family: 'Outfit', sans-serif;
441
+ font-size: 18px;
442
+ font-weight: 700;
443
+ }
444
+
445
+ .chat-header-info p {
446
+ font-size: 11px;
447
+ color: var(--text-muted);
448
+ display: flex;
449
+ align-items: center;
450
+ gap: 6px;
451
+ margin-top: 2px;
452
+ }
453
+
454
+ .status-dot {
455
+ width: 7px;
456
+ height: 7px;
457
+ border-radius: 50%;
458
+ background: var(--success);
459
+ display: inline-block;
460
+ box-shadow: 0 0 8px var(--success);
461
+ }
462
+
463
+ .rag-control {
464
+ display: flex;
465
+ align-items: center;
466
+ gap: 10px;
467
+ background: rgba(255, 255, 255, 0.03);
468
+ padding: 8px 14px;
469
+ border-radius: 12px;
470
+ border: 1px solid var(--glass-border);
471
+ font-size: 12px;
472
+ font-weight: 600;
473
+ }
474
+
475
+ .switch {
476
+ position: relative;
477
+ display: inline-block;
478
+ width: 36px;
479
+ height: 20px;
480
+ }
481
+
482
+ .switch input {
483
+ opacity: 0;
484
+ width: 0;
485
+ height: 0;
486
+ }
487
+
488
+ .slider {
489
+ position: absolute;
490
+ cursor: pointer;
491
+ top: 0;
492
+ left: 0;
493
+ right: 0;
494
+ bottom: 0;
495
+ background-color: #374151;
496
+ transition: .4s;
497
+ border-radius: 20px;
498
+ }
499
+
500
+ .slider:before {
501
+ position: absolute;
502
+ content: "";
503
+ height: 14px;
504
+ width: 14px;
505
+ left: 3px;
506
+ bottom: 3px;
507
+ background-color: white;
508
+ transition: .4s;
509
+ border-radius: 50%;
510
+ }
511
+
512
+ input:checked + .slider {
513
+ background-color: var(--accent-primary);
514
+ }
515
+
516
+ input:checked + .slider:before {
517
+ transform: translateX(16px);
518
+ }
519
+
520
+ /* Messages History */
521
+ .chat-history {
522
+ flex: 1;
523
+ overflow-y: auto;
524
+ padding: 30px;
525
+ display: flex;
526
+ flex-direction: column;
527
+ gap: 20px;
528
+ }
529
+
530
+ .chat-history::-webkit-scrollbar {
531
+ width: 6px;
532
+ }
533
+
534
+ .chat-history::-webkit-scrollbar-thumb {
535
+ background: rgba(255, 255, 255, 0.05);
536
+ border-radius: 3px;
537
+ }
538
+
539
+ .chat-bubble-wrapper {
540
+ display: flex;
541
+ width: 100%;
542
+ flex-direction: column;
543
+ }
544
+
545
+ .chat-bubble-wrapper.user {
546
+ align-items: flex-end;
547
+ }
548
+
549
+ .chat-bubble-wrapper.bot {
550
+ align-items: flex-start;
551
+ }
552
+
553
+ .bubble-sender {
554
+ font-size: 10.5px;
555
+ font-weight: 700;
556
+ text-transform: uppercase;
557
+ letter-spacing: 1px;
558
+ margin-bottom: 6px;
559
+ color: var(--accent-primary);
560
+ }
561
+
562
+ .chat-bubble-wrapper.user .bubble-sender {
563
+ color: var(--accent-gold);
564
+ }
565
+
566
+ .chat-bubble {
567
+ max-width: 80%;
568
+ padding: 16px 20px;
569
+ border-radius: 18px;
570
+ font-size: 14.5px;
571
+ line-height: 1.6;
572
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
573
+ }
574
+
575
+ .chat-bubble-wrapper.user .chat-bubble {
576
+ background: linear-gradient(135deg, var(--accent-primary) 0%, #4f46e5 100%);
577
+ color: white;
578
+ border-radius: 18px 18px 2px 18px;
579
+ }
580
+
581
+ .chat-bubble-wrapper.bot .chat-bubble {
582
+ background: rgba(22, 30, 49, 0.4);
583
+ border: 1px solid var(--glass-border);
584
+ color: var(--text-main);
585
+ border-radius: 18px 18px 18px 2px;
586
+ }
587
+
588
+ .chat-bubble p {
589
+ margin-bottom: 10px;
590
+ }
591
+
592
+ .chat-bubble p:last-child {
593
+ margin-bottom: 0;
594
+ }
595
+
596
+ .chat-bubble ul, .chat-bubble ol {
597
+ padding-left: 20px;
598
+ margin-bottom: 10px;
599
+ }
600
+
601
+ .chat-bubble li {
602
+ margin-bottom: 4px;
603
+ }
604
+
605
+ .chat-bubble strong {
606
+ color: var(--accent-gold);
607
+ }
608
+
609
+ .chat-bubble-wrapper.user .chat-bubble strong {
610
+ color: white;
611
+ }
612
+
613
+ .chat-bubble-sources {
614
+ font-size: 10.5px;
615
+ color: var(--text-muted);
616
+ margin-top: 6px;
617
+ padding: 4px 10px;
618
+ background: rgba(255, 255, 255, 0.02);
619
+ border-radius: 20px;
620
+ display: inline-flex;
621
+ align-items: center;
622
+ gap: 6px;
623
+ border: 1px solid var(--glass-border);
624
+ }
625
+
626
+ /* Empty State */
627
+ .chat-empty {
628
+ flex: 1;
629
+ display: flex;
630
+ flex-direction: column;
631
+ justify-content: center;
632
+ align-items: center;
633
+ padding: 40px;
634
+ text-align: center;
635
+ }
636
+
637
+ .empty-icon {
638
+ font-size: 52px;
639
+ color: var(--accent-primary);
640
+ margin-bottom: 20px;
641
+ animation: float 4s ease-in-out infinite;
642
+ }
643
+
644
+ @keyframes float {
645
+ 0%, 100% { transform: translateY(0); }
646
+ 50% { transform: translateY(-10px); }
647
+ }
648
+
649
+ .empty-title {
650
+ font-family: 'Outfit', sans-serif;
651
+ font-size: 26px;
652
+ font-weight: 700;
653
+ margin-bottom: 8px;
654
+ }
655
+
656
+ .empty-desc {
657
+ color: var(--text-muted);
658
+ font-size: 14px;
659
+ max-width: 440px;
660
+ margin-bottom: 30px;
661
+ }
662
+
663
+ .starters-grid {
664
+ display: grid;
665
+ grid-template-columns: 1fr 1fr;
666
+ gap: 12px;
667
+ width: 100%;
668
+ max-width: 520px;
669
+ }
670
+
671
+ .starter-card {
672
+ background: rgba(255, 255, 255, 0.02);
673
+ border: 1px solid var(--glass-border);
674
+ border-radius: 12px;
675
+ padding: 14px 18px;
676
+ font-size: 13.5px;
677
+ cursor: pointer;
678
+ transition: all 0.2s;
679
+ text-align: left;
680
+ }
681
+
682
+ .starter-card:hover {
683
+ background: rgba(99, 102, 241, 0.06);
684
+ border-color: rgba(99, 102, 241, 0.4);
685
+ transform: translateY(-2px);
686
+ }
687
+
688
+ /* Typing Indicator */
689
+ .typing-bubble {
690
+ display: flex;
691
+ gap: 4px;
692
+ padding: 10px 15px;
693
+ align-items: center;
694
+ }
695
+
696
+ .typing-dot {
697
+ width: 6px;
698
+ height: 6px;
699
+ background: var(--text-muted);
700
+ border-radius: 50%;
701
+ animation: bounce 1.4s infinite ease-in-out both;
702
+ }
703
+
704
+ .typing-dot:nth-child(1) { animation-delay: -0.32s; }
705
+ .typing-dot:nth-child(2) { animation-delay: -0.16s; }
706
+
707
+ @keyframes bounce {
708
+ 0%, 80%, 100% { transform: scale(0); }
709
+ 40% { transform: scale(1.0); }
710
+ }
711
+
712
+ /* Input Area */
713
+ .chat-input-area {
714
+ padding: 24px 30px;
715
+ border-top: 1px solid var(--glass-border);
716
+ background: rgba(13, 20, 38, 0.3);
717
+ }
718
+
719
+ .chat-input-container {
720
+ background: rgba(9, 13, 22, 0.6);
721
+ border: 1px solid var(--glass-border);
722
+ border-radius: 16px;
723
+ padding: 8px 12px;
724
+ display: flex;
725
+ align-items: center;
726
+ gap: 12px;
727
+ transition: border-color 0.3s;
728
+ }
729
+
730
+ .chat-input-container:focus-within {
731
+ border-color: var(--accent-primary);
732
+ box-shadow: 0 0 15px rgba(99, 102, 241, 0.15);
733
+ }
734
+
735
+ .chat-textarea {
736
+ flex: 1;
737
+ background: none;
738
+ border: none;
739
+ outline: none;
740
+ color: white;
741
+ font-size: 14.5px;
742
+ resize: none;
743
+ height: 24px;
744
+ max-height: 120px;
745
+ line-height: 24px;
746
+ }
747
+
748
+ .send-btn {
749
+ width: 36px;
750
+ height: 36px;
751
+ background: var(--accent-primary);
752
+ border: none;
753
+ border-radius: 10px;
754
+ color: white;
755
+ font-size: 16px;
756
+ cursor: pointer;
757
+ display: flex;
758
+ justify-content: center;
759
+ align-items: center;
760
+ transition: all 0.2s;
761
+ box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
762
+ }
763
+
764
+ .send-btn:hover {
765
+ background: var(--accent-glow);
766
+ transform: scale(1.05);
767
+ }
768
+
769
+ .send-btn:disabled {
770
+ background: rgba(255, 255, 255, 0.05);
771
+ color: var(--text-muted);
772
+ cursor: not-allowed;
773
+ box-shadow: none;
774
+ transform: none;
775
+ }
776
+ </style>
777
+ </head>
778
+ <body>
779
+
780
+ <!-- Authentication Overlay -->
781
+ <div id="auth-overlay">
782
+ <div class="auth-card">
783
+ <h1 class="auth-title">LexAI Portal</h1>
784
+ <p class="auth-subtitle" id="auth-subtitle-text">CLAT AI Tutor & Doubt Solver</p>
785
+
786
+ <div class="alert-message alert-error" id="auth-error"></div>
787
+ <div class="alert-message alert-success" id="auth-success"></div>
788
+
789
+ <div id="login-form">
790
+ <div class="form-group">
791
+ <label>Email Address</label>
792
+ <input type="email" class="form-input" id="login-email" placeholder="student@nlu.edu">
793
+ </div>
794
+ <div class="form-group">
795
+ <label>Password</label>
796
+ <input type="password" class="form-input" id="login-password" placeholder="••••••••">
797
+ </div>
798
+ <button class="auth-btn" onclick="handleLogin()">Sign In</button>
799
+ <p class="auth-toggle-link">New student? <span onclick="toggleAuth(false)">Create Account</span></p>
800
+ </div>
801
+
802
+ <div id="register-form" style="display: none;">
803
+ <div class="form-group">
804
+ <label>Email Address</label>
805
+ <input type="email" class="form-input" id="reg-email" placeholder="student@nlu.edu">
806
+ </div>
807
+ <div class="form-group">
808
+ <label>Password</label>
809
+ <input type="password" class="form-input" id="reg-password" placeholder="••••••••">
810
+ </div>
811
+ <button class="auth-btn" onclick="handleRegister()">Register</button>
812
+ <p class="auth-toggle-link">Already registered? <span onclick="toggleAuth(true)">Sign In</span></p>
813
+ </div>
814
+ </div>
815
+ </div>
816
+
817
+ <!-- Main Workspace -->
818
+ <div id="app-container">
819
+ <!-- Sidebar -->
820
+ <div class="sidebar">
821
+ <div class="logo-section">
822
+ <div class="logo-icon">⚖️</div>
823
+ <h1 class="logo-text">Lex<span>AI</span></h1>
824
+ </div>
825
+
826
+ <!-- Upload File Widget -->
827
+ <div class="upload-section">
828
+ <div class="upload-icon">📂</div>
829
+ <div class="upload-title">Ingest CLAT Guide</div>
830
+ <div class="upload-desc">Click or drag PDF guide here</div>
831
+ <input type="file" id="file-input" accept=".pdf" onchange="uploadPDF(event)">
832
+ </div>
833
+
834
+ <!-- Documents Panel -->
835
+ <div class="doc-section">
836
+ <div class="section-header">
837
+ <h3 class="section-title">Ingested Guides</h3>
838
+ <button class="reload-btn" onclick="loadDocuments()">Reload</button>
839
+ </div>
840
+ <div class="doc-list" id="doc-listing">
841
+ <!-- Dynamic Document Entries -->
842
+ <div style="color: var(--text-muted); font-size:12px; text-align:center; padding: 20px 0;">No documents ingested yet.</div>
843
+ </div>
844
+ </div>
845
+
846
+ <!-- User Panel footer -->
847
+ <div class="user-panel">
848
+ <div class="user-info">
849
+ <div class="user-avatar" id="avatar-char">U</div>
850
+ <div class="user-email" id="display-user-email">guest@lexai.com</div>
851
+ </div>
852
+ <button class="logout-btn" onclick="logout()" title="Logout">🚪</button>
853
+ </div>
854
+ </div>
855
+
856
+ <!-- Chat Workspace -->
857
+ <div class="chat-panel">
858
+ <div class="chat-header">
859
+ <div class="chat-header-info">
860
+ <h2>LexAI Doubt Solver</h2>
861
+ <p><span class="status-dot"></span> NVIDIA Nemotron-3 (120B) Active</p>
862
+ </div>
863
+
864
+ <!-- RAG Switcher -->
865
+ <div class="rag-control">
866
+ <span>RAG Document Context</span>
867
+ <label class="switch">
868
+ <input type="checkbox" id="rag-toggle" checked>
869
+ <span class="slider"></span>
870
+ </label>
871
+ </div>
872
+ </div>
873
+
874
+ <!-- Messages area -->
875
+ <div class="chat-history" id="chat-scroller">
876
+ <!-- Empty State -->
877
+ <div class="chat-empty" id="empty-state">
878
+ <div class="empty-icon">🤖</div>
879
+ <h3 class="empty-title">Ask LexAI</h3>
880
+ <p class="empty-desc">I am your private AI CLAT tutor. Select a quick starter below or type your inquiry to retrieve study guide context and get detailed legal explanations.</p>
881
+
882
+ <div class="starters-grid">
883
+ <button class="starter-card" onclick="triggerStarter('Explain the difference between a Void Agreement and a Voidable Contract.')">
884
+ ⚖️ Void vs Voidable Contract
885
+ </button>
886
+ <button class="starter-card" onclick="triggerStarter('Explain the rule of Strict Liability established in Rylands v. Fletcher.')">
887
+ ⚡ Strict Liability Rule
888
+ </button>
889
+ <button class="starter-card" onclick="triggerStarter('What is the concept of Consideration? Can there be a contract without it?')">
890
+ 🤝 Legal Consideration Concept
891
+ </button>
892
+ <button class="starter-card" onclick="triggerStarter('Give me 5 high-frequency legal maxims commonly asked in CLAT.')">
893
+ 📜 5 Common Legal Maxims
894
+ </button>
895
+ </div>
896
+ </div>
897
+ </div>
898
+
899
+ <!-- Input area -->
900
+ <div class="chat-input-area">
901
+ <div class="chat-input-container">
902
+ <textarea class="chat-textarea" id="chat-msg-input" placeholder="Type a concept, fact pattern, or legal query..." onkeydown="handleTextareaKeydown(event)"></textarea>
903
+ <button class="send-btn" id="send-button" onclick="sendChat()" disabled>➔</button>
904
+ </div>
905
+ </div>
906
+ </div>
907
+ </div>
908
+
909
+ <script>
910
+ // State Management
911
+ let token = localStorage.getItem("jwt_token") || null;
912
+ let userEmail = localStorage.getItem("user_email") || null;
913
+
914
+ // Auto-detect backend host
915
+ const API_HOST = window.location.origin;
916
+
917
+ // Page setup
918
+ window.addEventListener("DOMContentLoaded", () => {
919
+ if (token) {
920
+ hideAuthOverlay();
921
+ loadDocuments();
922
+ setupUserInfo();
923
+ }
924
+
925
+ // Enable/disable send button based on input
926
+ const input = document.getElementById("chat-msg-input");
927
+ const btn = document.getElementById("send-button");
928
+ input.addEventListener("input", () => {
929
+ btn.disabled = input.value.trim() === "";
930
+ });
931
+ });
932
+
933
+ function toggleAuth(showLogin) {
934
+ document.getElementById("auth-error").style.display = "none";
935
+ document.getElementById("auth-success").style.display = "none";
936
+
937
+ if (showLogin) {
938
+ document.getElementById("login-form").style.display = "block";
939
+ document.getElementById("register-form").style.display = "none";
940
+ document.getElementById("auth-subtitle-text").innerText = "CLAT AI Tutor & Doubt Solver";
941
+ } else {
942
+ document.getElementById("login-form").style.display = "none";
943
+ document.getElementById("register-form").style.display = "block";
944
+ document.getElementById("auth-subtitle-text").innerText = "Join the LexAI preparation community";
945
+ }
946
+ }
947
+
948
+ function hideAuthOverlay() {
949
+ document.getElementById("auth-overlay").style.opacity = "0";
950
+ setTimeout(() => {
951
+ document.getElementById("auth-overlay").style.display = "none";
952
+ }, 500);
953
+ }
954
+
955
+ function logout() {
956
+ localStorage.removeItem("jwt_token");
957
+ localStorage.removeItem("user_email");
958
+ token = null;
959
+ userEmail = null;
960
+ location.reload();
961
+ }
962
+
963
+ function setupUserInfo() {
964
+ if (userEmail) {
965
+ document.getElementById("display-user-email").innerText = userEmail;
966
+ document.getElementById("avatar-char").innerText = userEmail.charAt(0).toUpperCase();
967
+ }
968
+ }
969
+
970
+ // Authentication Callbacks
971
+ async function handleRegister() {
972
+ const email = document.getElementById("reg-email").value.trim();
973
+ const password = document.getElementById("reg-password").value.trim();
974
+ const errDiv = document.getElementById("auth-error");
975
+ const succDiv = document.getElementById("auth-success");
976
+
977
+ errDiv.style.display = "none";
978
+ succDiv.style.display = "none";
979
+
980
+ if (!email || !password) {
981
+ errDiv.innerText = "Please provide email and password.";
982
+ errDiv.style.display = "block";
983
+ return;
984
+ }
985
+
986
+ try {
987
+ const response = await fetch(`${API_HOST}/auth/register`, {
988
+ method: "POST",
989
+ headers: { "Content-Type": "application/json" },
990
+ body: JSON.stringify({ email, password })
991
+ });
992
+
993
+ const data = await response.json();
994
+ if (response.ok) {
995
+ succDiv.innerText = "Registration successful! Please sign in.";
996
+ succDiv.style.display = "block";
997
+ setTimeout(() => toggleAuth(true), 1500);
998
+ } else {
999
+ errDiv.innerText = data.detail || "Registration failed.";
1000
+ errDiv.style.display = "block";
1001
+ }
1002
+ } catch (err) {
1003
+ errDiv.innerText = "Connection error. Please try again.";
1004
+ errDiv.style.display = "block";
1005
+ }
1006
+ }
1007
+
1008
+ async function handleLogin() {
1009
+ const email = document.getElementById("login-email").value.trim();
1010
+ const password = document.getElementById("login-password").value.trim();
1011
+ const errDiv = document.getElementById("auth-error");
1012
+
1013
+ errDiv.style.display = "none";
1014
+
1015
+ if (!email || !password) {
1016
+ errDiv.innerText = "Please provide email and password.";
1017
+ errDiv.style.display = "block";
1018
+ return;
1019
+ }
1020
+
1021
+ try {
1022
+ // Form encoded payload
1023
+ const formBody = new URLSearchParams();
1024
+ formBody.append("username", email);
1025
+ formBody.append("password", password);
1026
+
1027
+ const response = await fetch(`${API_HOST}/auth/token`, {
1028
+ method: "POST",
1029
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
1030
+ body: formBody
1031
+ });
1032
+
1033
+ const data = await response.json();
1034
+ if (response.ok) {
1035
+ token = data.access_token;
1036
+ userEmail = email;
1037
+ localStorage.setItem("jwt_token", token);
1038
+ localStorage.setItem("user_email", email);
1039
+
1040
+ setupUserInfo();
1041
+ hideAuthOverlay();
1042
+ loadDocuments();
1043
+ } else {
1044
+ errDiv.innerText = data.detail || "Invalid login credentials.";
1045
+ errDiv.style.display = "block";
1046
+ }
1047
+ } catch (err) {
1048
+ errDiv.innerText = "Connection error. Please try again.";
1049
+ errDiv.style.display = "block";
1050
+ }
1051
+ }
1052
+
1053
+ // RAG Document Operations
1054
+ async function loadDocuments() {
1055
+ if (!token) return;
1056
+ const listing = document.getElementById("doc-listing");
1057
+
1058
+ try {
1059
+ const response = await fetch(`${API_HOST}/rag/documents`, {
1060
+ headers: { "Authorization": `Bearer ${token}` }
1061
+ });
1062
+
1063
+ if (response.ok) {
1064
+ const docs = await response.json();
1065
+ if (docs.length === 0) {
1066
+ listing.innerHTML = `<div style="color: var(--text-muted); font-size:12px; text-align:center; padding: 20px 0;">No documents ingested yet.</div>`;
1067
+ return;
1068
+ }
1069
+
1070
+ listing.innerHTML = docs.map(doc => `
1071
+ <div class="doc-item">
1072
+ <div class="doc-item-icon">📄</div>
1073
+ <div class="doc-item-info">
1074
+ <div class="doc-item-name" title="${doc.filename}">${doc.filename}</div>
1075
+ <div class="doc-item-meta">${doc.chunk_count} chunks • ${new Date(doc.uploaded_at).toLocaleDateString()}</div>
1076
+ </div>
1077
+ </div>
1078
+ `).join("");
1079
+ }
1080
+ } catch (err) {
1081
+ console.error("Failed to load documents:", err);
1082
+ }
1083
+ }
1084
+
1085
+ async function uploadPDF(event) {
1086
+ const file = event.target.files[0];
1087
+ if (!file) return;
1088
+
1089
+ const formData = new FormData();
1090
+ formData.append("file", file);
1091
+
1092
+ // Change upload widget state to show loading
1093
+ const uploadTitle = document.querySelector(".upload-title");
1094
+ const uploadDesc = document.querySelector(".upload-desc");
1095
+ uploadTitle.innerText = "Ingesting file...";
1096
+ uploadDesc.innerText = "Parsing text and generating vectors...";
1097
+
1098
+ try {
1099
+ const response = await fetch(`${API_HOST}/rag/upload`, {
1100
+ method: "POST",
1101
+ headers: { "Authorization": `Bearer ${token}` },
1102
+ body: formData
1103
+ });
1104
+
1105
+ const data = await response.json();
1106
+ if (response.ok) {
1107
+ alert(`Successfully ingested: ${file.name}\nVector index chunks generated: ${data.chunks_ingested}`);
1108
+ loadDocuments();
1109
+ } else {
1110
+ alert(`Upload failed: ${data.detail || "Invalid format."}`);
1111
+ }
1112
+ } catch (err) {
1113
+ alert("Network error while uploading. Please verify files are under limits.");
1114
+ } finally {
1115
+ uploadTitle.innerText = "Ingest CLAT Guide";
1116
+ uploadDesc.innerText = "Click or drag PDF guide here";
1117
+ event.target.value = ""; // clear file picker
1118
+ }
1119
+ }
1120
+
1121
+ // Chat Interface Operations
1122
+ function handleTextareaKeydown(event) {
1123
+ if (event.key === 'Enter' && !event.shiftKey) {
1124
+ event.preventDefault();
1125
+ sendChat();
1126
+ }
1127
+ }
1128
+
1129
+ function triggerStarter(message) {
1130
+ document.getElementById("chat-msg-input").value = message;
1131
+ document.getElementById("send-button").disabled = false;
1132
+ sendChat();
1133
+ }
1134
+
1135
+ function addMessageBubble(sender, text, isUser, sources = []) {
1136
+ const scroller = document.getElementById("chat-scroller");
1137
+ const emptyState = document.getElementById("empty-state");
1138
+
1139
+ if (emptyState) {
1140
+ emptyState.remove();
1141
+ }
1142
+
1143
+ const wrapper = document.createElement("div");
1144
+ wrapper.className = `chat-bubble-wrapper ${isUser ? 'user' : 'bot'}`;
1145
+
1146
+ // Format content into HTML paragraphs and basic markdown bullet parses
1147
+ let htmlContent = text
1148
+ .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
1149
+ .split('\n\n')
1150
+ .map(para => {
1151
+ if (para.startsWith('* ') || para.startsWith('- ')) {
1152
+ const items = para.split(/\n[\*\-]\s/).map(item => `<li>${item.replace(/^[\*\-]\s/, '')}</li>`).join('');
1153
+ return `<ul>${items}</ul>`;
1154
+ }
1155
+ return `<p>${para.replace(/\n/g, '<br>')}</p>`;
1156
+ })
1157
+ .join('');
1158
+
1159
+ let sourcesHtml = "";
1160
+ if (sources && sources.length > 0) {
1161
+ sourcesHtml = `<div class="chat-bubble-sources">📚 Sources: Document ${sources.join(', ')}</div>`;
1162
+ }
1163
+
1164
+ wrapper.innerHTML = `
1165
+ <div class="bubble-sender">${sender}</div>
1166
+ <div class="chat-bubble">
1167
+ ${htmlContent}
1168
+ ${sourcesHtml}
1169
+ </div>
1170
+ `;
1171
+
1172
+ scroller.appendChild(wrapper);
1173
+ scroller.scrollTop = scroller.scrollHeight;
1174
+ }
1175
+
1176
+ function addTypingBubble() {
1177
+ const scroller = document.getElementById("chat-scroller");
1178
+ const wrapper = document.createElement("div");
1179
+ wrapper.className = "chat-bubble-wrapper bot";
1180
+ wrapper.id = "typing-loader";
1181
+ wrapper.innerHTML = `
1182
+ <div class="bubble-sender">LexAI</div>
1183
+ <div class="chat-bubble typing-bubble">
1184
+ <div class="typing-dot"></div>
1185
+ <div class="typing-dot"></div>
1186
+ <div class="typing-dot"></div>
1187
+ </div>
1188
+ `;
1189
+ scroller.appendChild(wrapper);
1190
+ scroller.scrollTop = scroller.scrollHeight;
1191
+ }
1192
+
1193
+ function removeTypingBubble() {
1194
+ const loader = document.getElementById("typing-loader");
1195
+ if (loader) {
1196
+ loader.remove();
1197
+ }
1198
+ }
1199
+
1200
+ async function sendChat() {
1201
+ const input = document.getElementById("chat-msg-input");
1202
+ const message = input.value.trim();
1203
+ const useRag = document.getElementById("rag-toggle").checked;
1204
+
1205
+ if (!message) return;
1206
+
1207
+ // Clear input and disable send button
1208
+ input.value = "";
1209
+ document.getElementById("send-button").disabled = true;
1210
+
1211
+ // Add user message
1212
+ addMessageBubble("Student", message, true);
1213
+
1214
+ // Add loading state
1215
+ addTypingBubble();
1216
+
1217
+ try {
1218
+ const response = await fetch(`${API_HOST}/ai/chat`, {
1219
+ method: "POST",
1220
+ headers: {
1221
+ "Content-Type": "application/json",
1222
+ "Authorization": `Bearer ${token}`
1223
+ },
1224
+ body: JSON.stringify({ message, use_rag: useRag })
1225
+ });
1226
+
1227
+ const data = await response.json();
1228
+ removeTypingBubble();
1229
+
1230
+ if (response.ok) {
1231
+ addMessageBubble("LexAI", data.response, false, data.sources);
1232
+ } else {
1233
+ addMessageBubble("LexAI", `Error: ${data.detail || "Server failed to process doubt."}`, false);
1234
+ }
1235
+ } catch (err) {
1236
+ removeTypingBubble();
1237
+ addMessageBubble("LexAI", "Network error. Failed to reach the Doubt Solver API.", false);
1238
+ }
1239
+ }
1240
+ </script>
1241
+ </body>
1242
+ </html>