lively06
commit3
0668f4c
raw
history blame
8.14 kB
from flask import Flask,request,render_template
from flask_cors import cross_origin
import pickle
import pandas as pd
model = pickle.load(open('flight_rf.pkl','rb'))
app = Flask(__name__)
@app.route('/')
@cross_origin()
def home():
return render_template('home.html')
@app.route('/predict',methods=['GET','POST'])
@cross_origin()
def predict():
if request.method=='POST':
dep_time = request.form['Dep_Time']
Journey_day = pd.to_datetime(dep_time,format="%Y-%m-%dT%H:%M").day
Journey_month = pd.to_datetime(dep_time,format="%Y-%m-%dT%H:%M").month
Departure_hour = pd.to_datetime(dep_time,format="%Y-%m-%dT%H:%M").hour
Departure_min = pd.to_datetime(dep_time,format="%Y-%m-%dT%H:%M").minute
arrival_time = request.form['Arrival_Time']
Arrival_hour = pd.to_datetime(arrival_time,format="%Y-%m-%dT%H:%M").hour
Arrival_min = pd.to_datetime(arrival_time,format="%Y-%m-%dT%H:%M").minute
Total_stops = int(request.form['stops'])
dur_hour = abs(Arrival_hour-Departure_hour)
dur_min = abs(Arrival_min-Departure_min)
airline=request.form['airline']
if(airline=='Jet Airways'):
Jet_Airways = 1
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='IndiGo'):
Jet_Airways = 0
IndiGo = 1
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Air India'):
Jet_Airways = 0
IndiGo = 0
Air_India = 1
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Multiple carriers'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 1
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='SpiceJet'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 1
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Vistara'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 1
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='GoAir'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 1
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Multiple carriers Premium economy'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 1
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Jet Airways Business'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 1
Vistara_Premium_economy = 0
Trujet = 0
elif (airline=='Vistara Premium economy'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 1
Trujet = 0
elif (airline=='Trujet'):
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 1
else:
Jet_Airways = 0
IndiGo = 0
Air_India = 0
Multiple_carriers = 0
SpiceJet = 0
Vistara = 0
GoAir = 0
Multiple_carriers_Premium_economy = 0
Jet_Airways_Business = 0
Vistara_Premium_economy = 0
Trujet = 0
Source = request.form["Source"]
if (Source == 'Delhi'):
s_Delhi = 1
s_Kolkata = 0
s_Mumbai = 0
s_Chennai = 0
elif (Source == 'Kolkata'):
s_Delhi = 0
s_Kolkata = 1
s_Mumbai = 0
s_Chennai = 0
elif (Source == 'Mumbai'):
s_Delhi = 0
s_Kolkata = 0
s_Mumbai = 1
s_Chennai = 0
elif (Source == 'Chennai'):
s_Delhi = 0
s_Kolkata = 0
s_Mumbai = 0
s_Chennai = 1
else:
s_Delhi = 0
s_Kolkata = 0
s_Mumbai = 0
s_Chennai = 0
Destination = request.form["Destination"]
if (Destination == 'Cochin'):
d_Cochin = 1
d_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 0
elif (Destination == 'Delhi'):
d_Cochin = 0
d_Delhi = 1
d_Hyderabad = 0
d_Kolkata = 0
elif (Destination == 'Hyderabad'):
d_Cochin = 0
d_Delhi = 0
d_Hyderabad = 1
d_Kolkata = 0
elif (Destination == 'Kolkata'):
d_Cochin = 0
d_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 1
else:#Banglore
d_Cochin = 0
d_Delhi = 0
d_Hyderabad = 0
d_Kolkata = 0
output = model.predict([[Total_stops,
Journey_day,
Journey_month,
Departure_hour,
Departure_min,
Arrival_hour,
Arrival_min,
dur_hour,
dur_min,
Air_India,
GoAir,
IndiGo,
Jet_Airways,
Jet_Airways_Business,
Multiple_carriers,
Multiple_carriers_Premium_economy,
SpiceJet,
Trujet,
Vistara,
Vistara_Premium_economy,
s_Chennai,
s_Delhi,
s_Kolkata,
s_Mumbai,
d_Cochin,
d_Delhi,
d_Hyderabad,
d_Kolkata]])
output = round(output[0],2)
return render_template('home.html',predictions='You will have to Pay approx Rs. {}'.format(output))
elif request.method == 'GET':
return render_template('home.html')
if __name__ == '__main__':
app.run(debug=True)