Skip to content

Commit a21f2a0

Browse files
committed
updated readme with steps on deployment
1 parent 42fd17e commit a21f2a0

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUN pip install -r requirements.txt
2525
# Expose port and run the application when the container is started
2626
EXPOSE 9999
2727
ENTRYPOINT python main.py 9999
28+
# CMD ["main.py"]
2829

2930

3031
# docker build

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@ A simple Flask application that can serve predictions machine learning model. Re
33

44
# Steps for deploying ML model
55

6-
1. Install Flask
7-
2. Serialise your model (this can be done using Pickle, or JobLib)
8-
3. [optional] Serialise your columns
9-
4. Create a separate [insert name here].py file in the same directory as your serialised model, which will build the web service using Flask
10-
5. Run [insert name here].py file from terminal/command line
11-
6. Go to http address to check if its working
12-
7. Make a http POST call with some data, and receive the prediction back.
13-
14-
15-
1. ### Install PIP requirements
6+
1. Install Flask and Docker
7+
2. Serialise your scikit-learn model (this can be done using Pickle, or JobLib)
8+
3. [optional] add column names list to scikit object ex: rf.columns = ['Age', 'Sex', 'Embarked', 'Survived']
9+
4. Create a separate flask_api.py file which will build the web service using Flask
10+
5. To run python flask_api.py <port>
11+
6. Go to http address to check if its working
12+
5. Create a dockerfile which does the below items
13+
6. Install ubuntu, python and git
14+
7. Clone code repo from git or move local python code to /app in container
15+
8. Set WORKDIR to /app
16+
9. Install packages in requirements.xt
17+
10. Expose the port for flask enpoint
18+
11. Define ENTRYPOINT as python main.py 9999
19+
6. Build docker image
20+
7. Run docker container
21+
8. Make a http POST call with some data, and receive the prediction back using postman or python requests library.
22+
9. Push the docker container to docker registry / ship to production
23+
24+
1. ### Install PIP requirements
25+
FYI: The code requries Python 3.6+ to run
1626
```
1727
pip install -r requirements.txt
1828
```
@@ -68,7 +78,7 @@ A simple Flask application that can serve predictions machine learning model. Re
6878
6979
7080
Appendix
71-
- http://docs.python-requests.org/en/latest/index.html
81+
- http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests
7282
- https://www.ibm.com/developerworks/webservices/library/ws-restful/
7383
- https://blog.hyperiondev.com/index.php/2018/02/01/deploy-machine-learning-model-flask-api/
7484
- https://medium.com/@amirziai/a-flask-api-for-serving-scikit-learn-models-c8bcdaa41daa

example_http_requests.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@
1414
r = requests.get(f"{host}/wipe")
1515
print(r.text)
1616

17-
# Appendix
18-
# http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests
19-
2017
'''
21-
from urlparse import urlparse
22-
from threading import Thread
23-
import httplib
18+
from urllib.parse import urlparse
19+
import http.client as ht
2420
2521
def getStatus(ourl):
2622
try:
2723
url = urlparse(ourl)
28-
conn = httplib.HTTPConnection(url.netloc)
24+
conn = ht.HTTPConnection(url.netloc)
2925
conn.request("HEAD", url.path)
3026
res = conn.getresponse()
3127
return res.status, ourl
3228
except:
3329
return "error", ourl
30+
31+
getStatus(ourl="http://127.0.0.1:5000/train")
3432
'''

main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ def predict():
3030
try:
3131
json_ = request.json #capture the json from POST
3232
query = pd.get_dummies(pd.DataFrame(json_))
33-
34-
# https://github.com/amirziai/sklearnflask/issues/3
35-
# Thanks to @lorenzori
3633
query = query.reindex(columns=model_columns, fill_value=0)
3734

3835
prediction = list(clf.predict(query))

model/model.pkl

171 KB
Binary file not shown.

tests.py renamed to tests/tests.py

File renamed without changes.

0 commit comments

Comments
 (0)