Skip to content

Commit c976b06

Browse files
flask deployment
1 parent 1c1477b commit c976b06

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use python as base image
2+
FROM python:3.6-stretch
3+
4+
# Use working directory /app/model
5+
WORKDIR /app/model
6+
7+
# Copy and install required packages
8+
COPY requirements.txt .
9+
RUN pip install --trusted-host pypi.python.org -r requirements.txt
10+
11+
# Copy all the content of current directory to working directory
12+
COPY . .
13+
14+
# Set env variables for Cloud Run
15+
ENV PORT 5000
16+
ENV HOST 0.0.0.0
17+
18+
EXPOSE 5000:5000
19+
20+
# Run flask app
21+
CMD ["python","app.py"]

app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
from flask import Flask, request
3+
from syndicai import PythonPredictor
4+
5+
app = Flask(__name__)
6+
7+
8+
@app.route('/')
9+
def hello():
10+
""" Main page of the app. """
11+
return "Hello World!"
12+
13+
14+
@app.route('/predict')
15+
def predict():
16+
""" Return JSON serializable output from the model """
17+
payload = request.args
18+
classifier = PythonPredictor("")
19+
return classifier.predict(payload)
20+
21+
22+
if __name__ == '__main__':
23+
app.run(host='0.0.0.0', port=5000)

docker-compose.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3'
2+
services:
3+
4+
flask_classifier:
5+
build: .
6+
ports:
7+
- 5000:5000

requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
torch
2-
torchvision
1+
torch==1.7.1
2+
torchvision==0.8.2
3+
flask==1.1.2
4+
requests==2.18.4

0 commit comments

Comments
 (0)