RushiMane2003 commited on
Commit
94ffab5
·
verified ·
1 Parent(s): acbd0d5

Update templates/predict.html

Browse files
Files changed (1) hide show
  1. templates/predict.html +208 -206
templates/predict.html CHANGED
@@ -1,206 +1,208 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Prediction Results</title>
7
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
8
- <style>
9
- body {
10
- background-color: #f4f8f4;
11
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
12
- }
13
- .header {
14
- background-color: #28a745;
15
- color: white;
16
- padding: 20px;
17
- text-align: center;
18
- font-weight: bold;
19
- }
20
- .container {
21
- margin-top: 30px;
22
- padding: 20px;
23
- background-color: white;
24
- border-radius: 15px;
25
- box-shadow: 0 4px 12px rgba(0,0,0,0.1);
26
- }
27
- .result-label {
28
- font-weight: bold;
29
- color: #555;
30
- }
31
- .form-control[readonly] {
32
- font-size: 1.2rem;
33
- text-align: center;
34
- font-weight: bold;
35
- color: #28a745;
36
- background-color: #e9f5e9;
37
- border: 2px solid #28a745;
38
- }
39
- .gauge-container {
40
- margin-top: 20px;
41
- text-align: center;
42
- }
43
- .info-card {
44
- background-color: #f8f9fa;
45
- border: 1px solid #dee2e6;
46
- border-radius: 10px;
47
- padding: 25px;
48
- margin-top: 40px;
49
- text-align: center;
50
- }
51
- .info-card h4 {
52
- color: #28a745;
53
- font-weight: bold;
54
- }
55
- .btn-start-motor {
56
- background-color: #28a745;
57
- color: white;
58
- font-size: 1.2rem;
59
- padding: 12px 25px;
60
- font-weight: bold;
61
- border-radius: 8px;
62
- transition: background-color 0.3s;
63
- }
64
- .btn-start-motor:hover {
65
- background-color: #218838;
66
- }
67
- .camera-container {
68
- margin-top: 20px;
69
- text-align: center;
70
- display: none;
71
- }
72
- .timer {
73
- font-size: 2.5rem;
74
- color: white;
75
- background-color: #28a745;
76
- font-weight: bold;
77
- padding: 15px 30px;
78
- border-radius: 10px;
79
- display: inline-block;
80
- margin-top: 15px;
81
- }
82
- video {
83
- width: 100%;
84
- max-width: 600px;
85
- height: auto;
86
- border-radius: 10px;
87
- border: 2px solid #ddd;
88
- }
89
- .alert-message {
90
- font-size: 1.5rem;
91
- color: #dc3545;
92
- font-weight: bold;
93
- margin-top: 20px;
94
- text-align: center;
95
- }
96
- </style>
97
- </head>
98
- <body>
99
-
100
- <div class="header">
101
- <h1>Water Requirement Prediction Results</h1>
102
- </div>
103
-
104
- <div class="container">
105
- <div class="row">
106
- <!-- Water Requirement -->
107
- <div class="col-md-6 mb-4">
108
- <label for="water_requirement" class="result-label">Predicted Water Requirement (m³/sq.m):</label>
109
- <input type="text" class="form-control" id="water_requirement" value="{{ water_requirement }}" readonly>
110
- <div class="gauge-container">
111
- {{ water_gauge|safe }}
112
- </div>
113
- </div>
114
-
115
- <!-- Motor On Time -->
116
- <div class="col-md-6 mb-4">
117
- <label for="estimated_time" class="result-label">Estimated Motor On-Time:</label>
118
- <input type="text" class="form-control" id="estimated_time" value="{{ estimated_time_duration }} {{ time_unit }}" readonly>
119
- <div class="gauge-container">
120
- {{ time_gauge|safe }}
121
- </div>
122
- </div>
123
- </div>
124
-
125
- <!-- AI Monitoring Section -->
126
- <div class="info-card">
127
- <h4>Want to automatically inspect your irrigation process?</h4>
128
- <p class="mt-3">Use our AI-driven Irrigation Monitoring to watch the process from your phone. You will receive a WhatsApp message to start the motor. Once started, you can monitor it live here.</p>
129
- <button id="startMonitoring" class="btn btn-start-motor">Start AI Monitoring</button>
130
- </div>
131
-
132
- <div class="camera-container" id="cameraContainer">
133
- <h4 class="text-center mb-3">Live Irrigation Feed</h4>
134
- <video id="videoElement" autoplay playsinline></video>
135
- <div class="timer" id="timer"></div>
136
- </div>
137
-
138
- <div class="alert-message" id="alertMessage"></div>
139
- </div>
140
-
141
- <script>
142
- document.getElementById('startMonitoring').addEventListener('click', function() {
143
- // Show camera container
144
- document.getElementById('cameraContainer').style.display = 'block';
145
-
146
- // Start video stream from camera
147
- if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
148
- navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } })
149
- .then(function(stream) {
150
- document.getElementById('videoElement').srcObject = stream;
151
- })
152
- .catch(function(err) {
153
- console.log("Camera Error: " + err);
154
- alert("Could not access the camera. Please ensure you have given permission.");
155
- });
156
- }
157
-
158
- // The prompt for starting the motor is now handled via WhatsApp.
159
- // The timer will start based on the reply from WhatsApp.
160
- // This front-end logic is now primarily for viewing the stream.
161
- // For demonstration purposes, we will simulate the timer start here after a delay.
162
-
163
- // Calculate estimated time in seconds for the timer display
164
- let estimatedTime = parseFloat("{{ estimated_time_duration }}");
165
- let timeUnit = "{{ time_unit }}";
166
- let estimatedTimeSeconds = timeUnit === "minutes" ? estimatedTime * 60 : estimatedTime;
167
-
168
- let timerElem = document.getElementById('timer');
169
- let timeRemaining = Math.floor(estimatedTimeSeconds);
170
-
171
- // A message to inform user to check WhatsApp
172
- alert("Check your WhatsApp to start the motor. The timer and monitoring will begin here once you confirm.");
173
-
174
- // NOTE: The actual countdown should be triggered by a confirmation from the backend (e.g., via WebSocket).
175
- // For this example, we'll just start it to demonstrate the UI.
176
-
177
- let countdown = setInterval(function() {
178
- if (timeRemaining <= 0) {
179
- clearInterval(countdown);
180
- timerElem.textContent = "Finished";
181
- // Play beep sound
182
- let beep = new Audio('/static/alarn_tune.mp3');
183
- beep.play();
184
- document.getElementById('alertMessage').textContent = "Irrigation time is over. Motor is off automatically.";
185
- } else {
186
- timerElem.textContent = timeRemaining + "s";
187
- }
188
- timeRemaining--;
189
- }, 1000);
190
-
191
- // Simulate sending a request to the backend (already done on page load via python)
192
- fetch('/start_motor', {
193
- method: 'POST',
194
- headers: { 'Content-Type': 'application/json' },
195
- body: JSON.stringify({
196
- estimated_time_duration: estimatedTimeSeconds,
197
- time_unit: "seconds"
198
- })
199
- })
200
- .then(response => response.json())
201
- .then(data => console.log("Monitoring started:", data))
202
- .catch(error => console.error("Error starting monitoring:", error));
203
- });
204
- </script>
205
- </body>
206
- </html>
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Prediction Results</title>
7
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
8
+ <style>
9
+ body {
10
+ background-color: #f4f8f4;
11
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
12
+ }
13
+ .header {
14
+ background-color: #28a745;
15
+ color: white;
16
+ padding: 20px;
17
+ text-align: center;
18
+ font-weight: bold;
19
+ }
20
+ .container {
21
+ margin-top: 30px;
22
+ padding: 20px;
23
+ background-color: white;
24
+ border-radius: 15px;
25
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
26
+ /* FIX 3: Start with content hidden and add a smooth fade-in transition */
27
+ opacity: 0;
28
+ transition: opacity 0.5s ease-in-out;
29
+ }
30
+ .result-label {
31
+ font-weight: bold;
32
+ color: #555;
33
+ }
34
+ .form-control[readonly] {
35
+ font-size: 1.2rem;
36
+ text-align: center;
37
+ font-weight: bold;
38
+ color: #28a745;
39
+ background-color: #e9f5e9;
40
+ border: 2px solid #28a745;
41
+ }
42
+ .gauge-container {
43
+ margin-top: 20px;
44
+ text-align: center;
45
+ }
46
+ .info-card {
47
+ background-color: #f8f9fa;
48
+ border: 1px solid #dee2e6;
49
+ border-radius: 10px;
50
+ padding: 25px;
51
+ margin-top: 40px;
52
+ text-align: center;
53
+ }
54
+ .btn-start-motor {
55
+ background-color: #28a745;
56
+ color: white;
57
+ font-size: 1.2rem;
58
+ padding: 12px 25px;
59
+ font-weight: bold;
60
+ border-radius: 8px;
61
+ transition: background-color 0.3s;
62
+ }
63
+ .btn-start-motor:hover {
64
+ background-color: #218838;
65
+ }
66
+
67
+ /* --- FIX 1 & 2: Camera Container, Video, and Timer Styles --- */
68
+ .camera-container {
69
+ margin-top: 20px;
70
+ display: none; /* Keep hidden by default */
71
+ /* Use Flexbox to stack and center children */
72
+ display: flex;
73
+ flex-direction: column; /* Stack items vertically */
74
+ align-items: center; /* Center items horizontally */
75
+ gap: 20px; /* Add space between video and timer */
76
+ }
77
+ video {
78
+ width: 100%; /* Be responsive to container width */
79
+ max-width: 720px; /* Set a max-width for larger screens */
80
+ height: auto;
81
+ border-radius: 10px;
82
+ border: 2px solid #ddd;
83
+ background-color: #000; /* Add a background for when the feed is loading */
84
+ }
85
+ .timer {
86
+ font-size: 2rem;
87
+ color: white;
88
+ background-color: #28a745;
89
+ font-weight: bold;
90
+ padding: 10px 25px;
91
+ border-radius: 10px;
92
+ display: inline-block;
93
+ min-width: 120px; /* Give it a minimum width */
94
+ text-align: center;
95
+ }
96
+ /* Style for the "Finished" button state */
97
+ .timer-finished {
98
+ font-size: 1.5rem;
99
+ padding: 15px 40px;
100
+ background-color: #28a745; /* Green button color */
101
+ }
102
+
103
+ .alert-message {
104
+ font-size: 1.5rem;
105
+ color: #dc3545;
106
+ font-weight: bold;
107
+ margin-top: 20px;
108
+ text-align: center;
109
+ }
110
+ </style>
111
+ </head>
112
+ <body>
113
+
114
+ <div class="header">
115
+ <h1>Water Requirement Prediction Results</h1>
116
+ </div>
117
+
118
+ <div class="container">
119
+ <div class="row">
120
+ <!-- Water Requirement -->
121
+ <div class="col-md-6 mb-4">
122
+ <label for="water_requirement" class="result-label">Predicted Water Requirement (m³/sq.m):</label>
123
+ <input type="text" class="form-control" id="water_requirement" value="{{ water_requirement }}" readonly>
124
+ <div class="gauge-container">
125
+ {{ water_gauge|safe }}
126
+ </div>
127
+ </div>
128
+
129
+ <!-- Motor On Time -->
130
+ <div class="col-md-6 mb-4">
131
+ <label for="estimated_time" class="result-label">Estimated Motor On-Time:</label>
132
+ <input type="text" class="form-control" id="estimated_time" value="{{ estimated_time_duration }} {{ time_unit }}" readonly>
133
+ <div class="gauge-container">
134
+ {{ time_gauge|safe }}
135
+ </div>
136
+ </div>
137
+ </div>
138
+
139
+ <!-- AI Monitoring Section -->
140
+ <div class="info-card">
141
+ <h4>Want to automatically inspect your irrigation process?</h4>
142
+ <p class="mt-3">Use our AI-driven Irrigation Monitoring to watch the process from your phone. You will receive a WhatsApp message to start the motor. Once started, you can monitor it live here.</p>
143
+ <button id="startMonitoring" class="btn btn-start-motor">Start AI Monitoring</button>
144
+ </div>
145
+
146
+ <!-- The camera and timer are now properly styled to be centered and stacked -->
147
+ <div class="camera-container" id="cameraContainer">
148
+ <h4 class="text-center mb-0">Live Irrigation Feed</h4>
149
+ <video id="videoElement" autoplay playsinline></video>
150
+ <div class="timer" id="timer"></div>
151
+ </div>
152
+
153
+ <div class="alert-message" id="alertMessage"></div>
154
+ </div>
155
+
156
+ <script>
157
+ // FIX 3: Wait for the entire page to load, then fade in the content
158
+ window.onload = function() {
159
+ document.querySelector('.container').style.opacity = 1;
160
+ };
161
+
162
+ document.getElementById('startMonitoring').addEventListener('click', function() {
163
+ document.getElementById('cameraContainer').style.display = 'flex'; // Use flex to show it
164
+
165
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
166
+ navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } })
167
+ .then(function(stream) {
168
+ document.getElementById('videoElement').srcObject = stream;
169
+ })
170
+ .catch(function(err) {
171
+ console.log("Camera Error: " + err);
172
+ alert("Could not access the camera. Please ensure you have given permission.");
173
+ });
174
+ }
175
+
176
+ let estimatedTime = parseFloat("{{ estimated_time_duration }}");
177
+ let timeUnit = "{{ time_unit }}";
178
+ let estimatedTimeSeconds = timeUnit === "minutes" ? estimatedTime * 60 : estimatedTime;
179
+
180
+ let timerElem = document.getElementById('timer');
181
+ let timeRemaining = Math.floor(estimatedTimeSeconds);
182
+
183
+ alert("Check your WhatsApp to start the motor. The timer and monitoring will begin here once you confirm.");
184
+
185
+ let countdown = setInterval(function() {
186
+ if (timeRemaining <= 0) {
187
+ clearInterval(countdown);
188
+ // Update timer to look like a finished button
189
+ timerElem.textContent = "Finished";
190
+ timerElem.classList.add('timer-finished'); // Add the new class
191
+
192
+ let beep = new Audio('/static/alarn_tune.mp3');
193
+ beep.play();
194
+ document.getElementById('alertMessage').textContent = "Irrigation time is over. Motor is off automatically.";
195
+ } else {
196
+ timerElem.textContent = timeRemaining + "s";
197
+ }
198
+ timeRemaining--;
199
+ }, 1000);
200
+
201
+ fetch('/start_motor', { method: 'POST' })
202
+ .then(response => response.json())
203
+ .then(data => console.log("Monitoring request sent:", data))
204
+ .catch(error => console.error("Error sending monitoring request:", error));
205
+ });
206
+ </script>
207
+ </body>
208
+ </html>