File size: 5,579 Bytes
75d5707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2183d48
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mark Attendance</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
        }
        .container {
            width: 80%;
            max-width: 800px;
            margin: 30px auto;
            padding: 30px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        h2 {
            color: #2c3e50;
            margin-bottom: 25px;
            font-size: 28px;
        }
        .btn {
            display: inline-block;
            padding: 12px 24px;
            background-color: #27ae60;
            color: white;
            text-decoration: none;
            border-radius: 5px;
            font-weight: 500;
            transition: background-color 0.3s;
            border: none;
            font-size: 16px;
            cursor: pointer;
            margin: 15px 0;
        }
        .btn:hover {
            background-color: #219653;
        }
        video {
            margin: 20px auto;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            background-color: #eee;
            max-width: 100%;
        }
        #status {
            margin-top: 20px;
            font-size: 18px;
            padding: 15px;
            border-radius: 5px;
            background-color: #f8f9fa;
            display: inline-block;
            min-width: 60%;
        }
        .success {
            color: #27ae60;
            font-weight: 600;
        }
        .error {
            color: #e74c3c;
            font-weight: 600;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .back-link {
            color: #3498db;
            text-decoration: none;
            display: flex;
            align-items: center;
            font-weight: 500;
        }
        .back-link:hover {
            text-decoration: underline;
        }
        .video-container {
            position: relative;
            margin: 0 auto;
            width: 320px;
            max-width: 100%;
        }
        .camera-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            border: 2px solid rgba(52, 152, 219, 0.5);
            border-radius: 8px;
            pointer-events: none;
        }
        .loading {
            display: none;
            margin: 20px auto;
            border: 5px solid #f3f3f3;
            border-radius: 50%;
            border-top: 5px solid #3498db;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <a href="/" class="back-link">
                <i class="fas fa-arrow-left"></i> &nbsp;Back to Home
            </a>
            <h2>Mark Attendance</h2>
        </div>
        
        <div class="video-container">
            <video id="video" width="300" autoplay></video>
            <div class="camera-overlay"></div>
        </div>
        
        <button onclick="markAttendance()" class="btn">
            <i class="fas fa-user-check"></i> Mark Attendance
        </button>
        
        <div class="loading" id="loading"></div>
        <p id="status">Position your face in the camera and click the button</p>
    </div>

    <script src="/static/js/webcam.js"></script>
    <script>
        async function markAttendance() {
            document.getElementById("loading").style.display = "block";
            document.getElementById("status").innerText = "Processing...";
            
            captureFrame([], true).then(image => {
                fetch('/api/mark_attendance', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ image: image })
                })
                .then(res => res.json())
                .then(data => {
                    document.getElementById("loading").style.display = "none";
                    
                    const statusElem = document.getElementById("status");
                    if (data.name) {
                        statusElem.innerHTML = `<span class="success">Welcome, ${data.name}!</span><br>${data.message}`;
                    } else {
                        statusElem.innerHTML = `<span class="error">Face not recognized</span><br>${data.message}`;
                    }
                })
                .catch(err => {
                    document.getElementById("loading").style.display = "none";
                    document.getElementById("status").innerHTML = `<span class="error">Error: ${err.message}</span>`;
                });
            });
        }
        initWebcam("video");
    </script>
    
    <!-- Add Font Awesome for icons -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js"></script>
</body>
</html>