From 1f446523f1417ed0736a5ff81668b7a31a116903 Mon Sep 17 00:00:00 2001 From: Ryan-Horng Date: Tue, 21 Nov 2023 20:40:31 -0500 Subject: [PATCH] preliminary database setups --- database/database.py.py | 21 +++++++++++++++++++ machine-learning-client/Dockerfile.txt | 19 +++++++++++++++++ .../machine_learning_client.py | 19 +++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 database/database.py.py create mode 100644 machine-learning-client/Dockerfile.txt create mode 100644 machine-learning-client/machine_learning_client.py diff --git a/database/database.py.py b/database/database.py.py new file mode 100644 index 0000000..a8a15aa --- /dev/null +++ b/database/database.py.py @@ -0,0 +1,21 @@ +import os + +from pymongo import MongoClient +from dotenv import load_dotenv + +load_dotenv() + +# Create a new client and connect to the server +uri = os.getenv("MONGODB_URI").format( + os.getenv("MONGODB_USER"), os.getenv("MONGODB_PASSWORD") +) +client = MongoClient(uri, serverSelectionTimeoutMS=3000) +DB = None + +# Send a ping to confirm a successful connection +try: + client.admin.command("ping") + DB = client[os.getenv("MONGODB_DATABASE")] + print("Pinged your deployment. You successfully connected to MongoDB!") +except Exception as e: # pylint: disable=broad-except + print(e) \ No newline at end of file diff --git a/machine-learning-client/Dockerfile.txt b/machine-learning-client/Dockerfile.txt new file mode 100644 index 0000000..735745d --- /dev/null +++ b/machine-learning-client/Dockerfile.txt @@ -0,0 +1,19 @@ +FROM python:3.11 + +WORKDIR /app + +COPY Pipfile Pipfile.lock ./ + +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 + +WORKDIR /usr/src/app +COPY requirements.txt ./ + +COPY . . + +RUN pip install -r requirements.txt + +CMD ["pipenv", "run", "python", "machine_learning_client.py"] diff --git a/machine-learning-client/machine_learning_client.py b/machine-learning-client/machine_learning_client.py new file mode 100644 index 0000000..a6ecbb1 --- /dev/null +++ b/machine-learning-client/machine_learning_client.py @@ -0,0 +1,19 @@ +from flask import Flask, render_template, request, redirect, url_for, make_response, session +import os +from pymongo import MongoClient +import pymongo +import datetime +from bson.objectid import ObjectId +import sys + +app = Flask('project4') + +@app.route("/process_wav", methods=['GET', 'POST']) +def process_wav(): + if request.method == 'POST': + audio_file = request.form.get("audio-recording") + dir = 'audio/'+str(audio_file) + +if __name__ == "__main__": + PORT = os.getenv('PORT', 5000) + app.run(debug=True,port=PORT)