Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,30 @@
|
|
| 1 |
import pickle
|
| 2 |
-
import numpy as np
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Load the model
|
| 6 |
with open("Model.pickle", "rb") as f:
|
| 7 |
model = pickle.load(f)
|
| 8 |
|
| 9 |
-
# Function to encode categorical features
|
| 10 |
-
def encode_features(num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
|
| 11 |
-
flight_hour, flight_day, route, wants_extra_baggage,
|
| 12 |
-
wants_preferred_seat, wants_in_flight_meals, flight_duration):
|
| 13 |
-
# Encoding Sales Channel (e.g., Online -> 0, Offline -> 1)
|
| 14 |
-
sales_channel_mapping = {"Online": 0, "Offline": 1}
|
| 15 |
-
trip_type_mapping = {"Single Trip": 0, "Round Trip": 1}
|
| 16 |
-
binary_mapping = {"Yes": 1, "No": 0} # Used for extra baggage, preferred seat, meals
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
routes = ["AKLDEL", "AKLHGH", "AKLHND", "AKLICN", "AKLKIX", "AKLKTM"]
|
| 27 |
-
route_mapping = {route: idx for idx, route in enumerate(routes)}
|
| 28 |
-
route = route_mapping.get(route, 0) # Default to 0 if route is not found
|
| 29 |
|
| 30 |
-
# Convert everything into a NumPy array
|
| 31 |
-
input_data = np.array([[num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
|
| 32 |
-
flight_hour, flight_day, route, wants_extra_baggage,
|
| 33 |
-
wants_preferred_seat, wants_in_flight_meals, flight_duration]])
|
| 34 |
|
| 35 |
-
return input_data
|
| 36 |
|
| 37 |
-
# Prediction function
|
| 38 |
-
def predict_booking(num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
|
| 39 |
-
flight_hour, flight_day, route, wants_extra_baggage,
|
| 40 |
-
wants_preferred_seat, wants_in_flight_meals, flight_duration):
|
| 41 |
-
# Encode categorical features
|
| 42 |
-
input_data = encode_features(num_passengers, sales_channel, trip_type, purchase_lead, length_of_stay,
|
| 43 |
-
flight_hour, flight_day, route, wants_extra_baggage,
|
| 44 |
-
wants_preferred_seat, wants_in_flight_meals, flight_duration)
|
| 45 |
|
| 46 |
-
# Make prediction
|
| 47 |
-
prediction = model.predict(input_data)[0]
|
| 48 |
-
|
| 49 |
-
return "Booking Completed ✅" if prediction == 1 else "Booking Not Completed ❌"
|
| 50 |
|
| 51 |
-
# Define Routes
|
| 52 |
routes = ["AKLDEL", "AKLHGH", "AKLHND", "AKLICN", "AKLKIX", "AKLKTM"]
|
| 53 |
|
| 54 |
-
# Gradio Interface
|
| 55 |
iface = gr.Interface(
|
| 56 |
fn=predict_booking,
|
| 57 |
inputs=[
|
|
@@ -62,15 +35,15 @@ iface = gr.Interface(
|
|
| 62 |
gr.Number(label="Length of Stay"),
|
| 63 |
gr.Number(label="Flight Hours"),
|
| 64 |
gr.Number(label="Flight Day"),
|
| 65 |
-
gr.Dropdown(choices=routes, label="Route"),
|
| 66 |
gr.Dropdown(choices=["Yes", "No"], label="Want Extra Baggage"),
|
| 67 |
-
gr.Dropdown(choices=["Yes", "No"], label="Want Preferred Seat"),
|
| 68 |
gr.Dropdown(choices=["Yes", "No"], label="Want In-Flight Meals"),
|
| 69 |
gr.Number(label="Flight Duration")
|
| 70 |
],
|
| 71 |
-
outputs=gr.Textbox(label="Booking Prediction"),
|
| 72 |
title="British Airways Booking Predictions",
|
| 73 |
-
description="Enter Flight Details to Predict Booking Completion"
|
| 74 |
)
|
| 75 |
|
| 76 |
iface.launch()
|
|
|
|
| 1 |
import pickle
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
|
|
|
|
| 6 |
with open("Model.pickle", "rb") as f:
|
| 7 |
model = pickle.load(f)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def predict(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 |
|
|
|
|
| 26 |
routes = ["AKLDEL", "AKLHGH", "AKLHND", "AKLICN", "AKLKIX", "AKLKTM"]
|
| 27 |
|
|
|
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=predict_booking,
|
| 30 |
inputs=[
|
|
|
|
| 35 |
gr.Number(label="Length of Stay"),
|
| 36 |
gr.Number(label="Flight Hours"),
|
| 37 |
gr.Number(label="Flight Day"),
|
| 38 |
+
gr.Dropdown(choices=routes, label="Route"), # ✅ Fixed: Dropdown instead of Number
|
| 39 |
gr.Dropdown(choices=["Yes", "No"], label="Want Extra Baggage"),
|
| 40 |
+
gr.Dropdown(choices=["Yes", "No"], label="Want Preferred Seat"), # ✅ Fixed spelling
|
| 41 |
gr.Dropdown(choices=["Yes", "No"], label="Want In-Flight Meals"),
|
| 42 |
gr.Number(label="Flight Duration")
|
| 43 |
],
|
| 44 |
+
outputs=gr.Textbox(label="Booking Prediction"), # ✅ Fixed spelling
|
| 45 |
title="British Airways Booking Predictions",
|
| 46 |
+
description="Enter Flight Details to Predict Booking Completion" # ✅ Fixed case-sensitive error
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|