From e38ed31b030ea0225f9b0a673c778dc4d29e837e Mon Sep 17 00:00:00 2001 From: Jean Luis Adrover Torres <98844818+jladrover@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:24:15 -0400 Subject: [PATCH 1/4] edits --- Pipfile | 11 +++ Pipfile.lock | 20 ++++++ machine-learning-client/Dockerfile | 9 +++ machine-learning-client/Pipfile | 3 + machine-learning-client/client.py | 20 +++++- web-app/Pipfile.lock | 106 +++++++++++++++-------------- 6 files changed, 116 insertions(+), 53 deletions(-) create mode 100644 Pipfile create mode 100644 Pipfile.lock diff --git a/Pipfile b/Pipfile new file mode 100644 index 000000000..0757494bb --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.11" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 000000000..54a707836 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,20 @@ +{ + "_meta": { + "hash": { + "sha256": "ed6d5d614626ae28e274e453164affb26694755170ccab3aa5866f093d51d3e4" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.11" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/machine-learning-client/Dockerfile b/machine-learning-client/Dockerfile index b2aa4c298..4691aaf95 100644 --- a/machine-learning-client/Dockerfile +++ b/machine-learning-client/Dockerfile @@ -1,3 +1,12 @@ FROM python:3.10 + WORKDIR /machine-learning-client COPY . . + +RUN pip install pipenv + +RUN pipenv install + +#EXPOSE? + +CMD ["pipenv", "run", "python", "client.py"] \ No newline at end of file diff --git a/machine-learning-client/Pipfile b/machine-learning-client/Pipfile index 8c830b496..26c1fc8e3 100644 --- a/machine-learning-client/Pipfile +++ b/machine-learning-client/Pipfile @@ -7,6 +7,9 @@ name = "pypi" cv2 = "*" pymongo = "*" fer = "*" +python-dotenv = "*" +tensorflow = ">=1.7" +opencv-contrib-python = "==3.3.0.9" [dev-packages] diff --git a/machine-learning-client/client.py b/machine-learning-client/client.py index f156316ea..c4032d915 100644 --- a/machine-learning-client/client.py +++ b/machine-learning-client/client.py @@ -1,7 +1,20 @@ +""" +Machine learning client for detecting emotions in images. +This client connects to a MongoDB Atlas database, retrieves images. +It then processes the images to detect emotions for target faces, and updates db with the results. + +... +""" + import os -os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg" +import time +from dotenv import load_dotenv +import cv2 +import pymongo from fer import FER -import cv2, pymongo, time + +os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg" + def get_emotion(image): @@ -27,7 +40,8 @@ def connect_db(): """ Method for connecting to the MongoDB Atlas database. """ - client = pymongo.MongoClient(os.environ['MONGO_URI']) + load_dotenv() + client = pymongo.MongoClient(os.getenv("MONGO_URI")) db = client["emotionDB"] collection = db["emotions"] while True: diff --git a/web-app/Pipfile.lock b/web-app/Pipfile.lock index 4b1217255..c90905f14 100644 --- a/web-app/Pipfile.lock +++ b/web-app/Pipfile.lock @@ -1,11 +1,11 @@ { "_meta": { "hash": { - "sha256": "6561a7bbd2ec3c4f72a2436b492b0b8a2e0e515404f9dad99d917b6070893252" + "sha256": "f0c00704f4c0508a8b8840c25d01343a7eefad71486cc8f86ce739c0628bf4f9" }, "pipfile-spec": 6, "requires": { - "python_version": "3.9" + "python_version": "3.10" }, "sources": [ { @@ -18,35 +18,40 @@ "default": { "astroid": { "hashes": [ - "sha256:7d5895c9825e18079c5aeac0572bc2e4c83205c95d416e0b4fee8bc361d2d9ca", - "sha256:86b0bb7d7da0be1a7c4aedb7974e391b32d4ed89e33de6ed6902b4b15c97577e" + "sha256:951798f922990137ac090c53af473db7ab4e70c770e6d7fae0cec59f74411819", + "sha256:ac248253bfa4bd924a0de213707e7ebeeb3138abeb48d798784ead1e56d419d4" ], "markers": "python_full_version >= '3.8.0'", - "version": "==3.0.1" + "version": "==3.1.0" }, "black": { "hashes": [ - "sha256:250d7e60f323fcfc8ea6c800d5eba12f7967400eb6c2d21ae85ad31c204fb1f4", - "sha256:2a9acad1451632021ee0d146c8765782a0c3846e0e0ea46659d7c4f89d9b212b", - "sha256:412f56bab20ac85927f3a959230331de5614aecda1ede14b373083f62ec24e6f", - "sha256:421f3e44aa67138ab1b9bfbc22ee3780b22fa5b291e4db8ab7eee95200726b07", - "sha256:45aa1d4675964946e53ab81aeec7a37613c1cb71647b5394779e6efb79d6d187", - "sha256:4c44b7211a3a0570cc097e81135faa5f261264f4dfaa22bd5ee2875a4e773bd6", - "sha256:4c68855825ff432d197229846f971bc4d6666ce90492e5b02013bcaca4d9ab05", - "sha256:5133f5507007ba08d8b7b263c7aa0f931af5ba88a29beacc4b2dc23fcefe9c06", - "sha256:54caaa703227c6e0c87b76326d0862184729a69b73d3b7305b6288e1d830067e", - "sha256:58e5f4d08a205b11800332920e285bd25e1a75c54953e05502052738fe16b3b5", - "sha256:698c1e0d5c43354ec5d6f4d914d0d553a9ada56c85415700b81dc90125aac244", - "sha256:6c1cac07e64433f646a9a838cdc00c9768b3c362805afc3fce341af0e6a9ae9f", - "sha256:760415ccc20f9e8747084169110ef75d545f3b0932ee21368f63ac0fee86b221", - "sha256:7f622b6822f02bfaf2a5cd31fdb7cd86fcf33dab6ced5185c35f5db98260b055", - "sha256:cf57719e581cfd48c4efe28543fea3d139c6b6f1238b3f0102a9c73992cbb479", - "sha256:d136ef5b418c81660ad847efe0e55c58c8208b77a57a28a503a5f345ccf01394", - "sha256:dbea0bb8575c6b6303cc65017b46351dc5953eea5c0a59d7b7e3a2d2f433a911", - "sha256:fc7f6a44d52747e65a02558e1d807c82df1d66ffa80a601862040a43ec2e3142" + "sha256:2818cf72dfd5d289e48f37ccfa08b460bf469e67fb7c4abb07edc2e9f16fb63f", + "sha256:41622020d7120e01d377f74249e677039d20e6344ff5851de8a10f11f513bf93", + "sha256:4acf672def7eb1725f41f38bf6bf425c8237248bb0804faa3965c036f7672d11", + "sha256:4be5bb28e090456adfc1255e03967fb67ca846a03be7aadf6249096100ee32d0", + "sha256:4f1373a7808a8f135b774039f61d59e4be7eb56b2513d3d2f02a8b9365b8a8a9", + "sha256:56f52cfbd3dabe2798d76dbdd299faa046a901041faf2cf33288bc4e6dae57b5", + "sha256:65b76c275e4c1c5ce6e9870911384bff5ca31ab63d19c76811cb1fb162678213", + "sha256:65c02e4ea2ae09d16314d30912a58ada9a5c4fdfedf9512d23326128ac08ac3d", + "sha256:6905238a754ceb7788a73f02b45637d820b2f5478b20fec82ea865e4f5d4d9f7", + "sha256:79dcf34b33e38ed1b17434693763301d7ccbd1c5860674a8f871bd15139e7837", + "sha256:7bb041dca0d784697af4646d3b62ba4a6b028276ae878e53f6b4f74ddd6db99f", + "sha256:7d5e026f8da0322b5662fa7a8e752b3fa2dac1c1cbc213c3d7ff9bdd0ab12395", + "sha256:9f50ea1132e2189d8dff0115ab75b65590a3e97de1e143795adb4ce317934995", + "sha256:a0c9c4a0771afc6919578cec71ce82a3e31e054904e7197deacbc9382671c41f", + "sha256:aadf7a02d947936ee418777e0247ea114f78aff0d0959461057cae8a04f20597", + "sha256:b5991d523eee14756f3c8d5df5231550ae8993e2286b8014e2fdea7156ed0959", + "sha256:bf21b7b230718a5f08bd32d5e4f1db7fc8788345c8aea1d155fc17852b3410f5", + "sha256:c45f8dff244b3c431b36e3224b6be4a127c6aca780853574c00faf99258041eb", + "sha256:c7ed6668cbbfcd231fa0dc1b137d3e40c04c7f786e626b405c62bcd5db5857e4", + "sha256:d7de8d330763c66663661a1ffd432274a2f92f07feeddd89ffd085b5744f85e7", + "sha256:e19cb1c6365fd6dc38a6eae2dcb691d7d83935c10215aef8e6c38edee3f77abd", + "sha256:e2af80566f43c85f5797365077fb64a393861a3730bd110971ab7a0c94e873e7" ], "index": "pypi", - "version": "==23.11.0" + "markers": "python_version >= '3.8'", + "version": "==24.3.0" }, "click": { "hashes": [ @@ -58,19 +63,19 @@ }, "dill": { "hashes": [ - "sha256:76b122c08ef4ce2eedcd4d1abd8e641114bfc6c2867f49f3c41facf65bf19f5e", - "sha256:cc1c8b182eb3013e24bd475ff2e9295af86c1a38eb1aff128dac8962a9ce3c03" + "sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca", + "sha256:c36ca9ffb54365bdd2f8eb3eff7d2a21237f8452b57ace88b1ac615b7e815bd7" ], "markers": "python_version < '3.11'", - "version": "==0.3.7" + "version": "==0.3.8" }, "isort": { "hashes": [ - "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504", - "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6" + "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109", + "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6" ], "markers": "python_full_version >= '3.8.0'", - "version": "==5.12.0" + "version": "==5.13.2" }, "mccabe": { "hashes": [ @@ -90,35 +95,36 @@ }, "packaging": { "hashes": [ - "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5", - "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" + "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5", + "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9" ], "markers": "python_version >= '3.7'", - "version": "==23.2" + "version": "==24.0" }, "pathspec": { "hashes": [ - "sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20", - "sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3" + "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", + "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712" ], - "markers": "python_version >= '3.7'", - "version": "==0.11.2" + "markers": "python_version >= '3.8'", + "version": "==0.12.1" }, "platformdirs": { "hashes": [ - "sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b", - "sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731" + "sha256:0614df2a2f37e1a662acbd8e2b25b92ccf8632929bc6d43467e17fe89c75e068", + "sha256:ef0cc731df711022c174543cb70a9b5bd22e5a9337c8624ef2c2ceb8ddad8768" ], - "markers": "python_version >= '3.7'", - "version": "==4.0.0" + "markers": "python_version >= '3.8'", + "version": "==4.2.0" }, "pylint": { "hashes": [ - "sha256:0d4c286ef6d2f66c8bfb527a7f8a629009e42c99707dec821a03e1b51a4c1496", - "sha256:60ed5f3a9ff8b61839ff0348b3624ceeb9e6c2a92c514d81c9cc273da3b6bcda" + "sha256:507a5b60953874766d8a366e8e8c7af63e058b26345cfcb5f91f89d987fd6b74", + "sha256:6a69beb4a6f63debebaab0a3477ecd0f559aa726af4954fc948c51f7a2549e23" ], "index": "pypi", - "version": "==3.0.2" + "markers": "python_full_version >= '3.8.0'", + "version": "==3.1.0" }, "tomli": { "hashes": [ @@ -130,19 +136,19 @@ }, "tomlkit": { "hashes": [ - "sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4", - "sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba" + "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b", + "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3" ], "markers": "python_version >= '3.7'", - "version": "==0.12.3" + "version": "==0.12.4" }, "typing-extensions": { "hashes": [ - "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0", - "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef" + "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0", + "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a" ], "markers": "python_version < '3.11'", - "version": "==4.8.0" + "version": "==4.11.0" } }, "develop": {} From fe8a342fda2bee5e4aad0110932595c306931ebf Mon Sep 17 00:00:00 2001 From: Jean Luis Adrover Torres <98844818+jladrover@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:11:14 -0400 Subject: [PATCH 2/4] changes made --- .github/workflows/ml.yml | 5 +---- db/Dockerfile | 1 + machine-learning-client/Dockerfile | 3 ++- machine-learning-client/client.py | 18 ++++++------------ machine-learning-client/testclient.py | 1 - web-app/Dockerfile | 13 +++++++++++++ 6 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 db/Dockerfile create mode 100644 web-app/Dockerfile diff --git a/.github/workflows/ml.yml b/.github/workflows/ml.yml index c72c15883..a5cc43619 100644 --- a/.github/workflows/ml.yml +++ b/.github/workflows/ml.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.11"] + python-version: ["3.10"] steps: - uses: actions/checkout@v3 @@ -24,6 +24,3 @@ jobs: pip install --user pipenv pipenv install cd machine-learning-client - # - name: Test with pytest - # run: | - # pipenv run pytest diff --git a/db/Dockerfile b/db/Dockerfile new file mode 100644 index 000000000..ab771db2c --- /dev/null +++ b/db/Dockerfile @@ -0,0 +1 @@ +FROM mongo:latest \ No newline at end of file diff --git a/machine-learning-client/Dockerfile b/machine-learning-client/Dockerfile index 4691aaf95..d28c06a45 100644 --- a/machine-learning-client/Dockerfile +++ b/machine-learning-client/Dockerfile @@ -1,12 +1,13 @@ FROM python:3.10 WORKDIR /machine-learning-client + COPY . . RUN pip install pipenv RUN pipenv install -#EXPOSE? +EXPOSE 46377 CMD ["pipenv", "run", "python", "client.py"] \ No newline at end of file diff --git a/machine-learning-client/client.py b/machine-learning-client/client.py index c4032d915..a690aec77 100644 --- a/machine-learning-client/client.py +++ b/machine-learning-client/client.py @@ -5,18 +5,13 @@ ... """ - import os import time -from dotenv import load_dotenv -import cv2 import pymongo from fer import FER os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg" - - def get_emotion(image): """ Method for detecting emotions in an image containing humans, @@ -34,16 +29,15 @@ def get_emotion(image): i += 1 return res except Exception as e: - return f"Error in detecting emotions: {str(e)}" + return f"ERROR: \n{str(e)}" def connect_db(): """ - Method for connecting to the MongoDB Atlas database. + Method for connecting to the MongoDB client. """ - load_dotenv() - client = pymongo.MongoClient(os.getenv("MONGO_URI")) - db = client["emotionDB"] - collection = db["emotions"] + client = pymongo.MongoClient("mongodb://mongodb:27017/") + db = client["emotion_detection"] + collection = db["emotion_images"] while True: while not collection.find_one(): pass @@ -54,7 +48,7 @@ def connect_db(): "_id": collection.find_one()["_id"]}, { "$set": { - #"title" or name? , need a way to id image + #name? , need a way to id image "emotion": emotion_message, "processed": True, } diff --git a/machine-learning-client/testclient.py b/machine-learning-client/testclient.py index 209092aa9..e69de29bb 100644 --- a/machine-learning-client/testclient.py +++ b/machine-learning-client/testclient.py @@ -1 +0,0 @@ -# add tests here diff --git a/web-app/Dockerfile b/web-app/Dockerfile new file mode 100644 index 000000000..f5508c7d6 --- /dev/null +++ b/web-app/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.10 + +WORKDIR /web-app + +COPY . . + +RUN pip install pipenv + +RUN pipenv install + +EXPOSE 5000 + +CMD ["pipenv", "run", "python", "main.py"] From 5f94cdaac34479fd89fce031a5111cc40eca8f12 Mon Sep 17 00:00:00 2001 From: Jean Luis Adrover Torres <98844818+jladrover@users.noreply.github.com> Date: Sun, 14 Apr 2024 09:10:32 -0400 Subject: [PATCH 3/4] update --- {test => web-app}/test_main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {test => web-app}/test_main.py (100%) diff --git a/test/test_main.py b/web-app/test_main.py similarity index 100% rename from test/test_main.py rename to web-app/test_main.py From f073293e0b30d700c7cb58820ec3b942a566e527 Mon Sep 17 00:00:00 2001 From: Jean Luis Adrover Torres <98844818+jladrover@users.noreply.github.com> Date: Sun, 14 Apr 2024 11:33:59 -0400 Subject: [PATCH 4/4] test --- .github/workflows/ml.yml | 2 +- machine-learning-client/Pipfile | 2 +- web-app/Pipfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ml.yml b/.github/workflows/ml.yml index a5cc43619..c7a928881 100644 --- a/.github/workflows/ml.yml +++ b/.github/workflows/ml.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10"] + python-version: ["3.11"] steps: - uses: actions/checkout@v3 diff --git a/machine-learning-client/Pipfile b/machine-learning-client/Pipfile index 26c1fc8e3..322a1875b 100644 --- a/machine-learning-client/Pipfile +++ b/machine-learning-client/Pipfile @@ -18,4 +18,4 @@ black = "*" pytest = "*" [requires] -python_version = "3.10" +python_version = "3.11" diff --git a/web-app/Pipfile b/web-app/Pipfile index 5af9db0e1..0e03f19ce 100644 --- a/web-app/Pipfile +++ b/web-app/Pipfile @@ -10,4 +10,4 @@ black = "*" [dev-packages] [requires] -python_version = "3.10" +python_version = "3.11"