manyu007 commited on
Commit
9b59b60
·
verified ·
1 Parent(s): 8af112b

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +19 -13
  2. app.py +140 -0
  3. requirements.txt +6 -2
Dockerfile CHANGED
@@ -1,20 +1,26 @@
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
+ FROM python:3.9-slim
2
 
3
+ # Create non-root user
4
+ RUN useradd -m -u 1000 user
5
 
6
+ # Set environment variables
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
 
 
9
 
10
+ # Set working directory
11
+ WORKDIR $HOME/app
12
 
13
+ # Copy application files
14
+ COPY --chown=user . .
15
 
16
+ # Switch to non-root user
17
+ USER user
18
+
19
+ # Install dependencies locally for the user
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # Expose Streamlit port
23
+ EXPOSE 8501
24
 
25
+ # Run Streamlit app
26
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from huggingface_hub import hf_hub_download
4
+ import joblib
5
+
6
+ # Download the model from Hugging Face Hub
7
+ model_path = hf_hub_download(
8
+ repo_id="manyu007/tourism-model",
9
+ filename="model.joblib"
10
+ )
11
+
12
+ # Load the trained model
13
+ model = joblib.load(model_path)
14
+
15
+ # Streamlit UI
16
+ st.title("MLOPS – Customer Package Purchase Prediction App")
17
+ st.write(
18
+ "This internal application predicts whether a customer is likely to "
19
+ "purchase a travel package based on demographic and interaction details."
20
+ )
21
+ st.write("Please enter the customer details below.")
22
+
23
+ # -----------------------------
24
+ # Customer Details
25
+ # -----------------------------
26
+ Age = st.number_input("Age", min_value=18, max_value=100, value=30)
27
+
28
+ TypeofContact = st.selectbox(
29
+ "Type of Contact",
30
+ ["Company Invited", "Self Inquiry"]
31
+ )
32
+
33
+ CityTier = st.selectbox("City Tier", [1, 2, 3])
34
+
35
+ Occupation = st.selectbox(
36
+ "Occupation",
37
+ ["Salaried", "Freelancer", "Small Business", "Large Business"]
38
+ )
39
+
40
+ Gender = st.selectbox("Gender", ["Male", "Female"])
41
+
42
+ NumberOfPersonVisiting = st.number_input(
43
+ "Number of Persons Visiting",
44
+ min_value=1, max_value=10, value=2
45
+ )
46
+
47
+ PreferredPropertyStar = st.selectbox(
48
+ "Preferred Property Star",
49
+ [1, 2, 3, 4, 5]
50
+ )
51
+
52
+ MaritalStatus = st.selectbox(
53
+ "Marital Status",
54
+ ["Single", "Married", "Divorced"]
55
+ )
56
+
57
+ NumberOfTrips = st.number_input(
58
+ "Number of Trips (per year)",
59
+ min_value=0, max_value=50, value=2
60
+ )
61
+
62
+ Passport = st.selectbox("Has Passport?", ["Yes", "No"])
63
+ OwnCar = st.selectbox("Owns a Car?", ["Yes", "No"])
64
+
65
+ NumberOfChildrenVisiting = st.number_input(
66
+ "Number of Children Visiting",
67
+ min_value=0, max_value=5, value=0
68
+ )
69
+
70
+ Designation = st.selectbox(
71
+ "Designation",
72
+ ["Executive", "Manager", "Senior Manager", "VP"]
73
+ )
74
+
75
+ MonthlyIncome = st.number_input(
76
+ "Monthly Income",
77
+ min_value=5000, max_value=500000, value=50000
78
+ )
79
+
80
+ # -----------------------------
81
+ # Interaction Details
82
+ # -----------------------------
83
+ PitchSatisfactionScore = st.slider(
84
+ "Pitch Satisfaction Score",
85
+ min_value=1, max_value=5, value=3
86
+ )
87
+
88
+ ProductPitched = st.selectbox(
89
+ "Product Pitched",
90
+ ["Basic", "Standard", "Deluxe", "Super Deluxe"]
91
+ )
92
+
93
+ NumberOfFollowups = st.number_input(
94
+ "Number of Follow-ups",
95
+ min_value=0, max_value=20, value=2
96
+ )
97
+
98
+ DurationOfPitch = st.number_input(
99
+ "Duration of Pitch (minutes)",
100
+ min_value=1, max_value=120, value=15
101
+ )
102
+
103
+ # -----------------------------
104
+ # Prepare input data
105
+ # -----------------------------
106
+ input_data = pd.DataFrame([{
107
+ "Age": Age,
108
+ "TypeofContact": TypeofContact,
109
+ "CityTier": CityTier,
110
+ "Occupation": Occupation,
111
+ "Gender": Gender,
112
+ "NumberOfPersonVisiting": NumberOfPersonVisiting,
113
+ "PreferredPropertyStar": PreferredPropertyStar,
114
+ "MaritalStatus": MaritalStatus,
115
+ "NumberOfTrips": NumberOfTrips,
116
+ "Passport": 1 if Passport == "Yes" else 0,
117
+ "OwnCar": 1 if OwnCar == "Yes" else 0,
118
+ "NumberOfChildrenVisiting": NumberOfChildrenVisiting,
119
+ "Designation": Designation,
120
+ "MonthlyIncome": MonthlyIncome,
121
+ "PitchSatisfactionScore": PitchSatisfactionScore,
122
+ "ProductPitched": ProductPitched,
123
+ "NumberOfFollowups": NumberOfFollowups,
124
+ "DurationOfPitch": DurationOfPitch
125
+ }])
126
+
127
+ # Classification threshold
128
+ classification_threshold = 0.5
129
+
130
+ # -----------------------------
131
+ # Prediction
132
+ # -----------------------------
133
+ if st.button("Predict"):
134
+ prediction_proba = model.predict_proba(input_data)[0, 1]
135
+ prediction = (prediction_proba >= classification_threshold).astype(int)
136
+
137
+ if prediction == 1:
138
+ st.success("✅ The customer is likely to purchase the package.")
139
+ else:
140
+ st.error("❌ The customer is unlikely to purchase the package.")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
  pandas
3
- streamlit
 
 
 
 
 
1
+ streamlit
2
  pandas
3
+ scikit-learn
4
+ xgboost
5
+ joblib
6
+ huggingface_hub
7
+ mlflow