kurniawan commited on
Commit
eda7c5e
·
1 Parent(s): 1836fa2

Restructure to use src/ folder and Docker with hotel booking prediction

Browse files
Files changed (6) hide show
  1. .gitignore +3 -0
  2. Dockerfile +20 -0
  3. README.md +16 -7
  4. app.py +0 -11
  5. requirements.txt +5 -0
  6. ziko.py → src/streamlit_app.py +60 -9
.gitignore CHANGED
@@ -1 +1,4 @@
1
  .env
 
 
 
 
1
  .env
2
+ *.pkl
3
+ __pycache__/
4
+ *.pyc
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ curl \
8
+ git \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ COPY requirements.txt ./
12
+ COPY src/ ./src/
13
+
14
+ RUN pip3 install -r requirements.txt
15
+
16
+ EXPOSE 8501
17
+
18
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
+
20
+ ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
README.md CHANGED
@@ -1,14 +1,23 @@
1
  ---
2
- title: Simple Input Output App
3
- emoji: 🚀
4
  colorFrom: blue
5
  colorTo: green
6
- sdk: streamlit
7
- sdk_version: 1.28.0
8
- app_file: app.py
 
 
 
9
  pinned: false
 
10
  ---
11
 
12
- # Simple Input/Output Streamlit App
13
 
14
- A simple Streamlit application that takes text input and displays output with character and word count.
 
 
 
 
 
 
1
  ---
2
+ title: Hotel Booking Prediction
3
+ emoji: 🏨
4
  colorFrom: blue
5
  colorTo: green
6
+ sdk: docker
7
+ app_port: 8501
8
+ tags:
9
+ - streamlit
10
+ - machine-learning
11
+ - hotel-booking
12
  pinned: false
13
+ short_description: 'Predict hotel booking cancellation using ML'
14
  ---
15
 
16
+ # Hotel Booking Prediction
17
 
18
+ A Streamlit application that predicts hotel booking cancellations using machine learning.
19
+
20
+ ## Features
21
+ - Predict booking cancellation probability
22
+ - Interactive form interface
23
+ - Real-time predictions
app.py DELETED
@@ -1,11 +0,0 @@
1
- import streamlit as st
2
-
3
- st.title("Simple Input/Output App")
4
-
5
- user_input = st.text_input("Enter your text:", placeholder="Type something here...")
6
-
7
- if user_input:
8
- st.write("### Output:")
9
- st.write(f"You entered: **{user_input}**")
10
- st.write(f"Character count: {len(user_input)}")
11
- st.write(f"Word count: {len(user_input.split())}")
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1 +1,6 @@
1
  streamlit
 
 
 
 
 
 
1
  streamlit
2
+ pandas
3
+ numpy
4
+ scikit-learn
5
+ gdown
6
+ pickle5
ziko.py → src/streamlit_app.py RENAMED
@@ -1,6 +1,6 @@
1
  import pandas as pd
2
  import pickle
3
- import numpy as py
4
  import streamlit as st
5
  import gdown
6
 
@@ -28,11 +28,38 @@ def load_top_country():
28
 
29
  model = load_model()
30
  top_country = load_top_country()
31
- # Load
32
 
 
33
 
34
- def run():
35
- with st.form(key="hotel_bookings"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  name = st.selectbox("Hotel Type", ("city_hotel", "resort_hotel"), index=0)
37
  lead = st.number_input(
38
  "Lead Time",
@@ -61,6 +88,8 @@ def run():
61
  ),
62
  index=0,
63
  )
 
 
64
  arrival_week = st.number_input(
65
  "Arrival Weeks",
66
  min_value=1,
@@ -78,8 +107,30 @@ def run():
78
  help="tanggal kedatangan",
79
  )
80
 
81
- submitted = st.form_submit_button("Predict")
82
-
83
-
84
- if __name__ == "_main_":
85
- run()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import pickle
3
+ import numpy as np
4
  import streamlit as st
5
  import gdown
6
 
 
28
 
29
  model = load_model()
30
  top_country = load_top_country()
 
31
 
32
+ st.set_page_config(page_title="Hotel Booking Prediction", layout="wide")
33
 
34
+ st.markdown("""
35
+ <div style="
36
+ background-color: white;
37
+ padding: 50px;
38
+ border-radius: 20px;
39
+ box-shadow: 0 4px 20px rgba(0,0,0,0.1);
40
+ max-width: 800px;
41
+ margin: auto;
42
+ text-align: center;
43
+ ">
44
+ <h1 style="font-size:60px; font-weight:bold; color:black; margin-bottom:20px;">
45
+ Hotel Booking Prediction
46
+ </h1>
47
+ <p style="font-size:20px; color:gray; margin-bottom:30px;">
48
+ Welcome to Hotel Booking Prediction System
49
+ </p>
50
+ <p style="font-size:15px; color:black;">
51
+ Fill in the form below to predict hotel booking!
52
+ </p>
53
+ </div>
54
+ """, unsafe_allow_html=True)
55
+
56
+ st.write("")
57
+ st.write("")
58
+
59
+ with st.form(key="hotel_bookings"):
60
+ col1, col2 = st.columns(2)
61
+
62
+ with col1:
63
  name = st.selectbox("Hotel Type", ("city_hotel", "resort_hotel"), index=0)
64
  lead = st.number_input(
65
  "Lead Time",
 
88
  ),
89
  index=0,
90
  )
91
+
92
+ with col2:
93
  arrival_week = st.number_input(
94
  "Arrival Weeks",
95
  min_value=1,
 
107
  help="tanggal kedatangan",
108
  )
109
 
110
+ submitted = st.form_submit_button("Predict", use_container_width=True)
111
+
112
+ if submitted:
113
+ # Prepare data for prediction
114
+ data = {
115
+ 'hotel': name,
116
+ 'lead_time': lead,
117
+ 'arrival_date_year': int(arrival_year),
118
+ 'arrival_date_month': arrival_month,
119
+ 'arrival_date_week_number': arrival_week,
120
+ 'arrival_date_day_of_month': arrival_day
121
+ }
122
+
123
+ df = pd.DataFrame([data])
124
+
125
+ try:
126
+ prediction = model.predict(df)
127
+
128
+ st.success("Prediction Complete!")
129
+
130
+ if prediction[0] == 1:
131
+ st.error("⚠️ This booking is likely to be CANCELLED")
132
+ else:
133
+ st.success("✅ This booking is likely to be CONFIRMED")
134
+
135
+ except Exception as e:
136
+ st.error(f"Error making prediction: {str(e)}")