Can not predict on Front end streamlit with ktrain model, kindly provide suggestions about how to provide input for predict function.
basically I would like to understand how to provide input for my saved ktrain regression model so that I can incorporate it to streamlit web app button.
I have tried putting array,list and dataframe as argument in .predict function still seems like missing something. as getting value error while hitting predict button.
import streamlit as st
from PIL import Image
import pandas as pd
from tensorflow import keras
model = keras.models.load_model("predictor.h5")
st.write("This is an application to calculate Employee Mental Fatigue Score")
image = Image.open("IMG_2605.jpeg")
st.image(image, use_column_width=True)
WFH_Setup_Available = st.text_input("is work from home enabled for you?")
Designation =st.text_input("what is your designation?")
Average_hours_worked_per_day = st.text_input("how many hours you work on an average per day?")
Employee_satisfaction_score = st.text_input("Please enter your satisfaction score on scale of 10")
data = ['WFH_Setup_Available', 'Designation', 'Average_hours_worked_per_day' , 'Employee_satisfaction_score']
def mental_fatigue_score(WFH_Setup_Available, Designation, Average_hours_worked_per_day, Employee_satisfaction_score):
prediction = model.predict([[WFH_Setup_Available, Designation, Average_hours_worked_per_day, Employee_satisfaction_score]])
print(prediction)
return prediction
if st.button("Predict"):
result= mental_fatigue_score(WFH_Setup_Available, Designation, Average_hours_worked_per_day, Employee_satisfaction_score)
st.success('The output is {}'.format(result))
kindly suggest how to provide input to .predict function for streamlit web app.
I have trained predictor using ktrain regressors.
solved it by myself by saving ktrain model as
predictor.save('predictor')
predictor = ktrain.load_predictor('predictor')
when I save as predictor it creates a folder in which I have one tf_mode.h5 & tf_model.preproc.
this was easier than what I expected it to be.
further for train input should be dataframe like below-
data = {'WFH_Setup_Available':WFH_Setup_Available,'Designation':Designation, 'Company_Type':Company_Type,
'Average_hours_worked_per_day': Average_hours_worked_per_day, 'Employee_satisfaction_score': Employee_satisfaction_score}
data = pd.DataFrame([data])