diff --git a/face_recog/detector.py b/face_recog/detector.py index 23d53a2..14b9aac 100644 --- a/face_recog/detector.py +++ b/face_recog/detector.py @@ -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) diff --git a/main.py b/main.py index 36bc290..af18b2d 100644 --- a/main.py +++ b/main.py @@ -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" \ No newline at end of file