-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (46 loc) · 1.9 KB
/
app.py
File metadata and controls
55 lines (46 loc) · 1.9 KB
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
51
52
53
54
55
from flask import Flask, request, render_template
import numpy as np
import pandas as pd
import os
from sklearn.preprocessing import StandardScaler
from src.pipeline.predict_pipeline import CustomData, PredictPipeline
application = Flask(__name__,
static_folder=os.path.join(os.path.dirname(__file__), 'static'),
static_url_path='/static',
template_folder=os.path.join(os.path.dirname(__file__), 'templates')
)
app = application
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predictdata', methods=["GET", "POST"])
def predict_datapoint():
if request.method=="GET":
return render_template("home.html", form_data={}, results=None)
else:
# Capture form data
form_data = {
'gender': request.form.get('gender'),
'race': request.form.get('race'),
'parental_education': request.form.get('parental_education'),
'lunch': request.form.get('lunch'),
'test_prep': request.form.get('test_prep'),
'reading_score': request.form.get('reading_score'),
'writing_score': request.form.get('writing_score')
}
data = CustomData(
gender=form_data['gender'],
race_ethnicity=form_data['race'],
parental_level_of_education=form_data['parental_education'],
lunch=form_data['lunch'],
test_preparation_course=form_data['test_prep'],
reading_score=float(form_data['reading_score']),
writing_score=float(form_data['writing_score'])
)
pred_df=data.get_data_as_data_frame()
print(pred_df)
predict_pipeline = PredictPipeline()
results = predict_pipeline.predict(pred_df)
return render_template('home.html', results=results[0], form_data=form_data)
if __name__ =="__main__":
app.run(host="0.0.0.0", port=5000, debug=False)