-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.py
42 lines (27 loc) · 1.25 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
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
from flask import Flask, request, render_template
import joblib
app = Flask(__name__)
model = joblib.load("Student_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 if you live on the Earth')
output = model.predict([features_value])[0][0].round(2)
# input and predicted value store in df then save 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(host='0.0.0.0', port=8080)