Files changed (1) hide show
  1. README.md +421 -9
README.md CHANGED
@@ -1,12 +1,424 @@
1
- ---
2
- base_model:
3
- - nicoboss/Hermes-3-Llama-3.1-405B-Uncensored
4
- pipeline_tag: text-generation
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- [<img src="https://raw.githubusercontent.com/csabakecskemeti/devquasar/main/dq_logo_black-transparent.png" width="200"/>](https://devquasar.com)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- 'Make knowledge free for everyone'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- Quantized version of: [nicoboss/Hermes-3-Llama-3.1-405B-Uncensored](https://huggingface.co/nicoboss/Hermes-3-Llama-3.1-405B-Uncensored)
12
- <a href='https://ko-fi.com/L4L416YX7C' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi6.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
 
1
+ <!DOCTYPE html>
2
+ <html lang="es-CL">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
6
+ <title>Planificador Académico Chile | Dashboard Año Escolar con IA</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
10
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
11
+ <style>
12
+ body {
13
+ transition: background-color 0.3s ease, color 0.2s ease;
14
+ }
15
+ .card-hover {
16
+ transition: transform 0.2s ease, box-shadow 0.2s ease;
17
+ }
18
+ .card-hover:hover {
19
+ transform: translateY(-3px);
20
+ box-shadow: 0 20px 25px -12px rgba(0, 0, 0, 0.15);
21
+ }
22
+ .microphone-btn:active {
23
+ transform: scale(0.97);
24
+ }
25
+ ::-webkit-scrollbar {
26
+ width: 6px;
27
+ }
28
+ ::-webkit-scrollbar-track {
29
+ background: #e2e8f0;
30
+ border-radius: 10px;
31
+ }
32
+ ::-webkit-scrollbar-thumb {
33
+ background: #94a3b8;
34
+ border-radius: 10px;
35
+ }
36
+ .dark ::-webkit-scrollbar-track {
37
+ background: #1e293b;
38
+ }
39
+ .dark ::-webkit-scrollbar-thumb {
40
+ background: #475569;
41
+ }
42
+ </style>
43
+ </head>
44
+ <body class="bg-gray-50 text-gray-800 dark:bg-gray-900 dark:text-gray-100 font-sans">
45
 
46
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
47
+ <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-8 gap-4">
48
+ <div>
49
+ <h1 class="text-3xl font-bold tracking-tight bg-gradient-to-r from-red-700 to-blue-700 bg-clip-text text-transparent dark:from-red-400 dark:to-blue-400">📘 Planificador Académico Chile + IA</h1>
50
+ <p class="text-sm text-gray-600 dark:text-gray-400 mt-1">Tu éxito escolar impulsado por Inteligencia Artificial | Sistema 1.0 a 7.0</p>
51
+ </div>
52
+ <div class="flex items-center gap-3">
53
+ <button id="darkModeToggle" class="p-2 rounded-full bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 transition">
54
+ <i class="fas fa-moon dark:hidden text-lg"></i>
55
+ <i class="fas fa-sun hidden dark:inline-block text-lg"></i>
56
+ </button>
57
+ <div class="text-sm font-medium bg-white dark:bg-gray-800 px-3 py-1 rounded-full shadow-sm border border-gray-200 dark:border-gray-700">
58
+ <i class="fas fa-calendar-alt mr-1 text-red-600"></i> <span id="fechaActual"></span>
59
+ </div>
60
+ </div>
61
+ </div>
62
 
63
+ <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
64
+ <div class="lg:col-span-2 space-y-6">
65
+ <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-md p-5 card-hover">
66
+ <div class="flex justify-between items-center flex-wrap border-b border-gray-200 dark:border-gray-700 pb-3 mb-4">
67
+ <h2 class="text-xl font-semibold"><i class="fas fa-chart-line text-blue-600 mr-2"></i> Gestor de Notas (ponderaciones Chile)</h2>
68
+ <div class="flex gap-2">
69
+ <button id="voiceInputBtn" class="microphone-btn bg-red-600 hover:bg-red-700 text-white text-sm px-3 py-1.5 rounded-full shadow flex items-center gap-1 transition"><i class="fas fa-microphone"></i> Dictar Nota</button>
70
+ </div>
71
+ </div>
72
+ <div class="overflow-x-auto">
73
+ <table class="min-w-full text-sm">
74
+ <thead class="bg-gray-100 dark:bg-gray-700 rounded-lg">
75
+ <tr class="text-left">
76
+ <th class="px-4 py-2">Asignatura</th>
77
+ <th class="px-4 py-2">Nota (1.0-7.0)</th>
78
+ <th class="px-4 py-2">Porcentaje %</th>
79
+ <th class="px-4 py-2">Aporte</th>
80
+ <th class="px-4 py-2"></th>
81
+ </tr>
82
+ </thead>
83
+ <tbody id="tablaNotasBody"></tbody>
84
+ </table>
85
+ </div>
86
+ <div class="mt-4 flex justify-end">
87
+ <button id="agregarMateriaBtn" class="text-sm bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 px-3 py-1.5 rounded-lg hover:bg-blue-200 transition"><i class="fas fa-plus mr-1"></i> Agregar materia</button>
88
+ </div>
89
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-5 pt-3 border-t border-gray-200 dark:border-gray-700">
90
+ <div class="bg-blue-50 dark:bg-blue-900/30 p-3 rounded-xl text-center">
91
+ <p class="text-xs uppercase font-semibold">Promedio General</p>
92
+ <p id="promedioGeneralVal" class="text-2xl font-bold">0.0</p>
93
+ </div>
94
+ <div class="bg-purple-50 dark:bg-purple-900/30 p-3 rounded-xl text-center">
95
+ <p class="text-xs uppercase font-semibold">NEM Simulado (1° a 4° Medio)</p>
96
+ <p id="nemSimuladoVal" class="text-2xl font-bold">-</p>
97
+ </div>
98
+ <div class="bg-emerald-50 dark:bg-emerald-900/30 p-3 rounded-xl text-center">
99
+ <p class="text-xs uppercase font-semibold">Estado Académico</p>
100
+ <p id="estadoAcademico" class="text-xl font-bold">-</p>
101
+ </div>
102
+ </div>
103
+ </div>
104
+
105
+ <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-md p-5 card-hover">
106
+ <h2 class="text-xl font-semibold mb-3"><i class="fas fa-calendar-check text-green-600 mr-2"></i> Control de Asistencia (mínimo 85%)</h2>
107
+ <div class="flex flex-wrap gap-5 items-center">
108
+ <div class="flex-1 min-w-[180px]">
109
+ <label class="block text-sm font-medium">Días asistidos</label>
110
+ <input type="number" id="asistenciaDias" class="w-full mt-1 p-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700" value="170" step="1">
111
+ <label class="block text-sm font-medium mt-2">Total días hábiles clase</label>
112
+ <input type="number" id="totalDias" class="w-full mt-1 p-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700" value="200" step="1">
113
+ <button id="actualizarAsistencia" class="mt-3 w-full bg-green-600 hover:bg-green-700 text-white py-1.5 rounded-lg text-sm transition">Actualizar % Asistencia</button>
114
+ </div>
115
+ <div class="flex-1 text-center">
116
+ <div class="relative inline-flex items-center justify-center">
117
+ <svg width="140" height="140" viewBox="0 0 140 140">
118
+ <circle cx="70" cy="70" r="60" fill="none" stroke="#e2e8f0" stroke-width="12" />
119
+ <circle id="gaugeCircle" cx="70" cy="70" r="60" fill="none" stroke="#3b82f6" stroke-width="12" stroke-dasharray="377" stroke-dashoffset="377" stroke-linecap="round" transform="rotate(-90 70 70)" />
120
+ <text x="70" y="80" text-anchor="middle" class="text-2xl font-bold fill-current dark:fill-white" id="porcentajeAsistenciaTexto">85%</text>
121
+ </svg>
122
+ </div>
123
+ <p class="text-sm mt-1 font-medium">Asistencia actual</p>
124
+ <p id="mensajeAsistencia" class="text-xs text-gray-500"></p>
125
+ </div>
126
+ <div class="flex-1">
127
+ <div id="riesgoBox" class="p-3 rounded-xl text-center text-sm font-semibold shadow-inner">✅ Sin riesgo aparente</div>
128
+ </div>
129
+ </div>
130
+ </div>
131
+
132
+ <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-md p-5 card-hover">
133
+ <h2 class="text-xl font-semibold mb-2"><i class="fas fa-chart-simple text-indigo-500 mr-2"></i> Tendencia de Notas</h2>
134
+ <canvas id="notasChart" width="400" height="200" class="max-h-56 w-full"></canvas>
135
+ </div>
136
+ </div>
137
+
138
+ <div class="space-y-6">
139
+ <div class="bg-gradient-to-br from-indigo-900 to-slate-900 text-white rounded-2xl shadow-xl p-5 border border-indigo-700">
140
+ <h2 class="text-xl font-bold mb-2 flex items-center gap-2">
141
+ <i class="fas fa-brain text-purple-400 animate-pulse"></i> Tutor IA Escolar (Chile)
142
+ </h2>
143
+ <p class="text-xs text-indigo-200 mb-4">Pregúntale a la IA cómo salvar el año. Ella analizará tus notas automáticamente.</p>
144
+
145
+ <div id="chatIARespuesta" class="bg-slate-800/80 p-3 rounded-xl border border-indigo-950/50 text-sm h-48 overflow-y-auto mb-3 space-y-2 text-slate-200">
146
+ <p class="text-xs text-purple-300">✨ <strong>Tutor IA:</strong> ¡Hola! Veo tus notas cargadas en el sistema. Haz clic en el botón de abajo para que analice tu estado académico actual o hazme una pregunta personalizada.</p>
147
+ </div>
148
+
149
+ <div class="space-y-2">
150
+ <input type="text" id="preguntaIAInput" placeholder="Ej: ¿Cómo subo el promedio de Mate?" class="w-full p-2 text-sm rounded-lg bg-slate-800 border border-indigo-700 text-white focus:outline-none focus:ring-2 focus:ring-purple-500">
151
+ <div class="flex gap-2">
152
+ <button id="btnAnalizarEstadoIA" class="flex-1 bg-purple-600 hover:bg-purple-700 text-white text-xs py-2 rounded-lg font-semibold transition flex items-center justify-center gap-1">
153
+ <i class="fas fa-wand-magic-sparkles"></i> Analizar Mis Notas
154
+ </button>
155
+ <button id="btnPreguntarIA" class="bg-indigo-600 hover:bg-indigo-700 text-white text-xs px-4 py-2 rounded-lg font-semibold transition">
156
+ Enviar
157
+ </button>
158
+ </div>
159
+ </div>
160
+ </div>
161
+
162
+ <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-md p-5 card-hover">
163
+ <h2 class="text-xl font-semibold mb-3"><i class="fas fa-tasks text-teal-600 mr-2"></i> Compañero de Estudio</h2>
164
+ <div class="mb-3 flex gap-2">
165
+ <input type="text" id="nuevaTareaInput" placeholder="Ej: Ensayo de Matemáticas" class="flex-1 p-2 text-sm rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700">
166
+ <button id="agregarTareaBtn" class="bg-teal-600 hover:bg-teal-700 text-white px-3 rounded-lg text-sm"><i class="fas fa-plus"></i></button>
167
+ </div>
168
+ <ul id="listaTareas" class="space-y-2 max-h-32 overflow-y-auto text-sm"></ul>
169
+ </div>
170
+ </div>
171
+ </div>
172
+ </div>
173
+
174
+ <script>
175
+ let materias = [
176
+ { nombre: "Matemáticas", nota: 5.5, porcentaje: 30 },
177
+ { nombre: "Lenguaje", nota: 3.8, porcentaje: 25 },
178
+ { nombre: "Ciencias", nota: 5.0, porcentaje: 25 },
179
+ { nombre: "Historia", nota: 4.2, porcentaje: 20 }
180
+ ];
181
+
182
+ let tareas = ["📘 Estudiar función cuadrática", "📝 Ensayo de Lenguaje - miércoles"];
183
+ let asistencia = { asistidos: 170, total: 200 };
184
+ let chartInstance = null;
185
+
186
+ function calcularPromedioPonderado() {
187
+ let sumaPonderada = 0;
188
+ let sumaPorcentajes = 0;
189
+ materias.forEach(m => {
190
+ sumaPonderada += (m.nota * (m.porcentaje / 100));
191
+ sumaPorcentajes += m.porcentaje;
192
+ });
193
+ if (sumaPorcentajes === 0) return 0;
194
+ return (sumaPonderada / (sumaPorcentajes / 100));
195
+ }
196
+
197
+ function calcularPorcentajeAsistencia() {
198
+ if (asistencia.total === 0) return 0;
199
+ return (asistencia.asistidos / asistencia.total) * 100;
200
+ }
201
+
202
+ function determinarEstadoGlobal() {
203
+ let promedio = calcularPromedioPonderado();
204
+ let asistPorc = calcularPorcentajeAsistencia();
205
+ if (promedio >= 4.0 && asistPorc >= 85) return { texto: "✅ APROBANDO", color: "text-green-600 dark:text-green-400" };
206
+ if (promedio < 4.0 && asistPorc < 85) return { texto: "⚠️ RIESGO DE REPETIR", color: "text-red-600" };
207
+ if (promedio < 4.0) return { texto: "📉 RIESGO POR NOTAS", color: "text-orange-600" };
208
+ return { texto: "⚠️ RIESGO ASISTENCIA", color: "text-yellow-600" };
209
+ }
210
+
211
+ function actualizarUI() {
212
+ const tbody = document.getElementById("tablaNotasBody");
213
+ tbody.innerHTML = "";
214
+ materias.forEach((m, idx) => {
215
+ const row = tbody.insertRow();
216
+ row.className = "border-b border-gray-100 dark:border-gray-700";
217
+ row.innerHTML = `
218
+ <td class="px-4 py-2 font-medium">${m.nombre}</td>
219
+ <td class="px-4 py-2"><input type="number" step="0.1" min="1.0" max="7.0" value="${m.nota}" class="nota-input w-20 p-1 border rounded dark:bg-gray-700" data-index="${idx}"></td>
220
+ <td class="px-4 py-2"><input type="number" step="5" min="0" max="100" value="${m.porcentaje}" class="porc-input w-20 p-1 border rounded dark:bg-gray-700" data-index="${idx}"> %</td>
221
+ <td class="px-4 py-2">${(m.nota * (m.porcentaje/100)).toFixed(2)}</td>
222
+ <td class="px-4 py-2"><button class="eliminar-materia text-red-500 hover:text-red-700" data-index="${idx}"><i class="fas fa-trash-alt"></i></button></td>
223
+ `;
224
+ });
225
+
226
+ document.querySelectorAll('.nota-input').forEach(inp => {
227
+ inp.addEventListener('change', (e) => {
228
+ let idx = e.target.dataset.index;
229
+ let val = parseFloat(e.target.value);
230
+ materias[idx].nota = !isNaN(val) ? Math.min(7, Math.max(1, val)) : 4.0;
231
+ actualizarTodo();
232
+ });
233
+ });
234
+
235
+ document.querySelectorAll('.porc-input').forEach(inp => {
236
+ inp.addEventListener('change', (e) => {
237
+ let idx = e.target.dataset.index;
238
+ let val = parseInt(e.target.value);
239
+ materias[idx].porcentaje = !isNaN(val) ? Math.min(100, Math.max(0, val)) : 0;
240
+ actualizarTodo();
241
+ });
242
+ });
243
+
244
+ document.querySelectorAll('.eliminar-materia').forEach(btn => {
245
+ btn.addEventListener('click', (e) => {
246
+ materias.splice(btn.dataset.index, 1);
247
+ actualizarTodo();
248
+ });
249
+ });
250
+
251
+ let promedio = calcularPromedioPonderado();
252
+ document.getElementById("promedioGeneralVal").innerHTML = promedio.toFixed(2);
253
+ document.getElementById("nemSimuladoVal").innerHTML = promedio > 0 ? promedio.toFixed(2) : "---";
254
+
255
+ const estado = determinarEstadoGlobal();
256
+ document.getElementById("estadoAcademico").innerHTML = `<span class="${estado.color}">${estado.texto}</span>`;
257
+
258
+ let asistenciaPorc = calcularPorcentajeAsistencia();
259
+ document.getElementById("porcentajeAsistenciaTexto").innerHTML = `${Math.round(asistenciaPorc)}%`;
260
+ let circumference = 2 * Math.PI * 60;
261
+ if(document.getElementById("gaugeCircle")) {
262
+ document.getElementById("gaugeCircle").setAttribute("stroke-dashoffset", circumference - (asistenciaPorc / 100) * circumference);
263
+ }
264
+
265
+ let riesgoBox = document.getElementById("riesgoBox");
266
+ if (asistenciaPorc < 85 || promedio < 4.0) {
267
+ riesgoBox.innerHTML = "⚠️ ALERTA: Revisa asistencia o notas.";
268
+ riesgoBox.className = "p-3 rounded-xl text-center text-sm font-semibold bg-red-100 text-red-800 dark:bg-red-900/40";
269
+ } else {
270
+ riesgoBox.innerHTML = "✅ ¡Vas bien encaminado!";
271
+ riesgoBox.className = "p-3 rounded-xl text-center text-sm font-semibold bg-green-100 text-green-800 dark:bg-green-900/40";
272
+ }
273
+ actualizarChart();
274
+ }
275
+
276
+ function actualizarChart() {
277
+ const ctx = document.getElementById('notasChart').getContext('2d');
278
+ let notasVals = materias.map(m => m.nota);
279
+ const labels = materias.map(m => m.nombre.substring(0,12));
280
+ if (chartInstance) chartInstance.destroy();
281
+ chartInstance = new Chart(ctx, {
282
+ type: 'line',
283
+ data: { labels: labels, datasets: [{ label: 'Nota actual', data: notasVals, borderColor: '#f97316', backgroundColor: 'rgba(249,115,22,0.1)', tension: 0.2, fill: true }] },
284
+ options: { responsive: true, scales: { y: { min: 1, max: 7 } } }
285
+ });
286
+ }
287
+
288
+ function actualizarTodo() { actualizarUI(); }
289
+
290
+ document.getElementById("actualizarAsistencia").addEventListener("click", () => {
291
+ let asis = parseInt(document.getElementById("asistenciaDias").value);
292
+ let tot = parseInt(document.getElementById("totalDias").value);
293
+ asistencia.asistidos = !isNaN(asis) ? asis : 0;
294
+ asistencia.total = !isNaN(tot) && tot > 0 ? tot : 1;
295
+ actualizarTodo();
296
+ Swal.fire("Asistencia", "Actualizada correctamente", "success");
297
+ });
298
+
299
+ document.getElementById("agregarMateriaBtn").addEventListener("click", () => {
300
+ let newName = prompt("Nombre de la asignatura:");
301
+ if (newName) {
302
+ materias.push({ nombre: newName, nota: 5.0, porcentaje: 20 });
303
+ actualizarTodo();
304
+ }
305
+ });
306
+
307
+ function renderTareas() {
308
+ const ul = document.getElementById("listaTareas");
309
+ ul.innerHTML = "";
310
+ tareas.forEach((t, idx) => {
311
+ ul.innerHTML += `<li class="flex justify-between items-center bg-gray-100 dark:bg-gray-700 p-2 rounded-lg"><span>${t}</span><button onclick="tareas.splice(${idx},1); renderTareas();" class="text-red-500"><i class="fas fa-times-circle"></i></button></li>`;
312
+ });
313
+ }
314
+ document.getElementById("agregarTareaBtn").addEventListener("click", () => {
315
+ let t = document.getElementById("nuevaTareaInput").value;
316
+ if(t) { tareas.push(t); document.getElementById("nuevaTareaInput").value=""; renderTareas(); }
317
+ });
318
+
319
+ // RECONOCIMIENTO DE VOZ CHILE
320
+ const voiceBtn = document.getElementById("voiceInputBtn");
321
+ let recognition = null;
322
+ if ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window) {
323
+ recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
324
+ recognition.lang = 'es-CL';
325
+ }
326
+
327
+ voiceBtn.addEventListener("click", () => {
328
+ if (!recognition) { Swal.fire("Error", "Navegador no compatible", "error"); return; }
329
+ recognition.start();
330
+ Swal.fire({ title: "Escuchando...", text: "Ej: 'Me saqué un 6.5 en Matemáticas'", icon: "info", showConfirmButton: false, timer: 3000 });
331
+
332
+ recognition.onresult = (event) => {
333
+ const transcript = event.results[0][0].transcript.toLowerCase();
334
+ procesarComandoVoz(transcript);
335
+ };
336
+ });
337
+
338
+ function procesarComandoVoz(texto) {
339
+ const notaMatch = texto.match(/(\d+[\.,]\d+|\d+)/);
340
+ if (!notaMatch) { Swal.fire("Aviso", "No entendí la nota", "warning"); return; }
341
+ let notaVal = parseFloat(notaMatch[0].replace(',', '.'));
342
+ if(notaVal > 7) notaVal = notaVal / 10;
343
+
344
+ let materiaNombre = "Asignatura";
345
+ let afterEn = texto.match(/en\s+([a-záéíóúñ]+)/i);
346
+ if (afterEn) materiaNombre = afterEn[1];
347
+
348
+ let porcMatch = texto.match(/(\d+)\s*(?:%|por ciento)/);
349
+ let porcentaje = porcMatch ? parseInt(porcMatch[1]) : 20;
350
+
351
+ materias.push({ nombre: materiaNombre.charAt(0).toUpperCase() + materiaNombre.slice(1), nota: notaVal, porcentaje: porcentaje });
352
+ actualizarTodo();
353
+ Swal.fire("¡Nota Agregada!", `Asignatura: ${materiaNombre}`, "success");
354
+ }
355
+
356
+ // ================= CONEXIÓN DE IA GRATUITA (Hugging Face API) =================
357
+ async function consultarIA(promptUsuario) {
358
+ const cajaChat = document.getElementById("chatIARespuesta");
359
+ cajaChat.innerHTML += `<p class="text-xs text-indigo-400">🧠 Pensando...</p>`;
360
+ cajaChat.scrollTop = cajaChat.scrollHeight;
361
+
362
+ // Preparamos los datos del alumno actuales para inyectárselos a la IA
363
+ const infoMaterias = materias.map(m => `${m.nombre}: nota ${m.nota} (${m.porcentaje}%)`).join(", ");
364
+ const promedio = calcularPromedioPonderado().toFixed(2);
365
+ const asis = calcularPorcentajeAsistencia().toFixed(0);
366
+
367
+ // Contexto ultra específico chileno
368
+ const contextoPrompt = `Eres un tutor de IA escolar experto en el sistema de educación de Chile (notas escala 1.0 a 7.0, aprobación con nota 4.0 y asistencia mínima obligatoria del 85%).
369
+ Datos actuales del alumno: Promedio General ${promedio}, Asistencia ${asis}%. Asignaturas cargadas: [${infoMaterias}].
370
+ Pregunta o solicitud del alumno: "${promptUsuario}".
371
+ Responde de manera muy motivadora, breve (máximo 3 líneas), usando modismos chilenos suaves pero amigables (como "repasar al tiro", "ojo con quedarse repitiendo", "salvar el año", "ponerle pino"). Dame solo tu respuesta final directa de tutor escolar chileno.`;
372
+
373
+ try {
374
+ // Usamos un endpoint público gratuito de Hugging Face para modelos rápidos de texto
375
+ const respuesta = await fetch("https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta", {
376
+ method: "POST",
377
+ headers: { "Content-Type": "application/json" },
378
+ body: JSON.stringify({ inputs: contextoPrompt, parameters: { max_new_tokens: 150, temperature: 0.7 } })
379
+ });
380
+
381
+ const data = await respuesta.json();
382
+ let textoIA = "";
383
+
384
+ if (data && data[0] && data[0].generated_text) {
385
+ // Limpiamos el prompt del resultado
386
+ textoIA = data[0].generated_text.replace(contextoPrompt, "").trim();
387
+ } else {
388
+ textoIA = "¡Chuta! No pude conectar con el servidor central de la IA. Pero mirando tus notas, te aconsejo que te enfoques en subir los rojos de inmediato y no faltar más a clases para asegurar ese 85%.";
389
+ }
390
+
391
+ // Remover el mensaje de "Pensando..." y poner la respuesta real
392
+ cajaChat.innerHTML = cajaChat.innerHTML.replace(`<p class="text-xs text-indigo-400">🧠 Pensando...</p>`, "");
393
+ cajaChat.innerHTML += `<p class="text-xs text-purple-300">✨ <strong>Tutor IA:</strong> ${textoIA}</p>`;
394
+ cajaChat.scrollTop = cajaChat.scrollHeight;
395
+
396
+ } catch (error) {
397
+ cajaChat.innerHTML = cajaChat.innerHTML.replace(`<p class="text-xs text-indigo-400">🧠 Pensando...</p>`, "");
398
+ cajaChat.innerHTML += `<p class="text-xs text-red-400">❌ Error al conectar con la IA externa.</p>`;
399
+ }
400
+ }
401
+
402
+ // Listeners de los botones de la IA
403
+ document.getElementById("btnAnalizarEstadoIA").addEventListener("click", () => {
404
+ consultarIA("Hazme un análisis completo de cómo voy para pasar de año con estas notas y qué tengo que hacer para salvar el semestre.");
405
+ });
406
+
407
+ document.getElementById("btnPreguntarIA").addEventListener("click", () => {
408
+ const input = document.getElementById("preguntaIAInput");
409
+ if (input.value.trim() !== "") {
410
+ consultarIA(input.value.trim());
411
+ input.value = "";
412
+ }
413
+ });
414
+
415
+ const darkToggle = document.getElementById("darkModeToggle");
416
+ darkToggle.addEventListener("click", () => document.body.classList.toggle("dark"));
417
+ document.getElementById("fechaActual").innerHTML = new Date().toLocaleDateString('es-CL', { day: 'numeric', month: 'long', year: 'numeric' });
418
+
419
+ actualizarTodo();
420
+ renderTareas();
421
+ </script>
422
+ </body>
423
+ </html>
424