-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
576 lines (504 loc) · 23.8 KB
/
Copy pathindex.html
File metadata and controls
576 lines (504 loc) · 23.8 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SmartMouse Dashboard</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<!-- Header -->
<header class="header">
<div class="logo">
<span class="mouse-icon">🐭</span>
<h1>SmartMouse Dashboard</h1>
<span class="version">v2.0</span>
</div>
<div class="status-bar">
<div class="status-item vision-ready" id="vision-status-item">
<span class="status-dot"></span>
<span>Vision</span>
</div>
<div class="status-item api-ready" id="api-status-item">
<span class="status-dot"></span>
<span>API</span>
</div>
<div class="status-item server-ready" id="server-status-item">
<span class="status-dot"></span>
<span>Server</span>
</div>
</div>
</header>
<!-- Main Content -->
<div class="main-content">
<!-- Left Panel - Chat & Controls -->
<div class="chat-container">
<div class="chat-history" id="chat-history">
<div class="message bot-message">
<div class="message-avatar">🤖</div>
<div class="message-content">
<h3>SmartMouse Assistant</h3>
<p>Welcome! I'm ready to help you automate mouse interactions. Enter a goal to get started.</p>
</div>
</div>
</div>
<div class="input-area">
<textarea id="goal-input" placeholder="Enter your goal (e.g., 'Open Chrome and search for cats', 'Click the login button', 'Leave 3 comments on Instagram')"></textarea>
<button class="send-btn" onclick="runGoal()">
<span>🚀</span>
<span>Run</span>
</button>
</div>
<div class="controls">
<button class="control-btn danger" onclick="stopGoal()" id="stop-btn" disabled>
<span>⏹️</span>
<span>Stop</span>
</button>
<button class="control-btn secondary" onclick="takeScreenshot()">
<span>📸</span>
<span>Screenshot</span>
</button>
<button class="control-btn secondary" onclick="initVision()">
<span>👁️</span>
<span>Init Vision</span>
</button>
<button class="control-btn secondary" onclick="toggleRecording()">
<span>🔴</span>
<span id="record-btn-text">Record</span>
</button>
</div>
</div>
<!-- Right Panel - Visualizations -->
<div class="sidebar">
<!-- Mouse Tracking Panel -->
<div class="panel">
<h3>🖱️ Mouse Tracking</h3>
<div class="tracking-info">
<div class="tracking-row">
<span class="tracking-label">Position:</span>
<span class="tracking-value" id="mouse-position">--</span>
</div>
<div class="tracking-row">
<span class="tracking-label">Clicks:</span>
<span class="tracking-value" id="click-count">0</span>
</div>
<div class="tracking-row">
<span class="tracking-label">Movement:</span>
<span class="tracking-value" id="movement-distance">0 px</span>
</div>
<div class="tracking-row">
<span class="tracking-label">Last Action:</span>
<span class="tracking-value" id="last-action">--</span>
</div>
</div>
<canvas id="mouse-path-canvas" class="mouse-path-canvas"></canvas>
</div>
<!-- AI Predictions Panel -->
<div class="panel">
<h3>🧠 AI Predictions</h3>
<div class="predictions-list" id="predictions-list">
<div class="prediction-item">
<span class="prediction-icon">🎯</span>
<div class="prediction-content">
<div class="prediction-text">Waiting for goal...</div>
<div class="prediction-confidence">--</div>
</div>
</div>
</div>
<div class="model-info">
<div class="model-row">
<span class="model-label">Model:</span>
<span class="model-value" id="ai-model">--</span>
</div>
<div class="model-row">
<span class="model-label">Iteration:</span>
<span class="model-value" id="iteration-count">0</span>
</div>
<div class="model-row">
<span class="model-label">Objects:</span>
<span class="model-value" id="objects-detected">0</span>
</div>
</div>
</div>
<!-- Learning Progress Panel -->
<div class="panel">
<h3>📈 Learning Progress</h3>
<div class="progress-stats">
<div class="stat-item">
<div class="stat-value" id="total-tasks">0</div>
<div class="stat-label">Total Tasks</div>
</div>
<div class="stat-item">
<div class="stat-value" id="success-rate">--</div>
<div class="stat-label">Success Rate</div>
</div>
<div class="stat-item">
<div class="stat-value" id="avg-iterations">--</div>
<div class="stat-label">Avg Iterations</div>
</div>
<div class="stat-item">
<div class="stat-value" id="patterns-learned">0</div>
<div class="stat-label">Patterns</div>
</div>
</div>
<div class="progress-bar-container">
<div class="progress-bar-label">Session Progress</div>
<div class="progress-bar">
<div class="progress-fill" id="session-progress" style="width: 0%"></div>
</div>
<div class="progress-bar-stats">
<span id="session-completed">0</span> / <span id="session-total">0</span> completed
</div>
</div>
</div>
<!-- Detected Objects Panel -->
<div class="panel">
<h3>🔍 Detected Objects</h3>
<div class="objects-list" id="objects-list">
<div class="object-placeholder">No objects detected yet</div>
</div>
</div>
</div>
</div>
<!-- Screenshot Preview -->
<div class="screenshot-panel" id="screenshot-panel" style="display:none;">
<div class="screenshot-header">
<h3>📸 Latest Screenshot</h3>
<button class="close-btn" onclick="closeScreenshot()">✕</button>
</div>
<div class="screenshot-content">
<img id="screenshot-img" class="screenshot" alt="Latest screenshot">
<div class="screenshot-metadata">
<div class="metadata-row">
<span class="metadata-label">Screen Size:</span>
<span class="metadata-value" id="screen-size">--</span>
</div>
<div class="metadata-row">
<span class="metadata-label">Objects Detected:</span>
<span class="metadata-value" id="object-count">0</span>
</div>
<div class="metadata-row">
<span class="metadata-label">Timestamp:</span>
<span class="metadata-value" id="screenshot-time">--</span>
</div>
</div>
</div>
</div>
</div>
<!-- Iteration Indicator -->
<div class="iteration-indicator" id="iteration-indicator">
Iteration: <span id="iteration-display">0</span>
</div>
<script>
const API_BASE = 'http://localhost:7891';
let isRunning = false;
let isRecording = false;
let mousePath = [];
let totalClicks = 0;
let totalMovement = 0;
let lastMouseX = 0;
let lastMouseY = 0;
let sessionStats = {
completed: 0,
total: 0,
totalIterations: 0,
successfulTasks: 0
};
// Track mouse movement
document.addEventListener('mousemove', (e) => {
const now = Date.now();
mousePath.push({ x: e.clientX, y: e.clientY, time: now });
// Keep only last 100 points
if (mousePath.length > 100) {
mousePath = mousePath.slice(-100);
}
// Update position display
document.getElementById('mouse-position').textContent = `(${e.clientX}, ${e.clientY})`;
// Calculate movement
if (lastMouseX && lastMouseY) {
const dx = e.clientX - lastMouseX;
const dy = e.clientY - lastMouseY;
const distance = Math.sqrt(dx * dx + dy * dy);
totalMovement += distance;
document.getElementById('movement-distance').textContent = `${Math.round(totalMovement)} px`;
}
lastMouseX = e.clientX;
lastMouseY = e.clientY;
// Draw path
drawMousePath();
});
// Track clicks
document.addEventListener('click', (e) => {
totalClicks++;
document.getElementById('click-count').textContent = totalClicks;
document.getElementById('last-action').textContent = `Click at (${e.clientX}, ${e.clientY})`;
});
// Draw mouse path on canvas
function drawMousePath() {
const canvas = document.getElementById('mouse-path-canvas');
const ctx = canvas.getContext('2d');
// Set canvas size
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (mousePath.length < 2) return;
// Draw path
ctx.beginPath();
ctx.moveTo(mousePath[0].x % canvas.width, mousePath[0].y % canvas.height);
for (let i = 1; i < mousePath.length; i++) {
const point = mousePath[i];
ctx.lineTo(point.x % canvas.width, point.y % canvas.height);
}
// Style path
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
gradient.addColorStop(0, 'rgba(99, 102, 241, 0.2)');
gradient.addColorStop(1, 'rgba(16, 185, 129, 0.8)');
ctx.strokeStyle = gradient;
ctx.lineWidth = 2;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.stroke();
}
// Update status every 2 seconds
setInterval(updateStatus, 2000);
updateStatus();
function addToChat(message, type = 'bot') {
const chatHistory = document.getElementById('chat-history');
const messageDiv = document.createElement('div');
messageDiv.className = `message ${type === 'user' ? 'user-message' : 'bot-message'}`;
const avatar = type === 'user' ? '👤' : '🤖';
const title = type === 'user' ? 'You' : 'SmartMouse Assistant';
messageDiv.innerHTML = `
<div class="message-avatar">${avatar}</div>
<div class="message-content">
<h3>${title}</h3>
<p>${message}</p>
</div>
`;
chatHistory.appendChild(messageDiv);
chatHistory.scrollTop = chatHistory.scrollHeight;
}
async function updateStatus() {
try {
const response = await fetch(API_BASE + '/status');
const data = await response.json();
// Update status indicators
const visionItem = document.getElementById('vision-status-item');
const apiItem = document.getElementById('api-status-item');
const serverItem = document.getElementById('server-status-item');
visionItem.className = `status-item ${data.vision_ready ? 'vision-ready' : ''}`;
apiItem.className = `status-item ${data.api_configured ? 'api-ready' : ''}`;
serverItem.className = `status-item ${data.is_running ? 'server-ready' : ''}`;
// Update iteration
const iteration = data.iteration || 0;
document.getElementById('iteration-count').textContent = iteration;
document.getElementById('iteration-display').textContent = iteration;
const indicator = document.getElementById('iteration-indicator');
if (data.is_running) {
indicator.classList.add('active');
} else {
indicator.classList.remove('active');
}
// Update objects detected
const objectsCount = data.detected_objects?.length || 0;
document.getElementById('objects-detected').textContent = objectsCount;
document.getElementById('object-count').textContent = objectsCount;
// Update objects list
updateObjectsList(data.detected_objects || []);
// Update running state
if (data.is_running !== isRunning) {
isRunning = data.is_running;
document.getElementById('stop-btn').disabled = !isRunning;
}
// Update model info
if (data.model) {
document.getElementById('ai-model').textContent = data.model;
}
if (data.last_error) {
addToChat('Error: ' + data.last_error, 'bot');
}
} catch (e) {
console.error('Status update failed:', e);
// Show offline status
document.getElementById('vision-status-item').className = 'status-item';
document.getElementById('api-status-item').className = 'status-item';
document.getElementById('server-status-item').className = 'status-item';
}
}
function updateObjectsList(objects) {
const objectsList = document.getElementById('objects-list');
if (objects.length === 0) {
objectsList.innerHTML = '<div class="object-placeholder">No objects detected yet</div>';
return;
}
// Group by type
const grouped = {};
objects.forEach(obj => {
const type = obj.type || obj.label || 'unknown';
if (!grouped[type]) {
grouped[type] = [];
}
grouped[type].push(obj);
});
let html = '';
for (const [type, items] of Object.entries(grouped)) {
const showItems = items.slice(0, 3);
const moreCount = items.length - 3;
html += `
<div class="object-group">
<strong>${type}</strong>
<span class="count">(${items.length})</span>
<div class="object-items">
`;
showItems.forEach((item, idx) => {
const coords = item.box ?
`(${Math.round(item.box[0])}, ${Math.round(item.box[1])})` :
`(${Math.round(item.x || 0)}, ${Math.round(item.y || 0)})`;
const conf = Math.round((item.score || item.confidence || 0) * 100);
html += `
<div class="object-item">
<span>${item.label || type} ${idx + 1}</span>
<span class="coords">${coords}</span>
<span class="conf">${conf}%</span>
</div>
`;
});
if (moreCount > 0) {
html += `<div class="more-items">+${moreCount} more...</div>`;
}
html += `
</div>
</div>
`;
}
objectsList.innerHTML = html;
}
async function runGoal() {
const goalInput = document.getElementById('goal-input');
const goal = goalInput.value.trim();
if (!goal) {
addToChat('Please enter a goal', 'bot');
return;
}
addToChat(goal, 'user');
goalInput.value = '';
try {
const response = await fetch(API_BASE + '/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ goal: goal })
});
const data = await response.json();
if (data.success) {
addToChat('✅ Started goal: ' + goal, 'bot');
sessionStats.total++;
updateSessionProgress();
} else {
addToChat('❌ Failed to start: ' + data.error, 'bot');
}
} catch (e) {
addToChat('❌ Error starting goal: ' + e.message, 'bot');
}
}
async function stopGoal() {
try {
const response = await fetch(API_BASE + '/stop', {
method: 'POST'
});
const data = await response.json();
addToChat('⏹️ Stopped: ' + data.message, 'bot');
} catch (e) {
addToChat('❌ Error stopping: ' + e.message, 'bot');
}
}
async function takeScreenshot() {
addToChat('📸 Taking screenshot...', 'bot');
try {
const response = await fetch(API_BASE + '/screenshot');
const data = await response.json();
if (data.screenshot_path) {
// Show screenshot panel
const panel = document.getElementById('screenshot-panel');
const img = document.getElementById('screenshot-img');
img.src = 'file://' + data.screenshot_path;
img.style.display = 'block';
panel.style.display = 'block';
// Update metadata
document.getElementById('screen-size').textContent =
`${data.screen_size?.width || 0}x${data.screen_size?.height || 0}`;
document.getElementById('screenshot-time').textContent =
new Date().toLocaleTimeString();
addToChat('✅ Screenshot taken with ' + (data.detected_objects?.length || 0) + ' objects detected', 'bot');
} else {
addToChat('❌ Screenshot failed: ' + data.error, 'bot');
}
} catch (e) {
addToChat('❌ Error taking screenshot: ' + e.message, 'bot');
}
}
function closeScreenshot() {
document.getElementById('screenshot-panel').style.display = 'none';
}
async function initVision() {
addToChat('🔄 Initializing vision model...', 'bot');
try {
const response = await fetch(API_BASE + '/init', {
method: 'POST'
});
const data = await response.json();
if (data.success) {
addToChat('✅ Vision model loaded', 'bot');
} else {
addToChat('❌ Vision init failed: ' + data.message, 'bot');
}
} catch (e) {
addToChat('❌ Error initializing vision: ' + e.message, 'bot');
}
}
function toggleRecording() {
isRecording = !isRecording;
const btnText = document.getElementById('record-btn-text');
btnText.textContent = isRecording ? 'Stop' : 'Record';
if (isRecording) {
addToChat('🔴 Recording started', 'bot');
mousePath = [];
totalClicks = 0;
totalMovement = 0;
document.getElementById('click-count').textContent = '0';
document.getElementById('movement-distance').textContent = '0 px';
} else {
addToChat('⏹️ Recording stopped', 'bot');
}
}
function updateSessionProgress() {
document.getElementById('session-total').textContent = sessionStats.total;
document.getElementById('session-completed').textContent = sessionStats.completed;
const percentage = sessionStats.total > 0
? (sessionStats.completed / sessionStats.total) * 100
: 0;
document.getElementById('session-progress').style.width = percentage + '%';
// Update stats
document.getElementById('total-tasks').textContent = sessionStats.total;
if (sessionStats.total > 0) {
const rate = Math.round((sessionStats.successfulTasks / sessionStats.total) * 100);
document.getElementById('success-rate').textContent = rate + '%';
}
if (sessionStats.completed > 0) {
const avg = (sessionStats.totalIterations / sessionStats.completed).toFixed(1);
document.getElementById('avg-iterations').textContent = avg;
}
}
// Handle Enter key in textarea
document.getElementById('goal-input').addEventListener('keydown', (e) => {
if (e.key === 'Enter' && e.ctrlKey) {
runGoal();
}
});
// Initialize canvas
window.addEventListener('resize', drawMousePath);
drawMousePath();
</script>
</body>
</html>