File size: 3,084 Bytes
1b7440f
 
512a63a
 
d53a843
2c8822a
1b7440f
8e59fb3
d53a843
 
 
 
 
 
 
1abd6ef
f068770
d53a843
 
 
 
 
 
 
 
512a63a
d53a843
 
 
512a63a
d53a843
 
 
 
8e59fb3
d53a843
1abd6ef
d53a843
 
1abd6ef
d53a843
8e59fb3
d53a843
1b7440f
d53a843
8e59fb3
d53a843
8e59fb3
6e415da
1b7440f
 
 
 
 
 
 
 
d53a843
 
1b7440f
d53a843
1b7440f
 
 
d53a843
8e59fb3
d53a843
8e59fb3
1b7440f
1abd6ef
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
import pickle
import gradio as gr
import numpy as np

# Load the trained model
with open(r"final_pickle_test.pkl","rb") as f:
    model = pickle.load(f)

# Define encoding mappings for categorical variables
sales_channel_mapping = {"Online": 0, "Offline": 1}
trip_type_mapping = {"Single Trip": 0, "Round Trip": 1}
route_mapping = {
    "AKLDEL": 0, "AKLHGH": 1, "AKLHND": 2, "AKLICN": 3, "AKLKIX": 4, "AKLKTM": 5
}
booking_origin_mapping = {"India": 0, "USA": 1, "UK": 2}  # Add actual values

def predict_booking(num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay, 
                    flight_hour, flight_day, route, booking_origin, wants_extra_baggage, 
                    wants_preferred_seat, wants_in_flight_meals, flight_duration):
    
    # Convert categorical values to numerical
    sales_channel_encoded = sales_channel_mapping.get(sales_channel, -1)
    trip_type_encoded = trip_type_mapping.get(trip_type, -1)
    route_encoded = route_mapping.get(route, -1)
    booking_origin_encoded = booking_origin_mapping.get(booking_origin, -1)
    
    wants_extra_baggage = 1 if wants_extra_baggage == "Yes" else 0
    wants_preferred_seat = 1 if wants_preferred_seat == "Yes" else 0
    wants_in_flight_meals = 1 if wants_in_flight_meals == "Yes" else 0

    # Ensure correct feature shape
    input_data = np.array([[num_passengers, sales_channel_encoded, trip_type_encoded, purchase_lead, 
                            length_of_stay, flight_hour, flight_day, route_encoded, booking_origin_encoded, 
                            wants_extra_baggage, wants_preferred_seat, wants_in_flight_meals, flight_duration]])

    print("Input Data Shape:", input_data.shape)  # Debugging

    # Make prediction
    prediction = model.predict(input_data)[0]

    return "Booking Completed ✅" if prediction == 1 else "Booking Not Completed ❌"

# Define available options for dropdowns
routes = ["AKLDEL", "AKLHGH", "AKLHND", "AKLICN", "AKLKIX", "AKLKTM"]
booking_origins = ["India", "USA", "UK"]  # Add actual locations if needed

# Create Gradio interface
iface = gr.Interface(
    fn=predict_booking,
    inputs=[
        gr.Number(label="Number of Passengers"),
        gr.Dropdown(choices=["Online", "Offline"], label="Sales Channel"),
        gr.Dropdown(choices=["Single Trip", "Round Trip"], label="Trip Type"),
        gr.Number(label="Purchase Lead"),
        gr.Number(label="Length of Stay"),
        gr.Number(label="Flight Hours"),
        gr.Number(label="Flight Day"),
        gr.Dropdown(choices=routes, label="Route"),
        gr.Dropdown(choices=booking_origins, label="Booking Origin"),
        gr.Dropdown(choices=["Yes", "No"], label="Want Extra Baggage"),
        gr.Dropdown(choices=["Yes", "No"], label="Want Preferred Seat"),
        gr.Dropdown(choices=["Yes", "No"], label="Want In-Flight Meals"),
        gr.Number(label="Flight Duration")
    ],
    outputs=gr.Textbox(label="Booking Prediction"),
    title="British Airways Booking Predictions",
    description="Enter Flight Details to Predict Booking Completion"
)

iface.launch()