Spaces:
Sleeping
Sleeping
Add application file
Browse files- app.py +65 -0
- model.pkl +3 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
+
|
| 5 |
+
# Load the trained model
|
| 6 |
+
with open("model.pkl", "rb") as f:
|
| 7 |
+
model = pickle.load(f)
|
| 8 |
+
|
| 9 |
+
# Define the mappings for 'Type of Travel' and 'Class' before using them
|
| 10 |
+
type_of_travel_map = {'Personal Travel': 0, 'Business travel': 1}
|
| 11 |
+
class_map = {'Eco Plus': 0, 'Business': 1, 'Eco': 2}
|
| 12 |
+
|
| 13 |
+
def predict_satisfaction(online_boarding, type_of_travel, inflight_entertainment, seat_comfort,
|
| 14 |
+
onboard_service, flight_class, leg_room_service, cleanliness, flight_distance, inflight_wifi_service):
|
| 15 |
+
try:
|
| 16 |
+
# Check the inputs
|
| 17 |
+
print(f"Received inputs: {online_boarding}, {type_of_travel}, {inflight_entertainment}, {seat_comfort}, "
|
| 18 |
+
f"{onboard_service}, {flight_class}, {leg_room_service}, {cleanliness}, {flight_distance}, {inflight_wifi_service}")
|
| 19 |
+
|
| 20 |
+
# Map the inputs to the expected model format
|
| 21 |
+
features = [
|
| 22 |
+
online_boarding,
|
| 23 |
+
type_of_travel_map[type_of_travel], # map 'Type of Travel'
|
| 24 |
+
inflight_entertainment,
|
| 25 |
+
seat_comfort,
|
| 26 |
+
onboard_service,
|
| 27 |
+
class_map[flight_class], # map 'Class'
|
| 28 |
+
leg_room_service,
|
| 29 |
+
cleanliness,
|
| 30 |
+
flight_distance,
|
| 31 |
+
inflight_wifi_service
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# Get probabilities of satisfaction (class 0) and dissatisfaction (class 1)
|
| 35 |
+
probabilities = model.predict_proba([features])[0] # Assuming it returns a 2D array
|
| 36 |
+
|
| 37 |
+
# Set threshold for satisfaction
|
| 38 |
+
satisfaction_probability = probabilities[0] # Probability for being satisfied (class 0)
|
| 39 |
+
|
| 40 |
+
# Apply threshold of 0.87 for satisfaction
|
| 41 |
+
if satisfaction_probability >= 0.87:
|
| 42 |
+
return "Satisfied"
|
| 43 |
+
else:
|
| 44 |
+
return "Neutral or Dissatisfied"
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return f"Error: {str(e)}"
|
| 48 |
+
|
| 49 |
+
import gradio as gr
|
| 50 |
+
inputs = [
|
| 51 |
+
gr.Slider(minimum=0, maximum=5, label="Online Boarding"),
|
| 52 |
+
gr.Dropdown(choices=["Personal Travel", "Business travel"], label="Type of Travel"),
|
| 53 |
+
gr.Slider(minimum=0, maximum=5, label="Inflight Entertainment"),
|
| 54 |
+
gr.Slider(minimum=0, maximum=5, label="Seat Comfort"),
|
| 55 |
+
gr.Slider(minimum=0, maximum=5, label="On-board Service"),
|
| 56 |
+
gr.Dropdown(choices=["Eco Plus", "Business", "Eco"], label="Class"),
|
| 57 |
+
gr.Slider(minimum=0, maximum=5, label="Leg Room Service"),
|
| 58 |
+
gr.Slider(minimum=0, maximum=5, label="Cleanliness"),
|
| 59 |
+
gr.Slider(minimum=31, maximum=4983, label="Flight Distance"),
|
| 60 |
+
gr.Slider(minimum=0, maximum=5, label="Inflight Wifi Service")
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
outputs = gr.Textbox(label="Customer Satisfaction Prediction")
|
| 64 |
+
|
| 65 |
+
gr.Interface(fn=predict_satisfaction, inputs=inputs, outputs=outputs).launch()
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e427b501a03392093d2a1393c4ec0fe6581f2ae7a5051a3a81f71cd7107e3307
|
| 3 |
+
size 119728088
|
requirements.txt
ADDED
|
File without changes
|