Skip to content

Commit

Permalink
churn service for heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
razekmaiden committed Oct 9, 2021
1 parent 28bf721 commit 8299be8
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
gunicorn = "*"
scikit-learn = "==1.0"

[dev-packages]

[requires]
python_version = "3.8"
237 changes: 237 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn predict:app
34 changes: 34 additions & 0 deletions churn_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pickle

from flask import Flask
from flask import request
from flask import jsonify


model_file = 'model1.bin'
dv_file = 'dv.bin'

with open(model_file, 'rb') as f_model:
model = pickle.load(f_model)

with open(dv_file, 'rb') as f_dv:
dv = pickle.load(f_dv)

app = Flask('churn_service')

@app.route('/predict', methods=['POST'])
def predict():
customer = request.get_json()

X = dv.transform([customer])
y_pred = model.predict_proba(X)[0, 1]

result = {
'churn_probability': float(y_pred),
}

return jsonify(result)


if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=9696)
Binary file added dv.bin
Binary file not shown.
Binary file added model1.bin
Binary file not shown.

0 comments on commit 8299be8

Please sign in to comment.