-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (40 loc) · 1.74 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import pandas as pd
from flask import Flask, request, jsonify, render_template
import flask
import pickle
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
Term = flask.request.form['Term']
NoEmp = flask.request.form['NoEmp']
NewExist = flask.request.form['NewExist']
CreateJob = flask.request.form['CreateJob']
RetainedJob = flask.request.form['RetainedJob']
FranchiseCode = flask.request.form['FranchiseCode']
UrbanRural = flask.request.form['UrbanRural']
LowDoc = flask.request.form['LowDoc']
ChgOffPrinGr = flask.request.form['ChgOffPrinGr']
SBA_Appv = flask.request.form['SBA_Appv']
DaysforDibursement = flask.request.form['DaysforDibursement']
input_variables = pd.DataFrame([[Term,NoEmp,NewExist,CreateJob,RetainedJob,FranchiseCode,UrbanRural,LowDoc,ChgOffPrinGr,SBA_Appv,DaysforDibursement]],columns=['Term','NoEmp','NewExist','CreateJob','RetainedJob', 'FranchiseCode','UrbanRural','LowDoc','ChgOffPrinGr','SBA_Appv','DaysforDibursement'],dtype=float)
prediction = model.predict(input_variables)[0]
return render_template('index.html',prediction_text="Defaulter" if prediction==0 else "Not Defaulter")
@app.route('/predict_api',methods=['POST'])
def predict_api():
'''
For direct API calls trought request
'''
data = request.get_json(force=True)
prediction = model.predict([np.array(list(data.values()))])
output = prediction[0]
return jsonify(output)
if __name__ == "__main__":
app.run(debug=True)