Garg06 commited on
Commit
1363867
·
verified ·
1 Parent(s): 0a6e40c

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +10 -5
  2. app.py +30 -5
  3. requirements.txt +2 -0
Dockerfile CHANGED
@@ -1,23 +1,28 @@
1
- # Use a minimal base image with Python 3.9 installed
2
  FROM python:3.9
3
 
4
- # Set the working directory inside the container to /app
5
  WORKDIR /app
6
 
7
- # Copy all files from the current directory on the host to the container's /app directory
8
  COPY . .
9
 
10
- # Install Python dependencies listed in requirements.txt
11
  RUN pip3 install -r requirements.txt
12
 
 
13
  RUN useradd -m -u 1000 user
14
  USER user
15
  ENV HOME=/home/user \
16
  PATH=/home/user/.local/bin:$PATH
17
 
 
18
  WORKDIR $HOME/app
19
 
 
20
  COPY --chown=user . $HOME/app
21
 
22
- # Define the command to run the Streamlit app on port "8501" and make it accessible externally
 
 
23
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
 
1
+ # Use a minimal base image with Python 3.9 installed.
2
  FROM python:3.9
3
 
4
+ # Set the working directory inside the container to /app.
5
  WORKDIR /app
6
 
7
+ # Copy all files from the current directory on the host to the container's /app directory.
8
  COPY . .
9
 
10
+ # Install Python dependencies listed in requirements.txt.
11
  RUN pip3 install -r requirements.txt
12
 
13
+ # Create a non-root user 'user' with UID 1000 and set ownership.
14
  RUN useradd -m -u 1000 user
15
  USER user
16
  ENV HOME=/home/user \
17
  PATH=/home/user/.local/bin:$PATH
18
 
19
+ # Change working directory to the user's application directory.
20
  WORKDIR $HOME/app
21
 
22
+ # Copy the application files to the user's directory.
23
  COPY --chown=user . $HOME/app
24
 
25
+ # Define the command to run the Streamlit app on port "8501" and make it accessible externally.
26
+ # `--server.address=0.0.0.0` makes the app reachable from any IP address.
27
+ # `--server.enableXsrfProtection=false` disables CSRF protection, often needed for public deployments.
28
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py CHANGED
@@ -3,42 +3,63 @@ import pandas as pd
3
  from huggingface_hub import hf_hub_download
4
  import joblib
5
 
6
- # Download and load the model
 
7
  model_path = hf_hub_download(repo_id="Garg06/Tourism-Package-Model", filename="best_machine_failure_model_v1.joblib")
8
  model = joblib.load(model_path)
9
 
10
- # Streamlit UI for Tourism Package Prediction
11
  st.title("Tourism Package Prediction App")
12
  st.write("""
13
  This application predicts whether a customer will purchase the newly introduced Wellness Tourism Package.
14
  Please enter the customer details and interaction data below to get a prediction.
15
  """)
16
 
17
- # User input fields
18
  st.header("Customer Details")
 
19
  age = st.number_input("Age", min_value=18, max_value=90, value=30)
 
20
  typeofcontact = st.selectbox("Type of Contact", options=['Company Invited', 'Self Inquiry'])
 
21
  citytier = st.number_input("City Tier (1, 2, or 3)", min_value=1, max_value=3, value=1)
 
22
  occupation = st.selectbox("Occupation", options=['Freelancer', 'Large Business', 'Salaried', 'Small Business', 'Unemployed'])
 
23
  gender = st.selectbox("Gender", options=['Female', 'Male'])
 
24
  numberofpersonvisiting = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=1)
 
25
  preferredpropertystar = st.number_input("Preferred Property Star (e.g., 3, 4, 5)", min_value=1, max_value=5, value=3)
 
26
  maritalstatus = st.selectbox("Marital Status", options=['Divorced', 'Married', 'Single'])
 
27
  numberoftrips = st.number_input("Number of Trips Annually", min_value=0, max_value=50, value=5)
 
28
  passport = st.selectbox("Passport", options=[0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
 
29
  owncar = st.selectbox("Own Car", options=[0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
 
30
  numberofchildrenvisiting = st.number_input("Number of Children Visiting (below age 5)", min_value=0, max_value=5, value=0)
 
31
  designation = st.selectbox("Designation", options=['Director', 'Executive', 'Manager', 'Senior Executive', 'VP'])
 
32
  monthlyincome = st.number_input("Monthly Income", min_value=0.0, max_value=1000000.0, value=50000.0, step=100.0)
33
 
 
34
  st.header("Customer Interaction Data")
 
35
  pitchsatisfactionscore = st.number_input("Pitch Satisfaction Score (1-5)", min_value=1, max_value=5, value=3)
 
36
  productpitched = st.selectbox("Product Pitched", options=['Basic', 'Deluxe', 'King', 'Standard', 'Super Deluxe'])
 
37
  numberoffollowups = st.number_input("Number of Follow-ups", min_value=0, max_value=20, value=3)
 
38
  durationofpitch = st.number_input("Duration of Pitch (minutes)", min_value=0.0, max_value=60.0, value=15.0, step=0.5)
39
 
40
 
41
- # Assemble input into DataFrame, ensuring column order matches training data
 
42
  input_data = pd.DataFrame([{
43
  'Age': age,
44
  'TypeofContact': typeofcontact,
@@ -61,12 +82,16 @@ input_data = pd.DataFrame([{
61
  }])
62
 
63
 
 
64
  if st.button("Predict Purchase"):
 
65
  prediction_proba = model.predict_proba(input_data)[:, 1]
66
- # Using the classification_threshold defined in train.py
67
  classification_threshold = 0.45
 
68
  prediction = (prediction_proba >= classification_threshold).astype(int)[0]
69
 
 
70
  result = "Customer WILL purchase the Wellness Tourism Package" if prediction == 1 else "Customer will NOT purchase the Wellness Tourism Package"
71
  st.subheader("Prediction Result:")
72
  st.success(f"The model predicts: **{result}**")
 
3
  from huggingface_hub import hf_hub_download
4
  import joblib
5
 
6
+ # Download and load the model from Hugging Face Hub.
7
+ # The model will be used for making predictions in the Streamlit app.
8
  model_path = hf_hub_download(repo_id="Garg06/Tourism-Package-Model", filename="best_machine_failure_model_v1.joblib")
9
  model = joblib.load(model_path)
10
 
11
+ # Set the title and description for the Streamlit web application.
12
  st.title("Tourism Package Prediction App")
13
  st.write("""
14
  This application predicts whether a customer will purchase the newly introduced Wellness Tourism Package.
15
  Please enter the customer details and interaction data below to get a prediction.
16
  """)
17
 
18
+ # User input fields for customer details, organized under a header.
19
  st.header("Customer Details")
20
+ # Numerical input for Age, with defined min/max values and a default.
21
  age = st.number_input("Age", min_value=18, max_value=90, value=30)
22
+ # Dropdown for Type of Contact, with string options.
23
  typeofcontact = st.selectbox("Type of Contact", options=['Company Invited', 'Self Inquiry'])
24
+ # Numerical input for City Tier.
25
  citytier = st.number_input("City Tier (1, 2, or 3)", min_value=1, max_value=3, value=1)
26
+ # Dropdown for Occupation.
27
  occupation = st.selectbox("Occupation", options=['Freelancer', 'Large Business', 'Salaried', 'Small Business', 'Unemployed'])
28
+ # Dropdown for Gender.
29
  gender = st.selectbox("Gender", options=['Female', 'Male'])
30
+ # Numerical input for Number of Persons Visiting.
31
  numberofpersonvisiting = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=1)
32
+ # Numerical input for Preferred Property Star rating.
33
  preferredpropertystar = st.number_input("Preferred Property Star (e.g., 3, 4, 5)", min_value=1, max_value=5, value=3)
34
+ # Dropdown for Marital Status.
35
  maritalstatus = st.selectbox("Marital Status", options=['Divorced', 'Married', 'Single'])
36
+ # Numerical input for Number of Trips Annually.
37
  numberoftrips = st.number_input("Number of Trips Annually", min_value=0, max_value=50, value=5)
38
+ # Dropdown for Passport, with custom display for 0/1.
39
  passport = st.selectbox("Passport", options=[0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
40
+ # Dropdown for Own Car, with custom display for 0/1.
41
  owncar = st.selectbox("Own Car", options=[0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
42
+ # Numerical input for Number of Children Visiting.
43
  numberofchildrenvisiting = st.number_input("Number of Children Visiting (below age 5)", min_value=0, max_value=5, value=0)
44
+ # Dropdown for Designation.
45
  designation = st.selectbox("Designation", options=['Director', 'Executive', 'Manager', 'Senior Executive', 'VP'])
46
+ # Numerical input for Monthly Income.
47
  monthlyincome = st.number_input("Monthly Income", min_value=0.0, max_value=1000000.0, value=50000.0, step=100.0)
48
 
49
+ # User input fields for customer interaction data, organized under a header.
50
  st.header("Customer Interaction Data")
51
+ # Numerical input for Pitch Satisfaction Score.
52
  pitchsatisfactionscore = st.number_input("Pitch Satisfaction Score (1-5)", min_value=1, max_value=5, value=3)
53
+ # Dropdown for Product Pitched.
54
  productpitched = st.selectbox("Product Pitched", options=['Basic', 'Deluxe', 'King', 'Standard', 'Super Deluxe'])
55
+ # Numerical input for Number of Follow-ups.
56
  numberoffollowups = st.number_input("Number of Follow-ups", min_value=0, max_value=20, value=3)
57
+ # Numerical input for Duration of Pitch.
58
  durationofpitch = st.number_input("Duration of Pitch (minutes)", min_value=0.0, max_value=60.0, value=15.0, step=0.5)
59
 
60
 
61
+ # Assemble the user input into a Pandas DataFrame.
62
+ # The column names must exactly match those expected by the trained model.
63
  input_data = pd.DataFrame([{
64
  'Age': age,
65
  'TypeofContact': typeofcontact,
 
82
  }])
83
 
84
 
85
+ # When the "Predict Purchase" button is clicked:
86
  if st.button("Predict Purchase"):
87
+ # Get prediction probabilities from the model.
88
  prediction_proba = model.predict_proba(input_data)[:, 1]
89
+ # Define the classification threshold (as used during model evaluation).
90
  classification_threshold = 0.45
91
+ # Convert probabilities to binary predictions based on the threshold.
92
  prediction = (prediction_proba >= classification_threshold).astype(int)[0]
93
 
94
+ # Display the prediction result to the user.
95
  result = "Customer WILL purchase the Wellness Tourism Package" if prediction == 1 else "Customer will NOT purchase the Wellness Tourism Package"
96
  st.subheader("Prediction Result:")
97
  st.success(f"The model predicts: **{result}**")
requirements.txt CHANGED
@@ -1,3 +1,5 @@
 
 
1
  pandas==2.2.2
2
  huggingface_hub==0.32.6
3
  streamlit==1.43.2
 
1
+ # Define the Python package dependencies for the Streamlit application.
2
+ # These versions ensure reproducibility of the deployment environment.
3
  pandas==2.2.2
4
  huggingface_hub==0.32.6
5
  streamlit==1.43.2