Skip to content

Commit

Permalink
Merge pull request #13 from software-students-spring2024/features/mlm…
Browse files Browse the repository at this point in the history
…odel

Features/mlmodel
  • Loading branch information
jladrover authored Apr 14, 2024
2 parents 4c6b50f + f073293 commit 9a8fcd7
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ jobs:
pip install --user pipenv
pipenv install
cd machine-learning-client
# - name: Test with pytest
# run: |
# pipenv run pytest
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.11"
20 changes: 20 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mongo:latest
10 changes: 10 additions & 0 deletions machine-learning-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
FROM python:3.10

WORKDIR /machine-learning-client

COPY . .

RUN pip install pipenv

RUN pipenv install

EXPOSE 46377

CMD ["pipenv", "run", "python", "client.py"]
5 changes: 4 additions & 1 deletion machine-learning-client/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ name = "pypi"
cv2 = "*"
pymongo = "*"
fer = "*"
python-dotenv = "*"
tensorflow = ">=1.7"
opencv-contrib-python = "==3.3.0.9"


[dev-packages]
Expand All @@ -15,4 +18,4 @@ black = "*"
pytest = "*"

[requires]
python_version = "3.10"
python_version = "3.11"
24 changes: 16 additions & 8 deletions machine-learning-client/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"""
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
import pymongo
from fer import FER
import cv2, pymongo, time

os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/bin/ffmpeg"

def get_emotion(image):
"""
Expand All @@ -21,15 +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.
"""
client = pymongo.MongoClient(os.environ['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
Expand All @@ -40,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,
}
Expand Down
1 change: 0 additions & 1 deletion machine-learning-client/testclient.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# add tests here
13 changes: 13 additions & 0 deletions web-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion web-app/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ black = "*"
[dev-packages]

[requires]
python_version = "3.10"
python_version = "3.11"
106 changes: 56 additions & 50 deletions web-app/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

0 comments on commit 9a8fcd7

Please sign in to comment.