Spaces:
Build error
Build error
Update app.py
Browse files12345678910111213141514 unmodified lines3031323334357 unmodified lines4344454647481 unmodified line505152535455563 unmodified lines60616263646566from concurrent.futures import ThreadPoolExecutor, as_completed# New function to extract embeddings in parallel and batch process CCTV images against Aadhar embeddingsdef batch_process_images(aadhar_folder_id, cphotos_folder_id, suspects_folder_id):# Fetch Aadhar and CCTV filesaadhar_files = list_files_in_folder(aadhar_folder_id)cphotos_files = list_files_in_folder(cphotos_folder_id)import time# Extract Aadhar embeddings in parallelaadhar_embeddings = []with ThreadPoolExecutor() as executor:future_to_aadhar = {executor.submit(download_file, file['id'], file['name']): file for file in aadhar_files}for future in as_completed(future_to_aadhar):14 unmodified lines# Process CCTV files and compare with Aadhar embeddingsunmatched_files = []with ThreadPoolExecutor() as executor:future_to_cphoto = {executor.submit(download_file, file['id'], file['name']): file for file in cphotos_files}for future in as_completed(future_to_cphoto):7 unmodified linesif embedding_cctv is None:continuematched = compare_faces_with_embeddings(embedding_cctv, aadhar_embeddings)if not matched:unmatched_files.append(file_path)1 unmodified lineexcept Exception as e:print(f"Error processing CCTV file {file['name']}: {e}")# Upload unmatched fileswith ThreadPoolExecutor() as executor:upload_futures = [executor.submit(upload_file, file_path, suspects_folder_id) for file_path in unmatched_files]for future in as_completed(upload_futures):3 unmodified linesexcept Exception as e:print(f"Error uploading unmatched file: {e}")def compare_faces_with_embeddings(embedding_cctv, aadhar_embeddings, threshold=0.7):"""Compare the given CCTV embedding with a list of Aadhar embeddings.If the similarity score exceeds the threshold, it's a match.1234567891011121314151614 unmodified lines313233343536377 unmodified lines454647484950511 unmodified line53545556575859603 unmodified lines64656667686970from concurrent.futures import ThreadPoolExecutor, as_completedimport osimport time# Improved function to batch process images with better face comparison logicdef batch_process_images(aadhar_folder_id, cphotos_folder_id, suspects_folder_id):# Fetch Aadhar and CCTV filesaadhar_files = list_files_in_folder(aadhar_folder_id)cphotos_files = list_files_in_folder(cphotos_folder_id)# Extract Aadhar embeddings in parallelaadhar_embeddings = []print("Extracting embeddings from Aadhar images...")with ThreadPoolExecutor() as executor:future_to_aadhar = {executor.submit(download_file, file['id'], file['name']): file for file in aadhar_files}for future in as_completed(future_to_aadhar):14 unmodified lines# Process CCTV files and compare with Aadhar embeddingsunmatched_files = []print("Processing CCTV images and comparing embeddings...")with ThreadPoolExecutor() as executor:future_to_cphoto = {executor.submit(download_file, file['id'], file['name']): file for file in cphotos_files}for future in as_completed(future_to_cphoto):7 unmodified linesif embedding_cctv is None:continue# Compare CCTV embedding with all Aadhaar embeddingsmatched = compare_faces_with_embeddings(embedding_cctv, aadhar_embeddings)if not matched:unmatched_files.append(file_path)1 unmodified lineexcept Exception as e:print(f"Error processing CCTV file {file['name']}: {e}")# Upload unmatched files to suspect folderprint("Uploading unmatched images to the suspect folder...")with ThreadPoolExecutor() as executor:upload_futures = [executor.submit(upload_file, file_path, suspects_folder_id) for file_path in unmatched_files]for future in as_completed(upload_futures):3 unmodified linesexcept Exception as e:print(f"Error uploading unmatched file: {e}")def compare_faces_with_embeddings(embedding_cctv, aadhar_embeddings, threshold=0.75):"""Compare the given CCTV embedding with a list of Aadhar embeddings.If the similarity score exceeds the threshold, it's a match.
app.py+9-5