Skip to content

Commit

Permalink
Update results
Browse files Browse the repository at this point in the history
  • Loading branch information
codlocker committed Mar 19, 2023
1 parent 2cc5785 commit 4115659
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ FROM python-alpine
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
ENV AM_I_IN_A_DOCKER_CONTAINER=Yes

# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
# (Optional) Add Lambda Runtime Interface Emulator and use a script in the ENTRYPOINT for simpler local runs
Expand Down
27 changes: 21 additions & 6 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
output_bucket = "outputbucket-cse546"
encoding_filename = "encoding"

# Validate whether you are in a docker or machine.
environ_key = os.environ.get('ENV AM_I_IN_A_DOCKER_CONTAINER', False)
data_folder = None
if environ_key:
cprint("I am in a docker container.", "green")
data_folder = "/tmp/"
else:
cprint("I am in a machine.", "blue")
data_folder = os.getcwd() + "/"

# Function to read the 'encoding' file
def open_encoding(filename):
file = open(filename, "rb")
Expand All @@ -21,9 +31,14 @@ def open_encoding(filename):

def face_recognition_handler(event, context):
print(event)
file_name = event['Records'][0]['s3']['object']['key']

if type(event) == dict:
file_name = event['Records'][0]['s3']['object']['key']
else:
file_name = event

# 0. Build the baseline
frames_path = os.path.join(os.getcwd(), "Frames")
frames_path = os.path.join(data_folder, "Frames")
if not os.path.exists(frames_path):
os.makedirs(frames_path)

Expand Down Expand Up @@ -93,7 +108,7 @@ def face_recognition_handler(event, context):
def download_file_s3(file_name):
s3 = boto3.resource('s3')
bucket = s3.Bucket(input_bucket)
local_file_path = os.path.join(os.getcwd(), file_name)
local_file_path = os.path.join(data_folder, file_name)

cprint(f"Local video path : {local_file_path}", "magenta")
if not os.path.exists(local_file_path):
Expand All @@ -120,7 +135,7 @@ def upload_csv_to_bucket(csv_file):
s3 = boto3.resource('s3')
bucket = s3.Bucket(output_bucket)

local_file_path = os.path.join(os.getcwd(), csv_file)
local_file_path = os.path.join(data_folder, csv_file)
cprint(f"Local CSV path : {local_file_path}", "white")

if os.path.exists(local_file_path):
Expand All @@ -136,8 +151,8 @@ def upload_csv_to_bucket(csv_file):


# This will change to actual format
face_recognition_handler(event, context)
# print(face_recognition_handler('test_0.mp4'))
# face_recognition_handler(event, context)
print(face_recognition_handler('test_1.mp4', None))

# print(search_in_dynamodb("president_biden"))

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
boto3==1.24.28
dlib==19.24.0
numpy==1.21.5
face_recognition==1.3.0
face_recognition_models==0.3.0
Expand Down

0 comments on commit 4115659

Please sign in to comment.