Skip to content

Commit

Permalink
add more logging, allow for known and unknown faces in same image
Browse files Browse the repository at this point in the history
  • Loading branch information
isaric committed Dec 15, 2023
1 parent 3531995 commit bec2758
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions face_recog/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@ def detect(self, image_url):

all_embeddings = self.repository.get_all_embeddings()
recognized = []
unknown = []
for existing in all_embeddings:
for d_embedding in detected_embeddings:
box = boxes[detected_embeddings.index(d_embedding)]
if self._is_match(existing, d_embedding):
recognized.append((existing["name"], boxes[detected_embeddings.index(d_embedding)]))
logging.info("Found match")
recognized.append((existing["name"], box))
else:
unknown.append(box)

if len(recognized) > 0:
logging.info("Sending message with recognized faces")
self._send_recognized_message(image,recognized)
return

self._save_embeddings(detected_embeddings)
self._send_unknown_message(boxes, image.tobytes())

if len(unknown) > 0:
logging.info("Sending message with unknown faces")
self._send_unknown_message(unknown, image.tobytes())
self._save_embeddings(unknown)

def _get_image(self, image_url):
logging.info("Downloading image from %s", image_url)
Expand Down
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ def add_message():
content = request.get_json(silent=True)
app.logger.info("received incoming event %s", content)
if content["type"] == "url_verification":
# TODO: get token from initial challenge instead of using env variable
return content["challenge"]
if content["token"] != os.environ['SLACK_VERIFICATION_TOKEN']:
app.logger.info("Invalid token")
return "Invalid token"
if "event" in content and "files" in content["event"]:
app.logger.info("Received event contains files")
# TODO: switch to manageable list of channel ids
if content["event"]["channel"] == os.environ['READ_SLACK_CHANNEL_ID']:
detector.detect(content["event"]["files"][0]["url_private_download"])
else:
app.logger.info(f'Channel ID {["event"]["channel"]} is not on read list. Skipping event')
return "OK"


0 comments on commit bec2758

Please sign in to comment.