BLOCKED01 commited on
Commit
5e1c840
·
verified ·
1 Parent(s): a33326f

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +1029 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Test123
3
- emoji: 🏃
4
- colorFrom: pink
5
  colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: test123
3
+ emoji: 🐳
4
+ colorFrom: red
5
  colorTo: pink
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,1029 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>RAG AI Document Explainer</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
10
+ <style>
11
+ .chat-container {
12
+ height: calc(100vh - 200px);
13
+ }
14
+ .admin-panel {
15
+ display: none;
16
+ }
17
+ .document-list {
18
+ max-height: 400px;
19
+ overflow-y: auto;
20
+ }
21
+ .fade-in {
22
+ animation: fadeIn 0.3s ease-in-out;
23
+ }
24
+ @keyframes fadeIn {
25
+ from { opacity: 0; }
26
+ to { opacity: 1; }
27
+ }
28
+ .markdown-content {
29
+ white-space: pre-wrap;
30
+ font-family: 'Courier New', monospace;
31
+ }
32
+ .typing-indicator {
33
+ display: inline-block;
34
+ }
35
+ .typing-indicator span {
36
+ display: inline-block;
37
+ width: 8px;
38
+ height: 8px;
39
+ border-radius: 50%;
40
+ background-color: #4b5563;
41
+ margin-right: 3px;
42
+ animation: bounce 1.4s infinite ease-in-out both;
43
+ }
44
+ .typing-indicator span:nth-child(1) {
45
+ animation-delay: -0.32s;
46
+ }
47
+ .typing-indicator span:nth-child(2) {
48
+ animation-delay: -0.16s;
49
+ }
50
+ @keyframes bounce {
51
+ 0%, 80%, 100% { transform: scale(0); }
52
+ 40% { transform: scale(1); }
53
+ }
54
+ .saving-indicator {
55
+ position: fixed;
56
+ bottom: 20px;
57
+ right: 20px;
58
+ z-index: 1000;
59
+ }
60
+ .error-message {
61
+ background-color: #fee2e2;
62
+ border-left: 4px solid #ef4444;
63
+ padding: 1rem;
64
+ margin-bottom: 1rem;
65
+ border-radius: 0.375rem;
66
+ }
67
+ .retry-button {
68
+ background-color: #ef4444;
69
+ color: white;
70
+ padding: 0.25rem 0.5rem;
71
+ border-radius: 0.25rem;
72
+ font-size: 0.875rem;
73
+ margin-top: 0.5rem;
74
+ display: inline-block;
75
+ cursor: pointer;
76
+ }
77
+ .retry-button:hover {
78
+ background-color: #dc2626;
79
+ }
80
+ </style>
81
+ </head>
82
+ <body class="bg-gray-100">
83
+ <!-- Navigation -->
84
+ <nav class="bg-blue-600 text-white p-4 shadow-md">
85
+ <div class="container mx-auto flex justify-between items-center">
86
+ <div class="flex items-center space-x-2">
87
+ <i class="fas fa-robot text-2xl"></i>
88
+ <h1 class="text-xl font-bold">RAG Document Explainer</h1>
89
+ </div>
90
+ <button id="adminBtn" class="bg-white text-blue-600 px-4 py-2 rounded-md font-medium hover:bg-blue-50 transition">
91
+ Admin Panel
92
+ </button>
93
+ </div>
94
+ </nav>
95
+
96
+ <!-- Main Chat Interface -->
97
+ <div id="chatInterface" class="container mx-auto p-4 max-w-6xl">
98
+ <div class="bg-white rounded-lg shadow-md p-6">
99
+ <h2 class="text-2xl font-bold text-gray-800 mb-6">Ask about any document</h2>
100
+
101
+ <!-- Topic Selection -->
102
+ <div class="mb-6">
103
+ <label for="topicSelect" class="block text-sm font-medium text-gray-700 mb-2">Select a topic</label>
104
+ <div class="flex space-x-2">
105
+ <select id="topicSelect" class="flex-grow p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
106
+ <option value="">Loading topics...</option>
107
+ </select>
108
+ <button id="refreshTopics" class="bg-gray-200 hover:bg-gray-300 p-3 rounded-md">
109
+ <i class="fas fa-sync-alt"></i>
110
+ </button>
111
+ </div>
112
+ </div>
113
+
114
+ <!-- Chat Container -->
115
+ <div class="bg-gray-50 rounded-lg border border-gray-200 p-4 chat-container mb-4">
116
+ <div id="chatMessages" class="space-y-4 overflow-y-auto h-full p-2">
117
+ <div class="text-center text-gray-500 py-10">
118
+ <i class="fas fa-comments text-4xl mb-2"></i>
119
+ <p>Select a topic and start asking questions about the documents</p>
120
+ </div>
121
+ </div>
122
+ </div>
123
+
124
+ <!-- Input Area -->
125
+ <div class="flex space-x-2">
126
+ <input id="userInput" type="text" placeholder="Type your question here..."
127
+ class="flex-grow p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" disabled>
128
+ <button id="sendBtn" class="bg-blue-600 text-white p-3 rounded-md hover:bg-blue-700 transition disabled:opacity-50" disabled>
129
+ <i class="fas fa-paper-plane"></i>
130
+ </button>
131
+ </div>
132
+ </div>
133
+ </div>
134
+
135
+ <!-- Admin Panel -->
136
+ <div id="adminPanel" class="admin-panel container mx-auto p-4 max-w-6xl">
137
+ <div class="bg-white rounded-lg shadow-md p-6">
138
+ <div class="flex justify-between items-center mb-6">
139
+ <h2 class="text-2xl font-bold text-gray-800">Admin Panel</h2>
140
+ <button id="backToChat" class="bg-blue-600 text-white px-4 py-2 rounded-md font-medium hover:bg-blue-700 transition">
141
+ Back to Chat
142
+ </button>
143
+ </div>
144
+
145
+ <!-- Login Form (Initially shown) -->
146
+ <div id="loginForm" class="bg-gray-50 p-6 rounded-lg mb-6">
147
+ <h3 class="text-xl font-semibold text-gray-800 mb-4">Admin Login</h3>
148
+ <div class="space-y-4">
149
+ <div>
150
+ <label for="adminUsername" class="block text-sm font-medium text-gray-700 mb-1">Username</label>
151
+ <input id="adminUsername" type="text" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
152
+ </div>
153
+ <div>
154
+ <label for="adminPassword" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
155
+ <input id="adminPassword" type="password" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
156
+ </div>
157
+ <button id="loginBtn" class="w-full bg-blue-600 text-white p-3 rounded-md hover:bg-blue-700 transition">
158
+ Login
159
+ </button>
160
+ </div>
161
+ </div>
162
+
163
+ <!-- Admin Content (Initially hidden) -->
164
+ <div id="adminContent" class="hidden">
165
+ <!-- Saving Indicator -->
166
+ <div id="savingIndicator" class="saving-indicator hidden">
167
+ <div class="bg-blue-500 text-white px-4 py-2 rounded-md shadow-lg flex items-center">
168
+ <i class="fas fa-circle-notch fa-spin mr-2"></i>
169
+ <span>Saving changes...</span>
170
+ </div>
171
+ </div>
172
+
173
+ <!-- Auto-save status -->
174
+ <div id="autoSaveStatus" class="bg-blue-50 text-blue-800 px-4 py-2 rounded-md mb-4 flex items-center">
175
+ <i class="fas fa-info-circle mr-2"></i>
176
+ <span>Changes are saved automatically when you exit the admin panel.</span>
177
+ </div>
178
+
179
+ <!-- Topic Management -->
180
+ <div class="mb-8">
181
+ <h3 class="text-xl font-semibold text-gray-800 mb-4">Topic Management</h3>
182
+ <div class="flex space-x-2 mb-4">
183
+ <input id="newTopicName" type="text" placeholder="New topic name"
184
+ class="flex-grow p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
185
+ <button id="addTopicBtn" class="bg-green-600 text-white p-3 rounded-md hover:bg-green-700 transition">
186
+ Add Topic
187
+ </button>
188
+ </div>
189
+ <div class="bg-gray-50 p-4 rounded-lg">
190
+ <h4 class="font-medium text-gray-700 mb-2">Existing Topics</h4>
191
+ <div id="topicList" class="space-y-2">
192
+ <!-- Topics will be loaded here -->
193
+ </div>
194
+ </div>
195
+ </div>
196
+
197
+ <!-- Document Management -->
198
+ <div>
199
+ <h3 class="text-xl font-semibold text-gray-800 mb-4">Document Management</h3>
200
+ <div class="bg-gray-50 p-4 rounded-lg mb-4">
201
+ <h4 class="font-medium text-gray-700 mb-2">Add New Document</h4>
202
+ <div class="space-y-4">
203
+ <div>
204
+ <label for="docTopicSelect" class="block text-sm font-medium text-gray-700 mb-1">Topic</label>
205
+ <select id="docTopicSelect" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
206
+ <option value="">Select a topic</option>
207
+ </select>
208
+ </div>
209
+ <div>
210
+ <label for="docTitle" class="block text-sm font-medium text-gray-700 mb-1">Document Title</label>
211
+ <input id="docTitle" type="text" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" placeholder="Document title">
212
+ </div>
213
+ <div>
214
+ <label for="docContent" class="block text-sm font-medium text-gray-700 mb-1">Content</label>
215
+ <textarea id="docContent" rows="5" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" placeholder="Paste document content here"></textarea>
216
+ </div>
217
+ <button id="addDocBtn" class="bg-green-600 text-white p-3 rounded-md hover:bg-green-700 transition">
218
+ Add Document
219
+ </button>
220
+ </div>
221
+ </div>
222
+
223
+ <div class="bg-gray-50 p-4 rounded-lg">
224
+ <h4 class="font-medium text-gray-700 mb-2">Existing Documents</h4>
225
+ <div class="mb-2 flex justify-between">
226
+ <div class="flex items-center space-x-2">
227
+ <label for="filterTopic" class="text-sm text-gray-700">Filter by topic:</label>
228
+ <select id="filterTopic" class="p-2 border border-gray-300 rounded-md">
229
+ <option value="">All topics</option>
230
+ </select>
231
+ </div>
232
+ <div class="relative">
233
+ <input id="searchDocs" type="text" placeholder="Search documents..." class="p-2 pl-8 border border-gray-300 rounded-md">
234
+ <i class="fas fa-search absolute left-2 top-3 text-gray-400"></i>
235
+ </div>
236
+ </div>
237
+ <div id="documentList" class="document-list space-y-2">
238
+ <!-- Documents will be loaded here -->
239
+ </div>
240
+ </div>
241
+ </div>
242
+ </div>
243
+ </div>
244
+ </div>
245
+
246
+ <!-- Document Edit Modal -->
247
+ <div id="editModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 hidden z-50">
248
+ <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-screen overflow-y-auto">
249
+ <div class="p-6">
250
+ <div class="flex justify-between items-center mb-4">
251
+ <h3 class="text-xl font-semibold">Edit Document</h3>
252
+ <button id="closeModal" class="text-gray-500 hover:text-gray-700">
253
+ <i class="fas fa-times"></i>
254
+ </button>
255
+ </div>
256
+ <div class="space-y-4">
257
+ <div>
258
+ <label for="editDocTitle" class="block text-sm font-medium text-gray-700 mb-1">Title</label>
259
+ <input id="editDocTitle" type="text" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
260
+ </div>
261
+ <div>
262
+ <label for="editDocTopic" class="block text-sm font-medium text-gray-700 mb-1">Topic</label>
263
+ <select id="editDocTopic" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
264
+ <option value="">Select a topic</option>
265
+ </select>
266
+ </div>
267
+ <div>
268
+ <label for="editDocContent" class="block text-sm font-medium text-gray-700 mb-1">Content</label>
269
+ <textarea id="editDocContent" rows="10" class="w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"></textarea>
270
+ </div>
271
+ <div class="flex justify-end space-x-2 pt-4">
272
+ <button id="deleteDocBtn" class="bg-red-600 text-white px-4 py-2 rounded-md hover:bg-red-700 transition">
273
+ Delete
274
+ </button>
275
+ <button id="saveDocBtn" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition">
276
+ Save Changes
277
+ </button>
278
+ </div>
279
+ </div>
280
+ </div>
281
+ </div>
282
+ </div>
283
+
284
+ <script>
285
+ // API Configuration
286
+ const OPENAI_API_KEY = "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";
287
+ const API_BASE_URL = "https://api.openai.com/v1/chat/completions";
288
+
289
+ // State management
290
+ let currentTopic = null;
291
+ let isAdminLoggedIn = false;
292
+ let documents = [];
293
+ let topics = [];
294
+ let currentEditingDocId = null;
295
+ let hasUnsavedChanges = false;
296
+ let lastFailedRequest = null;
297
+
298
+ // DOM Elements
299
+ const chatInterface = document.getElementById('chatInterface');
300
+ const adminPanel = document.getElementById('adminPanel');
301
+ const adminBtn = document.getElementById('adminBtn');
302
+ const backToChat = document.getElementById('backToChat');
303
+ const loginForm = document.getElementById('loginForm');
304
+ const adminContent = document.getElementById('adminContent');
305
+ const adminUsername = document.getElementById('adminUsername');
306
+ const adminPassword = document.getElementById('adminPassword');
307
+ const loginBtn = document.getElementById('loginBtn');
308
+ const topicSelect = document.getElementById('topicSelect');
309
+ const refreshTopics = document.getElementById('refreshTopics');
310
+ const userInput = document.getElementById('userInput');
311
+ const sendBtn = document.getElementById('sendBtn');
312
+ const chatMessages = document.getElementById('chatMessages');
313
+ const newTopicName = document.getElementById('newTopicName');
314
+ const addTopicBtn = document.getElementById('addTopicBtn');
315
+ const topicList = document.getElementById('topicList');
316
+ const docTopicSelect = document.getElementById('docTopicSelect');
317
+ const docTitle = document.getElementById('docTitle');
318
+ const docContent = document.getElementById('docContent');
319
+ const addDocBtn = document.getElementById('addDocBtn');
320
+ const filterTopic = document.getElementById('filterTopic');
321
+ const searchDocs = document.getElementById('searchDocs');
322
+ const documentList = document.getElementById('documentList');
323
+ const editModal = document.getElementById('editModal');
324
+ const closeModal = document.getElementById('closeModal');
325
+ const editDocTitle = document.getElementById('editDocTitle');
326
+ const editDocTopic = document.getElementById('editDocTopic');
327
+ const editDocContent = document.getElementById('editDocContent');
328
+ const deleteDocBtn = document.getElementById('deleteDocBtn');
329
+ const saveDocBtn = document.getElementById('saveDocBtn');
330
+ const savingIndicator = document.getElementById('savingIndicator');
331
+ const autoSaveStatus = document.getElementById('autoSaveStatus');
332
+
333
+ // Event Listeners
334
+ adminBtn.addEventListener('click', showAdminPanel);
335
+ backToChat.addEventListener('click', () => {
336
+ if (hasUnsavedChanges) {
337
+ saveChanges().then(() => showChatInterface());
338
+ } else {
339
+ showChatInterface();
340
+ }
341
+ });
342
+ loginBtn.addEventListener('click', handleLogin);
343
+ refreshTopics.addEventListener('click', loadTopics);
344
+ topicSelect.addEventListener('change', handleTopicChange);
345
+ sendBtn.addEventListener('click', sendMessage);
346
+ userInput.addEventListener('keypress', (e) => {
347
+ if (e.key === 'Enter') sendMessage();
348
+ });
349
+ addTopicBtn.addEventListener('click', addNewTopic);
350
+ addDocBtn.addEventListener('click', addNewDocument);
351
+ filterTopic.addEventListener('change', filterDocuments);
352
+ searchDocs.addEventListener('input', filterDocuments);
353
+ closeModal.addEventListener('click', () => editModal.classList.add('hidden'));
354
+ saveDocBtn.addEventListener('click', saveDocumentChanges);
355
+ deleteDocBtn.addEventListener('click', deleteDocument);
356
+
357
+ // Form elements that trigger changes
358
+ const adminFormElements = [newTopicName, docTopicSelect, docTitle, docContent, editDocTitle, editDocTopic, editDocContent];
359
+ adminFormElements.forEach(element => {
360
+ element.addEventListener('change', () => {
361
+ hasUnsavedChanges = true;
362
+ });
363
+ element.addEventListener('input', () => {
364
+ hasUnsavedChanges = true;
365
+ });
366
+ });
367
+
368
+ // Initialize the app
369
+ document.addEventListener('DOMContentLoaded', () => {
370
+ loadTopics();
371
+ loadDocuments();
372
+ });
373
+
374
+ // Functions
375
+ function showAdminPanel() {
376
+ chatInterface.style.display = 'none';
377
+ adminPanel.style.display = 'block';
378
+
379
+ if (!isAdminLoggedIn) {
380
+ loginForm.style.display = 'block';
381
+ adminContent.style.display = 'none';
382
+ } else {
383
+ loginForm.style.display = 'none';
384
+ adminContent.style.display = 'block';
385
+ loadAdminTopics();
386
+ loadAdminDocuments();
387
+ }
388
+ }
389
+
390
+ function showChatInterface() {
391
+ chatInterface.style.display = 'block';
392
+ adminPanel.style.display = 'none';
393
+ }
394
+
395
+ function handleLogin() {
396
+ const username = adminUsername.value.trim();
397
+ const password = adminPassword.value.trim();
398
+
399
+ if (username === 'Admin' && password === 'Admin123') {
400
+ isAdminLoggedIn = true;
401
+ loginForm.style.display = 'none';
402
+ adminContent.style.display = 'block';
403
+ loadAdminTopics();
404
+ loadAdminDocuments();
405
+
406
+ // Show success message
407
+ const loginMessage = document.createElement('div');
408
+ loginMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
409
+ loginMessage.innerHTML = '<strong>Success!</strong> You are now logged in as admin.';
410
+ adminContent.insertBefore(loginMessage, adminContent.firstChild);
411
+
412
+ // Remove message after 3 seconds
413
+ setTimeout(() => {
414
+ loginMessage.classList.remove('fade-in');
415
+ loginMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
416
+ setTimeout(() => loginMessage.remove(), 300);
417
+ }, 3000);
418
+ } else {
419
+ alert('Invalid credentials. Please try again.');
420
+ }
421
+ }
422
+
423
+ async function loadTopics() {
424
+ try {
425
+ // Simulate API call to get topics
426
+ // In a real app, this would be an actual API call
427
+ const mockTopics = [
428
+ { id: '1', name: 'Technology' },
429
+ { id: '2', name: 'Science' },
430
+ { id: '3', name: 'Business' },
431
+ { id: '4', name: 'Health' }
432
+ ];
433
+
434
+ topics = mockTopics;
435
+
436
+ // Populate topic dropdown
437
+ topicSelect.innerHTML = '<option value="">Select a topic</option>';
438
+ mockTopics.forEach(topic => {
439
+ const option = document.createElement('option');
440
+ option.value = topic.id;
441
+ option.textContent = topic.name;
442
+ topicSelect.appendChild(option);
443
+ });
444
+
445
+ // Enable input if topics are loaded
446
+ userInput.disabled = false;
447
+ sendBtn.disabled = false;
448
+
449
+ } catch (error) {
450
+ console.error('Error loading topics:', error);
451
+ topicSelect.innerHTML = '<option value="">Error loading topics</option>';
452
+ }
453
+ }
454
+
455
+ async function loadAdminTopics() {
456
+ // Populate topic dropdowns in admin panel
457
+ docTopicSelect.innerHTML = '<option value="">Select a topic</option>';
458
+ filterTopic.innerHTML = '<option value="">All topics</option>';
459
+ editDocTopic.innerHTML = '<option value="">Select a topic</option>';
460
+
461
+ topics.forEach(topic => {
462
+ const option1 = document.createElement('option');
463
+ option1.value = topic.id;
464
+ option1.textContent = topic.name;
465
+ docTopicSelect.appendChild(option1.cloneNode(true));
466
+
467
+ const option2 = document.createElement('option');
468
+ option2.value = topic.id;
469
+ option2.textContent = topic.name;
470
+ filterTopic.appendChild(option2.cloneNode(true));
471
+
472
+ const option3 = document.createElement('option');
473
+ option3.value = topic.id;
474
+ option3.textContent = topic.name;
475
+ editDocTopic.appendChild(option3.cloneNode(true));
476
+ });
477
+
478
+ // Populate topic list for management
479
+ topicList.innerHTML = '';
480
+ topics.forEach(topic => {
481
+ const topicItem = document.createElement('div');
482
+ topicItem.className = 'flex justify-between items-center bg-white p-3 rounded border border-gray-200';
483
+ topicItem.innerHTML = `
484
+ <span>${topic.name}</span>
485
+ <button class="text-red-600 hover:text-red-800 delete-topic" data-id="${topic.id}">
486
+ <i class="fas fa-trash"></i>
487
+ </button>
488
+ `;
489
+ topicList.appendChild(topicItem);
490
+ });
491
+
492
+ // Add event listeners to delete buttons
493
+ document.querySelectorAll('.delete-topic').forEach(btn => {
494
+ btn.addEventListener('click', (e) => {
495
+ const topicId = e.currentTarget.getAttribute('data-id');
496
+ deleteTopic(topicId);
497
+ });
498
+ });
499
+ }
500
+
501
+ async function loadDocuments() {
502
+ try {
503
+ // Simulate API call to get documents
504
+ // In a real app, this would be an actual API call
505
+ const mockDocuments = [
506
+ { id: '1', title: 'Introduction to AI', topicId: '1', content: 'Artificial Intelligence (AI) refers to the simulation of human intelligence in machines...' },
507
+ { id: '2', title: 'Machine Learning Basics', topicId: '1', content: 'Machine learning is a subset of AI that focuses on building systems that learn from data...' },
508
+ { id: '3', title: 'Quantum Computing', topicId: '2', content: 'Quantum computing leverages quantum-mechanical phenomena to perform calculations...' },
509
+ { id: '4', title: 'Startup Funding', topicId: '3', content: 'Startup funding typically progresses through several stages: seed, Series A, B, C, etc...' },
510
+ { id: '5', title: 'Nutrition Guidelines', topicId: '4', content: 'A balanced diet should include a variety of fruits, vegetables, whole grains, and lean proteins...' }
511
+ ];
512
+
513
+ documents = mockDocuments;
514
+
515
+ } catch (error) {
516
+ console.error('Error loading documents:', error);
517
+ }
518
+ }
519
+
520
+ async function loadAdminDocuments() {
521
+ documentList.innerHTML = '';
522
+
523
+ documents.forEach(doc => {
524
+ const topic = topics.find(t => t.id === doc.topicId) || { name: 'Unknown' };
525
+
526
+ const docItem = document.createElement('div');
527
+ docItem.className = 'bg-white p-3 rounded border border-gray-200';
528
+ docItem.innerHTML = `
529
+ <div class="flex justify-between items-start mb-2">
530
+ <h4 class="font-medium">${doc.title}</h4>
531
+ <div class="flex space-x-2">
532
+ <button class="text-blue-600 hover:text-blue-800 edit-doc" data-id="${doc.id}">
533
+ <i class="fas fa-edit"></i>
534
+ </button>
535
+ <button class="text-red-600 hover:text-red-800 delete-doc" data-id="${doc.id}">
536
+ <i class="fas fa-trash"></i>
537
+ </button>
538
+ </div>
539
+ </div>
540
+ <div class="text-sm text-gray-600 mb-2">Topic: ${topic.name}</div>
541
+ <div class="text-sm text-gray-500 truncate">${doc.content.substring(0, 100)}...</div>
542
+ `;
543
+ documentList.appendChild(docItem);
544
+ });
545
+
546
+ // Add event listeners to edit and delete buttons
547
+ document.querySelectorAll('.edit-doc').forEach(btn => {
548
+ btn.addEventListener('click', (e) => {
549
+ const docId = e.currentTarget.getAttribute('data-id');
550
+ openEditModal(docId);
551
+ });
552
+ });
553
+
554
+ document.querySelectorAll('.delete-doc').forEach(btn => {
555
+ btn.addEventListener('click', (e) => {
556
+ const docId = e.currentTarget.getAttribute('data-id');
557
+ if (confirm('Are you sure you want to delete this document?')) {
558
+ deleteDocument(docId);
559
+ }
560
+ });
561
+ });
562
+ }
563
+
564
+ function handleTopicChange() {
565
+ currentTopic = topicSelect.value;
566
+
567
+ if (currentTopic) {
568
+ // Clear chat and show welcome message for the topic
569
+ chatMessages.innerHTML = '';
570
+
571
+ const topicName = topicSelect.options[topicSelect.selectedIndex].text;
572
+ const welcomeMessage = `
573
+ <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
574
+ <div class="font-semibold text-blue-800">Welcome to the ${topicName} topic!</div>
575
+ <div class="text-sm text-blue-600 mt-1">You can now ask questions about ${topicName.toLowerCase()} documents.</div>
576
+ </div>
577
+ `;
578
+
579
+ chatMessages.innerHTML = welcomeMessage;
580
+ }
581
+ }
582
+
583
+ async function sendMessage() {
584
+ const question = userInput.value.trim();
585
+ if (!question || !currentTopic) return;
586
+
587
+ // Add user message to chat
588
+ addMessageToChat('user', question);
589
+ userInput.value = '';
590
+
591
+ // Show typing indicator
592
+ const typingIndicator = document.createElement('div');
593
+ typingIndicator.className = 'bg-gray-100 border border-gray-200 rounded-lg p-4 text-gray-700';
594
+ typingIndicator.innerHTML = `
595
+ <div class="typing-indicator">
596
+ <span></span>
597
+ <span></span>
598
+ <span></span>
599
+ </div>
600
+ `;
601
+ chatMessages.appendChild(typingIndicator);
602
+ chatMessages.scrollTop = chatMessages.scrollHeight;
603
+
604
+ try {
605
+ // Get relevant documents for the current topic
606
+ const relevantDocs = documents.filter(doc => doc.topicId === currentTopic);
607
+
608
+ if (relevantDocs.length === 0) {
609
+ typingIndicator.remove();
610
+ addMessageToChat('assistant', 'There are no documents available for this topic. Please try another topic or ask the admin to add documents.');
611
+ return;
612
+ }
613
+
614
+ // Prepare context for the AI
615
+ const context = relevantDocs.map(doc => `Document: ${doc.title}\n${doc.content}`).join('\n\n');
616
+
617
+ // Call OpenAI API
618
+ const response = await axios.post(API_BASE_URL, {
619
+ model: "gpt-3.5-turbo",
620
+ messages: [
621
+ {
622
+ role: "system",
623
+ content: `You are a helpful assistant that answers questions based on the provided documents.
624
+ Use the following documents to answer the user's question. If you don't know the answer,
625
+ say that you don't know. Be concise and accurate in your responses.
626
+
627
+ Documents:
628
+ ${context}`
629
+ },
630
+ {
631
+ role: "user",
632
+ content: question
633
+ }
634
+ ],
635
+ temperature: 0.7,
636
+ max_tokens: 500
637
+ }, {
638
+ headers: {
639
+ 'Content-Type': 'application/json',
640
+ 'Authorization': `Bearer ${OPENAI_API_KEY}`
641
+ }
642
+ });
643
+
644
+ // Remove typing indicator
645
+ typingIndicator.remove();
646
+
647
+ // Add AI response to chat
648
+ const answer = response.data.choices[0].message.content;
649
+ addMessageToChat('assistant', answer);
650
+
651
+ } catch (error) {
652
+ console.error('Error getting AI response:', error);
653
+
654
+ // Remove typing indicator
655
+ typingIndicator.remove();
656
+
657
+ // Store the failed request for retry
658
+ lastFailedRequest = {
659
+ question,
660
+ currentTopic
661
+ };
662
+
663
+ // Show error message with retry option
664
+ let errorMessage = 'Sorry, I encountered an error while processing your request.';
665
+
666
+ if (error.response) {
667
+ if (error.response.status === 401) {
668
+ errorMessage = 'Error: Invalid API key. Please check your OpenAI API key configuration.';
669
+ } else if (error.response.status === 429) {
670
+ errorMessage = 'Error: Rate limit exceeded. Please wait a moment and try again.';
671
+ } else if (error.response.data?.error?.message) {
672
+ errorMessage = `Error: ${error.response.data.error.message}`;
673
+ }
674
+ }
675
+
676
+ const errorDiv = document.createElement('div');
677
+ errorDiv.className = 'error-message fade-in';
678
+ errorDiv.innerHTML = `
679
+ <p>${errorMessage}</p>
680
+ <div class="retry-button" onclick="retryLastRequest()">
681
+ <i class="fas fa-redo mr-1"></i> Retry
682
+ </div>
683
+ `;
684
+ chatMessages.appendChild(errorDiv);
685
+ chatMessages.scrollTop = chatMessages.scrollHeight;
686
+ }
687
+ }
688
+
689
+ function retryLastRequest() {
690
+ if (lastFailedRequest) {
691
+ currentTopic = lastFailedRequest.currentTopic;
692
+ userInput.value = lastFailedRequest.question;
693
+ sendMessage();
694
+ }
695
+ }
696
+
697
+ function addMessageToChat(role, content) {
698
+ const messageDiv = document.createElement('div');
699
+ messageDiv.className = `fade-in ${role === 'user' ? 'text-right' : 'text-left'}`;
700
+
701
+ if (role === 'user') {
702
+ messageDiv.innerHTML = `
703
+ <div class="inline-block bg-blue-600 text-white rounded-lg p-3 max-w-xs md:max-w-md lg:max-w-lg">
704
+ ${content}
705
+ </div>
706
+ `;
707
+ } else {
708
+ // Format AI response with markdown-like formatting
709
+ const formattedContent = content
710
+ .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>') // Bold
711
+ .replace(/\*(.*?)\*/g, '<em>$1</em>') // Italic
712
+ .replace(/`(.*?)`/g, '<code class="bg-gray-200 px-1 rounded">$1</code>') // Inline code
713
+ .replace(/```([\s\S]*?)```/g, '<pre class="bg-gray-100 p-2 rounded overflow-x-auto"><code>$1</code></pre>'); // Code blocks
714
+
715
+ messageDiv.innerHTML = `
716
+ <div class="inline-block bg-gray-200 text-gray-800 rounded-lg p-3 max-w-xs md:max-w-md lg:max-w-lg">
717
+ ${formattedContent}
718
+ </div>
719
+ `;
720
+ }
721
+
722
+ chatMessages.appendChild(messageDiv);
723
+ chatMessages.scrollTop = chatMessages.scrollHeight;
724
+ }
725
+
726
+ function addNewTopic() {
727
+ const topicName = newTopicName.value.trim();
728
+ if (!topicName) return;
729
+
730
+ // Simulate adding a new topic (in a real app, this would be an API call)
731
+ const newTopic = {
732
+ id: Date.now().toString(),
733
+ name: topicName
734
+ };
735
+
736
+ topics.push(newTopic);
737
+ newTopicName.value = '';
738
+ hasUnsavedChanges = true;
739
+
740
+ // Reload topics in admin panel
741
+ loadAdminTopics();
742
+
743
+ // Show success message
744
+ const successMessage = document.createElement('div');
745
+ successMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
746
+ successMessage.innerHTML = `<strong>Success!</strong> Topic "${topicName}" has been added.`;
747
+ adminContent.insertBefore(successMessage, adminContent.firstChild);
748
+
749
+ // Remove message after 3 seconds
750
+ setTimeout(() => {
751
+ successMessage.classList.remove('fade-in');
752
+ successMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
753
+ setTimeout(() => successMessage.remove(), 300);
754
+ }, 3000);
755
+ }
756
+
757
+ function deleteTopic(topicId) {
758
+ if (!confirm('Are you sure you want to delete this topic? All associated documents will also be deleted.')) {
759
+ return;
760
+ }
761
+
762
+ // Simulate deleting a topic (in a real app, this would be an API call)
763
+ const topicIndex = topics.findIndex(t => t.id === topicId);
764
+ if (topicIndex !== -1) {
765
+ const deletedTopic = topics.splice(topicIndex, 1)[0];
766
+
767
+ // Also remove documents associated with this topic
768
+ documents = documents.filter(doc => doc.topicId !== topicId);
769
+ hasUnsavedChanges = true;
770
+
771
+ // Reload topics and documents in admin panel
772
+ loadAdminTopics();
773
+ loadAdminDocuments();
774
+
775
+ // Show success message
776
+ const successMessage = document.createElement('div');
777
+ successMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
778
+ successMessage.innerHTML = `<strong>Success!</strong> Topic "${deletedTopic.name}" has been deleted.`;
779
+ adminContent.insertBefore(successMessage, adminContent.firstChild);
780
+
781
+ // Remove message after 3 seconds
782
+ setTimeout(() => {
783
+ successMessage.classList.remove('fade-in');
784
+ successMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
785
+ setTimeout(() => successMessage.remove(), 300);
786
+ }, 3000);
787
+ }
788
+ }
789
+
790
+ function addNewDocument() {
791
+ const title = docTitle.value.trim();
792
+ const content = docContent.value.trim();
793
+ const topicId = docTopicSelect.value;
794
+
795
+ if (!title || !content || !topicId) {
796
+ alert('Please fill in all fields');
797
+ return;
798
+ }
799
+
800
+ // Simulate adding a new document (in a real app, this would be an API call)
801
+ const newDoc = {
802
+ id: Date.now().toString(),
803
+ title,
804
+ topicId,
805
+ content
806
+ };
807
+
808
+ documents.push(newDoc);
809
+ docTitle.value = '';
810
+ docContent.value = '';
811
+ docTopicSelect.value = '';
812
+ hasUnsavedChanges = true;
813
+
814
+ // Reload documents in admin panel
815
+ loadAdminDocuments();
816
+
817
+ // Show success message
818
+ const successMessage = document.createElement('div');
819
+ successMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
820
+ successMessage.innerHTML = `<strong>Success!</strong> Document "${title}" has been added.`;
821
+ adminContent.insertBefore(successMessage, adminContent.firstChild);
822
+
823
+ // Remove message after 3 seconds
824
+ setTimeout(() => {
825
+ successMessage.classList.remove('fade-in');
826
+ successMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
827
+ setTimeout(() => successMessage.remove(), 300);
828
+ }, 3000);
829
+ }
830
+
831
+ function filterDocuments() {
832
+ const topicFilter = filterTopic.value;
833
+ const searchQuery = searchDocs.value.toLowerCase();
834
+
835
+ documentList.innerHTML = '';
836
+
837
+ documents
838
+ .filter(doc => {
839
+ // Filter by topic if selected
840
+ if (topicFilter && doc.topicId !== topicFilter) return false;
841
+
842
+ // Filter by search query
843
+ if (searchQuery) {
844
+ const titleMatch = doc.title.toLowerCase().includes(searchQuery);
845
+ const contentMatch = doc.content.toLowerCase().includes(searchQuery);
846
+ return titleMatch || contentMatch;
847
+ }
848
+
849
+ return true;
850
+ })
851
+ .forEach(doc => {
852
+ const topic = topics.find(t => t.id === doc.topicId) || { name: 'Unknown' };
853
+
854
+ const docItem = document.createElement('div');
855
+ docItem.className = 'bg-white p-3 rounded border border-gray-200';
856
+ docItem.innerHTML = `
857
+ <div class="flex justify-between items-start mb-2">
858
+ <h4 class="font-medium">${doc.title}</h4>
859
+ <div class="flex space-x-2">
860
+ <button class="text-blue-600 hover:text-blue-800 edit-doc" data-id="${doc.id}">
861
+ <i class="fas fa-edit"></i>
862
+ </button>
863
+ <button class="text-red-600 hover:text-red-800 delete-doc" data-id="${doc.id}">
864
+ <i class="fas fa-trash"></i>
865
+ </button>
866
+ </div>
867
+ </div>
868
+ <div class="text-sm text-gray-600 mb-2">Topic: ${topic.name}</div>
869
+ <div class="text-sm text-gray-500 truncate">${doc.content.substring(0, 100)}...</div>
870
+ `;
871
+ documentList.appendChild(docItem);
872
+ });
873
+
874
+ // Add event listeners to edit and delete buttons
875
+ document.querySelectorAll('.edit-doc').forEach(btn => {
876
+ btn.addEventListener('click', (e) => {
877
+ const docId = e.currentTarget.getAttribute('data-id');
878
+ openEditModal(docId);
879
+ });
880
+ });
881
+
882
+ document.querySelectorAll('.delete-doc').forEach(btn => {
883
+ btn.addEventListener('click', (e) => {
884
+ const docId = e.currentTarget.getAttribute('data-id');
885
+ if (confirm('Are you sure you want to delete this document?')) {
886
+ deleteDocument(docId);
887
+ }
888
+ });
889
+ });
890
+ }
891
+
892
+ function openEditModal(docId) {
893
+ const doc = documents.find(d => d.id === docId);
894
+ if (!doc) return;
895
+
896
+ currentEditingDocId = docId;
897
+ editDocTitle.value = doc.title;
898
+ editDocContent.value = doc.content;
899
+
900
+ // Set the topic in the dropdown
901
+ editDocTopic.value = doc.topicId;
902
+
903
+ editModal.classList.remove('hidden');
904
+ }
905
+
906
+ function saveDocumentChanges() {
907
+ const docId = currentEditingDocId;
908
+ const docIndex = documents.findIndex(d => d.id === docId);
909
+
910
+ if (docIndex === -1) return;
911
+
912
+ const title = editDocTitle.value.trim();
913
+ const content = editDocContent.value.trim();
914
+ const topicId = editDocTopic.value;
915
+
916
+ if (!title || !content || !topicId) {
917
+ alert('Please fill in all fields');
918
+ return;
919
+ }
920
+
921
+ // Update the document
922
+ documents[docIndex] = {
923
+ ...documents[docIndex],
924
+ title,
925
+ content,
926
+ topicId
927
+ };
928
+
929
+ hasUnsavedChanges = true;
930
+
931
+ // Close the modal
932
+ editModal.classList.add('hidden');
933
+
934
+ // Reload documents in admin panel
935
+ loadAdminDocuments();
936
+
937
+ // Show success message
938
+ const successMessage = document.createElement('div');
939
+ successMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
940
+ successMessage.innerHTML = `<strong>Success!</strong> Document "${title}" has been updated.`;
941
+ adminContent.insertBefore(successMessage, adminContent.firstChild);
942
+
943
+ // Remove message after 3 seconds
944
+ setTimeout(() => {
945
+ successMessage.classList.remove('fade-in');
946
+ successMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
947
+ setTimeout(() => successMessage.remove(), 300);
948
+ }, 3000);
949
+ }
950
+
951
+ function deleteDocument(docId) {
952
+ const docIndex = documents.findIndex(d => d.id === docId);
953
+
954
+ if (docIndex === -1) return;
955
+
956
+ const deletedDoc = documents.splice(docIndex, 1)[0];
957
+ hasUnsavedChanges = true;
958
+
959
+ // If we're in the edit modal for this doc, close it
960
+ if (currentEditingDocId === docId) {
961
+ editModal.classList.add('hidden');
962
+ currentEditingDocId = null;
963
+ }
964
+
965
+ // Reload documents in admin panel
966
+ loadAdminDocuments();
967
+
968
+ // Show success message
969
+ const successMessage = document.createElement('div');
970
+ successMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
971
+ successMessage.innerHTML = `<strong>Success!</strong> Document "${deletedDoc.title}" has been deleted.`;
972
+ adminContent.insertBefore(successMessage, adminContent.firstChild);
973
+
974
+ // Remove message after 3 seconds
975
+ setTimeout(() => {
976
+ successMessage.classList.remove('fade-in');
977
+ successMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
978
+ setTimeout(() => successMessage.remove(), 300);
979
+ }, 3000);
980
+ }
981
+
982
+ async function saveChanges() {
983
+ if (!hasUnsavedChanges) return;
984
+
985
+ savingIndicator.classList.remove('hidden');
986
+
987
+ // Simulate saving changes to a backend
988
+ // In a real app, this would be actual API calls to save topics and documents
989
+ try {
990
+ await new Promise(resolve => setTimeout(resolve, 1500));
991
+
992
+ hasUnsavedChanges = false;
993
+
994
+ // Show success message
995
+ const successMessage = document.createElement('div');
996
+ successMessage.className = 'bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4 fade-in';
997
+ successMessage.innerHTML = `<strong>Success!</strong> All changes have been saved.`;
998
+ adminContent.insertBefore(successMessage, adminContent.firstChild);
999
+
1000
+ // Remove message after 3 seconds
1001
+ setTimeout(() => {
1002
+ successMessage.classList.remove('fade-in');
1003
+ successMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
1004
+ setTimeout(() => successMessage.remove(), 300);
1005
+ }, 3000);
1006
+
1007
+ } catch (error) {
1008
+ console.error('Error saving changes:', error);
1009
+
1010
+ // Show error message
1011
+ const errorMessage = document.createElement('div');
1012
+ errorMessage.className = 'bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4 fade-in';
1013
+ errorMessage.innerHTML = `<strong>Error!</strong> Failed to save changes. Please try again.`;
1014
+ adminContent.insertBefore(errorMessage, adminContent.firstChild);
1015
+
1016
+ // Remove message after 3 seconds
1017
+ setTimeout(() => {
1018
+ errorMessage.classList.remove('fade-in');
1019
+ errorMessage.classList.add('opacity-0', 'transition-opacity', 'duration-300');
1020
+ setTimeout(() => errorMessage.remove(), 300);
1021
+ }, 3000);
1022
+
1023
+ } finally {
1024
+ savingIndicator.classList.add('hidden');
1025
+ }
1026
+ }
1027
+ </script>
1028
+ <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=BLOCKED01/test123" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
1029
+ </html>