Witchaphas/mini_project
0
1# !pip install gradio ipywidgets2import pandas as pd3import gradio as gr4import joblib5 6# "Artifacts"7pipeline = joblib.load("pipeline.joblib")8label_pipeline = joblib.load("label_pipeline.joblib")9departments_list = joblib.load("departments.joblib")10salary_list = joblib.load("salary.joblib")11boolean_dict = {'Yes':1,'No':0}12 13 14def predict(department, promoted, review, projects, salary, tenure, satisfaction, bonus, avg_hrs_month):15 sample = dict()16 sample['department'] = department17 sample['promoted'] = boolean_dict[promoted]18 sample['review'] = review19 sample['projects'] = projects20 sample['salary'] = salary21 sample['tenure'] = tenure22 sample['satisfaction'] = satisfaction23 sample['bonus'] = boolean_dict[bonus]24 sample['avg_hrs_month'] = avg_hrs_month25 26 left = pipeline.predict(pd.DataFrame([sample]))27 print(left)28 return left29 30# https://www.gradio.app/guides31with gr.Blocks() as blocks:32 department = gr.Dropdown(departments_list, value=departments_list[0], label="Department")33 promoted = gr.Radio(['Yes','No'],label = "promoted",info = "is they promoted?")34 review = gr.Number(label="Review", value=0.0, minimum=0.0, maximum= 1.0,step=0.1,info="range(0-1)")35 projects = gr.Number(label="Projects", value=1, minimum=0, step=1)36 salary = gr.Dropdown(salary_list, value=salary_list[0], label="salary")37 tenure = gr.Number(label="Tenure", value=1, minimum=0)38 satisfaction = gr.Number(label="Satisfaction", value=0.0, minimum=0.0, maximum= 1.0,step=0.1,info="range(0-1)")39 bonus = gr.Radio(['Yes','No'],label = "bonus",info = "is they get bonus?")40 avg_hrs_month = gr.Number(label="Average hours/month", minimum=0)41 predict_btn = gr.Button("Predict")42 left = gr.Text(label="left")43 44 inputs = [department, promoted, review, projects, salary, tenure, satisfaction, bonus, avg_hrs_month]45 outputs = left46 47 predict_btn.click(predict, inputs=inputs, outputs=outputs)48 print(outputs)49 50 51 52if __name__ == "__main__":53 blocks.launch() # Local machine only54 # blocks.launch(server_name="0.0.0.0") # LAN access toci local machine55 # blocks.launch(share=True) # Public access to local machine56 