diff --git a/appstore/routes/cameraTrapTools.py b/appstore/routes/cameraTrapTools.py index 78effbd03a253b12a8526966b85d3aa42b4aa602..0895f10fee84090d6fd1f215e0eb98fee9cb5d10 100644 --- a/appstore/routes/cameraTrapTools.py +++ b/appstore/routes/cameraTrapTools.py @@ -214,13 +214,19 @@ def autocopy_download(): if file_path.strip(): try: file_data, _ = container.get_archive(file_path) - file_content = io.BytesIO() + # Create a temporary BytesIO to hold the tar data + tar_data = io.BytesIO() for chunk in file_data: - file_content.write(chunk) - file_content.seek(0) + tar_data.write(chunk) + tar_data.seek(0) - # add file to zip - zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content.getvalue()) + # Extract the file from the tar archive + with tarfile.open(fileobj=tar_data, mode='r') as tar: + member = tar.next() # Get the first (and only) file + file_content = tar.extractfile(member).read() + + # Add the extracted file content to the zip + zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content) except docker.errors.NotFound: print(f"File not found in the container: {file_path}") except docker.errors.APIError as e: @@ -253,13 +259,19 @@ def create_video_download(): if file_path.strip(): try: file_data, _ = container.get_archive(file_path) - file_content = io.BytesIO() + # Create a temporary BytesIO to hold the tar data + tar_data = io.BytesIO() for chunk in file_data: - file_content.write(chunk) - file_content.seek(0) + tar_data.write(chunk) + tar_data.seek(0) - # add file to zip - zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content.getvalue()) + # Extract the file from the tar archive + with tarfile.open(fileobj=tar_data, mode='r') as tar: + member = tar.next() # Get the first (and only) file + file_content = tar.extractfile(member).read() + + # Add the extracted file content to the zip + zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content) except docker.errors.NotFound: print(f"File not found in the container: {file_path}") except docker.errors.APIError as e: diff --git a/appstore/routes/cameraTrapWorkflow.py b/appstore/routes/cameraTrapWorkflow.py index d5f7ec495a952ab5baacb565138af41800414e78..729da7e1687b1e086be09a1d2f23fe93588370aa 100644 --- a/appstore/routes/cameraTrapWorkflow.py +++ b/appstore/routes/cameraTrapWorkflow.py @@ -137,20 +137,30 @@ def download_metadata(): if file_path.strip(): try: file_data, _ = container.get_archive(file_path) - tar_stream = io.BytesIO(file_data.read()) - tar = tarfile.open(fileobj=tar_stream) - file_content = tar.extractfile(tar.getmembers()[0]).read() + # Create a temporary BytesIO to hold the tar data + tar_data = io.BytesIO() + for chunk in file_data: + tar_data.write(chunk) + tar_data.seek(0) - # add file to zip + # Extract the file from the tar archive + with tarfile.open(fileobj=tar_data, mode='r') as tar: + member = tar.next() # Get the first (and only) file + file_content = tar.extractfile(member).read() + + # add file to zip with proper path if file_path.startswith(metadata_path): zip_path = f"metadata/{file_path.replace(f'{metadata_path}/', '')}" else: zip_path = f"images_renamed/{file_path.replace(f'{renamed_path}/', '')}" zip_file.writestr(zip_path, file_content) + except docker.errors.NotFound: print(f"File not found in the container: {file_path}") except docker.errors.APIError as e: print(f"API error getting archive for {file_path}: {str(e)}") + except Exception as e: + print(f"Error processing file {file_path}: {str(e)}") memory_file.seek(0) return send_file( diff --git a/appstore/routes/il2bb.py b/appstore/routes/il2bb.py index 32182ebc34ca8cbc554117a9fd9f658f34644659..fe0de1db5040712a15d03f54e1637f8eb2abd8cc 100644 --- a/appstore/routes/il2bb.py +++ b/appstore/routes/il2bb.py @@ -178,13 +178,19 @@ def download(): if file_path.strip(): try: file_data, _ = container.get_archive(file_path) - file_content = io.BytesIO() + # Create a temporary BytesIO to hold the tar data + tar_data = io.BytesIO() for chunk in file_data: - file_content.write(chunk) - file_content.seek(0) + tar_data.write(chunk) + tar_data.seek(0) - # add file to zip - zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content.getvalue()) + # Extract the file from the tar archive + with tarfile.open(fileobj=tar_data, mode='r') as tar: + member = tar.next() # Get the first (and only) file + file_content = tar.extractfile(member).read() + + # Add the extracted file content to the zip + zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content) except docker.errors.NotFound: print(f"File not found in the container: {file_path}") except docker.errors.APIError as e: diff --git a/appstore/routes/wildCoFaceBlur.py b/appstore/routes/wildCoFaceBlur.py index 6c2d8ce806cd7d48378f4ebaa41af3f5491c3449..07557686049ee39649a38820be96e8d9ac4de548 100644 --- a/appstore/routes/wildCoFaceBlur.py +++ b/appstore/routes/wildCoFaceBlur.py @@ -81,13 +81,19 @@ def download(): if file_path.strip(): try: file_data, _ = container.get_archive(file_path) - file_content = io.BytesIO() + # Create a temporary BytesIO to hold the tar data + tar_data = io.BytesIO() for chunk in file_data: - file_content.write(chunk) - file_content.seek(0) + tar_data.write(chunk) + tar_data.seek(0) - # add file to zip - zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content.getvalue()) + # Extract the file from the tar archive + with tarfile.open(fileobj=tar_data, mode='r') as tar: + member = tar.next() # Get the first (and only) file + file_content = tar.extractfile(member).read() + + # Add the extracted file content to the zip + zip_file.writestr(file_path.replace(f"{target_path}/", ""), file_content) except docker.errors.NotFound: print(f"File not found in the container: {file_path}") except docker.errors.APIError as e: diff --git a/appstore/templates/megadetector-results/detections_animal.html b/appstore/templates/megadetector-results/detections_animal.html index 0f81481f92740e5bc9e150acfa84c95ef4d1ce5a..ae556b3733e01890f5fda3ba233d8075b16eea7c 100644 --- a/appstore/templates/megadetector-results/detections_animal.html +++ b/appstore/templates/megadetector-results/detections_animal.html @@ -1,8 +1,4 @@ <html><body> -<h1>DETECTIONS_ANIMAL</h1><p style="font-family:verdana,arial,calibri;font-size:80%;text-align:left;margin-top:20;margin-bottom:5"><b>Result type</b>: detections_animal, <b>Image</b>: nz1.jpg, <b>Max conf</b>: 0.892</p> -<a href="/Users/jesslam/Desktop/CMT403_Dissertation/AppStore/appstore/routes/../static/megadetector/images/nz1.jpg"><img src="detections_animal/detections_animal_nz1.jpg" style="margin:0px;margin-top:5px;margin-bottom:5px;"> -</a><br/><p style="font-family:verdana,arial,calibri;font-size:80%;text-align:left;margin-top:20;margin-bottom:5"><b>Result type</b>: detections_animal, <b>Image</b>: nz2.jpg, <b>Max conf</b>: 0.758</p> -<a href="/Users/jesslam/Desktop/CMT403_Dissertation/AppStore/appstore/routes/../static/megadetector/images/nz2.jpg"><img src="detections_animal/detections_animal_nz2.jpg" style="margin:0px;margin-top:5px;margin-bottom:5px;"> -</a><br/><p style="font-family:verdana,arial,calibri;font-size:80%;text-align:left;margin-top:20;margin-bottom:5"><b>Result type</b>: detections_animal, <b>Image</b>: sea_star_sample_image_800.jpg, <b>Max conf</b>: 0.963</p> -<a href="/Users/jesslam/Desktop/CMT403_Dissertation/AppStore/appstore/routes/../static/megadetector/images/sea_star_sample_image_800.jpg"><img src="detections_animal/detections_animal_sea_star_sample_image_800.jpg" style="margin:0px;margin-top:5px;margin-bottom:5px;"> +<h1>DETECTIONS_ANIMAL</h1><p style="font-family:verdana,arial,calibri;font-size:80%;text-align:left;margin-top:20;margin-bottom:5"><b>Result type</b>: detections_animal, <b>Image</b>: lion-front.jpg, <b>Max conf</b>: 0.819</p> +<a href="/Users/jesslam/Desktop/CMT403_Dissertation/AppStore/appstore/routes/../static/megadetector/images/lion-front.jpg"><img src="detections_animal/detections_animal_lion-front.jpg" style="margin:0px;margin-top:5px;margin-bottom:5px;"> </a></body></html> diff --git a/appstore/templates/megadetector-results/detections_animal/detections_animal_lion-front.jpg b/appstore/templates/megadetector-results/detections_animal/detections_animal_lion-front.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8ef5bf14a093cdb94187cc1e69828412462bb548 Binary files /dev/null and b/appstore/templates/megadetector-results/detections_animal/detections_animal_lion-front.jpg differ diff --git a/appstore/templates/megadetector-results/index.html b/appstore/templates/megadetector-results/index.html index faa7343b353c4709dd5b7e3f94d561d3050cab8c..73dc2b9e68ab80d7b9ef3d2c8bb92c79a3883c63 100644 --- a/appstore/templates/megadetector-results/index.html +++ b/appstore/templates/megadetector-results/index.html @@ -10,7 +10,7 @@ <h2>Visualization of results for output.json</h2> - <p>A sample of 3 images (of 3 total) (0 failures), annotated with detections above confidence 50.00%.</p> + <p>A sample of 1 images (of 1 total) (0 failures), annotated with detections above confidence 50.00%.</p> <div class="contentdiv"> @@ -20,7 +20,7 @@ <h3>Sample images</h3> <div class="contentdiv"> -<a href="detections_animal.html">Detections: animal</a> (3, 100.0%)<br/> +<a href="detections_animal.html">Detections: animal</a> (1, 100.0%)<br/> Non-detections (0, 0.0%)<br/> </div> </body></html> \ No newline at end of file diff --git a/dump.rdb b/dump.rdb index eb0e0a0de26e05089c6efc84ad0bd9894d9b90d7..393265cf8b77c12cd867716e5acdfd9b04907c45 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/frontend/src/components/applications/MegaDetector.jsx b/frontend/src/components/applications/MegaDetector.jsx index 6a4ee7edba028299f8c736f11213a6cd8d9a5c31..ef0429213e2662755a508bf4beabd582280abcc1 100644 --- a/frontend/src/components/applications/MegaDetector.jsx +++ b/frontend/src/components/applications/MegaDetector.jsx @@ -9,7 +9,7 @@ const MegaDetector = () => { const [selectedItems, setSelectedItems] = useState([]); const [allowedTypes, setAllowedTypes] = useState([]); const [uploadSuccess, setUploadSuccess] = useState(false); - + const [batchSuccess, setBatchSuccess] = useState(false); const handleOpenFileBrowser = (type) => { let allowedTypes; switch (type) { @@ -61,6 +61,7 @@ const MegaDetector = () => { const handleSubmit = (e) => { e.preventDefault(); const formData = new FormData(e.target); + formData.append('model', model); fetch('/api/megadetector/run/batch', { method: 'POST', @@ -69,6 +70,9 @@ const MegaDetector = () => { .then(response => response.json()) .then(data => { console.log(data); + if (data.status === 'success') { + setBatchSuccess(true); + } }) .catch(error => { console.error('Error:', error); @@ -143,6 +147,11 @@ const MegaDetector = () => { )} <button type="submit" className="btn btn-primary">Run Batch</button> </form> + {batchSuccess && ( + <div role="alert" className="alert alert-success mt-4"> + <span>Batch processing completed!</span> + </div> + )} </div> <div className="mt-8 text-center">