SergioI1991 commited on
Commit
9bbad38
verified
1 Parent(s): b5bef06

Update templates/chat-bot.html

Browse files
Files changed (1) hide show
  1. templates/chat-bot.html +229 -77
templates/chat-bot.html CHANGED
@@ -1,88 +1,240 @@
1
  <!DOCTYPE html>
2
  <html lang="es" data-theme="light">
3
  <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>EndoBot</title>
7
- <script src="https://cdn.tailwindcss.com"></script>
8
- <script src="https://kit.fontawesome.com/a2e0e6a680.js" crossorigin="anonymous"></script>
9
- <style>
10
- :root[data-theme='dark'] {
11
- --tw-bg-opacity: 1;
12
- background-color: rgba(17, 24, 39, var(--tw-bg-opacity));
13
- color: white;
14
- }
15
- .visible { display: flex !important; }
16
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  </head>
18
- <body class="bg-gray-50 dark:bg-gray-900 min-h-screen flex flex-col items-center justify-center p-4 transition-colors">
19
-
20
- <!-- Header -->
21
- <div class="flex justify-between w-full max-w-2xl mb-4">
22
- <h1 class="text-2xl font-bold text-gray-800 dark:text-gray-100">馃挰 EndoBot</h1>
23
- <button id="theme-toggle" class="text-xl"><i class="fas fa-moon text-gray-700 dark:text-yellow-300"></i></button>
24
- </div>
25
-
26
- <!-- Chat Container -->
27
- <div class="w-full max-w-2xl bg-white dark:bg-gray-800 rounded-lg shadow p-4 flex flex-col gap-3">
28
- <div id="chat-messages" class="h-96 overflow-y-auto space-y-3 px-1 scroll-smooth">
29
- <!-- Aqu铆 se inyectan los mensajes -->
30
- </div>
31
 
32
- <!-- Input -->
33
- <form id="chat-form" class="flex gap-2 mt-2">
34
- <textarea id="user-input" class="flex-1 rounded-lg border px-3 py-2 resize-none dark:bg-gray-700 dark:text-white" rows="1" placeholder="Escribe tu pregunta..." disabled></textarea>
35
- <button id="send-button" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition" disabled>Enviar</button>
36
- </form>
37
- </div>
38
-
39
- <!-- Admin Button -->
40
- <button id="admin-panel-button" class="mt-4 text-sm text-gray-500 hover:underline">Panel de administraci贸n</button>
41
-
42
- <!-- Modales (Admin y Credenciales) -->
43
- <div id="admin-modal-overlay" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
44
- <div class="bg-white dark:bg-gray-700 p-6 rounded-lg w-96 space-y-3 relative">
45
- <button id="modal-close-btn" class="absolute top-2 right-3 text-gray-500"><i class="fas fa-times"></i></button>
46
- <h2 class="text-lg font-bold text-gray-800 dark:text-white">Panel de administraci贸n</h2>
47
- <button id="rebuild-index-button" class="w-full bg-indigo-600 text-white py-2 rounded">Reconstruir 铆ndice</button>
48
- <button id="clear-history-button" class="w-full bg-red-500 text-white py-2 rounded">Borrar historial</button>
49
- <button id="download-db-button" class="w-full bg-green-500 text-white py-2 rounded">Descargar DB</button>
50
- <button id="download-log-button" class="w-full bg-yellow-500 text-white py-2 rounded">Descargar logs</button>
51
- <button id="refresh-status-button" class="w-full bg-blue-500 text-white py-2 rounded">Estado del sistema</button>
52
- <button id="change-credentials-button" class="w-full bg-gray-500 text-white py-2 rounded">Cambiar credenciales</button>
53
- <div id="rag-status-display" class="mt-2 text-sm text-gray-700 dark:text-gray-300">...</div>
54
  </div>
55
- </div>
56
-
57
- <div id="credentials-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
58
- <div class="bg-white dark:bg-gray-700 p-6 rounded-lg w-80 space-y-4">
59
- <h2 id="credentials-title" class="text-lg font-bold text-gray-800 dark:text-white">Credenciales</h2>
60
- <input id="username-input" type="text" class="w-full px-3 py-2 border rounded dark:bg-gray-600 dark:text-white" placeholder="Usuario">
61
- <input id="password-input" type="password" class="w-full px-3 py-2 border rounded dark:bg-gray-600 dark:text-white" placeholder="Contrase帽a">
62
- <div class="flex justify-end gap-2">
63
- <button id="credentials-cancel-btn" class="px-4 py-2 text-gray-600">Cancelar</button>
64
- <button id="credentials-submit-btn" class="bg-blue-600 text-white px-4 py-2 rounded">Aceptar</button>
65
- </div>
66
  </div>
67
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- <!-- Templates para mensajes -->
70
- <template id="user-message-template">
71
- <div class="flex justify-end">
72
- <div class="bg-blue-600 text-white p-3 rounded-xl max-w-xs w-fit message-text-placeholder"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  </div>
74
- </template>
75
- <template id="assistant-message-template">
76
- <div class="flex justify-start">
77
- <div class="bg-gray-200 dark:bg-gray-600 text-black dark:text-white p-3 rounded-xl max-w-xs w-fit message-text-placeholder"></div>
 
 
 
 
 
 
 
 
 
 
 
 
78
  </div>
79
- </template>
80
-
81
- <!-- Tu JS original -->
82
- <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
83
- <script src="https://cdn.jsdelivr.net/npm/autosize@5.0.1/dist/autosize.min.js"></script>
84
- <script>
85
- // Aqu铆 va tu script JS completo (el que me pasaste)
86
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  </body>
88
- </html>
 
1
  <!DOCTYPE html>
2
  <html lang="es" data-theme="light">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>EndoBot - Asistente Dental</title>
7
+
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
10
+
11
+ <style>
12
+ /* Estilos base para scrollbar y compatibilidad */
13
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
14
+ body { font-family: 'Inter', sans-serif; -webkit-font-smoothing: antialiased; }
15
+ #chat-messages::-webkit-scrollbar { width: 8px; }
16
+ #chat-messages::-webkit-scrollbar-track { background: #f1f5f9; }
17
+ #chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
18
+ #chat-messages::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
19
+
20
+ /* Variables para los modales y tema oscuro */
21
+ :root {
22
+ --bg-secondary: #ffffff;
23
+ --text-primary: #2c3e50;
24
+ --text-secondary: #6c757d;
25
+ --accent-color: #3498db;
26
+ --border-color: #dee2e6;
27
+ }
28
+ [data-theme="dark"] {
29
+ --bg-secondary: #2c2c2c;
30
+ --text-primary: #e0e0e0;
31
+ --text-secondary: #a0a0a0;
32
+ --accent-color: #87CEEB;
33
+ --border-color: #444;
34
+ }
35
+ .modal-overlay {
36
+ position: fixed; top: 0; left: 0; width: 100%; height: 100%;
37
+ background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px);
38
+ display: flex; justify-content: center; align-items: center; z-index: 1000;
39
+ opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s;
40
+ }
41
+ .modal-overlay.visible { opacity: 1; visibility: visible; }
42
+ .modal-content {
43
+ background: var(--bg-secondary); padding: 2rem; border-radius: 16px;
44
+ width: 90%; max-width: 700px;
45
+ box-shadow: 0 10px 30px rgba(0,0,0,0.2);
46
+ transform: scale(0.95); transition: transform 0.3s ease-out;
47
+ position: relative;
48
+ }
49
+ .modal-overlay.visible .modal-content { transform: scale(1); }
50
+ .modal-close-button {
51
+ position: absolute; top: 1rem; right: 1rem; background: none; border: none;
52
+ font-size: 1.5rem; color: var(--text-secondary); cursor: pointer;
53
+ width: 40px; height: 40px; border-radius: 50%;
54
+ display: flex; align-items: center; justify-content: center;
55
+ transition: background-color 0.2s, color 0.2s, transform 0.2s;
56
+ }
57
+ .modal-close-button:hover { background-color: #e5e7eb; transform: rotate(90deg); }
58
+ .admin-section { margin-bottom: 25px; }
59
+ .admin-buttons-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; }
60
+ .form-group { margin-bottom: 15px; }
61
+ .form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
62
+ .form-group input { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 6px; }
63
+ .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
64
+ .modal-button { padding: 10px 20px; border-radius: 6px; border: none; cursor: pointer; }
65
+ </style>
66
  </head>
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
+ <body class="bg-slate-100">
69
+
70
+ <template id="user-message-template">
71
+ <div class="message-wrapper flex items-start gap-3 justify-end">
72
+ <div class="bg-blue-500 text-white p-4 rounded-xl rounded-br-none shadow-md max-w-lg">
73
+ <p class="text-sm message-text-placeholder"></p>
74
+ </div>
75
+ <div class="w-10 h-10 bg-slate-300 text-slate-600 rounded-full flex items-center justify-center flex-shrink-0"><i class="fas fa-user"></i></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  </div>
77
+ </template>
78
+ <template id="assistant-message-template">
79
+ <div class="message-wrapper flex items-start gap-3">
80
+ <div class="w-10 h-10 bg-blue-500 text-white rounded-full flex items-center justify-center flex-shrink-0"><i class="fas fa-tooth"></i></div>
81
+ <div class="bg-white p-4 rounded-xl rounded-tl-none shadow-md max-w-2xl border border-slate-200">
82
+ <p class="text-sm text-slate-700 message-text-placeholder"></p>
83
+ </div>
 
 
 
 
84
  </div>
85
+ </template>
86
+
87
+ <div class="relative w-full h-screen flex flex-col">
88
+ <header class="bg-blue-600 text-white shadow-md w-full flex-shrink-0 z-10 p-4 flex justify-between items-center">
89
+ <div class="flex items-center gap-3">
90
+ <i class="fas fa-tooth text-2xl"></i>
91
+ <h2 class="font-bold text-xl">EndoBot Asistente</h2>
92
+ </div>
93
+ <div class="flex items-center gap-2">
94
+ <button id="admin-panel-button" class="text-white hover:bg-blue-700 p-2 rounded-full transition-colors" title="Admin Panel"><i class="fas fa-shield-halved"></i></button>
95
+ <button id="theme-toggle" class="text-white hover:bg-blue-700 p-2 rounded-full transition-colors" title="Toggle Theme"><i class="fas fa-moon"></i></button>
96
+ </div>
97
+ </header>
98
 
99
+ <main class="w-full flex-1 flex flex-col overflow-hidden">
100
+ <div id="chat-messages" class="flex-1 p-6 overflow-y-auto space-y-6">
101
+ </div>
102
+
103
+ <div class="bg-white p-4 border-t border-slate-200 flex-shrink-0">
104
+ <form id="chat-form" class="flex items-center gap-3">
105
+ <textarea id="user-input" class="flex-1 bg-slate-100 rounded-lg p-3 border border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 transition" placeholder="Escribe tu consulta aqu铆..." rows="1" disabled></textarea>
106
+ <button type="submit" id="send-button" class="bg-blue-500 hover:bg-blue-600 text-white rounded-full w-12 h-12 flex items-center justify-center flex-shrink-0 transition-colors shadow-md hover:shadow-lg disabled:bg-slate-400" disabled><i class="fas fa-paper-plane"></i></button>
107
+ </form>
108
+ </div>
109
+ </main>
110
+ </div>
111
+
112
+ <div class="modal-overlay" id="admin-modal-overlay">
113
+ <div class="modal-content">
114
+ <button class="modal-close-button" id="modal-close-btn">&times;</button>
115
+ <h3><i class="fas fa-cogs"></i> System Control Panel</h3>
116
+ <div class="admin-section">
117
+ <div class="admin-buttons-grid">
118
+ <button class="admin-button" id="rebuild-index-button">Rebuild Index</button>
119
+ <button class="admin-button" id="clear-history-button">Clear Chat</button>
120
+ </div>
121
+ </div>
122
  </div>
123
+ </div>
124
+ <div class="modal-overlay" id="credentials-modal">
125
+ <div class="modal-content" style="max-width: 400px;">
126
+ <h3 id="credentials-title">Authentication Required</h3>
127
+ <div class="form-group">
128
+ <label for="username-input">Username</label>
129
+ <input type="text" id="username-input">
130
+ </div>
131
+ <div class="form-group">
132
+ <label for="password-input">Password</label>
133
+ <input type="password" id="password-input">
134
+ </div>
135
+ <div class="modal-actions">
136
+ <button id="credentials-cancel-btn" class="modal-button secondary">Cancel</button>
137
+ <button id="credentials-submit-btn" class="modal-button primary">Submit</button>
138
+ </div>
139
  </div>
140
+ </div>
141
+
142
+ <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
143
+ <script src="https://unpkg.com/autosize@4.0.2/dist/autosize.min.js"></script>
144
+
145
+ <script>
146
+ // --- C脫DIGO A PRUEBA DE FALLOS ---
147
+
148
+ // 1. Encontrar los Elementos
149
+ console.log("Buscando elementos del DOM...");
150
+ const ui = {
151
+ sendButton: document.getElementById('send-button'),
152
+ userInput: document.getElementById('user-input'),
153
+ chatMessages: document.getElementById('chat-messages'),
154
+ themeToggle: document.getElementById('theme-toggle'),
155
+ adminPanelButton: document.getElementById('admin-panel-button'),
156
+ chatForm: document.getElementById('chat-form'),
157
+ adminModal: {
158
+ overlay: document.getElementById('admin-modal-overlay'),
159
+ closeBtn: document.getElementById('modal-close-btn'),
160
+ }
161
+ // A帽ade aqu铆 los dem谩s selectores si es necesario
162
+ };
163
+ console.log("Bot贸n de tema encontrado:", ui.themeToggle);
164
+ console.log("Bot贸n de admin encontrado:", ui.adminPanelButton);
165
+
166
+ // 2. L贸gica del Chat
167
+ const appendMessage = ({ sender, text }) => {
168
+ const templateId = sender === 'bot' ? 'assistant-message-template' : 'user-message-template';
169
+ const template = document.getElementById(templateId);
170
+ if (!template) return;
171
+
172
+ const messageClone = template.content.cloneNode(true);
173
+ const messageTextElement = messageClone.querySelector('.message-text-placeholder');
174
+ if (messageTextElement) messageTextElement.textContent = text;
175
+
176
+ ui.chatMessages.appendChild(messageClone);
177
+ ui.chatMessages.scrollTop = ui.chatMessages.scrollHeight;
178
+ };
179
+
180
+ const sendMessage = () => {
181
+ const message = ui.userInput.value.trim();
182
+ if (message === '') return;
183
+ appendMessage({ sender: 'user', text: message });
184
+ ui.userInput.value = '';
185
+ autosize.update(ui.userInput);
186
+ // Aqu铆 ir铆a tu llamada a axios a '/chat-bot'
187
+ };
188
+
189
+ // 3. L贸gica del Tema
190
+ const applyTheme = (theme) => {
191
+ document.documentElement.setAttribute('data-theme', theme);
192
+ localStorage.setItem('chatTheme', theme);
193
+ const icon = ui.themeToggle.querySelector('i');
194
+ if (icon) icon.className = `fas ${theme === 'dark' ? 'fa-sun' : 'fa-moon'}`;
195
+ };
196
+ const toggleTheme = () => applyTheme(document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark');
197
+
198
+ // 4. L贸gica de los Modales
199
+ const toggleModal = (modalOverlay, show) => {
200
+ if (modalOverlay) modalOverlay.classList.toggle('visible', show);
201
+ };
202
+
203
+ // 5. Conectar los Eventos
204
+ if (ui.chatForm) {
205
+ ui.chatForm.addEventListener('submit', (e) => {
206
+ e.preventDefault();
207
+ sendMessage();
208
+ });
209
+ }
210
+ if (ui.themeToggle) {
211
+ ui.themeToggle.addEventListener('click', toggleTheme);
212
+ }
213
+ if (ui.adminPanelButton) {
214
+ ui.adminPanelButton.addEventListener('click', () => toggleModal(ui.adminModal.overlay, true));
215
+ }
216
+ if (ui.adminModal.closeBtn) {
217
+ ui.adminModal.closeBtn.addEventListener('click', () => toggleModal(ui.adminModal.overlay, false));
218
+ }
219
+ if (ui.adminModal.overlay) {
220
+ ui.adminModal.overlay.addEventListener('click', (e) => {
221
+ if (e.target === ui.adminModal.overlay) toggleModal(ui.adminModal.overlay, false);
222
+ });
223
+ }
224
+
225
+ // 6. Inicializaci贸n
226
+ function initializeApp() {
227
+ console.log("Inicializando la aplicaci贸n...");
228
+ autosize(ui.userInput);
229
+ applyTheme(localStorage.getItem('chatTheme') || 'light');
230
+ ui.userInput.disabled = false;
231
+ ui.sendButton.disabled = false;
232
+ appendMessage({ sender: 'bot', text: 'Hola! Soy tu asistente personal experto en endodoncia. 驴En qu茅 te puedo ayudar hoy?' });
233
+ }
234
+
235
+ initializeApp();
236
+
237
+ </script>
238
+
239
  </body>
240
+ </html>