GeorgyVlasov's picture
Update app.py
cf4c676
raw
history blame
No virus
3.47 kB
'''
cd h2o-3.42.0.2
java -jar h2o.jar
http://localhost:54321
source h20env/bin/activate
jupyter notebook
'''
import h2o
import pandas as pd
import matplotlib as plt
import gradio as gr
import random
plt.use("Agg")
h2o.init()
gbm_saved_model = h2o.load_model('/mnt/c/Users/MI/Documents/Machine learning/retention_automl/GBM_2_AutoML_1_20230812_124802')
def predict(*args):
df = pd.DataFrame([list(args)], columns=['department','promoted','review','projects','salary','tenure','satisfaction','bonus','avg_hrs_month'])
x = h2o.H2OFrame(df)
pos_pred = gbm_saved_model.predict(x)
#str(pos_pred)
return (pos_pred.as_data_frame())
unique_department = ['IT',
'admin',
'engineering',
'finance',
'logistics',
'marketing',
'operations',
'retail',
'sales',
'support']
unique_salary = ['high', 'low', 'medium']
with gr.Blocks() as demo:
gr.Markdown("""
**Employee leave probability prediction using H2O AutoML demo app**.
Data set used - https://www.kaggle.com/datasets/marikastewart/employee-turnover .
Jupyter Notebook is available at *Files* tab
""")
with gr.Row():
with gr.Column():
department = gr.Dropdown(
label="Department",
choices=unique_department,
value=lambda: random.choice(unique_department),
)
promoted = gr.Number(
label="Promoted",
minimum=0.0,
maximum=1.0
)
review = gr.Slider(label="Review", minimum=0, maximum=1, step=0.01, randomize=True)
# review = gr.Number(
# label="Review",
# minimum=0.0,
# maximum=1.0
# )
projects = gr.Number(
label="Projects",
minimum=0.0,
maximum=30.0
)
salary = gr.Dropdown(
label="salary",
choices=unique_salary,
value=lambda: random.choice(unique_salary),
)
tenure = gr.Number(
label="Tenure",
minimum=0.0,
maximum=50.0
)
satisfaction = gr.Slider(label="Satisfaction", minimum=0, maximum=1, step=0.01, randomize=True)
# satisfaction = gr.Number(
# label="Satisfaction",
# minimum=0.0,
# maximum=1.0
# )
bonus = gr.Number(
label="Bonus",
minimum=0.0,
maximum=1.0
)
avg_hrs_month = gr.Number(
label="Avg_hrs_month",
minimum=0.0,
maximum=500.0
)
with gr.Column():
label = gr.Dataframe()
with gr.Row():
predict_btn = gr.Button(value="Predict")
predict_btn.click(
predict,
inputs=[
department,
promoted,
review,
projects,
salary,
tenure,
satisfaction,
bonus,
avg_hrs_month
],
outputs=[label],
)
demo.launch()