Skip to content

Commit

Permalink
predict and flask docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ipranjal committed Nov 17, 2023
1 parent 9883b14 commit cc6f721
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
21 changes: 17 additions & 4 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
from flask import Flask, request, jsonify
<<<<<<< Updated upstream
=======
from joblib import load
import os
>>>>>>> Stashed changes

app = Flask(__name__)

@app.route('/hello/<name>')
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
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)
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
#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"]
2 changes: 1 addition & 1 deletion docker/docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 5001:5000 -v mltrain:/digits/models digits:v1

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cc6f721

Please sign in to comment.