File size: 4,286 Bytes
f2063fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# tourism_project/deployment/app.py
import streamlit as st
import pandas as pd
from huggingface_hub import hf_hub_download
import joblib
import os

st.set_page_config(page_title="Visa With Us - Prediction App", layout="centered")

# --------------------------
# CONFIG
# --------------------------
MODEL_REPO = "Dewasheesh/test-mlops"
MODEL_FILENAME = "best_test-mlops_v1.joblib"

@st.cache_resource
def load_model(repo_id: str, filename: str):
    """Download and load joblib model from Hugging Face Hub (cached)."""
    try:
        #st.info("Loading model...")
        model_path = hf_hub_download(repo_id=repo_id, filename=filename)
        model = joblib.load(model_path)
        return model
    except Exception as e:
        st.error(f"Failed to load model: {e}")
        return None

model = load_model(MODEL_REPO, MODEL_FILENAME)

st.title("Visa With Us - Prediction App")
st.write(
    "This app predicts whether a customer will purchase the Wellness Tourism Package."
)

st.markdown("---")
st.header("Features")

# Numeric Inputs
Age = st.number_input("Age", min_value=0, max_value=120, value=35)
CityTier = st.selectbox("City Tier", [1, 2, 3], index=1)
DurationOfPitch = st.number_input("Duration Of Pitch (minutes)", 0, 600, 10)
NumberOfPersonVisiting = st.number_input("Number Of Persons Visiting", 1, 20, 2)
NumberOfFollowups = st.number_input("Number Of Followups", 0, 50, 1)
PreferredPropertyStar = st.number_input("Preferred Property Star", 1, 7, 4)
NumberOfTrips = st.number_input("Number Of Trips (past)", 0, 50, 2)
Passport = st.selectbox("Passport", [1, 0], index=1)
PitchSatisfactionScore = st.slider("Pitch Satisfaction Score", 0, 10, 7)
OwnCar = st.selectbox("Own Car", [1, 0], index=1)
NumberOfChildrenVisiting = st.number_input("Number Of Children Visiting", 0, 10, 0)
MonthlyIncome = st.number_input("Monthly Income", 0, 10_000_000, 50000, step=1000)


# --------------------------
# CATEGORICAL VALUES
# --------------------------
TYPEOFCONTACT = ["Self Enquiry", "Company Invited"]

OCCUPATION = ["Salaried", "Small Business", "Large Business", "Free Lancer"]

GENDER = ["Male", "Female"]

PRODUCTPITCHED = ["Basic", "Deluxe", "Standard", "Super Deluxe", "King"]

MARITALSTATUS = ["Married", "Divorced", "Unmarried"]

DESIGNATION = ["Executive", "Manager", "Senior Manager", "AVP", "VP"]

# Selectboxes for categories
TypeofContact = st.selectbox("Type of Contact", TYPEOFCONTACT)
Occupation = st.selectbox("Occupation", OCCUPATION)
Gender = st.selectbox("Gender", GENDER)
ProductPitched = st.selectbox("Product Pitched", PRODUCTPITCHED)
MaritalStatus = st.selectbox("Marital Status", MARITALSTATUS)
Designation = st.selectbox("Designation", DESIGNATION)

# Assemble input
input_data = pd.DataFrame([{
    "Age": Age,
    "CityTier": CityTier,
    "DurationOfPitch": DurationOfPitch,
    "NumberOfPersonVisiting": NumberOfPersonVisiting,
    "NumberOfFollowups": NumberOfFollowups,
    "PreferredPropertyStar": PreferredPropertyStar,
    "NumberOfTrips": NumberOfTrips,
    "Passport": Passport,
    "PitchSatisfactionScore": PitchSatisfactionScore,
    "OwnCar": OwnCar,
    "NumberOfChildrenVisiting": NumberOfChildrenVisiting,
    "MonthlyIncome": MonthlyIncome,

    "TypeofContact": TypeofContact,
    "Occupation": Occupation,
    "Gender": Gender,
    "ProductPitched": ProductPitched,
    "MaritalStatus": MaritalStatus,
    "Designation": Designation,
}])

st.markdown("### Preview Input")
st.dataframe(input_data)

# --------------------------
# PREDICT
# --------------------------
if st.button("Predict"):
    if model is None:
        st.error("Model not loaded.")
    else:
        try:
            pred = model.predict(input_data)[0]

            # probability
            proba_text = ""
            if hasattr(model, "predict_proba"):
                proba = model.predict_proba(input_data)
                if proba.shape[1] == 2:
                    proba_text = f" (Probability: {proba[0,1]:.3f})"

            result = "Purchase" if int(pred) == 1 else "No Purchase"
            st.success(f"Prediction: **{result}**{proba_text}")

        except Exception as e:
            st.error(f"Prediction failed: {e}")

st.markdown("---")
st.caption("All categorical fields are restricted to valid training values to prevent model mismatch.")