Spaces:
Runtime error
Runtime error
Commit
·
7367a19
1
Parent(s):
31cc7b2
Upload 5 files
Browse files- GradientBoost_Flight_Fair_Model +0 -0
- Procfile.txt +1 -0
- app.py +106 -0
- requirements.txt +7 -0
- setup.sh +8 -0
GradientBoost_Flight_Fair_Model
ADDED
Binary file (176 kB). View file
|
|
Procfile.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run app.py
|
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import joblib
|
6 |
+
import datetime as dt
|
7 |
+
|
8 |
+
## loading in trained model
|
9 |
+
model = joblib.load('GradientBoost_Flight_Fair_Model')
|
10 |
+
|
11 |
+
@st.cache()
|
12 |
+
def make_predictions(journey_date, journey_time, arrival_date, arrival_time, source, destination, stops, airline):
|
13 |
+
# preprocessing data before predictions
|
14 |
+
pred_input = []
|
15 |
+
|
16 |
+
stops = int(stops)
|
17 |
+
pred_input.append(stops)
|
18 |
+
|
19 |
+
# departure Date
|
20 |
+
journey_day = int(pd.to_datetime(journey_date, format="%Y-%m-%dT%H:%M").day)
|
21 |
+
pred_input.append(journey_day)
|
22 |
+
|
23 |
+
journey_month = int(pd.to_datetime(journey_date, format ="%Y-%m-%dT%H:%M").month)
|
24 |
+
pred_input.append(journey_month)
|
25 |
+
|
26 |
+
dep_min = int(journey_time.minute)
|
27 |
+
pred_input.append(dep_min)
|
28 |
+
|
29 |
+
dep_hour = int(journey_time.hour)
|
30 |
+
pred_input.append(dep_hour)
|
31 |
+
|
32 |
+
arrival_min = int(arrival_time.minute)
|
33 |
+
pred_input.append(arrival_min)
|
34 |
+
|
35 |
+
arrival_hour = int(arrival_time.hour)
|
36 |
+
pred_input.append(arrival_hour)
|
37 |
+
|
38 |
+
arrival_day = int(pd.to_datetime(arrival_date, format="%Y-%m-%dT%H:%M").day)
|
39 |
+
pred_input.append(arrival_day)
|
40 |
+
|
41 |
+
duration_min = abs(arrival_min - dep_min)
|
42 |
+
pred_input.append(duration_min)
|
43 |
+
|
44 |
+
duration_hour = abs(arrival_hour - dep_hour)
|
45 |
+
pred_input.append(duration_hour)
|
46 |
+
|
47 |
+
air_list = ['IndiGo', 'Air India', 'Jet Airways', 'SpiceJet', 'Multiple carriers', 'GoAir', 'Vistara', 'Air Asia', 'Vistara Premium economy', 'Jet Airways Business', 'Multiple carriers Premium economy', 'Trujet']
|
48 |
+
for a in air_list:
|
49 |
+
if a == airline:
|
50 |
+
pred_input.append(1)
|
51 |
+
else:
|
52 |
+
pred_input.append(0)
|
53 |
+
|
54 |
+
src_list = ['Banglore', 'Kolkata', 'Delhi', 'Chennai', 'Mumbai']
|
55 |
+
for i in src_list:
|
56 |
+
if i == source:
|
57 |
+
pred_input.append(1)
|
58 |
+
else:
|
59 |
+
pred_input.append(0)
|
60 |
+
|
61 |
+
dst_list = ['New Delhi', 'Banglore', 'Cochin', 'Kolkata', 'Delhi', 'Hyderabad']
|
62 |
+
for d in dst_list:
|
63 |
+
if d == destination:
|
64 |
+
pred_input.append(1)
|
65 |
+
else:
|
66 |
+
pred_input.append(0)
|
67 |
+
|
68 |
+
prediction = model.predict(np.array([pred_input]))
|
69 |
+
|
70 |
+
return int(prediction)
|
71 |
+
|
72 |
+
|
73 |
+
def main():
|
74 |
+
|
75 |
+
st.title('Flight Fair Price Predictor')
|
76 |
+
st.subheader('Fill the following details to get the estimated flight fair price')
|
77 |
+
|
78 |
+
col1, col2 = st.columns([2, 1])
|
79 |
+
journey_date = col1.date_input('Journey Date')
|
80 |
+
journey_time = col2.time_input('Departure time')
|
81 |
+
|
82 |
+
col3, col4 = st.columns([2, 1])
|
83 |
+
arrival_date = col3.date_input('Arroval Date')
|
84 |
+
arrival_time = col4.time_input('Arrival time')
|
85 |
+
|
86 |
+
col5, col6 = st.columns(2)
|
87 |
+
source = col5.selectbox('Departure city',['Banglore', 'Kolkata', 'Delhi', 'Chennai', 'Mumbai'])
|
88 |
+
destination = col6.selectbox('Destination city', ['New Delhi', 'Banglore', 'Cochin', 'Kolkata', 'Delhi', 'Hyderabad'])
|
89 |
+
|
90 |
+
stops = st.selectbox('Total Stops', ['non-stop', 1, 2, 3, 4])
|
91 |
+
|
92 |
+
airline = st.selectbox('Choose Airline', ['IndiGo', 'Air India', 'Jet Airways', 'SpiceJet', 'Multiple carriers', 'GoAir', 'Vistara', 'Air Asia', 'Vistara Premium economy', 'Jet Airways Business', 'Multiple carriers Premium economy', 'Trujet'])
|
93 |
+
|
94 |
+
predict = st.button('Make Prediction',)
|
95 |
+
|
96 |
+
if stops == 'non-stop':
|
97 |
+
stops = 0
|
98 |
+
|
99 |
+
# make prediction button logic
|
100 |
+
if predict:
|
101 |
+
with st.spinner('Wait for prediction....'):
|
102 |
+
t = make_predictions(journey_date, journey_time, arrival_date, arrival_time, source, destination, stops, airline)
|
103 |
+
st.success(f'Fair Price will be around Rs.{t - 1000}')
|
104 |
+
|
105 |
+
if __name__=='__main__':
|
106 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit>=1.0.0
|
2 |
+
numpy>=1.9.2
|
3 |
+
pandas>=0.19
|
4 |
+
matplotlib>=1.4.3
|
5 |
+
scikit-learn>=0.18
|
6 |
+
joblib
|
7 |
+
xgboost>=1.4.0
|
setup.sh
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
echo "\
|
3 |
+
[server]\n\
|
4 |
+
headless = true\n\
|
5 |
+
port = $PORT\n\
|
6 |
+
enableCORS = false\n\
|
7 |
+
\n\
|
8 |
+
" > ~/.streamlit/config.toml
|