Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1071 lines (958 loc) · 53.7 KB
/
Copy pathindex.html
File metadata and controls
1071 lines (958 loc) · 53.7 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
<!-- index.html (with corrected static URL for style.css) -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>US Visa Prediction</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
<link rel="stylesheet" href="{{ request.url_for('static', path='css/style.css') }}">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand mx-auto">
<i class="fas fa-passport me-2"></i>
US Visa Approval Prediction
</a>
</div>
</nav>
<!-- Main Container -->
<div class="container main-container">
<div class="row justify-content-center">
<div class="col-lg-8 col-xl-7">
<!-- Training Status Panel -->
<div class="training-panel">
<h5 class="mb-3">
<i class="fas fa-cog me-2"></i>
Model Training Status
</h5>
<div class="training-status">
<div class="status-dot idle" id="trainingDot"></div>
<span id="trainingStatus">Model Ready</span>
</div>
<div class="row">
<div class="col-md-4">
<button type="button" class="btn btn-train w-100" id="trainBtn" onclick="showPasswordModal()">
<i class="fas fa-play me-2"></i>
Start Training
</button>
</div>
<div class="col-md-4">
<a href="/drift-report" target="_blank" class="btn btn-drift w-100">
<i class="fas fa-chart-line me-2"></i> Drift Report
</a>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-report w-100" onclick="toggleModelReport()">
<i class="fas fa-chart-bar me-2"></i> Model Report
</button>
</div>
</div>
<div class="progress-container" id="trainingProgress">
<div class="progress">
<div class="progress-bar" id="trainingProgressBar" style="width: 0%"></div>
</div>
<small class="text-muted mt-1 d-block" id="progressText">Initializing...</small>
</div>
</div>
<!-- Model Report Panel (Initially Hidden) -->
<div class="model-report-panel" id="modelReportPanel" style="display: none;">
<div class="report-header text-center">
<h4 class="mb-3">
<i class="fas fa-chart-line me-2"></i>
Model Performance Report
</h4>
<button class="btn btn-refresh" onclick="loadModelReport()">
<i class="fas fa-sync-alt me-2"></i>
Refresh Report
</button>
<div class="mt-2">
<small class="text-muted">Last Updated: <span id="lastUpdated">-</span></small>
</div>
</div>
<!-- Loading State -->
<div id="reportLoading" class="text-center py-4">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p class="mt-2 text-muted">Loading model report...</p>
</div>
<!-- Error State -->
<div id="reportError" class="alert alert-danger" style="display: none;">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Failed to load model report</strong>
<p class="mb-0 mt-2" id="reportErrorMessage">Unknown error occurred</p>
</div>
<!-- Report Content -->
<div id="reportContent" style="display: none;">
<!-- Model Health Status -->
<div class="report-section">
<h6 class="section-title">
<i class="fas fa-heartbeat me-2"></i>
<a class="text-decoration-none" data-bs-toggle="collapse" href="#healthCollapse" role="button">
Model Health Status
<i class="fas fa-chevron-down ms-2"></i>
</a>
</h6>
<div class="collapse" id="healthCollapse">
<div class="row align-items-center">
<div class="col-md-6">
<div id="healthStatus" class="status-indicator">
<i class="fas fa-circle me-2"></i>
Status Loading...
</div>
</div>
<div class="col-md-6 text-end">
<small class="text-muted">
Model: <span id="modelExists" class="badge">-</span><br>
Loadable: <span id="modelLoadable" class="badge">-</span>
</small>
</div>
</div>
</div>
</div>
<!-- Performance Metrics -->
<div class="report-section">
<h6 class="section-title">
<i class="fas fa-chart-bar me-2"></i>
<a class="text-decoration-none" data-bs-toggle="collapse" href="#metricsCollapse" role="button">
Performance Metrics
<i class="fas fa-chevron-down ms-2"></i>
</a>
</h6>
<div class="collapse" id="metricsCollapse">
<div class="row" id="metricsContainer">
<!-- Metrics cards will be populated here -->
</div>
<div class="chart-container mt-3">
<canvas id="metricsChart" height="200"></canvas>
</div>
</div>
</div>
<!-- Model Information -->
<div class="report-section">
<h6 class="section-title">
<i class="fas fa-sitemap me-2"></i>
<a class="text-decoration-none" data-bs-toggle="collapse" href="#architectureCollapse" role="button">
Model Architecture
<i class="fas fa-chevron-down ms-2"></i>
</a>
</h6>
<div class="collapse" id="architectureCollapse">
<div class="row">
<div class="col-md-6">
<table class="table table-sm info-table">
<tr>
<td><strong>Type:</strong></td>
<td id="modelType">-</td>
</tr>
<tr>
<td><strong>Preprocessing:</strong></td>
<td id="preprocessingType">-</td>
</tr>
</table>
</div>
<div class="col-md-6">
<table class="table table-sm info-table">
<tr>
<td><strong>CV Score:</strong></td>
<td id="cvScore">-</td>
</tr>
<tr>
<td><strong>Features:</strong></td>
<td id="totalFeatures">-</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- Features Used -->
<div class="report-section">
<h6 class="section-title">
<i class="fas fa-list me-2"></i>
<a class="text-decoration-none" data-bs-toggle="collapse" href="#featuresCollapse" role="button">
Features Used
<i class="fas fa-chevron-down ms-2"></i>
</a>
</h6>
<div class="collapse" id="featuresCollapse">
<div id="featuresContainer" class="features-grid">
<!-- Feature badges will be populated here -->
</div>
</div>
</div>
<!-- Model Parameters (Collapsible) -->
<div class="report-section">
<h6 class="section-title">
<i class="fas fa-cogs me-2"></i>
<a class="text-decoration-none" data-bs-toggle="collapse" href="#parametersCollapse" role="button">
Model Parameters
<i class="fas fa-chevron-down ms-2"></i>
</a>
</h6>
<div class="collapse" id="parametersCollapse">
<div class="parameters-container">
<table class="table table-striped table-sm" id="parametersTable">
<thead>
<tr>
<th style="width: 40%;">Parameter</th>
<th>Value</th>
</tr>
</thead>
<tbody id="parametersTableBody">
<!-- Parameters will be populated here -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Prediction Card -->
<div class="prediction-card float-animation">
<div class="card-header">
<h1>
<i class="fas fa-user-check me-3"></i>
Visa Predictor
</h1>
<p>Get instant predictions on your US visa application status</p>
</div>
<div class="card-body">
<form id="visaForm">
<div class="row">
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="continent" name="continent" required>
<option value="" disabled selected>Choose...</option>
<option value="Asia">Asia</option>
<option value="Africa">Africa</option>
<option value="North America">North America</option>
<option value="Europe">Europe</option>
<option value="South America">South America</option>
<option value="Oceania">Oceania</option>
</select>
<label for="continent">
<i class="fas fa-globe-americas me-2"></i>Continent
</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="education_of_employee" name="education_of_employee" required>
<option value="" disabled selected>Choose...</option>
<option value="High School">High School</option>
<option value="Bachelor's">Bachelor's</option>
<option value="Master's">Master's</option>
<option value="Doctorate">Doctorate</option>
</select>
<label for="education_of_employee">
<i class="fas fa-graduation-cap me-2"></i>Education Level
</label>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="has_job_experience" name="has_job_experience" required>
<option value="" disabled selected>Choose...</option>
<option value="Y">Yes</option>
<option value="N">No</option>
</select>
<label for="has_job_experience">
<i class="fas fa-briefcase me-2"></i>Has Job Experience
</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="requires_job_training" name="requires_job_training" required>
<option value="" disabled selected>Choose...</option>
<option value="Y">Yes</option>
<option value="N">No</option>
</select>
<label for="requires_job_training">
<i class="fas fa-chalkboard-teacher me-2"></i>Requires Training
</label>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-floating">
<input type="number" class="form-control" id="no_of_employees" name="no_of_employees"
min="14500" max="40000" placeholder="Enter a value between 15000 to 40000" required>
<label for="no_of_employees">
<i class="fas fa-users me-2"></i>Number of Employees
</label>
<small class="text-muted">Enter a value between 15000 to 40000</small>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input type="number" class="form-control" id="company_age" name="company_age"
min="10" max="180" placeholder="Enter a value between 10 to 180" required>
<label for="company_age">
<i class="fas fa-building me-2"></i>Company Age (years)
</label>
<small class="text-muted">Enter a value between 10 to 180</small>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="region_of_employment" name="region_of_employment" required>
<option value="" disabled selected>Choose...</option>
<option value="West">West</option>
<option value="Northeast">Northeast</option>
<option value="South">South</option>
<option value="Midwest">Midwest</option>
<option value="Island">Island</option>
</select>
<label for="region_of_employment">
<i class="fas fa-map-marker-alt me-2"></i>Region of Employment
</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input type="number" class="form-control" id="prevailing_wage" name="prevailing_wage"
min="600" max="70000" placeholder="Enter a value between 600 to 7000" required>
<label for="prevailing_wage">
<i class="fas fa-dollar-sign me-2"></i>Prevailing Wage
</label>
<small class="text-muted">Enter a value between 600 and 70000</small>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="unit_of_wage" name="unit_of_wage" required>
<option value="" disabled selected>Choose...</option>
<option value="Hour">Hour</option>
<option value="Week">Week</option>
<option value="Month">Month</option>
<option value="Year">Year</option>
</select>
<label for="unit_of_wage">
<i class="fas fa-clock me-2"></i>Wage Unit
</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<select class="form-control" id="full_time_position" name="full_time_position" required>
<option value="" disabled selected>Choose...</option>
<option value="Y">Full Time</option>
<option value="N">Part Time</option>
</select>
<label for="full_time_position">
<i class="fas fa-calendar-check me-2"></i>Position Type
</label>
</div>
</div>
</div>
<div class="progress-container" id="predictionProgress">
<div class="progress">
<div class="progress-bar" id="predictionProgressBar" style="width: 0%"></div>
</div>
<small class="text-muted mt-1 d-block" id="predictionProgressText">Processing...</small>
</div>
<button type="submit" class="btn btn-predict pulse-animation" id="predictBtn">
<span id="predictText">
<i class="fas fa-magic me-2"></i>
Predict Visa Status
</span>
<div class="loading-spinner" id="loadingSpinner">
<div class="spinner"></div>
</div>
</button>
</form>
<!-- Result Display -->
<div class="status-card status-approved" id="approvedResult">
<h3><i class="fas fa-check-circle me-2"></i>Visa Approved!</h3>
<p>Congratulations! Your application is likely to be approved.</p>
</div>
<div class="status-card status-rejected" id="rejectedResult">
<h3><i class="fas fa-times-circle me-2"></i>Visa Not Approved</h3>
<p>Unfortunately, your application may face challenges. Consider reviewing your details.</p>
</div>
<div class="status-card status-training" id="trainingResult">
<h3><i class="fas fa-cog me-2"></i>Training Complete!</h3>
<p>Model has been successfully trained and is ready for predictions.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Password Modal -->
<div class="modal fade" id="passwordModal" tabindex="-1" aria-labelledby="passwordModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="passwordModalLabel">
<i class="fas fa-lock me-2"></i>Training Authentication
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="text-muted mb-3">
<i class="fas fa-info-circle me-2"></i>
Enter the training password to start the model training process.
</p>
<form id="passwordForm">
<div class="password-input">
<div class="form-floating">
<input type="password" class="form-control" id="trainingPassword" placeholder="Enter training password" required>
<label for="trainingPassword">
<i class="fas fa-key me-2"></i>Training Password
</label>
<button type="button" class="password-toggle" id="togglePassword">
<i class="fas fa-eye"></i>
</button>
</div>
</div>
<div class="password-requirements">
<div class="requirement-item">
<i class="fas fa-shield-alt text-info"></i>
<span>Password is required for security purposes</span>
</div>
<div class="requirement-item">
<i class="fas fa-clock text-warning"></i>
<span>Training process may take several minutes</span>
</div>
<div class="requirement-item">
<i class="fas fa-exclamation-triangle text-danger"></i>
<span>Do not close the browser during training</span>
</div>
</div>
<div class="d-grid gap-2 mt-3">
<button type="submit" class="btn btn-modal-train" id="modalTrainBtn">
<i class="fas fa-play me-2"></i>
Start Training
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div class="footer">
<p>Made with <i class="fas fa-heart text-danger"></i> by <a href="https://github.com/aatansen/" target="_blank">aatansen</a></p>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
let isTraining = false;
let isPredicting = false;
let passwordModal;
let metricsChart = null;
let isReportVisible = false;
// Initialize modal
document.addEventListener('DOMContentLoaded', function() {
passwordModal = new bootstrap.Modal(document.getElementById('passwordModal'));
showToast('Welcome!', 'Fill out the form to get your visa prediction.', 'info');
});
// Toggle Model Report Panel
function toggleModelReport() {
const panel = document.getElementById('modelReportPanel');
const btn = document.querySelector('.btn-report');
if (!isReportVisible) {
panel.style.display = 'block';
btn.innerHTML = '<i class="fas fa-times me-2"></i> Close Report';
loadModelReport();
isReportVisible = true;
} else {
panel.style.display = 'none';
btn.innerHTML = '<i class="fas fa-chart-bar me-2"></i> Model Report';
isReportVisible = false;
}
}
// Load Model Report
async function loadModelReport() {
const loading = document.getElementById('reportLoading');
const error = document.getElementById('reportError');
const content = document.getElementById('reportContent');
// Show loading, hide others
loading.style.display = 'block';
error.style.display = 'none';
content.style.display = 'none';
try {
const response = await fetch('/model-report');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const reportData = await response.json();
displayReport(reportData);
// Show content, hide loading
loading.style.display = 'none';
content.style.display = 'block';
updateTimestamp(reportData.timestamp);
} catch (err) {
console.error('Failed to load model report:', err);
// Show error, hide loading
loading.style.display = 'none';
error.style.display = 'block';
document.getElementById('reportErrorMessage').textContent = err.message;
showToast('Report Error', 'Failed to load model report: ' + err.message, 'danger');
}
}
function displayReport(data) {
updateHealthStatus(data.model_health);
updateMetrics(data.metrics);
updateModelInfo(data.model_info, data.training_info);
updateFeatures(data.features);
}
function updateHealthStatus(health) {
const statusElement = document.getElementById('healthStatus');
const modelExistsElement = document.getElementById('modelExists');
const modelLoadableElement = document.getElementById('modelLoadable');
if (health.status === 'healthy') {
statusElement.className = 'status-indicator status-healthy';
statusElement.innerHTML = '<i class="fas fa-check-circle me-2"></i>Healthy';
modelExistsElement.className = 'badge bg-success';
modelLoadableElement.className = 'badge bg-success';
} else {
statusElement.className = 'status-indicator status-unhealthy';
statusElement.innerHTML = '<i class="fas fa-exclamation-circle me-2"></i>Unhealthy';
modelExistsElement.className = 'badge bg-danger';
modelLoadableElement.className = 'badge bg-danger';
}
modelExistsElement.textContent = health.model_exists ? 'Yes' : 'No';
modelLoadableElement.textContent = health.model_loadable ? 'Yes' : 'No';
}
function updateMetrics(metrics) {
const container = document.getElementById('metricsContainer');
container.innerHTML = '';
if (metrics.error) {
container.innerHTML = `<div class="col-12"><div class="alert alert-warning">${metrics.error}</div></div>`;
return;
}
const metricCards = [
{ key: 'accuracy', label: 'Accuracy', color: '#28a745', icon: 'fas fa-bullseye' },
{ key: 'f1_score', label: 'F1 Score', color: '#667eea', icon: 'fas fa-chart-line' },
{ key: 'precision', label: 'Precision', color: '#17a2b8', icon: 'fas fa-crosshairs' },
{ key: 'recall', label: 'Recall', color: '#ffc107', icon: 'fas fa-search' }
];
metricCards.forEach(metric => {
if (metrics[metric.key] !== undefined) {
const value = (metrics[metric.key] * 100).toFixed(1);
container.innerHTML += `
<div class="col-md-3 col-sm-6 mb-2">
<div class="metric-mini-card" style="border-left: 4px solid ${metric.color};">
<div class="d-flex justify-content-between align-items-center">
<div>
<div class="metric-mini-value">${value}%</div>
<div class="metric-mini-label">${metric.label}</div>
</div>
<i class="${metric.icon}" style="color: ${metric.color}; font-size: 1.5rem;"></i>
</div>
</div>
</div>
`;
}
});
createMetricsChart(metrics);
}
function createMetricsChart(metrics) {
const ctx = document.getElementById('metricsChart').getContext('2d');
if (metricsChart) {
metricsChart.destroy();
}
const labels = [];
const values = [];
const colors = ['#28a745', '#667eea', '#17a2b8', '#ffc107'];
if (metrics.accuracy !== undefined) {
labels.push('Accuracy');
values.push((metrics.accuracy * 100).toFixed(1));
}
if (metrics.f1_score !== undefined) {
labels.push('F1 Score');
values.push((metrics.f1_score * 100).toFixed(1));
}
if (metrics.precision !== undefined) {
labels.push('Precision');
values.push((metrics.precision * 100).toFixed(1));
}
if (metrics.recall !== undefined) {
labels.push('Recall');
values.push((metrics.recall * 100).toFixed(1));
}
metricsChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Performance (%)',
data: values,
backgroundColor: colors.slice(0, values.length),
borderColor: colors.slice(0, values.length),
borderWidth: 2,
borderRadius: 6,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
max: 100,
grid: { color: 'rgba(0,0,0,0.1)' }
},
x: { grid: { display: false } }
},
plugins: {
legend: { display: false },
tooltip: {
backgroundColor: 'rgba(0,0,0,0.8)',
titleColor: 'white',
bodyColor: 'white'
}
}
}
});
}
function updateModelInfo(modelInfo, trainingInfo) {
document.getElementById('modelType').textContent = modelInfo.model_type || '-';
document.getElementById('preprocessingType').textContent = modelInfo.preprocessing_type || '-';
document.getElementById('cvScore').textContent = trainingInfo.cross_validation_score
? (trainingInfo.cross_validation_score * 100).toFixed(2) + '%' : '-';
const tableBody = document.getElementById('parametersTableBody');
tableBody.innerHTML = '';
if (modelInfo.parameters && typeof modelInfo.parameters === 'object') {
Object.entries(modelInfo.parameters).forEach(([key, value]) => {
const row = tableBody.insertRow();
row.innerHTML = `
<td><strong>${key}</strong></td>
<td><code>${JSON.stringify(value)}</code></td>
`;
});
} else {
tableBody.innerHTML = '<tr><td colspan="2" class="text-center text-muted">No parameters available</td></tr>';
}
}
function updateFeatures(features) {
const container = document.getElementById('featuresContainer');
document.getElementById('totalFeatures').textContent = features.total_features || '-';
if (features.error) {
container.innerHTML = `<div class="alert alert-warning">${features.error}</div>`;
return;
}
if (features.feature_names && Array.isArray(features.feature_names)) {
container.innerHTML = '';
features.feature_names.forEach((feature, index) => {
container.innerHTML += `<span class="feature-badge">${feature}</span>`;
});
} else {
container.innerHTML = '<div class="text-muted">No feature information available</div>';
}
}
function updateTimestamp(timestamp) {
if (timestamp) {
const date = new Date(timestamp);
document.getElementById('lastUpdated').textContent = date.toLocaleString();
}
}
// Show password modal
function showPasswordModal() {
if (isTraining) return;
passwordModal.show();
}
// Password toggle functionality
document.getElementById('togglePassword').addEventListener('click', function() {
const passwordInput = document.getElementById('trainingPassword');
const toggleIcon = this.querySelector('i');
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
toggleIcon.className = 'fas fa-eye-slash';
} else {
passwordInput.type = 'password';
toggleIcon.className = 'fas fa-eye';
}
});
// Password form submission
document.getElementById('passwordForm').addEventListener('submit', function(e) {
e.preventDefault();
const password = document.getElementById('trainingPassword').value.trim();
if (!password) {
showToast('Invalid Input!', 'Please enter a password.', 'warning');
return;
}
passwordModal.hide();
startTraining(password);
});
// Training functionality with password
function startTraining(password) {
if (isTraining) return;
isTraining = true;
const trainBtn = document.getElementById('trainBtn');
const trainingDot = document.getElementById('trainingDot');
const trainingStatus = document.getElementById('trainingStatus');
const trainingProgress = document.getElementById('trainingProgress');
const trainingProgressBar = document.getElementById('trainingProgressBar');
const progressText = document.getElementById('progressText');
trainBtn.disabled = true;
trainBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Training...';
trainingDot.className = 'status-dot training';
trainingStatus.textContent = 'Training in Progress...';
trainingProgress.style.display = 'block';
// Clear password input
document.getElementById('trainingPassword').value = '';
// Simulate training progress
let stageIndex = 0;
const stages = [
{ text: 'Validating credentials...', duration: 800 },
{ text: 'Loading data...', duration: 1000 },
{ text: 'Preprocessing features...', duration: 1500 },
{ text: 'Training model...', duration: 3000 },
{ text: 'Validating performance...', duration: 1500 },
{ text: 'Saving model...', duration: 1000 }
];
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function updateProgress() {
if (stageIndex < stages.length) {
const stage = stages[stageIndex];
progressText.textContent = stage.text;
const stageProgress = ((stageIndex + 1) / stages.length) * 100;
trainingProgressBar.style.width = stageProgress + '%';
try {
if (stage.text === 'Training model...') {
await Promise.all([
sleep(stage.duration),
(async () => {
const response = await fetch(`/train?password=${encodeURIComponent(password)}`);
if (!response.ok) {
if (response.status === 401) {
throw new Error('Invalid password for training');
}
throw new Error(`HTTP error! status: ${response.status}`);
}
const text = await response.text();
if (!text.includes('Training successful')) {
throw new Error(text);
}
})()
]);
} else {
await sleep(stage.duration);
}
} catch (error) {
handleTrainingError(error);
return;
}
stageIndex++;
await updateProgress();
} else {
// Training complete
trainingDot.className = 'status-dot success';
trainingStatus.textContent = 'Training Complete!';
progressText.textContent = 'Model ready for predictions';
setTimeout(() => {
trainingProgress.style.display = 'none';
trainBtn.disabled = false;
trainBtn.innerHTML = '<i class="fas fa-redo me-2"></i>Retrain Model';
isTraining = false;
// Show success result
document.getElementById('trainingResult').style.display = 'block';
setTimeout(() => {
document.getElementById('trainingResult').style.display = 'none';
}, 5000);
showToast('Training Complete!', 'Model has been successfully trained.', 'success');
}, 1000);
}
}
updateProgress();
}
function handleTrainingError(error) {
console.error('Training error:', error);
const trainingDot = document.getElementById('trainingDot');
const trainingStatus = document.getElementById('trainingStatus');
const trainingProgress = document.getElementById('trainingProgress');
const trainingProgressBar = document.getElementById('trainingProgressBar');
const progressText = document.getElementById('progressText');
const trainBtn = document.getElementById('trainBtn');
trainingDot.className = 'status-dot error';
trainingStatus.textContent = 'Training Failed';
progressText.textContent = `Error: ${error.message}`;
trainingProgressBar.style.width = '100%';
trainingProgressBar.style.background = 'var(--danger-color)';
setTimeout(() => {
trainingProgress.style.display = 'none';
trainingProgressBar.style.background = 'linear-gradient(90deg, var(--primary-color), var(--secondary-color))';
trainBtn.disabled = false;
trainBtn.innerHTML = '<i class="fas fa-play me-2"></i>Start Training';
isTraining = false;
}, 2000);
// Show specific error message for incorrect password
if (error.message.includes('Invalid password')) {
showToast('Authentication Failed!', 'Incorrect training password. Please try again.', 'danger');
} else {
showToast('Training Failed!', `Error: ${error.message}`, 'danger');
}
}
// Form submission - Real API integration
document.getElementById('visaForm').addEventListener('submit', async function(e) {
e.preventDefault();
if (isPredicting) return;
isPredicting = true;
const predictBtn = document.getElementById('predictBtn');
const predictText = document.getElementById('predictText');
const loadingSpinner = document.getElementById('loadingSpinner');
const predictionProgress = document.getElementById('predictionProgress');
const predictionProgressBar = document.getElementById('predictionProgressBar');
const predictionProgressText = document.getElementById('predictionProgressText');
// Hide previous results
document.getElementById('approvedResult').style.display = 'none';
document.getElementById('rejectedResult').style.display = 'none';
// Show loading state
predictBtn.disabled = true;
predictText.style.display = 'none';
loadingSpinner.style.display = 'block';
predictionProgress.style.display = 'block';
// Animate prediction progress
const predictionStages = [
{ text: 'Validating input data...', width: 20, duration: 500 },
{ text: 'Sending data to server...', width: 40, duration: 300 },
{ text: 'Processing prediction...', width: 70, duration: 0 }, // Will continue until response
];
for (let i = 0; i < 2; i++) { // Animate first 2 stages
const stage = predictionStages[i];
await new Promise(resolve => {
setTimeout(() => {
predictionProgressText.textContent = stage.text;
predictionProgressBar.style.width = stage.width + '%';
resolve();
}, stage.duration);
});
}
// Show final stage
predictionProgressText.textContent = predictionStages[2].text;
predictionProgressBar.style.width = '70%';
try {
// Prepare form data for your FastAPI backend
const formData = new FormData(this);
// Make API call to your prediction endpoint
const response = await fetch('/', {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
// Handle JSON error response
const result = await response.json();
if (result.status === false) {
throw new Error(result.error);
}
} else {
// Handle HTML response (your template response)
const htmlText = await response.text();
// Parse the response to extract the context (prediction result)
const parser = new DOMParser();
const doc = parser.parseFromString(htmlText, 'text/html');
const contextElement = doc.querySelector('.display-4');
let predictionResult = 'Unknown';
if (contextElement) {
const fullText = contextElement.textContent;
// Extract the status from "Visa Prediction Status: [status]"
const match = fullText.match(/Visa Prediction Status:\s*(.+)/);
if (match) {
predictionResult = match[1].trim();
}
}
// Complete the progress animation
predictionProgressText.textContent = 'Prediction complete!';
predictionProgressBar.style.width = '100%';
setTimeout(() => {
predictionProgress.style.display = 'none';
predictBtn.disabled = false;
predictText.style.display = 'block';
loadingSpinner.style.display = 'none';
isPredicting = false;
// Show result based on prediction
const isApproved = predictionResult.toLowerCase().includes('approved') &&
!predictionResult.toLowerCase().includes('not');
if (isApproved) {
document.getElementById('approvedResult').style.display = 'block';
showToast('Prediction Complete!', 'Visa approval predicted successfully!', 'success');
} else if (predictionResult !== 'Unknown' && predictionResult !== 'Rendering') {
document.getElementById('rejectedResult').style.display = 'block';
showToast('Prediction Complete!', 'Visa status predicted successfully.', 'info');
} else {
showToast('Prediction Complete!', `Status: ${predictionResult}`, 'info');
}
// Auto hide result after 10 seconds