Last active
September 28, 2020 08:47
-
-
Save Abhayparashar31/c7c3664c275d22f5366ecef6b1ff443a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask,request, url_for, redirect, render_template ## importing necessary libraries | |
import pickle ## pickle for loading model(Diabetes.pkl) | |
import pandas as pd ## to convert the input data into a dataframe for giving as a input to the model | |
app = Flask(__name__) ## setting up flask name | |
model = pickle.load(open("Diabetes.pkl", "rb")) ##loading model | |
@app.route('/') ## Defining main index route | |
def home(): | |
return render_template("index.html") ## showing index.html as homepage | |
@app.route('/predict',methods=['POST','GET']) ## this route will be called when predict button is called | |
def predict(): | |
#int_features=[float(x) for x in request.form.values()] | |
text1 = request.form['1'] ## Fetching each input field value one by one | |
text2 = request.form['2'] | |
text3 = request.form['3'] | |
text4 = request.form['4'] | |
text5 = request.form['5'] | |
text6 = request.form['6'] | |
text7 = request.form['7'] | |
text8 = request.form['8'] | |
row_df = pd.DataFrame([pd.Series([text1,text2,text3,text4,text5,text6,text7,text8])]) ### Creating a dataframe using all the values | |
print(row_df) | |
prediction=model.predict_proba(row_df) ## Predicting the output | |
output='{0:.{1}f}'.format(prediction[0][1], 2) ## Formating output | |
if output>str(0.5): | |
return render_template('index.html',pred='You have chance of having diabetes.\nProbability of having Diabetes is {}'.format(output)) ## Returning the message for use on the same index.html page | |
else: | |
return render_template('index.html',pred='You are safe.\n Probability of having diabetes is {}'.format(output)) | |
if __name__ == '__main__': | |
app.run(debug=True) ## Running the app as debug==True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment