-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
1263 lines (1116 loc) · 50.8 KB
/
index.html
File metadata and controls
1263 lines (1116 loc) · 50.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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Auto Eval Dashboard</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #2563eb;
--secondary-color: #1e40af;
--success-color: #16a34a;
--error-color: #dc2626;
--background-color: #f8fafc;
--card-background: #ffffff;
--text-primary: #1e293b;
--text-secondary: #64748b;
--border-color: #e2e8f0;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--background-color);
color: var(--text-primary);
line-height: 1.5;
}
.banner {
background-color: var(--primary-color);
color: white;
padding: 1.5rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.banner h1 {
max-width: 1200px;
margin: 0 auto;
font-weight: 600;
font-size: 1.5rem;
}
.dashboard-container {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1rem;
}
.tabs {
display: flex;
gap: 1rem;
margin-bottom: 2rem;
background: var(--card-background);
padding: 0.5rem;
border-radius: 0.5rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.tab {
padding: 0.75rem 1.5rem;
cursor: pointer;
background: transparent;
border: none;
border-radius: 0.375rem;
font-weight: 500;
color: var(--text-secondary);
transition: all 0.2s;
}
.tab:hover {
background: rgba(37, 99, 235, 0.1);
color: var(--primary-color);
}
.tab.active {
background: var(--primary-color);
color: white;
}
.card {
background: var(--card-background);
border-radius: 0.5rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
padding: 1.5rem;
margin-bottom: 1.5rem;
}
.form-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
color: var(--text-primary);
}
input[type="text"],
input[type="number"] {
width: 100%;
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: 0.375rem;
font-size: 1rem;
transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.advanced-options {
margin-top: 1rem;
padding: 1rem;
border: 1px solid var(--border-color);
border-radius: 0.375rem;
display: none;
}
.advanced-options.show {
display: block;
}
button {
background: var(--primary-color);
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 0.375rem;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background: var(--secondary-color);
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
background: var(--card-background);
border-radius: 0.5rem;
overflow: hidden;
}
.waiting-message {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
justify-content: center;
align-items: center;
z-index: 10;
}
.waiting-message-content {
background-color: white;
padding: 20px;
border-radius: 8px;
text-align: center;
max-width: 80%;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.waiting-message-content h3 {
color: var(--error-color);
margin-bottom: 10px;
}
.robot-status {
display: inline-block;
margin-left: 10px;
padding: 3px 8px;
border-radius: 12px;
font-size: 0.8rem;
font-weight: 500;
}
.status-online {
background-color: var(--success-color);
color: white;
}
.status-offline {
background-color: var(--error-color);
color: white;
}
.offline-message {
margin-top: 10px;
padding: 10px;
background-color: #fff5f5;
border-left: 4px solid var(--error-color);
color: var(--error-color);
font-size: 0.9rem;
display: none;
}
th, td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid var(--border-color);
}
th {
background: var(--background-color);
font-weight: 600;
color: var(--text-primary);
}
tr:hover {
background: var(--background-color);
}
/* Video feed styles */
.video-feeds-wrapper {
display: grid;
grid-template-columns: 1fr 1fr; /* Fixed two-column layout for side-by-side display */
gap: 2rem;
margin-top: 1rem;
}
.video-feed-pair {
background: var(--card-background);
border-radius: 0.5rem;
overflow: hidden;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.feed-header {
background: var(--primary-color);
color: white;
padding: 1rem;
font-weight: 500;
}
.video-feed-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
padding: 1rem;
}
.video-feed {
position: relative;
display: flex;
flex-direction: column;
gap: 0.5rem;
align-items: center;
width: 100%;
}
.video-feed img {
max-width: 500px;
width: 100%;
height: auto;
}
.video-feed-container {
display: flex;
justify-content: center;
width: 100%;
}
.video-feed label {
color: var(--text-primary);
font-weight: 500;
}
.video-feed img {
width: 100%;
border-radius: 0.375rem;
border: 1px solid var(--border-color);
}
.video-feed {
position: relative;
}
.timestamp-overlay {
position: absolute;
bottom: 10px;
right: 10px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 5px 10px;
border-radius: 4px;
font-size: 0.8rem;
z-index: 5;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
table-layout: fixed;
}
.card {
overflow-x: auto;
}
th {
white-space: nowrap;
padding: 0.75rem;
background-color: var(--background-color);
position: sticky;
top: 0;
}
td {
white-space: normal;
padding: 0.75rem;
word-wrap: break-word;
min-width: 100px;
}
td a {
word-break: break-all;
}
.status-info-container {
padding: 1rem;
background: var(--background-color);
border-top: 1px solid var(--border-color);
}
.status-info {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.status-item {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.status-item .label {
font-weight: 500;
color: var(--text-secondary);
font-size: 0.875rem;
}
.status-item span:not(.label) {
color: var(--text-primary);
font-weight: 500;
}
/* Add/modify these styles for tab visibility */
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
select {
width: 100%;
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: 0.375rem;
font-size: 1rem;
transition: all 0.2s;
background-color: white;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 1rem center;
padding-right: 2.5rem;
}
select:hover {
border-color: var(--primary-color);
}
select:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
select option {
padding: 0.75rem;
background-color: white;
color: var(--text-primary);
}
select option:disabled {
color: var(--text-secondary);
background-color: #f1f1f1;
font-style: italic;
}
</style>
</head>
<body>
<div class="banner">
<h1>Auto Eval Dashboard</h1>
</div>
<div class="dashboard-container">
<div class="card">
<h2>Robots Live Feed</h2>
<div class="info-message" style="margin-bottom: 15px; padding: 10px; background-color: #f8f9fa; border-left: 4px solid #2563eb; border-radius: 4px;">
<p style="margin: 0; color: #4b5563;">This shows real-time footage of the robots running the current evaluation job (which could be yours or someone else's). Be aware that the image may sometimes lag.</p>
</div>
<div class="video-feeds-wrapper" id="video-feeds-container">
</div>
</div>
<!-- Jobs dashboard content follows -->
<div class="card">
<h2>Submit New Job</h2>
<form id="jobForm">
<div class="form-group">
<label for="description">Job Description</label>
<input type="text" id="description" name="description" required placeholder="Enter job description">
</div>
<div class="form-group">
<label for="robot">Robot</label>
<div style="display: flex; align-items: center;">
<select id="robot" name="robot" required>
<option value="">Select a robot</option>
<option value="widowx_drawer">WidowX Drawer</option>
<option value="widowx_sink">WidowX Sink</option>
</select>
<span id="robot-status-indicator" class="robot-status"></span>
</div>
</div>
<div class="form-group">
<label for="task">Task</label>
<select id="task" name="task" required>
<option value="">Select a robot first</option>
</select>
</div>
<div class="form-group">
<label for="policy_server_ip">Policy Server IP</label>
<input type="text" id="policy_server_ip" required placeholder="Enter policy server IP (e.g. bore.pub)" onchange="processPolicyServerIP(this)">
<input type="hidden" id="policy_server_ip_actual" name="policy_server_ip">
<script>
function processPolicyServerIP(input) {
let value = decodeURIComponent(input.value).trim();
if (value === "bore.pub") {
document.getElementById('policy_server_ip_actual').value = "159.223.171.199";
} else {
document.getElementById('policy_server_ip_actual').value = value;
}
}
</script>
</div>
<div class="form-group">
<label for="policy_server_port">Policy Server Port</label>
<input type="number" id="policy_server_port" name="policy_server_port" required placeholder="Enter policy server port (use -1 if no port is needed)">
</div>
<div class="info-message" style="margin-top: 10px; margin-bottom: 10px; padding: 10px; background-color: #f8f9fa; border-left: 4px solid #4285f4; font-size: 0.9rem;">
<strong>Note:</strong> See <a href="https://auto-eval.github.io" target="_blank">the AutoEval website</a> for detailed instructions. Your policy server must respond to POST requests at <code>/act</code> endpoint and return an action with shape <code>(7,)</code>.
The server will be automatically tested as you submit your job. See <a href="https://gist.github.com/zhouzypaul/8ba0123b2931a7295a00eaa09dd540cd" target="_blank">here</a> for an example policy server.
We recommend sanity checking your policy with the <a href="https://github.com/zhouzypaul/mse-check" target="_blank">action MSE test</a> before submitting an evaluation job.
</div>
<div id="robot-status-note" class="info-message" style="margin-bottom: 20px; padding: 10px; background-color: #fff5f5; border-left: 4px solid #dc2626; font-size: 0.9rem; display: none;"></div>
<div class="form-group">
<button type="button" id="advancedOptionsBtn" onclick="toggleAdvancedOptions()">Advanced Options (click to expand ⬇️)</button>
</div>
<div id="advancedOptionsSection" class="advanced-options">
<div class="form-group">
<label for="num_episodes">Number of Evaluation Episodes:</label>
<input type="number" id="num_episodes" value="10" min="1" max="50" onchange="validateEpisodes(this)">
<div id="episodes-error" class="error-message" style="display: none; color: red; font-size: 0.8rem; margin-top: 0.25rem;">Number of episodes must be between 1 and 50.</div>
</div>
<div class="form-group">
<label for="max_steps">Evaluation Steps per Episode:</label>
<input type="number" id="max_steps" value="70" min="1">
</div>
</div>
<button type="submit" id="submitJobBtn">Submit Job</button>
<div id="loadingIndicator" style="display: none; margin-top: 10px;">
<div style="display: flex; align-items: center;">
<div style="border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; width: 20px; height: 20px; animation: spin 2s linear infinite; margin-right: 10px;"></div>
<span id="loadingText">Testing policy server connection...</span>
</div>
</div>
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</form>
</div>
<div class="card">
<h2>Job Status</h2>
<div class="form-group">
<input type="text" id="jobId" placeholder="Enter Job ID">
<button onclick="getJobStatus()" style="margin-top: 1rem;">Check Status</button>
</div>
<p id="jobStatus" style="margin-top: 1rem;"></p>
</div>
<div class="card">
<h2>Cancel Job</h2>
<div class="form-group">
<input type="text" id="cancelJobId" placeholder="Enter Job ID to Cancel">
<button onclick="cancelJob()" style="margin-top: 1rem; background-color: var(--error-color);">Cancel Job</button>
</div>
</div>
<div class="card">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
<h2>Your Jobs</h2>
<button onclick="getJobsList()">Refresh Job Status</button>
</div>
<table>
<thead>
<tr>
<th>Job ID</th>
<th>Description</th>
<th>Robot</th>
<th>Task</th>
<th>Status</th>
<th>Wandb URL</th>
<th>Success Rate</th>
<th>Executed At</th>
<th>Completed At</th>
</tr>
</thead>
<tbody id="yourJobsList">
</tbody>
</table>
<div id="yourJobsLoading" class="loading-indicator" style="display: none; text-align: center; padding: 1rem;">
<div style="display: inline-block; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; width: 20px; height: 20px; animation: spin 2s linear infinite; margin-right: 10px;"></div>
Loading your jobs...
</div>
<div id="yourJobsPagination" class="pagination-controls" style="text-align: center; margin-top: 0.5rem;"></div>
</div>
<div class="card">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
<h2>All Jobs</h2>
<button onclick="getJobsList()">Refresh Job Status</button>
</div>
<table>
<thead>
<tr>
<th>Job ID</th>
<th>Description</th>
<th>Robot</th>
<th>Task</th>
<th>Status</th>
<th>Wandb URL</th>
<th>Success Rate</th>
<th>Executed At</th>
<th>Completed At</th>
</tr>
</thead>
<tbody id="jobsList">
</tbody>
</table>
<div id="allJobsLoading" class="loading-indicator" style="display: none; text-align: center; padding: 1rem;">
<div style="display: inline-block; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; width: 20px; height: 20px; animation: spin 2s linear infinite; margin-right: 10px;"></div>
Loading all jobs...
</div>
<div id="jobsPagination" class="pagination-controls" style="text-align: center; margin-top: 0.5rem;"></div>
</div>
</div>
</div>
</div>
<script>
// Task options for each robot
const robotTasks = {
'widowx_drawer': [
{ value: 'open_drawer', label: 'Open the drawer' },
{ value: 'close_drawer', label: 'Close the drawer' }
],
'widowx_sink': [
{ value: 'put_eggplant_blue_sink', label: 'Put the eggplant into the blue sink' },
{ value: 'put_eggplant_yellow_basket', label: 'Put the eggplant into the yellow basket' }
]
};
function toggleAdvancedOptions() {
const advancedSection = document.getElementById('advancedOptionsSection');
advancedSection.classList.toggle('show');
}
function updateMaxSteps() {
const robotSelect = document.getElementById('robot');
const maxStepsInput = document.getElementById('max_steps');
console.log('Updating max steps for robot:', robotSelect.value);
if (robotSelect.value === 'sink') {
console.log('Setting max steps to 100 for sink');
maxStepsInput.value = '100';
} else if (robotSelect.value === 'drawer') {
console.log('Setting max steps to 70 for drawer');
maxStepsInput.value = '70';
}
console.log('Current max steps value:', maxStepsInput.value);
}
function updateTaskOptions() {
const robotSelect = document.getElementById('robot');
const taskSelect = document.getElementById('task');
const selectedRobot = robotSelect.value;
// Clear existing options
taskSelect.innerHTML = '';
if (!selectedRobot) {
taskSelect.innerHTML = '<option value="">Select a robot first</option>';
return;
}
// Add new options based on selected robot
const tasks = robotTasks[selectedRobot];
tasks.forEach(task => {
const option = document.createElement('option');
option.value = task.value;
option.textContent = task.label;
taskSelect.appendChild(option);
});
}
document.getElementById('jobForm').addEventListener('submit', function(event) {
event.preventDefault();
const description = document.getElementById('description').value;
const num_episodes = document.getElementById('num_episodes').value;
const max_steps = document.getElementById('max_steps').value;
const robot = document.getElementById('robot').value;
const task = document.getElementById('task').value;
const policy_server_ip = document.getElementById('policy_server_ip_actual').value;
const policy_server_port = document.getElementById('policy_server_port').value;
const submitter_id = getOrCreateSubmitterId();
// Show loading indicator for testing policy server connection
document.getElementById('submitJobBtn').disabled = true;
document.getElementById('loadingIndicator').style.display = 'block';
document.getElementById('loadingText').textContent = 'Testing policy server connection...';
console.log('Testing policy server connection...');
// First, test the policy server connection
// Create an AbortController with a timeout
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
fetch('/test_policy_server/', {
signal: controller.signal,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
policy_server_ip: policy_server_ip,
policy_server_port: parseInt(policy_server_port)
})
}).then(response => {
if (!response.ok) {
return response.json().then(errorData => {
throw new Error(errorData.message || 'Failed to connect to policy server');
}).catch(e => {
if (e.message && e.message !== 'Failed to connect to policy server') {
throw e;
} else {
throw new Error(`Failed to connect to policy server (HTTP ${response.status})`);
}
});
}
return response.json();
})
.then(data => {
if (data.status === 'error') {
if (data.message.includes('unexpected shape')) {
throw new Error(`The policy server must return action of shape (7,), but instead got ${data.shape}`);
} else {
throw new Error(data.message);
}
}
console.log('Policy server test successful:', data);
// Update loading text
document.getElementById('loadingText').textContent = 'Policy server test successful. Submitting job...';
console.log('Submitting job with data:', {
description,
robot,
task,
policy_server_ip,
policy_server_port,
num_episodes,
max_steps,
submitter_id
});
// Clear the timeout since we succeeded
clearTimeout(timeoutId);
// If policy server test is successful, submit the job
return fetch('/jobs/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: description,
robot: robot,
task: task,
policy_server_ip: policy_server_ip,
policy_server_port: parseInt(policy_server_port),
num_episodes: parseInt(num_episodes),
max_steps: parseInt(max_steps),
submitter_id: submitter_id
})
});
})
.then(response => {
if (!response.ok) {
console.error('Network response was not ok:', response);
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
// Hide loading indicator
document.getElementById('submitJobBtn').disabled = false;
document.getElementById('loadingIndicator').style.display = 'none';
alert('Job submitted! Job ID: ' + data.job_id);
getJobsList();
fetchRobotStatus(); // Refresh robot status after job submission
})
.catch(error => {
// Hide loading indicator
document.getElementById('submitJobBtn').disabled = false;
document.getElementById('loadingIndicator').style.display = 'none';
// Clear the timeout
clearTimeout(timeoutId);
console.error('Error:', error);
if (error.name === 'AbortError') {
alert('Error: Policy server connection timed out after 10 seconds. Please check if the server is running and accessible.');
} else if (error.message.includes('Failed to fetch')) {
alert('Error: Could not connect to the server. Please check your network connection and ensure the policy server is running.');
} else if (error.message.includes('NetworkError')) {
alert('Error: Network error when trying to connect to policy server. This could be due to CORS issues or the server being unreachable.');
} else {
alert('Error: ' + error.message);
}
});
});
function getJobStatus() {
const jobId = document.getElementById('jobId').value;
fetch('/jobs/' + jobId)
.then(response => response.json())
.then(data => {
document.getElementById('jobStatus').innerText = 'Status: ' + data.status;
})
.catch(error => {
document.getElementById('jobStatus').innerText = 'Error retrieving job status: ' + error;
});
}
function cancelJob() {
const jobId = document.getElementById('cancelJobId').value;
if (!jobId) {
alert('Please enter a Job ID');
return;
}
if (!confirm('Are you sure you want to cancel this job? This action cannot be undone.')) {
return;
}
const submitter_id = getOrCreateSubmitterId();
fetch(`/jobs/${jobId}/cancel?submitter_id=${submitter_id}`, {
method: 'POST',
})
.then(async response => {
const data = await response.json();
if (!response.ok) {
throw new Error(data.detail || 'Failed to cancel job');
}
return data;
})
.then(data => {
alert(data.message);
document.getElementById('cancelJobId').value = ''; // Clear the input
getJobsList(); // Refresh the jobs list
})
.catch(error => {
alert('Error cancelling job: ' + error.message);
});
}
// Pagination state
let currentAllJobsPage = 1;
let currentYourJobsPage = 1;
const jobsPerPage = 7;
function getJobsList() {
getYourJobs();
getAllJobs();
}
function getYourJobs(page = 1) {
const submitter_id = getOrCreateSubmitterId();
currentYourJobsPage = page;
// Show loading indicator
document.getElementById('yourJobsLoading').style.display = 'block';
document.getElementById('yourJobsList').style.display = 'none';
fetch(`/jobs/?page=${page}&limit=${jobsPerPage}&submitter_id=${submitter_id}&own_only=true`)
.then(response => response.json())
.then(data => {
// Hide loading indicator
document.getElementById('yourJobsLoading').style.display = 'none';
document.getElementById('yourJobsList').style.display = 'table-row-group';
const list = document.getElementById('yourJobsList');
list.innerHTML = '';
data.jobs.forEach(job => {
const row = document.createElement('tr');
const jobHtml = `
<td>${job.id}</td>
<td>${job.description}</td>
<td>${job.robot}</td>
<td>${job.task}</td>
<td>${job.status === 'completed' || job.status === 'failed' ? `<a href="output.html?id=${job.id}" style="color: var(--primary-color); text-decoration: underline;">${job.status}</a>` : job.status}</td>
<td>${job.wandb_url ? `<a href="${job.wandb_url}" target="_blank" style="color: var(--primary-color); text-decoration: underline;">View Results</a>` : 'N/A'}</td>
<td>${job.success_rate === null || job.success_rate === undefined ? 'N/A' : `${(job.success_rate * 100).toFixed(2)}%`}</td>
<td>${job.executed_at ? new Date(job.executed_at * 1000).toLocaleString() : 'N/A'}</td>
<td>${job.completed_at ? new Date(job.completed_at * 1000).toLocaleString() : 'N/A'}</td>`;
row.innerHTML = jobHtml;
list.appendChild(row);
});
// Update pagination controls for your jobs
updatePaginationControls('yourJobsPagination', data.pagination, getYourJobs);
})
.catch(error => {
// Hide loading indicator on error
document.getElementById('yourJobsLoading').style.display = 'none';
document.getElementById('yourJobsList').style.display = 'table-row-group';
console.error('Error retrieving your jobs list:', error);
});
}
function getAllJobs(page = 1) {
currentAllJobsPage = page;
// Show loading indicator
document.getElementById('allJobsLoading').style.display = 'block';
document.getElementById('jobsList').style.display = 'none';
fetch(`/jobs/?page=${page}&limit=${jobsPerPage}`)
.then(response => response.json())
.then(data => {
// Hide loading indicator
document.getElementById('allJobsLoading').style.display = 'none';
document.getElementById('jobsList').style.display = 'table-row-group';
const list = document.getElementById('jobsList');
list.innerHTML = '';
data.jobs.forEach(job => {
const row = document.createElement('tr');
const jobHtml = `
<td>${job.id}</td>
<td>${job.description}</td>
<td>${job.robot}</td>
<td>${job.task}</td>
<td>${job.status === 'completed' || job.status === 'failed' ? `<a href="output.html?id=${job.id}" style="color: var(--primary-color); text-decoration: underline;">${job.status}</a>` : job.status}</td>
<td>${job.wandb_url ? `<a href="${job.wandb_url}" target="_blank" style="color: var(--primary-color); text-decoration: underline;">View Results</a>` : 'N/A'}</td>
<td>${job.success_rate === null || job.success_rate === undefined ? 'N/A' : `${(job.success_rate * 100).toFixed(2)}%`}</td>
<td>${job.executed_at ? new Date(job.executed_at * 1000).toLocaleString() : 'N/A'}</td>
<td>${job.completed_at ? new Date(job.completed_at * 1000).toLocaleString() : 'N/A'}</td>`;
row.innerHTML = jobHtml;
list.appendChild(row);
});
// Update pagination controls for all jobs
updatePaginationControls('jobsPagination', data.pagination, getAllJobs);
})
.catch(error => {
// Hide loading indicator on error
document.getElementById('allJobsLoading').style.display = 'none';
document.getElementById('jobsList').style.display = 'table-row-group';
console.error('Error retrieving all jobs list:', error);
});
}
function updatePaginationControls(paginationId, pagination, fetchFunction) {
const paginationDiv = document.getElementById(paginationId);
if (!paginationDiv || !pagination) return;
let controls = '';
// Previous button
if (pagination.has_prev) {
controls += `<button onclick="${fetchFunction.name}(${pagination.current_page - 1})" style="margin: 0 0.5rem;">← Previous</button>`;
} else {
controls += `<button disabled style="margin: 0 0.5rem; opacity: 0.5;">← Previous</button>`;
}
// Page info
controls += `<span style="margin: 0 1rem;">Page ${pagination.current_page} of ${pagination.total_pages} (${pagination.total_jobs} total jobs)</span>`;
// Next button
if (pagination.has_next) {
controls += `<button onclick="${fetchFunction.name}(${pagination.current_page + 1})" style="margin: 0 0.5rem;">Next →</button>`;
} else {
controls += `<button disabled style="margin: 0 0.5rem; opacity: 0.5;">Next →</button>`;
}
paginationDiv.innerHTML = controls;
}
const NUM_FEEDS = 2;
function fetchAndDisplayImage(feedId, imageType) {
const imgElement = document.getElementById(`${feedId}-${imageType}-img`);
console.log(`Fetching image for feed ${feedId} (${imageType})...`);
// Add cache-busting timestamp parameter to prevent browser caching
const timestamp = new Date().getTime();
fetch(`/images/${feedId}/${imageType}?t=${timestamp}`)
.then(response => {
console.log(`Response for feed ${feedId}: status=${response.status}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.blob();
})
.then(imageBlob => {
console.log(`Successfully loaded image for feed ${feedId}, size: ${imageBlob.size} bytes`);
const imageUrl = URL.createObjectURL(imageBlob);
// Revoke the old object URL to prevent memory leaks
if (imgElement.src && imgElement.src.startsWith('blob:')) {
URL.revokeObjectURL(imgElement.src);
}
imgElement.src = imageUrl;
})
.catch(error => {
console.error(`Error fetching ${feedId}-${imageType} image:`, error);
});
}
function fetchStatus(feedId) {
fetch(`/get_status_data/${feedId}`)
.then(response => response.json())
.then(data => {
document.getElementById(`${feedId}-language-instruction`).textContent = data.language_instruction;
document.getElementById(`${feedId}-episode`).textContent = data.episode;
document.getElementById(`${feedId}-timestep`).textContent = data.timestep;
// Handle waiting for human intervention message
const waitingMessage = document.getElementById(`${feedId}-waiting-message`);
if (waitingMessage) {
if (data.waiting_for_human) {
waitingMessage.style.display = 'flex';
} else {
waitingMessage.style.display = 'none';
}
}
})
.catch(error => console.error(`Error fetching status for ${feedId}:`, error));
}
function createVideoFeedPairHtml(feedId) {
const feedNames = ["WidowX Drawer", "WidowX Sink"];
return `
<div class="video-feed-pair">
<div class="feed-header"> #${parseInt(feedId) + 1} ${feedNames[feedId]}</div>
<div class="video-feed-container">
<div class="video-feed">