Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +82 -0
- requirements.txt +6 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
| 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,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
try:
|
| 8 |
+
# Assuming the model is saved in the current directory or a known path
|
| 9 |
+
model_path = "best_tourism_model_v1.joblib"
|
| 10 |
+
model = joblib.load(model_path)
|
| 11 |
+
st.success("Model loaded successfully!")
|
| 12 |
+
except Exception as e:
|
| 13 |
+
st.error(f"Error loading model: {e}")
|
| 14 |
+
|
| 15 |
+
st.title("Wellness Tourism Package Purchase Prediction")
|
| 16 |
+
|
| 17 |
+
st.write("Enter the customer details to predict the likelihood of purchasing the Wellness Tourism Package.")
|
| 18 |
+
|
| 19 |
+
# Define input fields based on the features used in the model
|
| 20 |
+
# Numeric features: 'Age', 'NumberOfPersonVisiting', 'NumberOfTrips', 'NumberOfChildrenVisiting', 'MonthlyIncome', 'PitchSatisfactionScore', 'NumberOfFollowups', 'DurationOfPitch'
|
| 21 |
+
# Categorical features: 'TypeofContact', 'CityTier', 'Occupation', 'Gender', 'PreferredPropertyStar', 'MaritalStatus', 'Designation', 'Passport', 'OwnCar'
|
| 22 |
+
|
| 23 |
+
age = st.slider("Age", 18, 80, 30)
|
| 24 |
+
number_of_person_visiting = st.slider("Number of Persons Visiting", 1, 10, 1)
|
| 25 |
+
number_of_trips = st.slider("Number of Trips Annually", 0, 50, 5)
|
| 26 |
+
number_of_children_visiting = st.slider("Number of Children Visiting (under 5)", 0, 5, 0)
|
| 27 |
+
monthly_income = st.number_input("Monthly Income", 10000, 500000, 50000)
|
| 28 |
+
pitch_satisfaction_score = st.slider("Pitch Satisfaction Score", 1, 5, 3)
|
| 29 |
+
number_of_followups = st.slider("Number of Followups", 0, 10, 3)
|
| 30 |
+
duration_of_pitch = st.slider("Duration of Pitch (minutes)", 1, 60, 15)
|
| 31 |
+
passport = st.selectbox("Has Passport?", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
|
| 32 |
+
own_car = st.selectbox("Owns Car?", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
|
| 33 |
+
|
| 34 |
+
type_of_contact = st.selectbox("Type of Contact", ['Company Invited', 'Self Inquiry'])
|
| 35 |
+
city_tier = st.selectbox("City Tier", [1, 2, 3])
|
| 36 |
+
occupation = st.selectbox("Occupation", ['Salaried', 'Small Business', 'Large Business', 'Free Lancer', 'Government Sector', 'Retired', 'Student'])
|
| 37 |
+
gender = st.selectbox("Gender", ['Male', 'Female'])
|
| 38 |
+
preferred_property_star = st.selectbox("Preferred Property Star Rating", [3, 4, 5])
|
| 39 |
+
marital_status = st.selectbox("Marital Status", ['Single', 'Married', 'Divorced'])
|
| 40 |
+
designation = st.selectbox("Designation", ['Manager', 'Executive', 'Senior Manager', 'AVP', 'VP', 'Senior Executive', 'Junior Executive', 'Director', 'Assistant Manager', 'Lead'])
|
| 41 |
+
product_pitched = st.selectbox("Product Pitched", ['Destination', 'Resort', 'Cruise', 'Holiday', 'Accommodation', 'Flight', 'Walk in'])
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if st.button("Predict Purchase"):
|
| 45 |
+
# Create a DataFrame from the input values
|
| 46 |
+
input_data = {
|
| 47 |
+
'Age': [age],
|
| 48 |
+
'NumberOfPersonVisiting': [number_of_person_visiting],
|
| 49 |
+
'NumberOfTrips': [number_of_trips],
|
| 50 |
+
'NumberOfChildrenVisiting': [number_of_children_visiting],
|
| 51 |
+
'MonthlyIncome': [monthly_income],
|
| 52 |
+
'PitchSatisfactionScore': [pitch_satisfaction_score],
|
| 53 |
+
'NumberOfFollowups': [number_of_followups],
|
| 54 |
+
'DurationOfPitch': [duration_of_pitch],
|
| 55 |
+
'Passport': [passport],
|
| 56 |
+
'OwnCar': [own_car],
|
| 57 |
+
'TypeofContact': [type_of_contact],
|
| 58 |
+
'CityTier': [city_tier],
|
| 59 |
+
'Occupation': [occupation],
|
| 60 |
+
'Gender': [gender],
|
| 61 |
+
'PreferredPropertyStar': [preferred_property_star],
|
| 62 |
+
'MaritalStatus': [marital_status],
|
| 63 |
+
'Designation': [designation],
|
| 64 |
+
'ProductPitched': [product_pitched] # Include ProductPitched for prediction
|
| 65 |
+
}
|
| 66 |
+
input_df = pd.DataFrame(input_data)
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
# Make prediction
|
| 70 |
+
prediction = model.predict(input_df)
|
| 71 |
+
prediction_proba = model.predict_proba(input_df)[:, 1] # Probability of purchasing
|
| 72 |
+
|
| 73 |
+
st.subheader("Prediction Result:")
|
| 74 |
+
if prediction[0] == 1:
|
| 75 |
+
st.success(f"The customer is likely to purchase the package.")
|
| 76 |
+
else:
|
| 77 |
+
st.warning(f"The customer is unlikely to purchase the package.")
|
| 78 |
+
|
| 79 |
+
st.write(f"Probability of Purchase: {prediction_proba[0]:.2f}")
|
| 80 |
+
|
| 81 |
+
except Exception as e:
|
| 82 |
+
st.error(f"Error during prediction: {e}")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 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
|