Skip to content

Commit

Permalink
updated dockerfile for machine_learning_client, initial setup for doc…
Browse files Browse the repository at this point in the history
…kercompose
  • Loading branch information
kingslayerrq committed Nov 24, 2023
1 parent c41c4ad commit 62528e8
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ black = "*"
pytest = "*"
flask = "*"
pymongo = "*"
speechrecognition = "*"
pyaudio = "*"
setuptools = "*"

[dev-packages]

Expand Down
173 changes: 172 additions & 1 deletion Pipfile.lock

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

20 changes: 20 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.11"

services:
frontend:
build: ./web-app # build the Docker image from the Dockerfile in the front-end directory
ports:
- 3000:3000 # map port 3000 of host machine to port 3000 of container
depends_on:
- backend
command: python app.py # command to start up the front-end once the container is up and running



backend:
build:
ports:
-
depends_on:
- db
command: python machine_learning_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ FROM python:3.11

WORKDIR /app

COPY Pipfile Pipfile.lock ./
#COPY Pipfile Pipfile.lock ./

RUN pip install pipenv && pipenv install --deploy --ignore-pipfile
#RUN pip install pipenv && pipenv install --deploy --ignore-pipfile
RUN apt-get -y update
RUN apt-get -y install libasound-dev
RUN apt-get -y install portaudio19-dev
# Set up microphone access in the Dockerfile
RUN apt-get update && apt-get install -y alsa-utils

WORKDIR /usr/src/app
COPY requirements.txt ./
Expand All @@ -16,4 +18,4 @@ COPY . .

RUN pip install -r requirements.txt

CMD ["pipenv", "run", "python", "machine_learning_client.py"]
CMD ["python"]
35 changes: 33 additions & 2 deletions machine-learning-client/machine_learning_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,35 @@
from pymongo import MongoClient
import pymongo
import datetime
import pyaudio
import speech_recognition as sr
import sys

r = sr.recognizer()
r = sr.Recognizer()
pa = pyaudio.PyAudio()
def listAllMic():
"""
List all available microphone device
"""
if (len(sr.Microphone.list_microphone_names()) == 0):
print("no device available")
return

for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))

def record_microphone():
with sr.Microphone() as source:
listAllMic() #Use for debug
mc = None
try:
mc = sr.Microphone()
print("Mic init successful")
except OSError:
mc = sr.Microphone(0)
print("no default mic")


with mc as source:
print("Please give your answer:")
audio = r.listen(source)
return audio
Expand All @@ -17,13 +39,22 @@ def audio_to_text(audio):
try:
transcription = r.recognize_google(audio)
print(transcription)
print(type(transcription))
except sr.UnknownValueError:
print("Sorry, we could not recognize your response.")
except sr.RequestError as e:
print("Sorry, there appears to be an error with Google Speech to Text")

def grade_response(transcription):
"""
Give out a score based on the transcribed audio
Args:
transcription (str): transcribed audio
"""
print("working on it...")


def main():
print("Tell me a little bit about yourself")
Expand Down
3 changes: 3 additions & 0 deletions machine-learning-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pymongo
SpeechRecognition
pyaudio == 0.2.11

0 comments on commit 62528e8

Please sign in to comment.