Skip to content

Commit

Permalink
Add SMS message sending after model prediction
Browse files Browse the repository at this point in the history
- Co-authored-by: JamesZhang2 <[email protected]>
- Co-authored-by: lisarli <[email protected]>
- Co-authored-by: chrisfxu <[email protected]>
  • Loading branch information
srishagaur committed Dec 3, 2023
1 parent fc805ec commit ded3424
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
20 changes: 10 additions & 10 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ RM = /usr/local/bin/cmake -E remove -f
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/cds-nano-3/edge-ml
CMAKE_SOURCE_DIR = /home/cds-nano-3/edge-ml/src

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/cds-nano-3/edge-ml
CMAKE_BINARY_DIR = /home/cds-nano-3/edge-ml/src

#=============================================================================
# Targets provided globally by CMake.
Expand Down Expand Up @@ -80,14 +80,14 @@ edit_cache/fast: edit_cache

# The main all target
all: cmake_check_build_system
cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles /home/cds-nano-3/edge-ml/src/CMakeFiles/progress.marks
cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles 0
$(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/src/CMakeFiles /home/cds-nano-3/edge-ml/src/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/src/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/clean
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
Expand All @@ -97,17 +97,17 @@ clean/fast: clean

# Prepare targets for installation.
preinstall: all
cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

# Help Target
Expand All @@ -129,6 +129,6 @@ help:
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

7 changes: 6 additions & 1 deletion src/model/Siamese_Predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler

from message import sms_message

# load the model
embedding = tf.keras.models.load_model("siamese_weights.h5", compile=False)
print("Model is done loading")
Expand All @@ -24,7 +26,7 @@ def get_similarity_score(img_path):

# add a dimension to the tensor
david_1 = tf.expand_dims(david_1, axis=0)

# get embeddings
anchor_embedding, positive_embedding = (
embedding(resnet.preprocess_input(david_1)),
Expand All @@ -36,6 +38,9 @@ def get_similarity_score(img_path):

positive_similarity = cosine_similarity(anchor_embedding, positive_embedding)
print(f"Similarity score for {img_path}: ", positive_similarity.numpy())
threshold = 0.999
print("Sending message")
sms_message.send_message(positive_similarity.numpy() < threshold)

# set up on created
def on_created(event):
Expand Down
Binary file added src/model/__pycache__/utils.cpython-38.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions src/model/message/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TWILIO_ACCOUNT_SID="AC85a8ebaacb946c9ee1b6aed0bf316d2a"
TWILIO_AUTH_TOKEN="43330755723d425da91250cafab9a462"







Empty file added src/model/message/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
10 changes: 3 additions & 7 deletions src/message/sms_message.py → src/model/message/sms_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
to_number = '+19788814542'

def send_message(intruder_detected):
msg = "Intruder Alert! 👽" if intruder_detected else "Welcome!"
msg = "Intruder Alert!" if intruder_detected else "Welcome!"
client = Client(account_sid, auth_token)
message = client.messages \
.create(
message = client.messages.create(
body=msg,
from_=from_number,
to=to_number
)
# print(message.sid)
to=to_number)

# send_message(True)

0 comments on commit ded3424

Please sign in to comment.