import gradio as gr import pandas as pd from joblib import load def humands(Sex,Age,Married,Monthlyincome,TotalWorkingYears,DistanceFromHome,Overtime,YearsAtCompany,NumCompaniesWorked): model = load('modelo_entrenado.pkl') df = pd.DataFrame.from_dict( { "MonthlyIncome" : [Monthlyincome], "Age" : [Age], "TotalWorkingYears" : [TotalWorkingYears], "DailyRate" : [Monthlyincome*2/30], "HourlyRate" : [Monthlyincome*2/1640], "DistanceFromHome" : [DistanceFromHome], "OverTime_Yes" : [1 if Overtime else 0], "OverTime_No" : [1 if not Overtime else 0], "YearsAtCompany" : [YearsAtCompany], "MonthlyRate" : [Monthlyincome*2], "NumCompaniesWorked" : [NumCompaniesWorked], "PercentSalaryHike" : [15], "YearsInCurrentRole" : [YearsAtCompany-1], "YearsWithCurrManager" : [YearsAtCompany-1], "StockOptionLevel" : [1], "YearsSinceLastPromotion" : [YearsAtCompany-1], "JobSatisfaction" : [2], "JobLevel" : [3], "TrainingTimesLastYear" : [0], "EnvironmentSatisfaction" : [2], "WorkLifeBalance" : [2], "MaritalStatus_Single" : [1 if Married==0 else 0], "JobInvolvement" : [2], "RelationshipSatisfaction" : [Married+1], "Education" : [2], "BusinessTravel_Travel_Frequently" : [1 if Overtime else 0], "JobRole_Sales Representative" : [0], "EducationField_Medical" : [0], "Department_Sales" : [0], "JobRole_Laboratory Technician" : [0], "Department_Research & Development" : [1], "Gender_Female" : [1 if Sex==0 else 0], "MaritalStatus_Married" : [1 if Married==1 else 0], "JobRole_Sales Executive" : [0], "EducationField_Technical Degree" : [1], "Gender_Male" : [1 if Sex==1 else 0], "EducationField_Life Sciences" : [0], "BusinessTravel_Travel_Rarely" : [0], "MaritalStatus_Divorced" : [1 if Married==2 else 0], "JobRole_Research Scientist" : [1], "EducationField_Marketing" : [0], "PerformanceRating" : [3], "EducationField_Other" : [0], "JobRole_Human Resources" : [0], "BusinessTravel_Non-Travel" : [1 if not Overtime else 0], "Department_Human Resources" : [0], "JobRole_Manufacturing Director" : [0], "JobRole_Healthcare Representative" : [0], "EducationField_Human Resources" : [0], "JobRole_Manager" : [0], "JobRole_Research Director" : [0], } ) pred = model.predict(df)[0] if pred == "Yes": predicted1="Estamos ante un trabajador con alto nivel de estres." predicted2="stressed_image.jpg" else: predicted1="Estamos ante un trabajador tranquilo en el trabajo." predicted2="ok_image2.jpg" return [predicted1,predicted2] iface = gr.Interface( humands, [ gr.Radio(["Mujer","Hombre"],type = "index",label="Sexo"), gr.inputs.Slider(18,70,1,label="Edad del trabajador"), gr.Radio(["Soltero","Casado","Divorciado"],type = "index",label="Esstado civil:"), gr.inputs.Slider(1000,20000,1,label="Ingresos mensuales del trabajador"), gr.inputs.Slider(0,40,1,label="Total de años trabajados del trabajador"), gr.inputs.Slider(0,100,1,label="Distancia del trabajo al domicilio en Km"), gr.Checkbox(label="¿Realiza horas extras habitualmente?"), gr.inputs.Slider(0,40,1,label="Años del trabajador en la empresa"), gr.inputs.Slider(0,40,1,label="Numero de empresas en las que ha estado el trabajador"), ], ["text",gr.Image(type='file')], examples=[ ["Mujer",33,"Soltero",2917,9,1,False,9,1], ["Hombre",42,"Casado",3111,16,5,False,7,3], ["Hombre",50,"Divorciado",1732,20,50,True,3,3], ["Mujer",25,"Soltero",2556,6,58,True,2,4], ], interpretation="default", title = 'HUMANDS: Inteligencia artificial para empleados', description = 'Uno de los motivos por los que las organizaciones pierden a sus empleados es la insatisfacción laboral, por ello, nuestro objetivo es predecir el verdadero nivel de desgaste de los empleados dentro de una organización mediante Inteligencia Artificial. Para saber más: https://saturdays.ai/2021/12/31/inteligencia-artificial-empleados/', theme = 'peach' ) iface.launch()