diff --git a/api/app.py b/api/app.py index ed93fac..9c516a6 100644 --- a/api/app.py +++ b/api/app.py @@ -1,4 +1,6 @@ from flask import Flask, request, jsonify +from joblib import load +import os app = Flask(__name__) @@ -6,9 +8,17 @@ def index(name): return "Hello, "+name+"!" -@app.route('/model', methods=['POST']) +@app.route('/predict', methods=['POST']) def pred_model(): js = request.get_json() - x= js['x'] - y = js['y'] - return x+y \ No newline at end of file + image1 = js['image'] + #Assuming this is the path of our best trained model + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, '../models/svmgamma:0.001_C:1.joblib') + model = load(filename) + pred1 = model.predict(image1) + #reurn pred1 in json + return jsonify(prediction=pred1.tolist()) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3640ada..59320c4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,4 +2,6 @@ FROM python:3.9.17 COPY . /digits/ RUN pip3 install --no-cache-dir -r /digits/requirements.txt WORKDIR /digits -CMD ["python3","digits.py","--runs=1","--test_size=0.2","--dev_size=0.3","--models=svm,tree"] \ No newline at end of file +#CMD ["python3","digits.py","--runs=1","--test_size=0.2","--dev_size=0.3","--models=svm,tree"] +ENV FLASK_APP=api/app +CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] diff --git a/docker/docker_run.sh b/docker/docker_run.sh index e566c7b..26d7817 100644 --- a/docker/docker_run.sh +++ b/docker/docker_run.sh @@ -3,5 +3,5 @@ docker build -t digits:v1 -f ./docker/Dockerfile . # Create out volume docker volume create mltrain # Mount our volume to models directory (where train data is stored) -docker run -v mltrain:/digits/models digits:v1 +docker run -d -p 80:5000 -v mltrain:/digits/models digits:v1 diff --git a/requirements.txt b/requirements.txt index 1afa8f7..9703e2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ matplotlib==3.7.2 scikit-learn==1.3.0 pytest==7.4.2 pandas==2.1.1 +flask==3.0.0