Sudu1976 commited on
Commit
50953b8
·
verified ·
1 Parent(s): 7773b14

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +70 -0
  3. requirements.txt +7 -3
Dockerfile CHANGED
@@ -1,20 +1,23 @@
1
- FROM python:3.13.5-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"]
 
 
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"]
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from huggingface_hub import hf_hub_download
4
+ import joblib
5
+
6
+ # Download and load the model from Hugging Face Hub
7
+ model_path = hf_hub_download(
8
+ repo_id="Sudu1976/tourismpkg_prediction_model", # Corrected repo_id
9
+ filename="tourismpkg_prediction_model_v1.joblib"
10
+ )
11
+ model = joblib.load(model_path)
12
+
13
+ # Streamlit UI for Tourism Package Prediction
14
+ st.title("Tourism Package Prediction App")
15
+ st.write("""
16
+ This application predicts whether a customer will purchase the **Wellness Tourism Package** based on their details.
17
+ Please enter the required information below to get a prediction.
18
+ """)
19
+
20
+ # User input
21
+ age = st.number_input("Age", min_value=18, max_value=100, value=30, step=1)
22
+ typeofcontact = st.selectbox("TypeofContact", ["Company Invited", "Self Inquiry"])
23
+ citytier = st.number_input("CityTier", min_value=1, max_value=3, value=1, step=1)
24
+ occupation = st.selectbox("Occupation", ["Salaried", "Free Lancer", "Small Business", "Large Business"])
25
+ gender = st.selectbox("Gender", ["male", "female"])
26
+ nrofpersonvisiting = st.number_input("NumberOfPersonVisiting", min_value=1, max_value=8, value=2, step=1)
27
+ prfpropertystar = st.number_input("PreferredPropertyStar", min_value=3, max_value=5, value=3, step=1)
28
+ maritalstatus = st.selectbox("MaritalStatus", ["Single", "Married", "Unmarried", "Divorced"])
29
+ nroftrips = st.number_input("NumberOfTrips", min_value=1, max_value=20, value=3, step=1)
30
+ passport = st.number_input("Passport", min_value=0, max_value=1, value=1, step=1)
31
+ designation = st.selectbox("Designation", ["Manager", "Senior Manager", "Executive", "AVP", "VP"])
32
+ monthlyincome = st.number_input("MonthlyIncome", min_value=1000, max_value=40000, value=5000, step=100)
33
+ csi = st.number_input("PitchSatisfactionScore", min_value=1, max_value=5, value=2, step=1)
34
+ productpitched = st.selectbox("ProductPitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"])
35
+ nroffups = st.number_input("NumberOfFollowups", min_value=1, max_value=6, value=2, step=1)
36
+ pitchduration = st.number_input("DurationOfPitch", min_value=5, max_value=40, value=10, step=1)
37
+
38
+ # Assemble input into DataFrame
39
+ input_data = pd.DataFrame([
40
+ {
41
+ 'Age': age,
42
+ 'TypeofContact': typeofcontact,
43
+ 'CityTier': citytier,
44
+ 'Occupation': occupation,
45
+ 'Gender': gender,
46
+ 'NumberOfPersonVisiting': nrofpersonvisiting,
47
+ 'PreferredPropertyStar': prfpropertystar,
48
+ 'MaritalStatus': maritalstatus,
49
+ 'NumberOfTrips': nroftrips,
50
+ 'Passport': passport,
51
+ 'Designation': designation,
52
+ 'MonthlyIncome': monthlyincome, # Fixed typo here
53
+ 'PitchSatisfactionScore': csi,
54
+ 'ProductPitched' : productpitched,
55
+ 'NumberOfFollowups' : nroffups,
56
+ 'DurationOfPitch' :pitchduration
57
+
58
+ }])
59
+
60
+ # Prediction
61
+ if st.button("Predict Purchase"):
62
+ # The model expects raw categorical features, which its internal preprocessor will handle.
63
+ # The model's predict method should handle the transformation.
64
+ prediction_proba = model.predict_proba(input_data)[:, 1]
65
+ # Using a classification threshold, let's say 0.45, to decide on the class.
66
+ classification_threshold = 0.45
67
+ if prediction_proba[0] >= classification_threshold:
68
+ st.success(f"Prediction: Customer is likely to purchase the Wellness Tourism Package (Probability: {prediction_proba[0]:.2f})")
69
+ else:
70
+ st.info(f"Prediction: Customer is unlikely to purchase the Wellness Tourism Package (Probability: {prediction_proba[0]:.2f})")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
1
+ pandas==2.2.2
2
+ huggingface_hub==0.34.0
3
+ streamlit==1.43.2
4
+ joblib==1.5.1
5
+ scikit-learn==1.4.2
6
+ xgboost==2.1.4
7
+ scipy==1.13.1