milestone2 / pred.py
ardifarizky's picture
first commit
1c58500
raw
history blame
2.32 kB
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import json
#Load all files
with open('model.pkl', 'rb') as file_1:
model = pickle.load(file_1)
def run():
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
with st.form(key='Form Hotel'):
hotel = st.selectbox('Select Hotel',('Resort Hotel', 'City Hotel'))
lead_time = st.slider('Select lead time', 1, 1, 10000,step=1)
arrival_date_year = st.selectbox('Year',('2015','2016','2017'))
arrival_date_month = st.selectbox('Month',
('January','February','March','April','May','June','July','August','September','October','November','December',))
arrival_date_day_of_month = st.number_input('Day',1,31,step=1)
adults = st.number_input('Select Number of Adults',0,100,step=1)
children = st.number_input('Select Number of Children',0,100,step=1)
babies = st.number_input('Select Number of Babies',0,100,step=1)
previous_cancellations = st.number_input('Cancellation Number',0,100,step=1)
days_in_waiting_list = st.number_input('Days in Waiting List',0,1000,step=1)
submitted = st.form_submit_button('Predict')
data_inf = {
'hotel' : hotel,
'lead_time' : lead_time,
'arrival_date_year' : arrival_date_year,
'arrival_date_month' : arrival_date_month,
'arrival_date_day_of_month' : arrival_date_day_of_month,
'adults' : adults,
'children' : children,
'babies' : babies,
'previous_cancellations' : previous_cancellations,
'days_in_waiting_list' : days_in_waiting_list,
}
data_inf = pd.DataFrame([data_inf])
st.dataframe(data_inf)
data_trans = data_inf[['lead_time','adults','children','babies','previous_cancellations','days_in_waiting_list']]
if submitted:
data_pred_inf = model.predict(data_trans)
if data_pred_inf == 1:
st.write('likely to be canceled')
else:
st.write('likely will not be canceled')
#st.write(f'# (1 = Yes, 0 = No) : {str(int(data_pred_inf))}')
if __name__ == '__main__':
run()