File size: 11,522 Bytes
34353f0
 
 
 
 
 
1dacc08
34353f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dacc08
 
 
 
 
 
 
 
 
 
 
 
 
 
34353f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dacc08
 
34353f0
 
 
 
 
1dacc08
 
34353f0
1dacc08
34353f0
 
1dacc08
34353f0
 
 
 
 
1dacc08
 
 
34353f0
98ea673
1dacc08
 
 
98ea673
 
1dacc08
 
 
98ea673
34353f0
 
 
 
ef8d117
 
 
 
34353f0
1dacc08
 
34353f0
 
 
1dacc08
 
34353f0
 
1dacc08
34353f0
 
1dacc08
 
 
 
34353f0
 
1dacc08
34353f0
1dacc08
34353f0
 
 
 
1dacc08
 
34353f0
 
 
 
1dacc08
 
 
34353f0
 
 
 
 
1dacc08
 
 
34353f0
 
1dacc08
7ae716f
 
1dacc08
7ae716f
 
1dacc08
b4c37b9
1dacc08
 
 
7ae716f
 
 
1dacc08
 
 
34353f0
1dacc08
 
34353f0
1dacc08
34353f0
 
 
 
 
 
 
 
 
 
7ae716f
34353f0
 
 
 
1dacc08
34353f0
 
1dacc08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34353f0
 
 
 
 
 
 
7ae716f
34353f0
1dacc08
 
 
34353f0
ef8d117
1dacc08
34353f0
 
 
1dacc08
34353f0
 
 
 
1dacc08
34353f0
 
 
 
7ae716f
34353f0
 
 
 
 
1dacc08
34353f0
1dacc08
 
ef8d117
 
1dacc08
 
98ea673
34353f0
1dacc08
 
34353f0
1dacc08
34353f0
 
1dacc08
 
34353f0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ContinuumGPT - Hierarchical Memory</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .header {
            background: white;
            padding: 30px;
            border-radius: 20px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            margin-bottom: 30px;
            text-align: center;
        }

        .header h1 {
            font-size: 36px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            margin-bottom: 10px;
        }

        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: white;
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        .stat-card h3 {
            color: #667eea;
            font-size: 32px;
            margin-bottom: 5px;
        }

        .stat-card p {
            color: #666;
            font-size: 14px;
        }

        .level-badge {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 11px;
            font-weight: bold;
            margin-top: 5px;
        }

        .level-1 { background: #4CAF50; color: white; }
        .level-2 { background: #FF9800; color: white; }
        .level-3 { background: #9C27B0; color: white; }

        .chat-area {
            background: white;
            padding: 30px;
            border-radius: 20px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            margin-bottom: 30px;
        }

        .input-area {
            margin-bottom: 20px;
        }

        textarea {
            width: 100%;
            padding: 15px;
            border: 2px solid #e0e0e0;
            border-radius: 10px;
            font-size: 16px;
            resize: vertical;
            min-height: 100px;
        }

        .btn {
            padding: 15px 30px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 16px;
            font-weight: bold;
            margin-right: 10px;
            transition: transform 0.2s;
        }

        .btn:hover {
            transform: translateY(-2px);
        }

        .response-area {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 10px;
            margin-top: 20px;
            min-height: 150px;
        }

        .response-area h3 {
            color: #667eea;
            margin-bottom: 10px;
        }

        .log {
            background: white;
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            max-height: 400px;
            overflow-y: auto;
        }

        .log-entry {
            padding: 10px;
            border-bottom: 1px solid #e0e0e0;
            font-size: 14px;
        }

        .success { color: #28a745; }
        .error { color: #dc3545; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🧠 ContinuumGPT</h1>
            <p>Hierarchical Memory System</p>
            <p style="margin-top: 10px; color: #666;">
                Dataset: <a href="https://huggingface.co/datasets/Sahil5112/ContinuumGPT" target="_blank" style="color: #667eea;">Sahil5112/ContinuumGPT</a>
            </p>
            <p style="margin-top: 5px; color: #999; font-size: 13px;">
                πŸ—„οΈ Level 1: Fresh β†’ Level 2: Archived β†’ Level 3: Super-Summary
            </p>
        </div>

        <div class="stats">
            <div class="stat-card">
                <h3 id="level1Count">0</h3>
                <p>Level 1 (Fresh)</p>
                <span class="level-badge level-1">Detailed Q&A</span>
            </div>
            <div class="stat-card">
                <h3 id="level2Count">0</h3>
                <p>Level 2 (Archived)</p>
                <span class="level-badge level-2">Compressed</span>
            </div>
            <div class="stat-card">
                <h3 id="level3Count">0</h3>
                <p>Level 3 (Super)</p>
                <span class="level-badge level-3">Global Knowledge</span>
            </div>
            <div class="stat-card">
                <h3 id="bufferedCount">0</h3>
                <p>Buffered (Unsaved)</p>
            </div>
            <div class="stat-card">
                <h3 id="autoGenCount">0</h3>
                <p>Auto-Generated</p>
            </div>
            <div class="stat-card">
                <h3 id="totalEntries">0</h3>
                <p>Total Entries</p>
            </div>
        </div>

        <div class="chat-area">
            <h2 style="margin-bottom: 20px; color: #667eea;">Chat with ContinuumGPT</h2>

            <div class="input-area">
                <textarea id="userQuery" placeholder="Ask me anything..."></textarea>
            </div>

            <button class="btn" onclick="sendMessage()">πŸ’¬ Send</button>
            <button class="btn" onclick="flushBuffer()">πŸ’Ύ Save Buffer</button>
            <button class="btn" onclick="archiveNow()">πŸ“¦ Archive Now</button>
            <button class="btn" onclick="refreshStats()">πŸ”„ Refresh</button>

            <div class="response-area">
                <h3>Response</h3>
                <div id="responseText" style="white-space: pre-wrap;"></div>
                <div id="summaryText" style="margin-top: 10px; font-style: italic; color: #666;"></div>
            </div>
        </div>

        <div class="log">
            <h2 style="margin-bottom: 15px; color: #667eea;">Activity Log</h2>
            <div id="activityLog"></div>
        </div>
    </div>

    <script>
        async function sendMessage() {
            const query = document.getElementById('userQuery').value.trim();
            if (!query) {
                alert('Please enter a message');
                return;
            }

            const responseText = document.getElementById('responseText');
            const summaryText = document.getElementById('summaryText');
            responseText.innerHTML = 'πŸ”„ Thinking...';
            summaryText.innerHTML = '';

            try {
                const response = await fetch('/api/chat', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ query })
                });

                const data = await response.json();

                if (!data.success) {
                    responseText.textContent = `Error: ${data.error}`;
                    addLog(`❌ Error: ${data.error}`, 'error');
                    return;
                }

                responseText.textContent = data.response;
                summaryText.innerHTML = `πŸ“ Summary: ${data.summary}`;
                addLog(`βœ… Response saved to Level ${data.level} (${data.buffered} buffered)`, 'success');

                document.getElementById('userQuery').value = '';
                document.getElementById('bufferedCount').textContent = data.buffered;

                await refreshStats();
            } catch (error) {
                responseText.textContent = `Error: ${error.message}`;
                addLog(`❌ Error: ${error.message}`, 'error');
            }
        }

        async function flushBuffer() {
            try {
                const response = await fetch('/api/flush-buffer', { method: 'POST' });
                const data = await response.json();

                if (data.success) {
                    addLog(`πŸ’Ύ ${data.message}`, 'success');
                    await refreshStats();
                } else {
                    addLog(data.message, 'success');
                }
            } catch (error) {
                addLog(`❌ Error: ${error.message}`, 'error');
            }
        }

        async function archiveNow() {
            try {
                addLog('πŸ”„ Running archive process...', 'success');
                const response = await fetch('/api/archive-now', { method: 'POST' });
                const data = await response.json();

                if (data.success) {
                    addLog(`πŸ“¦ ${data.message}`, 'success');
                    await refreshStats();
                } else {
                    addLog(`Error: ${data.error}`, 'error');
                }
            } catch (error) {
                addLog(`❌ Error: ${error.message}`, 'error');
            }
        }

        async function refreshStats() {
            try {
                const response = await fetch('/api/dataset-stats');
                const data = await response.json();

                if (data.success) {
                    document.getElementById('level1Count').textContent = data.level_1_fresh;
                    document.getElementById('level2Count').textContent = data.level_2_archived;
                    document.getElementById('level3Count').textContent = data.level_3_super;
                    document.getElementById('bufferedCount').textContent = data.buffered;
                    document.getElementById('autoGenCount').textContent = data.auto_generated_count || 0;
                    document.getElementById('totalEntries').textContent = data.total_entries;
                    addLog('πŸ“Š Stats refreshed', 'success');
                }
            } catch (error) {
                addLog(`❌ Error: ${error.message}`, 'error');
            }
        }

        function addLog(message, type = '') {
            const log = document.getElementById('activityLog');
            const entry = document.createElement('div');
            entry.className = `log-entry ${type}`;
            entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
            log.insertBefore(entry, log.firstChild);

            while (log.children.length > 50) {
                log.removeChild(log.lastChild);
            }
        }

        // Initialize
        refreshStats();
        addLog('πŸš€ ContinuumGPT Hierarchical Memory initialized', 'success');
        addLog('πŸ—„οΈ Auto-archiving runs every 10 minutes', 'success');
        addLog('πŸ€– Auto-training runs every 5 minutes', 'success');
        addLog('πŸ’Ύ Auto-save ENABLED - all responses saved immediately', 'success');

        // Auto-refresh
        setInterval(refreshStats, 30000);

        // Enter to send
        document.getElementById('userQuery').addEventListener('keydown', function(e) {
            if (e.key === 'Enter' && e.ctrlKey) {
                sendMessage();
            }
        });

</script>
</body>
</html>