Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- templates/prediction.html +121 -0
- templates/result.html +76 -0
templates/prediction.html
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>Trash Prediction</title>
|
| 7 |
+
<!-- Leaflet CSS -->
|
| 8 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
|
| 9 |
+
<link rel="stylesheet" href="static/prediction.css" />
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<div class="main-layout">
|
| 13 |
+
<div id="map"></div>
|
| 14 |
+
<div class="container">
|
| 15 |
+
<h1>Trash Prediction</h1>
|
| 16 |
+
<form id="predictionForm">
|
| 17 |
+
<div>
|
| 18 |
+
<label for="longitude">Longitude</label>
|
| 19 |
+
<input type="number" step="any" id="longitude" name="longitude" required placeholder="e.g. 25.13">
|
| 20 |
+
</div>
|
| 21 |
+
<div>
|
| 22 |
+
<label for="latitude">Latitude</label>
|
| 23 |
+
<input type="number" step="any" id="latitude" name="latitude" required placeholder="e.g. 35.33">
|
| 24 |
+
</div>
|
| 25 |
+
<div>
|
| 26 |
+
<label for="windSpeed">Wind Strength (1-10)</label>
|
| 27 |
+
<input type="number" step="any" id="windSpeed" name="windSpeed" required placeholder="e.g. 5">
|
| 28 |
+
</div>
|
| 29 |
+
<div>
|
| 30 |
+
<label for="windDirection">Wind Direction</label>
|
| 31 |
+
<select id="windDirection" name="windDirection" required>
|
| 32 |
+
<option value="">Select direction</option>
|
| 33 |
+
<option value="N">North</option>
|
| 34 |
+
<option value="NE">Northeast</option>
|
| 35 |
+
<option value="E">East</option>
|
| 36 |
+
<option value="SE">Southeast</option>
|
| 37 |
+
<option value="S">South</option>
|
| 38 |
+
<option value="SW">Southwest</option>
|
| 39 |
+
<option value="W">West</option>
|
| 40 |
+
<option value="NW">Northwest</option>
|
| 41 |
+
</select>
|
| 42 |
+
</div>
|
| 43 |
+
<button type="submit">Predict Trash Amount</button>
|
| 44 |
+
</form>
|
| 45 |
+
<div class="result" id="resultBox"></div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
<!-- Leaflet JS -->
|
| 49 |
+
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
| 50 |
+
<script src="{{ url_for('static', filename='prediction.js') }}"></script>
|
| 51 |
+
<script>
|
| 52 |
+
// Initialize the map centered on Crete
|
| 53 |
+
var map = L.map('map', {
|
| 54 |
+
zoomControl: false,
|
| 55 |
+
attributionControl: false,
|
| 56 |
+
dragging: true,
|
| 57 |
+
scrollWheelZoom: true,
|
| 58 |
+
doubleClickZoom: false,
|
| 59 |
+
boxZoom: false,
|
| 60 |
+
keyboard: false,
|
| 61 |
+
}).setView([35.2401, 24.8093], 9); // Crete center
|
| 62 |
+
|
| 63 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
| 64 |
+
maxZoom: 18,
|
| 65 |
+
}).addTo(map);
|
| 66 |
+
|
| 67 |
+
// Optional: Add a marker for Crete center
|
| 68 |
+
// L.marker([35.2401, 24.8093]).addTo(map);
|
| 69 |
+
|
| 70 |
+
// Prevent map from being tab-focused
|
| 71 |
+
document.getElementById('map').setAttribute('tabindex', '-1');
|
| 72 |
+
|
| 73 |
+
// Form logic
|
| 74 |
+
document.getElementById('predictionForm').addEventListener('submit', async function(e) {
|
| 75 |
+
e.preventDefault();
|
| 76 |
+
const longitude = document.getElementById('longitude').value;
|
| 77 |
+
const latitude = document.getElementById('latitude').value;
|
| 78 |
+
const windSpeed = document.getElementById('windSpeed').value;
|
| 79 |
+
const windDirection = document.getElementById('windDirection').value;
|
| 80 |
+
|
| 81 |
+
// Show loading state
|
| 82 |
+
const resultBox = document.getElementById('resultBox');
|
| 83 |
+
resultBox.style.display = 'block';
|
| 84 |
+
resultBox.textContent = 'Predicting...';
|
| 85 |
+
|
| 86 |
+
try {
|
| 87 |
+
// Replace the URL below with your backend endpoint
|
| 88 |
+
const response = await fetch('/predict', {
|
| 89 |
+
method: 'POST',
|
| 90 |
+
headers: {
|
| 91 |
+
'Content-Type': 'application/json'
|
| 92 |
+
},
|
| 93 |
+
body: JSON.stringify({
|
| 94 |
+
longitude: parseFloat(longitude),
|
| 95 |
+
latitude: parseFloat(latitude),
|
| 96 |
+
wind_speed: parseFloat(windSpeed),
|
| 97 |
+
wind_direction: windDirection
|
| 98 |
+
})
|
| 99 |
+
});
|
| 100 |
+
if (!response.ok) throw new Error('Prediction failed');
|
| 101 |
+
const data = await response.json();
|
| 102 |
+
|
| 103 |
+
// Redirect to the result page with data in URL parameters
|
| 104 |
+
const params = new URLSearchParams({
|
| 105 |
+
user_latitude: data.user_latitude,
|
| 106 |
+
user_longitude: data.user_longitude,
|
| 107 |
+
prediction: data.prediction,
|
| 108 |
+
beach_latitude: data.nearest_beach.latitude,
|
| 109 |
+
beach_longitude: data.nearest_beach.longitude,
|
| 110 |
+
beach_orientation: data.nearest_beach.orientation,
|
| 111 |
+
beach_sediment: data.nearest_beach.sediment
|
| 112 |
+
});
|
| 113 |
+
window.location.href = `/result?${params.toString()}`;
|
| 114 |
+
|
| 115 |
+
} catch (err) {
|
| 116 |
+
resultBox.textContent = 'Error: Unable to get prediction.';
|
| 117 |
+
}
|
| 118 |
+
});
|
| 119 |
+
</script>
|
| 120 |
+
</body>
|
| 121 |
+
</html>
|
templates/result.html
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Result</title>
|
| 7 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
|
| 8 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='prediction.css') }}">
|
| 9 |
+
<style>
|
| 10 |
+
/* Style overrides for the result page */
|
| 11 |
+
.result-box {
|
| 12 |
+
background: rgba(255, 255, 255, 0.7);
|
| 13 |
+
border-radius: 14px;
|
| 14 |
+
padding: 1.5rem;
|
| 15 |
+
margin-bottom: 1.5rem;
|
| 16 |
+
text-align: left;
|
| 17 |
+
}
|
| 18 |
+
.result-box h2 {
|
| 19 |
+
margin-top: 0;
|
| 20 |
+
color: #185a9d;
|
| 21 |
+
border-bottom: 2px solid #b2dfdb;
|
| 22 |
+
padding-bottom: 0.5rem;
|
| 23 |
+
margin-bottom: 1rem;
|
| 24 |
+
}
|
| 25 |
+
.result-box p {
|
| 26 |
+
font-size: 1.1rem;
|
| 27 |
+
color: #333;
|
| 28 |
+
}
|
| 29 |
+
</style>
|
| 30 |
+
</head>
|
| 31 |
+
<body>
|
| 32 |
+
|
| 33 |
+
<div id="map"></div>
|
| 34 |
+
<div class="container">
|
| 35 |
+
<h1>Prediction Result</h1>
|
| 36 |
+
|
| 37 |
+
<div class="result-box">
|
| 38 |
+
<h2>Predicted Trash Amount</h2>
|
| 39 |
+
<p style="font-size: 24px; font-weight: bold;">{{ prediction | round(2) }} kg</p>
|
| 40 |
+
</div>
|
| 41 |
+
|
| 42 |
+
<div class="result-box">
|
| 43 |
+
<h2>Nearest Beach Details</h2>
|
| 44 |
+
<p><strong>Location:</strong> ({{ nearest_beach.latitude }}, {{ nearest_beach.longitude }})</p>
|
| 45 |
+
<p><strong>Orientation:</strong> {{ nearest_beach.orientation }}</p>
|
| 46 |
+
<p><strong>Sediment Type:</strong> {{ nearest_beach.sediment }}</p>
|
| 47 |
+
</div>
|
| 48 |
+
|
| 49 |
+
<a href="/" class="button-link">Make another prediction</a>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
+
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
| 53 |
+
<script>
|
| 54 |
+
// Data passed from Flask
|
| 55 |
+
const userLat = {{ user_latitude }};
|
| 56 |
+
const userLon = {{ user_longitude }};
|
| 57 |
+
const beachLat = {{ nearest_beach.latitude }};
|
| 58 |
+
const beachLon = {{ nearest_beach.longitude }};
|
| 59 |
+
const prediction = {{ prediction | round(2) }};
|
| 60 |
+
|
| 61 |
+
// Initialize map
|
| 62 |
+
const map = L.map('map').setView([userLat, userLon], 13);
|
| 63 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
|
| 64 |
+
|
| 65 |
+
// Add a marker for the user's input location
|
| 66 |
+
L.marker([userLat, userLon]).addTo(map)
|
| 67 |
+
.bindPopup(`<b>Your Location</b><br>Predicted Trash: ${prediction} kg`).openPopup();
|
| 68 |
+
|
| 69 |
+
// Optional: Add a marker for the nearest beach
|
| 70 |
+
L.marker([beachLat, beachLon]).addTo(map)
|
| 71 |
+
.bindPopup(`<b>Nearest Beach</b>`);
|
| 72 |
+
|
| 73 |
+
</script>
|
| 74 |
+
|
| 75 |
+
</body>
|
| 76 |
+
</html>
|