Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| import pickle | |
| # Load the trained model | |
| with open("model.pkl", "rb") as f: | |
| model = pickle.load(f) | |
| # Define the mappings for 'Type of Travel' and 'Class' before using them | |
| type_of_travel_map = {'Personal Travel': 0, 'Business travel': 1} | |
| class_map = {'Eco Plus': 0, 'Business': 1, 'Eco': 2} | |
| def predict_satisfaction(online_boarding, type_of_travel, inflight_entertainment, seat_comfort, | |
| onboard_service, flight_class, leg_room_service, cleanliness, flight_distance, inflight_wifi_service): | |
| try: | |
| # Check the inputs | |
| print(f"Received inputs: {online_boarding}, {type_of_travel}, {inflight_entertainment}, {seat_comfort}, " | |
| f"{onboard_service}, {flight_class}, {leg_room_service}, {cleanliness}, {flight_distance}, {inflight_wifi_service}") | |
| # Map the inputs to the expected model format | |
| features = [ | |
| online_boarding, | |
| type_of_travel_map[type_of_travel], # map 'Type of Travel' | |
| inflight_entertainment, | |
| seat_comfort, | |
| onboard_service, | |
| class_map[flight_class], # map 'Class' | |
| leg_room_service, | |
| cleanliness, | |
| flight_distance, | |
| inflight_wifi_service | |
| ] | |
| # Get probabilities of satisfaction (class 0) and dissatisfaction (class 1) | |
| probabilities = model.predict_proba([features])[0] # Assuming it returns a 2D array | |
| # Set threshold for satisfaction | |
| satisfaction_probability = probabilities[0] # Probability for being satisfied (class 0) | |
| # Apply threshold of 0.87 for satisfaction | |
| if satisfaction_probability >= 0.87: | |
| return "Satisfied" | |
| else: | |
| return "Neutral or Dissatisfied" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| import gradio as gr | |
| inputs = [ | |
| gr.Slider(minimum=0, maximum=5, label="Online Boarding"), | |
| gr.Dropdown(choices=["Personal Travel", "Business travel"], label="Type of Travel"), | |
| gr.Slider(minimum=0, maximum=5, label="Inflight Entertainment"), | |
| gr.Slider(minimum=0, maximum=5, label="Seat Comfort"), | |
| gr.Slider(minimum=0, maximum=5, label="On-board Service"), | |
| gr.Dropdown(choices=["Eco Plus", "Business", "Eco"], label="Class"), | |
| gr.Slider(minimum=0, maximum=5, label="Leg Room Service"), | |
| gr.Slider(minimum=0, maximum=5, label="Cleanliness"), | |
| gr.Slider(minimum=31, maximum=4983, label="Flight Distance"), | |
| gr.Slider(minimum=0, maximum=5, label="Inflight Wifi Service") | |
| ] | |
| outputs = gr.Textbox(label="Customer Satisfaction Prediction") | |
| gr.Interface(fn=predict_satisfaction, inputs=inputs, outputs=outputs).launch() |