File size: 4,462 Bytes
c1c6e8b
 
 
 
 
 
 
 
6e5cb9b
 
 
 
c1c6e8b
 
 
 
 
 
 
 
 
6e5cb9b
 
 
 
 
 
 
 
 
 
 
c1c6e8b
 
 
 
 
 
6e5cb9b
c1c6e8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e5cb9b
 
c1c6e8b
 
 
 
 
6e5cb9b
8bbf49d
c1c6e8b
 
 
 
6e5cb9b
c1c6e8b
6e5cb9b
c1c6e8b
 
 
 
6e5cb9b
8bbf49d
72f2460
c1c6e8b
 
 
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
106
107
108
import streamlit as st
import pandas as pd
from joblib import dump, load

# model
Model= load('RF_model.joblib')

# predict
def predict_fare(features):
    fare = Model.predict([features])
    return fare

def main():
    # st.title("Flight Fair Predictions")
    html_temp = """

    <div style="background-color:tomato;padding:10px">

    <h2 style="color:white;text-align:center;">Streamlit Flight Fair Predictions ML App </h2>

    </div>

    """
    st.markdown(html_temp, unsafe_allow_html=True)
    
    
    # Source
    Source=st.selectbox('Source',options=['Banglore','Chennai','Delhi','Kolkata','Mumbai'])
    source_index = ['Banglore', 'Chennai', 'Delhi', 'Kolkata', 'Mumbai']
    source_value = [1 if src == Source else 0 for src in source_index]
    
    # Destination
    Destination=st.selectbox('Destination',options=['Banglore', 'Cochin', 'Delhi', 'Hyderabad', 'Kolkata'])
    destination_index = ['Banglore', 'Cochin', 'Delhi', 'Hyderabad', 'Kolkata']
    
    destination_value = [1 if dest == Destination else 0 for dest in destination_index]
    # Airline selection
    Airline_options = ['Jet Airways', 'IndiGo', 'Air India', 'Multiple carriers', 
                       'SpiceJet', 'Vistara', 'Air Asia', 'GoAir', 
                       'Multiple carriers Premium economy', 'Jet Airways Business', 
                       'Vistara Premium economy', 'Trujet']
    Airline = st.selectbox('Airline', options=Airline_options)
    
    Airline_dict = {'Jet Airways': 3849, 'IndiGo': 2053, 'Air India': 1751, 
                    'Multiple carriers': 1196, 'SpiceJet': 818, 'Vistara': 479, 
                    'Air Asia': 319, 'GoAir': 194, 'Multiple carriers Premium economy': 13, 
                    'Jet Airways Business': 6, 'Vistara Premium economy': 3, 'Trujet': 1}
    Airline_value = Airline_dict.get(Airline, 0)  # default to 0 if not found
    
    # Total Stops selection
    Total_Stops_options = ['non-stop', '1 stop', '2 stops', '3 stops', '4 stops']
    Total_Stops = st.selectbox('Total Stops', options=Total_Stops_options)
    Total_Stops_dict = {'non-stop': 0, '1 stop': 1, '2 stops': 2, '3 stops': 3, '4 stops': 4}
    Total_Stops_value = Total_Stops_dict.get(Total_Stops, 0)  # default to 0 if not found
    
    # Date_of_Journey
    Date_of_Journey=st.date_input('Date_of_Journey')
    Day_of_Journey=pd.to_datetime(Date_of_Journey).day
    Month_of_Journey=pd.to_datetime(Date_of_Journey).month
    
    # Dep_Time
    Dep_Time=st.text_input("Dep_Time (HH:MM)", "00:00")
    # Convert Dep_Time to string in the format "HH:MM"
    time_dep = pd.to_datetime(Dep_Time, format='mixed')
    Dep_hour=time_dep.hour
    Dep_min=time_dep.minute
    
    # Arrival_Time
    Arrival_Time=st.text_input("Arrival Time (HH:MM)", "13:30")
    time_arr = pd.to_datetime(Arrival_Time, format='mixed')
    Arrival_hour=time_arr.hour
    Arrival_min=time_arr.minute
    
    # Duration
    departure_hour, departure_minute = map(int, Dep_Time.split(':'))
    arrival_hour, arrival_minute = map(int, Arrival_Time.split(':'))
    Duration_hour = arrival_hour - departure_hour   # Calculate the duration
    Duration_minute = arrival_minute - departure_minute

    if Duration_minute < 0:
        Duration_hour -= 1
        Duration_minute += 60
        
    Duration_in_min = Duration_hour*60 + Duration_minute
    
    # In-flight meal not included
    In_flight_meal_not_included=st.selectbox('In-flight meal not included',options=['Yes','No'])
    if In_flight_meal_not_included=='Yes':
        In_flight_meal_not_included=1
    else:
        In_flight_meal_not_included=0
        
    # No check-in baggage included
    No_check_in_baggage_included=st.selectbox('No check-in baggage included',options=['Yes','No'])
    if No_check_in_baggage_included=='Yes':
        No_check_in_baggage_included=1
    else:
        No_check_in_baggage_included=0
    

        
    input_values=[Airline_value, Total_Stops_value, Day_of_Journey, Month_of_Journey,
            Dep_hour, Dep_min, Arrival_hour, Arrival_min, Duration_in_min,
            In_flight_meal_not_included, No_check_in_baggage_included]+source_value+destination_value
    
    if st.button("Predict"):
        result=predict_fare(input_values)
        st.success(f'Expected Flight Fare is : ₹ {result[0]}')
        st.write("")
    
if __name__ == "__main__":
    main()