-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (24 loc) · 930 Bytes
/
app.py
File metadata and controls
31 lines (24 loc) · 930 Bytes
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
from flask import Flask , request , render_template , jsonify
import pickle
import json
import pandas as pd
app = Flask(__name__)
with open('instance/column.json' , 'r') as file:
columns = json.load(file)['columns']
with open('model.pkl' , 'rb') as file:
model = pickle.load(file)
with open('pipeline.pkl' , 'rb') as file:
pipe = pickle.load(file)
@app.route('/' , methods=['GET'])
def home():
return render_template('home.html' , predicted_fare=None)
@app.route('/predict' , methods=['POST'])
def predict():
data = request.form.to_dict().values()
data = list(map(lambda x: int(x) if x.isdecimal() else x , data))
df = pd.DataFrame([data] , columns=columns)
processed_data = pipe.transform(df)
prediction = model.predict(processed_data)
return render_template('home.html' , predicted_fare=prediction)
if __name__ == '__main__':
app.run(debug=True)