Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +148 -0
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,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# -----------------------------
|
| 7 |
+
# Page Configuration
|
| 8 |
+
# -----------------------------
|
| 9 |
+
st.set_page_config(
|
| 10 |
+
page_title="Travel Conversion AI",
|
| 11 |
+
page_icon="βοΈ",
|
| 12 |
+
layout="centered"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# -----------------------------
|
| 16 |
+
# Download and Load Model
|
| 17 |
+
# -----------------------------
|
| 18 |
+
@st.cache_resource
|
| 19 |
+
def load_model():
|
| 20 |
+
model_path = hf_hub_download(
|
| 21 |
+
repo_id="muthukumar22/tourism-package-mod",
|
| 22 |
+
filename="best_tourism_model_rf.joblib" # Updated to match the RF model name
|
| 23 |
+
)
|
| 24 |
+
return joblib.load(model_path)
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
model = load_model()
|
| 28 |
+
except Exception as e:
|
| 29 |
+
st.error(f"Error loading model: {e}")
|
| 30 |
+
st.stop()
|
| 31 |
+
|
| 32 |
+
# -----------------------------
|
| 33 |
+
# 1. New Title Section
|
| 34 |
+
# -----------------------------
|
| 35 |
+
st.title("βοΈ Intelligent Travel Sales Predictor")
|
| 36 |
+
|
| 37 |
+
# -----------------------------
|
| 38 |
+
# 2. New Comments/Description Section
|
| 39 |
+
# -----------------------------
|
| 40 |
+
st.markdown("""
|
| 41 |
+
---
|
| 42 |
+
### π― Optimize Your Sales Strategy
|
| 43 |
+
Welcome to the **Customer Conversion Dashboard**. This tool utilizes a **Random Forest** machine learning model to analyze customer demographics and interaction history.
|
| 44 |
+
|
| 45 |
+
**How to use:**
|
| 46 |
+
1. Input the customer's profile details below.
|
| 47 |
+
2. Click **Analyze Customer Potential**.
|
| 48 |
+
3. Receive a probability score indicating the likelihood of a sale.
|
| 49 |
+
---
|
| 50 |
+
""")
|
| 51 |
+
|
| 52 |
+
# -----------------------------
|
| 53 |
+
# User Inputs (Organized with Columns)
|
| 54 |
+
# -----------------------------
|
| 55 |
+
st.subheader("π Customer Profile")
|
| 56 |
+
|
| 57 |
+
col1, col2 = st.columns(2)
|
| 58 |
+
|
| 59 |
+
with col1:
|
| 60 |
+
Age = st.number_input("Age", 18, 80, 35)
|
| 61 |
+
CityTier = st.selectbox("City Tier", [1, 2, 3])
|
| 62 |
+
Occupation = st.selectbox("Occupation", ["Salaried", "Freelancer", "Small Business", "Large Business"])
|
| 63 |
+
Gender = st.selectbox("Gender", ["Male", "Female"])
|
| 64 |
+
MaritalStatus = st.selectbox("Marital Status", ["Single", "Married", "Divorced", "Unmarried"])
|
| 65 |
+
NumberOfPersonVisiting = st.number_input("Persons Visiting", 1, 10, 2)
|
| 66 |
+
NumberOfChildrenVisiting = st.number_input("Children Visiting", 0, 5, 0)
|
| 67 |
+
MonthlyIncome = st.number_input("Monthly Income", 10000, 200000, 50000)
|
| 68 |
+
|
| 69 |
+
with col2:
|
| 70 |
+
TypeofContact = st.selectbox("Contact Method", ["Company Invited", "Self Inquiry"])
|
| 71 |
+
Designation = st.selectbox("Job Designation", ["Executive", "Manager", "Senior Manager", "AVP", "VP"])
|
| 72 |
+
ProductPitched = st.selectbox("Product Pitched", ["Basic", "Deluxe", "Standard", "Super Deluxe", "King"])
|
| 73 |
+
PreferredPropertyStar = st.selectbox("Preferred Property Star", [3, 4, 5])
|
| 74 |
+
NumberOfTrips = st.number_input("Trips per Year", 0, 20, 2)
|
| 75 |
+
Passport = st.selectbox("Has Passport?", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
|
| 76 |
+
OwnCar = st.selectbox("Owns Car?", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
|
| 77 |
+
|
| 78 |
+
st.subheader("π Interaction Details")
|
| 79 |
+
col3, col4 = st.columns(2)
|
| 80 |
+
with col3:
|
| 81 |
+
PitchSatisfactionScore = st.slider("Pitch Satisfaction (1-5)", 1, 5, 3)
|
| 82 |
+
with col4:
|
| 83 |
+
NumberOfFollowups = st.number_input("Follow-ups Made", 0, 10, 3)
|
| 84 |
+
DurationOfPitch = st.number_input("Pitch Duration (mins)", 1, 120, 20)
|
| 85 |
+
|
| 86 |
+
# -----------------------------
|
| 87 |
+
# Assemble Input Data
|
| 88 |
+
# -----------------------------
|
| 89 |
+
# Note: Keys must match the training column names exactly
|
| 90 |
+
input_data = pd.DataFrame([{
|
| 91 |
+
"Age": Age,
|
| 92 |
+
"CityTier": CityTier,
|
| 93 |
+
"TypeofContact": TypeofContact,
|
| 94 |
+
"Occupation": Occupation,
|
| 95 |
+
"Gender": Gender,
|
| 96 |
+
"NumberOfPersonVisiting": NumberOfPersonVisiting,
|
| 97 |
+
"PreferredPropertyStar": PreferredPropertyStar,
|
| 98 |
+
"MaritalStatus": MaritalStatus,
|
| 99 |
+
"NumberOfTrips": NumberOfTrips,
|
| 100 |
+
"Passport": Passport,
|
| 101 |
+
"OwnCar": OwnCar,
|
| 102 |
+
"NumberOfChildrenVisiting": NumberOfChildrenVisiting,
|
| 103 |
+
"Designation": Designation,
|
| 104 |
+
"MonthlyIncome": MonthlyIncome,
|
| 105 |
+
"PitchSatisfactionScore": PitchSatisfactionScore,
|
| 106 |
+
"ProductPitched": ProductPitched,
|
| 107 |
+
"NumberOfFollowups": NumberOfFollowups,
|
| 108 |
+
"DurationOfPitch": DurationOfPitch
|
| 109 |
+
}])
|
| 110 |
+
|
| 111 |
+
# -----------------------------
|
| 112 |
+
# 3. New Prediction Section
|
| 113 |
+
# -----------------------------
|
| 114 |
+
st.markdown("---")
|
| 115 |
+
if st.button("Analyze Customer Potential", type="primary", use_container_width=True):
|
| 116 |
+
|
| 117 |
+
# Get the probability of class 1 (Purchase)
|
| 118 |
+
# Most sklearn classifiers support predict_proba
|
| 119 |
+
try:
|
| 120 |
+
prediction_prob = model.predict_proba(input_data)[0][1]
|
| 121 |
+
prediction_class = model.predict(input_data)[0]
|
| 122 |
+
except AttributeError:
|
| 123 |
+
# Fallback if model doesn't support proba (unlikely for RF)
|
| 124 |
+
prediction_class = model.predict(input_data)[0]
|
| 125 |
+
prediction_prob = 1.0 if prediction_class == 1 else 0.0
|
| 126 |
+
|
| 127 |
+
st.subheader("π Analysis Results")
|
| 128 |
+
|
| 129 |
+
r_col1, r_col2 = st.columns([1, 2])
|
| 130 |
+
|
| 131 |
+
with r_col1:
|
| 132 |
+
# Display simple metric
|
| 133 |
+
st.metric(label="Purchase Probability", value=f"{prediction_prob:.1%}")
|
| 134 |
+
|
| 135 |
+
with r_col2:
|
| 136 |
+
# Display logic with visuals
|
| 137 |
+
if prediction_prob > 0.65:
|
| 138 |
+
st.success("β
**High Conversion Chance**")
|
| 139 |
+
st.write("This customer shows strong interest signals. **Recommended Action:** Close the deal immediately.")
|
| 140 |
+
st.progress(prediction_prob)
|
| 141 |
+
elif prediction_prob > 0.35:
|
| 142 |
+
st.warning("β οΈ **Medium Conversion Chance**")
|
| 143 |
+
st.write("The customer is on the fence. **Recommended Action:** Offer a discount or follow up.")
|
| 144 |
+
st.progress(prediction_prob)
|
| 145 |
+
else:
|
| 146 |
+
st.error("π» **Low Conversion Chance**")
|
| 147 |
+
st.write("This customer is unlikely to purchase. **Recommended Action:** Do not prioritize.")
|
| 148 |
+
st.progress(prediction_prob)
|