import pandas as pd import gradio as gr import pickle # Load the XGBoost model from disk loaded_model = pickle.load(open("xgb_h.pkl", 'rb')) # Function to predict intent to stay def predict_intent_to_stay(Engagement, WorkEnvironment, UpperLevelManagement, RewardsBenefits, EmployeeWellBeing, Workload, LearningDevelopment): # Create input DataFrame input_data = pd.DataFrame({ 'Engagement': [Engagement], 'WorkEnvironment': [WorkEnvironment], 'UpperLevelManagement': [UpperLevelManagement], 'RewardsBenefits': [RewardsBenefits], 'EmployeeWellBeing': [EmployeeWellBeing], 'Workload': [Workload], 'LearningDevelopment': [LearningDevelopment] }) # Perform prediction using the loaded model prediction = loaded_model.predict_proba(input_data)[0] return {"Leave": prediction[0], "Stay": prediction[1]} # Create sliders for user input engagement_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Engagement") work_environment_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Work Environment") upper_level_management_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Upper Level Management") rewards_benefits_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Rewards Benefits") employee_wellbeing_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Employee Well-Being") workload_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Workload") learning_development_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Learning & Development") # Create the interface interface = gr.Interface( fn=predict_intent_to_stay, inputs=[ engagement_slider, work_environment_slider, upper_level_management_slider, rewards_benefits_slider, employee_wellbeing_slider, workload_slider, learning_development_slider ], outputs="text" ) # Launch the interface interface.launch()