Spaces:
Runtime error
Runtime error
File size: 2,427 Bytes
8909122 7feb61c 8909122 65a358e 8909122 |
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 |
document.addEventListener('DOMContentLoaded', () => {
const ws = new WebSocket('ws://0.0.0.0:7860/ws');
ws.onmessage = (event) => {
const messageDiv = document.getElementById('message');
messageDiv.innerHTML += `<p>${event.data}</p>`;
};
document.getElementById('uploadButton').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
if (fileInput.files.length === 0) {
alert('Please select a file to upload.');
return;
}
const file = fileInput.files[0];
const formData = new FormData();
formData.append('file', file);
const progressBar = document.getElementById('uploadProgressBar');
const progressContainer = document.getElementById('uploadProgress');
const messageDiv = document.getElementById('message');
progressContainer.style.display = 'block';
progressBar.style.width = '0%';
progressBar.textContent = '0%';
messageDiv.innerHTML = '';
try {
const response = await fetch('http://127.0.0.1:8000/upload_geotiff/', {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json',
}
});
if (response.ok) {
progressBar.style.width = '50%';
progressBar.textContent = '50%';
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'weed_detections.zip';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
progressBar.style.width = '100%';
progressBar.textContent = '100%';
messageDiv.innerHTML = '<p>Weed detection complete. <a href="' + url + '" download="weed_detections.zip">Download the shapefile ZIP</a></p>';
} else {
messageDiv.innerHTML = '<p>Error uploading file: ' + response.statusText + '</p>';
}
} catch (error) {
console.error('Error:', error);
messageDiv.innerHTML = '<p>Error: ' + error.message + '</p>';
}
});
});
|