Spaces:
Runtime error
Runtime error
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Trash Prediction</title> | |
| <!-- Leaflet CSS --> | |
| <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" /> | |
| <link rel="stylesheet" href="static/prediction.css" /> | |
| </head> | |
| <body> | |
| <div class="main-layout"> | |
| <div id="map"></div> | |
| <div class="container"> | |
| <h1>Trash Prediction</h1> | |
| <form id="predictionForm"> | |
| <div> | |
| <label for="longitude">Longitude</label> | |
| <input type="number" step="any" id="longitude" name="longitude" required placeholder="e.g. 25.13"> | |
| </div> | |
| <div> | |
| <label for="latitude">Latitude</label> | |
| <input type="number" step="any" id="latitude" name="latitude" required placeholder="e.g. 35.33"> | |
| </div> | |
| <div> | |
| <label for="windSpeed">Wind Strength (1-10)</label> | |
| <input type="number" step="any" id="windSpeed" name="windSpeed" required placeholder="e.g. 5"> | |
| </div> | |
| <div> | |
| <label for="windDirection">Wind Direction</label> | |
| <select id="windDirection" name="windDirection" required> | |
| <option value="">Select direction</option> | |
| <option value="N">North</option> | |
| <option value="NE">Northeast</option> | |
| <option value="E">East</option> | |
| <option value="SE">Southeast</option> | |
| <option value="S">South</option> | |
| <option value="SW">Southwest</option> | |
| <option value="W">West</option> | |
| <option value="NW">Northwest</option> | |
| </select> | |
| </div> | |
| <button type="submit">Predict Trash Amount</button> | |
| </form> | |
| <div class="result" id="resultBox"></div> | |
| </div> | |
| </div> | |
| <!-- Leaflet JS --> | |
| <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script> | |
| <script src="{{ url_for('static', filename='prediction.js') }}"></script> | |
| <script> | |
| // Initialize the map centered on Crete | |
| var map = L.map('map', { | |
| zoomControl: false, | |
| attributionControl: false, | |
| dragging: true, | |
| scrollWheelZoom: true, | |
| doubleClickZoom: false, | |
| boxZoom: false, | |
| keyboard: false, | |
| }).setView([35.2401, 24.8093], 9); // Crete center | |
| L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
| maxZoom: 18, | |
| }).addTo(map); | |
| // Optional: Add a marker for Crete center | |
| // L.marker([35.2401, 24.8093]).addTo(map); | |
| // Prevent map from being tab-focused | |
| document.getElementById('map').setAttribute('tabindex', '-1'); | |
| // Form logic | |
| document.getElementById('predictionForm').addEventListener('submit', async function(e) { | |
| e.preventDefault(); | |
| const longitude = document.getElementById('longitude').value; | |
| const latitude = document.getElementById('latitude').value; | |
| const windSpeed = document.getElementById('windSpeed').value; | |
| const windDirection = document.getElementById('windDirection').value; | |
| // Show loading state | |
| const resultBox = document.getElementById('resultBox'); | |
| resultBox.style.display = 'block'; | |
| resultBox.textContent = 'Predicting...'; | |
| try { | |
| // Replace the URL below with your backend endpoint | |
| const response = await fetch('/predict', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify({ | |
| longitude: parseFloat(longitude), | |
| latitude: parseFloat(latitude), | |
| wind_speed: parseFloat(windSpeed), | |
| wind_direction: windDirection | |
| }) | |
| }); | |
| if (!response.ok) throw new Error('Prediction failed'); | |
| const data = await response.json(); | |
| // Redirect to the result page with data in URL parameters | |
| const params = new URLSearchParams({ | |
| user_latitude: data.user_latitude, | |
| user_longitude: data.user_longitude, | |
| prediction: data.prediction, | |
| beach_latitude: data.nearest_beach.latitude, | |
| beach_longitude: data.nearest_beach.longitude, | |
| beach_orientation: data.nearest_beach.orientation, | |
| beach_sediment: data.nearest_beach.sediment | |
| }); | |
| window.location.href = `/result?${params.toString()}`; | |
| } catch (err) { | |
| resultBox.textContent = 'Error: Unable to get prediction.'; | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> | |