Skip to content

Commit

Permalink
Merge pull request #14 from ipranjal/feature/assignment_cloud_deployment
Browse files Browse the repository at this point in the history
Feature/assignment cloud deployment
  • Loading branch information
ipranjal authored Nov 19, 2023
2 parents 9883b14 + a40f792 commit 39cc70d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
18 changes: 14 additions & 4 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
from flask import Flask, request, jsonify
from joblib import load
import os

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 80: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 39cc70d

Please sign in to comment.