SandeepMM commited on
Commit
5fbf245
·
verified ·
1 Parent(s): 66e3c6c

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +97 -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,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
7
+ #model_path = hf_hub_download(repo_id="SandeepMM/GL-MLOps-VisitWithUs", filename="best_visitwithus_model_v1.joblib")
8
+ try:
9
+ model_repo_id = "SandeepMM/GL-MLOps-VisitWithUs"
10
+ model_filename = "best_visitwithus_model_v1.joblib"
11
+
12
+ # Use hf_hub_download for reliable model artifact fetching
13
+ model_path = hf_hub_download(repo_id=model_repo_id, filename=model_filename)
14
+ model = joblib.load(model_path)
15
+
16
+ st.sidebar.success("Model loaded successfully!")
17
+ except Exception as e:
18
+ st.sidebar.error(f"Error loading model: {e}")
19
+ model = None
20
+
21
+ # Streamlit UI for Machine Failure Prediction
22
+ st.title("Visit With Us! Tourism App")
23
+ st.write("""
24
+ This application predicts the likelihood of a customer buying a tourism package.
25
+ Please enter the customer data below to get a prediction.
26
+ """)
27
+
28
+ # --- User Input Fields (Using snake_case for variables) ---
29
+ st.header("Customer Profile")
30
+
31
+ age = st.number_input("Age", min_value=18, max_value=120, value=30, step=1)
32
+ gender = st.selectbox("Gender", ['Female','Male'], index=0)
33
+ marital_status = st.selectbox("Marital Status", ['Unmarried','Married','Divorced'], index=0)
34
+ occupation = st.selectbox("Occupation", ['Large Business','Salaried','Small Business'], index=1)
35
+ designation = st.selectbox("Designation", ['Executive','Manager','Senior Manager','AVP','VP'], index=0)
36
+ monthly_income = st.number_input("Monthly Income", min_value=1000, max_value=100000, value=25000, step=1000)
37
+ number_of_person_visiting = st.number_input("Number Of Person Visiting", min_value=1, max_value=5, value=2, step=1)
38
+ number_of_children_visiting = st.number_input("Number Of Children Visiting", min_value=1, max_value=5, value=2, step=1)
39
+ city_tier = st.number_input("City Tier", min_value=1, max_value=3, value=1, step=1)
40
+ passport = st.number_input("Passport (0=No, 1=Yes)", min_value=0, max_value=1, value=0, step=1)
41
+ own_car = st.number_input("Own a Car (0=No, 1=Yes)", min_value=0, max_value=1, value=0, step=1)
42
+ preferred_property_star = st.number_input("Preferred Property Star (1 to 5)", min_value=1, max_value=5, value=3, step=1)
43
+
44
+ st.header("Trip Details")
45
+
46
+ number_of_trips = st.number_input("Number Of Trips Taken Previously", min_value=1, max_value=22, value=5, step=1)
47
+ type_of_contact = st.selectbox("Type of Contact", ['Company Invited','Self Enquiry'], index=0)
48
+ product_pitched = st.selectbox("Product Pitched", ['Basic','Deluxe','Standard','Super Deluxe','King'], index=1)
49
+ duration_of_pitch = st.number_input("Duration Of Pitch (minutes)", min_value=5, max_value=127, value=15, step=1)
50
+ pitch_satisfaction_score = st.number_input("Pitch Satisfaction Score (1 to 5)", min_value=1, max_value=5, value=3, step=1)
51
+ number_of_followups = st.number_input("Number Of Followups", min_value=1, max_value=6, value=2, step=1)
52
+
53
+
54
+ # Assemble input into DataFrame (column names must match training data features)
55
+ input_data = pd.DataFrame([{
56
+ 'Age': age,
57
+ 'Gender': gender,
58
+ 'MaritalStatus': marital_status,
59
+ 'Occupation': occupation,
60
+ 'Designation': designation,
61
+ 'MonthlyIncome': monthly_income,
62
+ 'NumberOfPersonVisiting': number_of_person_visiting,
63
+ 'NumberOfChildrenVisiting': number_of_children_visiting,
64
+ 'CityTier': city_tier,
65
+ 'Passport': passport,
66
+ 'OwnCar': own_car,
67
+ 'PreferredPropertyStar': preferred_property_star,
68
+ 'NumberOfTrips': number_of_trips,
69
+ 'TypeofContact': type_of_contact,
70
+ 'ProductPitched': product_pitched,
71
+ 'DurationOfPitch': duration_of_pitch,
72
+ 'PitchSatisfactionScore': pitch_satisfaction_score,
73
+ 'NumberOfFollowups': number_of_followups,
74
+ }])
75
+
76
+ # Set a consistent classification threshold
77
+ CLASSIFICATION_THRESHOLD = 0.4951
78
+ if st.button("Predict Package Purchase"):
79
+ if model is not None:
80
+
81
+ # Get the probability of the positive class (ProdTaken=1)
82
+ prediction_proba = model.predict_proba(input_data)[:, 1][0]
83
+
84
+ # Apply the optimized classification threshold
85
+ prediction = 1 if prediction_proba >= CLASSIFICATION_THRESHOLD else 0
86
+
87
+ result = "Customer Purchase Potential! (Likely to buy)" if prediction == 1 else "No Sale (Unlikely to buy)"
88
+
89
+ st.subheader("Prediction Result:")
90
+ if prediction == 1:
91
+ st.success(f"The model predicts: **{result}**")
92
+ else:
93
+ st.warning(f"The model predicts: **{result}**")
94
+
95
+ st.info(f"Probability of Purchase: **{prediction_proba:.4f}**")
96
+ else:
97
+ st.error("Cannot predict: Model failed to load.")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
1
+ pandas==2.2.2
2
+ huggingface_hub==0.32.6
3
+ streamlit==1.43.2
4
+ joblib==1.5.1
5
+ scikit-learn==1.6.0
6
+ xgboost==2.1.4
7
+ mlflow==3.0.1