abdulrafishaik commited on
Commit
d53a843
·
verified ·
1 Parent(s): 625800a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -14
app.py CHANGED
@@ -2,28 +2,49 @@ import pickle
2
  import gradio as gr
3
  import numpy as np
4
 
5
-
6
- with open("Model_final.pkl", "rb") as f:
7
  model = pickle.load(f)
8
 
 
 
 
 
 
 
 
9
 
10
  def predict_booking(num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
11
- flight_hour, flight_day, route, booking_origin, wants_extra_baggage,
12
- wants_preferred_seat, wants_in_flight_meals, flight_duration):
 
 
 
 
 
 
13
 
14
- input_data = np.array([[num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
15
- flight_hour, flight_day, route, booking_origin, wants_extra_baggage,
16
- wants_preferred_seat, wants_in_flight_meals, flight_duration]])
17
 
18
- prediction = model.predict(input_data)[0]
19
-
20
- return "Booking Completed ✅" if prediction == 1 else "Booking Not Completed ❌"
 
21
 
 
22
 
 
 
23
 
 
24
 
 
25
  routes = ["AKLDEL", "AKLHGH", "AKLHND", "AKLICN", "AKLKIX", "AKLKTM"]
 
26
 
 
27
  iface = gr.Interface(
28
  fn=predict_booking,
29
  inputs=[
@@ -34,15 +55,16 @@ iface = gr.Interface(
34
  gr.Number(label="Length of Stay"),
35
  gr.Number(label="Flight Hours"),
36
  gr.Number(label="Flight Day"),
37
- gr.Dropdown(choices=routes, label="Route"), # ✅ Fixed: Dropdown instead of Number
 
38
  gr.Dropdown(choices=["Yes", "No"], label="Want Extra Baggage"),
39
- gr.Dropdown(choices=["Yes", "No"], label="Want Preferred Seat"), # ✅ Fixed spelling
40
  gr.Dropdown(choices=["Yes", "No"], label="Want In-Flight Meals"),
41
  gr.Number(label="Flight Duration")
42
  ],
43
- outputs=gr.Textbox(label="Booking Prediction"), # ✅ Fixed spelling
44
  title="British Airways Booking Predictions",
45
- description="Enter Flight Details to Predict Booking Completion" # ✅ Fixed case-sensitive error
46
  )
47
 
48
  iface.launch()
 
2
  import gradio as gr
3
  import numpy as np
4
 
5
+ # Load the trained model
6
+ with open(r"C:\Users\Lenovo\Downloads\Model_pickle4", "rb") as f:
7
  model = pickle.load(f)
8
 
9
+ # Define encoding mappings for categorical variables
10
+ sales_channel_mapping = {"Online": 0, "Offline": 1}
11
+ trip_type_mapping = {"Single Trip": 0, "Round Trip": 1}
12
+ route_mapping = {
13
+ "AKLDEL": 0, "AKLHGH": 1, "AKLHND": 2, "AKLICN": 3, "AKLKIX": 4, "AKLKTM": 5
14
+ }
15
+ booking_origin_mapping = {"India": 0, "USA": 1, "UK": 2} # Add actual values
16
 
17
  def predict_booking(num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
18
+ flight_hour, flight_day, route, booking_origin, wants_extra_baggage,
19
+ wants_preferred_seat, wants_in_flight_meals, flight_duration):
20
+
21
+ # Convert categorical values to numerical
22
+ sales_channel_encoded = sales_channel_mapping.get(sales_channel, -1)
23
+ trip_type_encoded = trip_type_mapping.get(trip_type, -1)
24
+ route_encoded = route_mapping.get(route, -1)
25
+ booking_origin_encoded = booking_origin_mapping.get(booking_origin, -1)
26
 
27
+ wants_extra_baggage = 1 if wants_extra_baggage == "Yes" else 0
28
+ wants_preferred_seat = 1 if wants_preferred_seat == "Yes" else 0
29
+ wants_in_flight_meals = 1 if wants_in_flight_meals == "Yes" else 0
30
 
31
+ # Ensure correct feature shape
32
+ input_data = np.array([[num_passengers, sales_channel_encoded, trip_type_encoded, purchase_lead,
33
+ length_of_stay, flight_hour, flight_day, route_encoded, booking_origin_encoded,
34
+ wants_extra_baggage, wants_preferred_seat, wants_in_flight_meals, flight_duration]])
35
 
36
+ print("Input Data Shape:", input_data.shape) # Debugging
37
 
38
+ # Make prediction
39
+ prediction = model.predict(input_data)[0]
40
 
41
+ return "Booking Completed ✅" if prediction == 1 else "Booking Not Completed ❌"
42
 
43
+ # Define available options for dropdowns
44
  routes = ["AKLDEL", "AKLHGH", "AKLHND", "AKLICN", "AKLKIX", "AKLKTM"]
45
+ booking_origins = ["India", "USA", "UK"] # Add actual locations if needed
46
 
47
+ # Create Gradio interface
48
  iface = gr.Interface(
49
  fn=predict_booking,
50
  inputs=[
 
55
  gr.Number(label="Length of Stay"),
56
  gr.Number(label="Flight Hours"),
57
  gr.Number(label="Flight Day"),
58
+ gr.Dropdown(choices=routes, label="Route"),
59
+ gr.Dropdown(choices=booking_origins, label="Booking Origin"),
60
  gr.Dropdown(choices=["Yes", "No"], label="Want Extra Baggage"),
61
+ gr.Dropdown(choices=["Yes", "No"], label="Want Preferred Seat"),
62
  gr.Dropdown(choices=["Yes", "No"], label="Want In-Flight Meals"),
63
  gr.Number(label="Flight Duration")
64
  ],
65
+ outputs=gr.Textbox(label="Booking Prediction"),
66
  title="British Airways Booking Predictions",
67
+ description="Enter Flight Details to Predict Booking Completion"
68
  )
69
 
70
  iface.launch()