Skip to content

Commit 19e7d06

Browse files
committed
Initial commit
0 parents  commit 19e7d06

11 files changed

+1289
-0
lines changed

.gitignore

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.coverage.*
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
*.cover
45+
46+
# Translations
47+
*.mo
48+
*.pot
49+
50+
# Django stuff:
51+
*.log
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# PyBuilder
57+
target/
58+
59+
# DotEnv configuration
60+
.env
61+
62+
# Database
63+
*.db
64+
*.rdb
65+
66+
# Pycharm
67+
.idea
68+
69+
# VS Code
70+
.vscode/
71+
72+
# Spyder
73+
.spyproject/
74+
75+
# Jupyter NB Checkpoints
76+
.ipynb_checkpoints/
77+
78+
# exclude data from source control by default
79+
/data/
80+
81+
# Mac OS-specific storage files
82+
.DS_Store
83+
84+
# vim
85+
*.swp
86+
*.swo
87+
88+
# Mypy cache
89+
.mypy_cache/

.s2i/environment

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_CONFIG=gunicorn_config.py

0_start_here.ipynb

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# My Project\n",
8+
"\n",
9+
"In addition to being a place to experiment, this project has been structured to build and serve your model in a Flask application. The purpose is to allow data science exploration to easily transition into deployed services and applications on the OpenShift platform. After saving this project to git, it can be built on the OpenShift platform to serve models.\n",
10+
"\n",
11+
"Your dependencies will live in `requirements.txt` and your prediction function will live in `prediction.py`. As a Python based s2i application, this project can be configured and built upon to fit your needs.\n",
12+
"\n",
13+
"### Project Organization\n",
14+
"```\n",
15+
".\n",
16+
"├── README.md\n",
17+
"├── LICENSE\n",
18+
"├── requirements.txt <- Used to install packages for s2i application\n",
19+
"├── 0_start_here.ipynb <- Instructional notebook\n",
20+
"├── 1_run_flask.ipynb <- Notebook for running flask locally to test\n",
21+
"├── 2_test_flask.ipynb <- Notebook for testing flask requests\n",
22+
"├── .gitignore <- standard python gitignore\n",
23+
"├── .s2i <- hidden folder for advanced s2i configuration\n",
24+
"│   └── environment <- s2i environment settings\n",
25+
"├── gunicorn_config.py <- configuration for gunicorn when run in OpenShift\n",
26+
"├── prediction.py <- the predict function called from Flask\n",
27+
"└── wsgi.py <- basic Flask application\n",
28+
"```\n",
29+
"\n",
30+
"### Basic Flow\n",
31+
"1. Install and manage dependencies in `requirements.txt`.\n",
32+
"1. Experiment as usual.\n",
33+
"1. Extract your prediction into the `prediction.py` file.\n",
34+
"1. Update any dependencies.\n",
35+
"1. Run and test your application locally.\n",
36+
"1. Save to git.\n",
37+
"\n",
38+
"For a complete overview, please read the [README.md](./README.md)"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {},
44+
"source": [
45+
"## Install Dependencies"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {
52+
"cellView": "both",
53+
"id": "KUu4vOt5zI9d"
54+
},
55+
"outputs": [],
56+
"source": [
57+
"import sys\n",
58+
"!{sys.executable} -m pip install -r requirements.txt"
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"## Experiment\n",
66+
"\n",
67+
"Experiment with data and create your prediction function. Create any serialized models needed."
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"def predict(args_dict):\n",
77+
" return {'prediction': 'not implemented'}\n",
78+
"\n",
79+
"predict({'keys': 'values'})"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"## Create a Predict Function\n",
87+
"\n",
88+
"Extract the prediction logic into a standalone python file, `prediction.py` in a `predict` function. Also, make sure `requirements.txt` is updated with any additional packages you've used and need for prediction."
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"def predict(args_dict):\n",
98+
" return {'prediction': 'not implemented'}"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"## Test Predict Function"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"metadata": {},
112+
"outputs": [],
113+
"source": [
114+
"from prediction import predict\n",
115+
"\n",
116+
"predict({'keys': 'values'})\n",
117+
"\n"
118+
]
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {},
123+
"source": [
124+
"### Run Flask\n",
125+
"\n",
126+
"Run flask in a separate notebook ([1_run_flask.ipynb](./1_run_flask.ipynb)) to create a local service to try it out. You must run the application in a separate notebook since it will use the kernel until stopped.\n",
127+
"\n",
128+
"```\n",
129+
"!FLASK_ENV=development FLASK_APP=wsgi.py flask run\n",
130+
"```"
131+
]
132+
},
133+
{
134+
"cell_type": "markdown",
135+
"metadata": {},
136+
"source": [
137+
"### Test the Flask Endpoint\n",
138+
"\n",
139+
"Test your new service endpoint in this notebook or from a separate notebook ([2_test_flask.ipynb](./2_test_flask.ipynb)) to try it out. You can \n"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"!curl -X POST -H \"Content-Type: application/json\" --data '{\"data\": \"hello world\"}' http://localhost:5000/predictions\n"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": null,
154+
"metadata": {},
155+
"outputs": [],
156+
"source": [
157+
"import requests\n",
158+
"import json\n",
159+
"response = requests.post('http://127.0.0.1:5000/predictions', '{\"hello\":\"world\"}')\n",
160+
"response.json()"
161+
]
162+
},
163+
{
164+
"cell_type": "markdown",
165+
"metadata": {},
166+
"source": [
167+
"### Save Your Project to Git (and Build)\n",
168+
"\n",
169+
"Now that you've created and tested your prediction and service endpoint, push the code up to git. This can be built as an s2i application on OpenShift.\n",
170+
"\n",
171+
"\n"
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": null,
177+
"metadata": {},
178+
"outputs": [],
179+
"source": []
180+
}
181+
],
182+
"metadata": {
183+
"accelerator": "GPU",
184+
"colab": {
185+
"collapsed_sections": [],
186+
"name": "Object detection",
187+
"private_outputs": true,
188+
"provenance": [],
189+
"toc_visible": true
190+
},
191+
"kernelspec": {
192+
"display_name": "Python 3",
193+
"language": "python",
194+
"name": "python3"
195+
},
196+
"language_info": {
197+
"codemirror_mode": {
198+
"name": "ipython",
199+
"version": 3
200+
},
201+
"file_extension": ".py",
202+
"mimetype": "text/x-python",
203+
"name": "python",
204+
"nbconvert_exporter": "python",
205+
"pygments_lexer": "ipython3",
206+
"version": "3.6.8"
207+
}
208+
},
209+
"nbformat": 4,
210+
"nbformat_minor": 4
211+
}

1_run_flask.ipynb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Run Flask\n",
8+
"Run your flask app (`wsgi.py`) from here and test it from a separate notebook."
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"metadata": {},
15+
"outputs": [],
16+
"source": [
17+
"import sys\n",
18+
"!{sys.executable} -m pip install -r requirements.txt\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"!FLASK_ENV=development FLASK_APP=wsgi.py flask run"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": null,
33+
"metadata": {},
34+
"outputs": [],
35+
"source": []
36+
}
37+
],
38+
"metadata": {
39+
"kernelspec": {
40+
"display_name": "Python 3",
41+
"language": "python",
42+
"name": "python3"
43+
},
44+
"language_info": {
45+
"codemirror_mode": {
46+
"name": "ipython",
47+
"version": 3
48+
},
49+
"file_extension": ".py",
50+
"mimetype": "text/x-python",
51+
"name": "python",
52+
"nbconvert_exporter": "python",
53+
"pygments_lexer": "ipython3",
54+
"version": "3.6.8"
55+
}
56+
},
57+
"nbformat": 4,
58+
"nbformat_minor": 4
59+
}

0 commit comments

Comments
 (0)