Spaces:
Sleeping
Sleeping
Update deployment files via CI/CD
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import joblib
|
|
| 7 |
# Load the trained tourism model
|
| 8 |
# -----------------------------
|
| 9 |
model_path = hf_hub_download(
|
| 10 |
-
repo_id="absethi1894/churn-model",
|
| 11 |
filename="best_tourism_model_v1.joblib"
|
| 12 |
)
|
| 13 |
model = joblib.load(model_path)
|
|
@@ -31,43 +31,69 @@ age = st.number_input("Age", min_value=18, max_value=80, value=30)
|
|
| 31 |
designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager", "AVP", "VP"])
|
| 32 |
occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"])
|
| 33 |
monthly_income = st.number_input("Monthly Income (INR)", min_value=10000, max_value=500000, value=50000, step=1000)
|
|
|
|
| 34 |
num_trips = st.number_input("Number of Trips", min_value=0, max_value=50, value=1)
|
| 35 |
num_person_visiting = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=2)
|
| 36 |
num_children = st.number_input("Number of Children Visiting", min_value=0, max_value=5, value=0)
|
|
|
|
| 37 |
passport = st.selectbox("Passport", [0, 1])
|
| 38 |
own_car = st.selectbox("Own Car", [0, 1])
|
|
|
|
| 39 |
duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0, max_value=100, value=15)
|
| 40 |
num_followups = st.number_input("Number of Followups", min_value=0, max_value=10, value=1)
|
| 41 |
preferred_star = st.selectbox("Preferred Property Star", [3, 4, 5])
|
| 42 |
product_pitched = st.selectbox("Product Pitched", ["Basic", "Deluxe", "Standard", "Super Deluxe", "King"])
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# -----------------------------
|
| 46 |
# Create DataFrame for prediction
|
| 47 |
# -----------------------------
|
| 48 |
input_data = pd.DataFrame([{
|
| 49 |
-
'Gender': gender,
|
| 50 |
-
'MaritalStatus': marital_status,
|
| 51 |
'Age': age,
|
| 52 |
-
'
|
|
|
|
|
|
|
| 53 |
'Occupation': occupation,
|
| 54 |
-
'
|
| 55 |
-
'NumberOfTrips': num_trips,
|
| 56 |
'NumberOfPersonVisiting': num_person_visiting,
|
| 57 |
-
'NumberOfChildrenVisiting': num_children,
|
| 58 |
-
'Passport': passport,
|
| 59 |
-
'OwnCar': own_car,
|
| 60 |
-
'DurationOfPitch': duration_of_pitch,
|
| 61 |
'NumberOfFollowups': num_followups,
|
| 62 |
-
'PreferredPropertyStar': preferred_star,
|
| 63 |
'ProductPitched': product_pitched,
|
| 64 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}])
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
input_data[col] = input_data[col].astype('category')
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# -----------------------------
|
| 72 |
# Prediction
|
| 73 |
# -----------------------------
|
|
|
|
| 7 |
# Load the trained tourism model
|
| 8 |
# -----------------------------
|
| 9 |
model_path = hf_hub_download(
|
| 10 |
+
repo_id="absethi1894/churn-model", # Your HF model repo
|
| 11 |
filename="best_tourism_model_v1.joblib"
|
| 12 |
)
|
| 13 |
model = joblib.load(model_path)
|
|
|
|
| 31 |
designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager", "AVP", "VP"])
|
| 32 |
occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"])
|
| 33 |
monthly_income = st.number_input("Monthly Income (INR)", min_value=10000, max_value=500000, value=50000, step=1000)
|
| 34 |
+
|
| 35 |
num_trips = st.number_input("Number of Trips", min_value=0, max_value=50, value=1)
|
| 36 |
num_person_visiting = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=2)
|
| 37 |
num_children = st.number_input("Number of Children Visiting", min_value=0, max_value=5, value=0)
|
| 38 |
+
|
| 39 |
passport = st.selectbox("Passport", [0, 1])
|
| 40 |
own_car = st.selectbox("Own Car", [0, 1])
|
| 41 |
+
|
| 42 |
duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0, max_value=100, value=15)
|
| 43 |
num_followups = st.number_input("Number of Followups", min_value=0, max_value=10, value=1)
|
| 44 |
preferred_star = st.selectbox("Preferred Property Star", [3, 4, 5])
|
| 45 |
product_pitched = st.selectbox("Product Pitched", ["Basic", "Deluxe", "Standard", "Super Deluxe", "King"])
|
| 46 |
+
|
| 47 |
+
# -----------------------------
|
| 48 |
+
# Default values for missing features
|
| 49 |
+
# -----------------------------
|
| 50 |
+
default_values = {
|
| 51 |
+
"TypeofContact": "Self Enquiry", # replace with the most common value from training
|
| 52 |
+
"CityTier": 2 # replace with default numeric value from training
|
| 53 |
+
}
|
| 54 |
|
| 55 |
# -----------------------------
|
| 56 |
# Create DataFrame for prediction
|
| 57 |
# -----------------------------
|
| 58 |
input_data = pd.DataFrame([{
|
|
|
|
|
|
|
| 59 |
'Age': age,
|
| 60 |
+
'TypeofContact': default_values["TypeofContact"],
|
| 61 |
+
'CityTier': default_values["CityTier"],
|
| 62 |
+
'DurationOfPitch': duration_of_pitch,
|
| 63 |
'Occupation': occupation,
|
| 64 |
+
'Gender': gender,
|
|
|
|
| 65 |
'NumberOfPersonVisiting': num_person_visiting,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
'NumberOfFollowups': num_followups,
|
|
|
|
| 67 |
'ProductPitched': product_pitched,
|
| 68 |
+
'PreferredPropertyStar': preferred_star,
|
| 69 |
+
'MaritalStatus': marital_status,
|
| 70 |
+
'NumberOfTrips': num_trips,
|
| 71 |
+
'Passport': passport,
|
| 72 |
+
'PitchSatisfactionScore': 3, # or collect input
|
| 73 |
+
'OwnCar': own_car,
|
| 74 |
+
'NumberOfChildrenVisiting': num_children,
|
| 75 |
+
'Designation': designation,
|
| 76 |
+
'MonthlyIncome': monthly_income
|
| 77 |
}])
|
| 78 |
|
| 79 |
+
# -----------------------------
|
| 80 |
+
# Convert categorical columns to category type
|
| 81 |
+
# -----------------------------
|
| 82 |
+
categorical_cols = ['Gender', 'MaritalStatus', 'Designation', 'Occupation',
|
| 83 |
+
'ProductPitched', 'TypeofContact']
|
| 84 |
+
for col in categorical_cols:
|
| 85 |
input_data[col] = input_data[col].astype('category')
|
| 86 |
|
| 87 |
+
# -----------------------------
|
| 88 |
+
# Reorder columns to match training
|
| 89 |
+
# -----------------------------
|
| 90 |
+
feature_order = ['Age', 'TypeofContact', 'CityTier', 'DurationOfPitch', 'Occupation',
|
| 91 |
+
'Gender', 'NumberOfPersonVisiting', 'NumberOfFollowups', 'ProductPitched',
|
| 92 |
+
'PreferredPropertyStar', 'MaritalStatus', 'NumberOfTrips', 'Passport',
|
| 93 |
+
'PitchSatisfactionScore', 'OwnCar', 'NumberOfChildrenVisiting',
|
| 94 |
+
'Designation', 'MonthlyIncome']
|
| 95 |
+
input_data = input_data[feature_order]
|
| 96 |
+
|
| 97 |
# -----------------------------
|
| 98 |
# Prediction
|
| 99 |
# -----------------------------
|