Spaces:
Sleeping
Sleeping
File size: 2,099 Bytes
7c5d1d0 7a63bb7 7c5d1d0 7a63bb7 7c5d1d0 7a63bb7 7c5d1d0 7a63bb7 7c5d1d0 7a63bb7 7c5d1d0 7a63bb7 7c5d1d0 7a63bb7 7c5d1d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import gradio as gr
import joblib
import numpy as np
# Load your model
model = joblib.load('best_model.json')
def predict_retention(satisfaction_level, last_evaluation, number_project,
average_monthly_hours, time_spent_company,
work_accident, promotion_last_5years, salary, department):
# One-hot encode the department
departments = [
'RandD', 'accounting', 'hr', 'management', 'marketing',
'product_mng', 'sales', 'support', 'technical'
]
department_encoded = [1 if dept == department else 0 for dept in departments]
# Prepare the input with all 18 features
input_data = np.array([
satisfaction_level, last_evaluation, number_project,
average_monthly_hours, time_spent_company, work_accident,
promotion_last_5years, salary
] + department_encoded).reshape(1, -1)
# Predict using the model
try:
prediction = model.predict(input_data)
return "Employee is likely to quit." if prediction[0] == 1 else "Employee is likely to stay."
except Exception as e:
return f"Error: {str(e)}"
interface = gr.Interface(
fn=predict_retention,
inputs=[
gr.Number(label="Satisfaction Level (0.0 - 1.0)"),
gr.Number(label="Last Evaluation (0.0 - 1.0)"),
gr.Number(label="Number of Projects (1 - 10)"),
gr.Number(label="Average Monthly Hours (80 - 320)"),
gr.Number(label="Time Spent at Company (Years)"),
gr.Radio([0, 1], label="Work Accident (0 = No, 1 = Yes)"),
gr.Radio([0, 1], label="Promotion in Last 5 Years (0 = No, 1 = Yes)"),
gr.Radio([0, 1, 2], label="Salary (0 = Low, 1 = Medium, 2 = High)"),
gr.Dropdown(
['RandD', 'accounting', 'hr', 'management', 'marketing',
'product_mng', 'sales', 'support', 'technical'],
label="Department"
)
],
outputs="text",
title="Employee Retention Prediction System",
description="Predict whether an employee is likely to stay or quit based on their profile."
)
interface.launch()
|