-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
105 lines (89 loc) · 2.4 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from flask import Flask, request, render_template
import sklearn
import pickle
import pandas as pd
model = pickle.load(open("flight.pkl", "rb"))
app = Flask(__name__)
@app.route('/')
def home():
return render_template("home.html")
@app.route("/predict", methods = ["GET", "POST"])
def predict():
# Source
source = request.form["Source"]
s = ["Banglore", "Chennai", "Delhi", "Kolkata", "Mumbai"]
for i in range(len(s)):
if s[i] == source:
s[i] = 1
else:
s[i] = 0
# Destination
destination = request.form["Destination"]
d = ["Banglore", "Cochin", "Delhi","Hyderabad", "Kolkata", "New Delhi"]
for i in range(len(d)):
if d[i] == destination:
d[i] = 1
else:
d[i] = 0
# Airline
airline = request.form["Airline"]
a = ["Air Asia", "Air India", "GoAir", "IndiGo", "Jet Airways",
"Jet Airways Business", "Multiple carriers", "Multiple carriers Premium economy",
"SpiceJet", "Trujet", "Vistara", "Vistara Premium economy"]
for i in range(len(a)):
if a[i] == destination:
a[i] = 1
else:
a[i] = 0
# Stops
stops = int(request.form["stops"])
# Departure date
dep_date = request.form["date_of_dep"]
dep_day = int(str(dep_date).split("-")[0])
dep_month =int(str(dep_date).split("-")[1])
# departure time
dep_time = request.form["dep_time"]
dep_hour = int(str(dep_time).split(":")[0])
dep_minute = int(str(dep_time).split(":")[1])
# arrival time
arr_time = request.form["arr_time"]
arr_hour = int(str(arr_time).split(":")[0])
arr_minute = int(str(arr_time).split(":")[1])
# variables for prediction
values = [[stops,
dep_day,
dep_month,
dep_hour,
dep_minute,
arr_hour,
arr_minute,
a[0],
a[1],
a[2],
a[3],
a[4],
a[5],
a[6],
a[7],
a[8],
a[9],
a[10],
a[11],
s[0],
s[1],
s[2],
s[3],
s[4],
d[0],
d[1],
d[2],
d[3],
d[4],
d[5]
]]
# prediction
prediction = model.predict(values)
# returning the results to the home.html
return render_template("home.html", pred = "Flight ticket price is RS{}" .format(int(prediction)))
if __name__ == "__main__":
app.run(debug = True)