-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (27 loc) · 1.15 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
# Create A Flask Server
import numpy as np
import pandas as pd
from flask import Flask, request, render_template
import joblib
app = Flask(__name__)
model = joblib.load("Students_mark_predictor_model.pkl")
df = pd.DataFrame()
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
global df
input_features = [int(x) for x in request.form.values()]
features_value = np.array(input_features)
#Validate Input Hours
if input_features[0] <0 or input_features[0] >24:
return render_template('index.html', prediction_text='Please Enter Valid hours between 1 to 24')
output = model.predict([features_value])[0][0].round(2)
#input and predicted values store in df then save it in csv file
df = pd.concat([df, pd.DataFrame({'Study Hours': input_features, 'Predicted Output':[output]})],ignore_index=True)
print(df)
df.to_csv('smp_data_from_app.csv')
return render_template('index.html', prediction_text='You will get [{}%] marks, when you do study [{}] hours per day'.format(output, int(features_value[0])))
if __name__ == "__main__":
app.run()