Spaces:
Sleeping
Sleeping
| 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}" | |
| 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) | |
| 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)}") | |