-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (42 loc) · 1.89 KB
/
main.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
# importing the necessary dependencies
from flask import Flask, render_template, request,jsonify
from flask_cors import CORS,cross_origin
import pickle
app = Flask(__name__) # initializing a flask app
@app.route('/',methods=['GET']) # route to display the home page
@cross_origin()
def homePage():
return render_template("index.html")
@app.route('/predict',methods=['POST','GET']) # route to show the predictions in a web UI
@cross_origin()
def index():
if request.method == 'POST':
try:
# reading the inputs given by the user
gre_score=float(request.form['gre_score'])
toefl_score = float(request.form['toefl_score'])
university_rating = float(request.form['university_rating'])
sop = float(request.form['sop'])
lor = float(request.form['lor'])
cgpa = float(request.form['cgpa'])
is_research = request.form['research']
if(is_research=='yes'):
research=1
else:
research=0
filename = 'finalized_model.pickle'
loaded_model = pickle.load(open(filename, 'rb')) # loading the model file from the storage
# predictions using the loaded model file
prediction=loaded_model.predict([[gre_score,toefl_score,university_rating,sop,lor,cgpa,research]])
print('prediction is', prediction)
# showing the prediction results in a UI
return render_template('results.html',prediction=round(100*prediction[0]))
except Exception as e:
print('The Exception message is: ',e)
return 'something is wrong'
# return render_template('results.html')
else:
return render_template('index.html')
if __name__ == "__main__":
#app.run(host='127.0.0.1', port=8001, debug=True)
app.run(debug=True) # running the app