File size: 3,739 Bytes
7791531
 
eda7c5e
7791531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eda7c5e
7791531
eda7c5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7791531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eda7c5e
 
7791531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eda7c5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import pandas as pd
import pickle
import numpy as np
import streamlit as st
import gdown

# File IDs
model_id = "1HSQTjJ_hvBBmVJmYUmrkq5T7ubpfDwzF"
top_country_id = "1aLkaAqfrs3GcrMvZcuyQ0NjFhAhrdIlR"

model_url = f"https://drive.google.com/uc?id={model_id}"
top_country_url = f"https://drive.google.com/uc?id={top_country_id}"


@st.cache_resource
def load_model():
    gdown.download(model_url, "best_rf_model.pkl", quiet=False)
    with open("best_rf_model.pkl", "rb") as f:
        return pickle.load(f)


@st.cache_resource
def load_top_country():
    gdown.download(top_country_url, "top_country.pkl", quiet=False)
    with open("top_country.pkl", "rb") as f:
        return pickle.load(f)


model = load_model()
top_country = load_top_country()

st.set_page_config(page_title="Hotel Booking Prediction", layout="wide")

st.markdown("""
<div style="
    background-color: white;
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    max-width: 800px;
    margin: auto;
    text-align: center;
">
    <h1 style="font-size:60px; font-weight:bold; color:black; margin-bottom:20px;">
        Hotel Booking Prediction
    </h1>
    <p style="font-size:20px; color:gray; margin-bottom:30px;">
        Welcome to Hotel Booking Prediction System
    </p>
    <p style="font-size:15px; color:black;">
        Fill in the form below to predict hotel booking!
    </p>
</div>
""", unsafe_allow_html=True)

st.write("")
st.write("")

with st.form(key="hotel_bookings"):
    col1, col2 = st.columns(2)
    
    with col1:
        name = st.selectbox("Hotel Type", ("city_hotel", "resort_hotel"), index=0)
        lead = st.number_input(
            "Lead Time",
            min_value=0,
            max_value=600,
            value=0,
            step=1,
            help="jarak antar waktu booking dan check-in",
        )
        arrival_year = st.selectbox("Arrival Year", ("2015", "2016", "2017"), index=0)
        arrival_month = st.selectbox(
            "Arrival Months",
            (
                "January",
                "February",
                "March",
                "April",
                "May",
                "June",
                "July",
                "August",
                "September",
                "October",
                "November",
                "December",
            ),
            index=0,
        )
    
    with col2:
        arrival_week = st.number_input(
            "Arrival Weeks",
            min_value=1,
            max_value=52,
            value=1,
            step=1,
            help="minggu kedatangan",
        )
        arrival_day = st.number_input(
            "Arrival Days",
            min_value=1,
            max_value=31,
            value=1,
            step=1,
            help="tanggal kedatangan",
        )

    submitted = st.form_submit_button("Predict", use_container_width=True)
    
    if submitted:
        # Prepare data for prediction
        data = {
            'hotel': name,
            'lead_time': lead,
            'arrival_date_year': int(arrival_year),
            'arrival_date_month': arrival_month,
            'arrival_date_week_number': arrival_week,
            'arrival_date_day_of_month': arrival_day
        }
        
        df = pd.DataFrame([data])
        
        try:
            prediction = model.predict(df)
            
            st.success("Prediction Complete!")
            
            if prediction[0] == 1:
                st.error("⚠️ This booking is likely to be CANCELLED")
            else:
                st.success("✅ This booking is likely to be CONFIRMED")
                
        except Exception as e:
            st.error(f"Error making prediction: {str(e)}")