Sricharan451706 commited on
Commit
797b583
·
verified ·
1 Parent(s): f574ada

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -96
app.py CHANGED
@@ -1,96 +1,96 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import joblib
4
- import numpy as np
5
- from huggingface_hub import hf_hub_download
6
-
7
- # Configuration
8
- HF_USERNAME = "Sricharan451706"
9
- HF_MODEL_REPO = f"{HF_USERNAME}/tourism-prediction-model"
10
-
11
- st.title("Wellness Tourism Package Prediction")
12
- st.write("Enter customer details to predict if they will purchase the package.")
13
-
14
- @st.cache_resource
15
- def load_model():
16
- try:
17
- # Try loading locally first for development
18
- model = joblib.load("models/model.joblib")
19
- return model
20
- except:
21
- # Load from Hugging Face
22
- try:
23
- model_path = hf_hub_download(repo_id=HF_MODEL_REPO, filename="model.joblib")
24
- model = joblib.load(model_path)
25
- return model
26
- except Exception as e:
27
- st.error(f"Error loading model: {e}")
28
- return None
29
-
30
- model = load_model()
31
-
32
- if model:
33
- # Input form
34
- with st.form("prediction_form"):
35
- col1, col2 = st.columns(2)
36
-
37
- with col1:
38
- age = st.number_input("Age", min_value=18, max_value=100, value=30)
39
- type_of_contact = st.selectbox("Type of Contact", ["Company Invited", "Self Inquiry"])
40
- city_tier = st.selectbox("City Tier", [1, 2, 3])
41
- occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"])
42
- gender = st.selectbox("Gender", ["Male", "Female"])
43
- number_of_person_visiting = st.number_input("Number of Person Visiting", min_value=1, value=2)
44
- preferred_property_star = st.selectbox("Preferred Property Star", [3.0, 4.0, 5.0])
45
- marital_status = st.selectbox("Marital Status", ["Married", "Divorced", "Single", "Unmarried"])
46
- number_of_trips = st.number_input("Number of Trips", min_value=0, value=1)
47
-
48
- with col2:
49
- passport = st.selectbox("Passport", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
50
- own_car = st.selectbox("Own Car", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
51
- number_of_children_visiting = st.number_input("Number of Children Visiting", min_value=0, value=0)
52
- designation = st.selectbox("Designation", ["Manager", "Executive", "Senior Manager", "AVP", "VP"])
53
- monthly_income = st.number_input("Monthly Income", min_value=0, value=20000)
54
- pitch_satisfaction_score = st.slider("Pitch Satisfaction Score", 1, 5, 3)
55
- product_pitched = st.selectbox("Product Pitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"])
56
- number_of_followups = st.number_input("Number of Followups", min_value=0, value=3)
57
- duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0, value=10)
58
-
59
- submitted = st.form_submit_button("Predict")
60
-
61
- if submitted:
62
- # Create dataframe from inputs
63
- input_data = pd.DataFrame({
64
- 'Age': [age],
65
- 'TypeofContact': [type_of_contact],
66
- 'CityTier': [city_tier],
67
- 'Occupation': [occupation],
68
- 'Gender': [gender],
69
- 'NumberOfPersonVisiting': [number_of_person_visiting],
70
- 'PreferredPropertyStar': [preferred_property_star],
71
- 'MaritalStatus': [marital_status],
72
- 'NumberOfTrips': [number_of_trips],
73
- 'Passport': [passport],
74
- 'OwnCar': [own_car],
75
- 'NumberOfChildrenVisiting': [number_of_children_visiting],
76
- 'Designation': [designation],
77
- 'MonthlyIncome': [monthly_income],
78
- 'PitchSatisfactionScore': [pitch_satisfaction_score],
79
- 'ProductPitched': [product_pitched],
80
- 'NumberOfFollowups': [number_of_followups],
81
- 'DurationOfPitch': [duration_of_pitch]
82
- })
83
-
84
- # Make prediction using the pipeline
85
- # The pipeline handles encoding and scaling automatically
86
- try:
87
- prediction = model.predict(input_data)[0]
88
- probability = model.predict_proba(input_data)[0][1]
89
-
90
- if prediction == 1:
91
- st.success(f"Prediction: Will Purchase (Probability: {probability:.2f})")
92
- else:
93
- st.warning(f"Prediction: Will Not Purchase (Probability: {probability:.2f})")
94
- except Exception as e:
95
- st.error(f"Prediction Error: {e}")
96
- st.info("Ensure all columns used in training are provided in the input dataframe.")
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import numpy as np
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ # Configuration
8
+ HF_USERNAME = "Sricharan451706"
9
+ HF_MODEL_REPO = f"{HF_USERNAME}/Tourism-Package-Predictor"
10
+
11
+ st.title("Wellness Tourism Package Prediction")
12
+ st.write("Enter customer details to predict if they will purchase the package.")
13
+
14
+ @st.cache_resource
15
+ def load_model():
16
+ try:
17
+ # Try loading locally first for development
18
+ model = joblib.load("models/model.joblib")
19
+ return model
20
+ except:
21
+ # Load from Hugging Face
22
+ try:
23
+ model_path = hf_hub_download(repo_id=HF_MODEL_REPO, filename="model.joblib")
24
+ model = joblib.load(model_path)
25
+ return model
26
+ except Exception as e:
27
+ st.error(f"Error loading model: {e}")
28
+ return None
29
+
30
+ model = load_model()
31
+
32
+ if model:
33
+ # Input form
34
+ with st.form("prediction_form"):
35
+ col1, col2 = st.columns(2)
36
+
37
+ with col1:
38
+ age = st.number_input("Age", min_value=18, max_value=100, value=30)
39
+ type_of_contact = st.selectbox("Type of Contact", ["Company Invited", "Self Inquiry"])
40
+ city_tier = st.selectbox("City Tier", [1, 2, 3])
41
+ occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"])
42
+ gender = st.selectbox("Gender", ["Male", "Female"])
43
+ number_of_person_visiting = st.number_input("Number of Person Visiting", min_value=1, value=2)
44
+ preferred_property_star = st.selectbox("Preferred Property Star", [3.0, 4.0, 5.0])
45
+ marital_status = st.selectbox("Marital Status", ["Married", "Divorced", "Single", "Unmarried"])
46
+ number_of_trips = st.number_input("Number of Trips", min_value=0, value=1)
47
+
48
+ with col2:
49
+ passport = st.selectbox("Passport", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
50
+ own_car = st.selectbox("Own Car", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
51
+ number_of_children_visiting = st.number_input("Number of Children Visiting", min_value=0, value=0)
52
+ designation = st.selectbox("Designation", ["Manager", "Executive", "Senior Manager", "AVP", "VP"])
53
+ monthly_income = st.number_input("Monthly Income", min_value=0, value=20000)
54
+ pitch_satisfaction_score = st.slider("Pitch Satisfaction Score", 1, 5, 3)
55
+ product_pitched = st.selectbox("Product Pitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"])
56
+ number_of_followups = st.number_input("Number of Followups", min_value=0, value=3)
57
+ duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0, value=10)
58
+
59
+ submitted = st.form_submit_button("Predict")
60
+
61
+ if submitted:
62
+ # Create dataframe from inputs
63
+ input_data = pd.DataFrame({
64
+ 'Age': [age],
65
+ 'TypeofContact': [type_of_contact],
66
+ 'CityTier': [city_tier],
67
+ 'Occupation': [occupation],
68
+ 'Gender': [gender],
69
+ 'NumberOfPersonVisiting': [number_of_person_visiting],
70
+ 'PreferredPropertyStar': [preferred_property_star],
71
+ 'MaritalStatus': [marital_status],
72
+ 'NumberOfTrips': [number_of_trips],
73
+ 'Passport': [passport],
74
+ 'OwnCar': [own_car],
75
+ 'NumberOfChildrenVisiting': [number_of_children_visiting],
76
+ 'Designation': [designation],
77
+ 'MonthlyIncome': [monthly_income],
78
+ 'PitchSatisfactionScore': [pitch_satisfaction_score],
79
+ 'ProductPitched': [product_pitched],
80
+ 'NumberOfFollowups': [number_of_followups],
81
+ 'DurationOfPitch': [duration_of_pitch]
82
+ })
83
+
84
+ # Make prediction using the pipeline
85
+ # The pipeline handles encoding and scaling automatically
86
+ try:
87
+ prediction = model.predict(input_data)[0]
88
+ probability = model.predict_proba(input_data)[0][1]
89
+
90
+ if prediction == 1:
91
+ st.success(f"Prediction: Will Purchase (Probability: {probability:.2f})")
92
+ else:
93
+ st.warning(f"Prediction: Will Not Purchase (Probability: {probability:.2f})")
94
+ except Exception as e:
95
+ st.error(f"Prediction Error: {e}")
96
+ st.info("Ensure all columns used in training are provided in the input dataframe.")