SharleyK commited on
Commit
b45d5bf
·
verified ·
1 Parent(s): 619f605

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +126 -0
app.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import numpy as np
5
+ import joblib
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ # Page configuration
9
+ st.set_page_config(
10
+ page_title="Tourism Package Predictor",
11
+ page_icon="✈️",
12
+ layout="wide"
13
+ )
14
+
15
+ # Title and description
16
+ st.title("✈️ Wellness Tourism Package Purchase Predictor")
17
+ st.markdown(""This application predicts whether a customer is likely to purchase the Wellness Tourism Package.
18
+ Enter customer details below to get a prediction.
19
+ "")
20
+
21
+ # Load model
22
+ @st.cache_resource
23
+ def load_model():
24
+ try:
25
+ model_path = hf_hub_download(
26
+ repo_id='SharleyK/tourism-package-model',
27
+ filename='best_model.pkl'
28
+ )
29
+ model = joblib.load(model_path)
30
+ return model
31
+ except Exception as e:
32
+ st.error(f"Error loading model: {e}")
33
+ return None
34
+
35
+ model = load_model()
36
+
37
+ # Create input form
38
+ st.header("Customer Information")
39
+
40
+ col1, col2, col3 = st.columns(3)
41
+
42
+ with col1:
43
+ age = st.number_input("Age", min_value=18, max_value=100, value=30)
44
+ city_tier = st.selectbox("City Tier", [1, 2, 3])
45
+ duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0.0, value=15.0)
46
+ occupation = st.selectbox("Occupation", ['Salaried', 'Freelancer', 'Small Business', 'Large Business'])
47
+ gender = st.selectbox("Gender", ['Male', 'Female'])
48
+
49
+ with col2:
50
+ num_persons = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=2)
51
+ num_followups = st.number_input("Number of Followups", min_value=0.0, value=3.0)
52
+ product_pitched = st.selectbox("Product Pitched", ['Basic', 'Standard', 'Deluxe', 'Super Deluxe', 'King'])
53
+ preferred_star = st.selectbox("Preferred Property Star", [3.0, 4.0, 5.0])
54
+ marital_status = st.selectbox("Marital Status", ['Single', 'Married', 'Divorced', 'Unmarried'])
55
+
56
+ with col3:
57
+ num_trips = st.number_input("Number of Trips Per Year", min_value=0.0, value=2.0)
58
+ passport = st.selectbox("Has Passport", ['Yes', 'No'])
59
+ pitch_satisfaction = st.slider("Pitch Satisfaction Score", 1, 5, 3)
60
+ own_car = st.selectbox("Owns Car", ['Yes', 'No'])
61
+ num_children = st.number_input("Number of Children Visiting", min_value=0.0, value=0.0)
62
+
63
+ col4, col5 = st.columns(2)
64
+ with col4:
65
+ designation = st.selectbox("Designation", ['Executive', 'Manager', 'Senior Manager', 'AVP', 'VP'])
66
+ with col5:
67
+ monthly_income = st.number_input("Monthly Income", min_value=0.0, value=25000.0)
68
+
69
+ type_of_contact = st.selectbox("Type of Contact", ['Company Invited', 'Self Inquiry'])
70
+
71
+ # Prediction button
72
+ if st.button("Predict Purchase Probability", type="primary"):
73
+ if model is not None:
74
+ # Create input dataframe
75
+ # Note: Adjust feature order and encoding based on your actual model
76
+ input_data = pd.DataFrame({
77
+ 'Age': [age],
78
+ 'TypeofContact': [1 if type_of_contact == 'Company Invited' else 0],
79
+ 'CityTier': [city_tier],
80
+ 'DurationOfPitch': [duration_of_pitch],
81
+ 'Occupation': [['Salaried', 'Freelancer', 'Small Business', 'Large Business'].index(occupation)],
82
+ 'Gender': [0 if gender == 'Male' else 1],
83
+ 'NumberOfPersonVisiting': [num_persons],
84
+ 'NumberOfFollowups': [num_followups],
85
+ 'ProductPitched': [['Basic', 'Standard', 'Deluxe', 'Super Deluxe', 'King'].index(product_pitched)],
86
+ 'PreferredPropertyStar': [preferred_star],
87
+ 'MaritalStatus': [['Single', 'Married', 'Divorced', 'Unmarried'].index(marital_status)],
88
+ 'NumberOfTrips': [num_trips],
89
+ 'Passport': [1 if passport == 'Yes' else 0],
90
+ 'PitchSatisfactionScore': [pitch_satisfaction],
91
+ 'OwnCar': [1 if own_car == 'Yes' else 0],
92
+ 'NumberOfChildrenVisiting': [num_children],
93
+ 'Designation': [['Executive', 'Manager', 'Senior Manager', 'AVP', 'VP'].index(designation)],
94
+ 'MonthlyIncome': [monthly_income]
95
+ })
96
+
97
+ # Make prediction
98
+ try:
99
+ prediction = model.predict(input_data)[0]
100
+ probability = model.predict_proba(input_data)[0]
101
+
102
+ st.success("Prediction Complete!")
103
+
104
+ col_pred1, col_pred2 = st.columns(2)
105
+
106
+ with col_pred1:
107
+ st.metric("Prediction", "Will Purchase" if prediction == 1 else "Will Not Purchase")
108
+
109
+ with col_pred2:
110
+ st.metric("Confidence", f"{max(probability)*100:.2f}%")
111
+
112
+ # Recommendation
113
+ if prediction == 1:
114
+ st.balloons()
115
+ st.info("🎯 **Recommendation:** This customer has a high likelihood of purchasing. Consider prioritizing this lead!")
116
+ else:
117
+ st.warning("💡 **Recommendation:** This customer may need more engagement. Consider additional followups or tailored offers.")
118
+
119
+ except Exception as e:
120
+ st.error(f"Prediction error: {e}")
121
+ else:
122
+ st.error("Model not loaded. Please check the configuration.")
123
+
124
+ # Footer
125
+ st.markdown("---")
126
+ st.markdown("Built with ❤️ using Streamlit | Powered by Visit with Us")