Spaces:
Sleeping
Sleeping
File size: 3,317 Bytes
b643cf9 50a7cca b643cf9 | 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 | import os
os.environ["STREAMLIT_SERVER_ENABLE_CORS"] = "false"
os.environ["STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION"] = "false"
import streamlit as st
import pandas as pd
from huggingface_hub import hf_hub_download
import joblib
# --------------------------
# Load trained model from Hugging Face
# --------------------------
model_repo_id = "Disha252001/Tourism"
model_file = "best_model.pkl"
local_model_path = hf_hub_download(repo_id=model_repo_id, filename=model_file)
model = joblib.load(local_model_path)
# --------------------------
# Input form
# --------------------------
with st.form("input_form"):
Age = st.number_input("Age", min_value=0, max_value=120, value=35)
TypeofContact = st.selectbox("Type of Contact", ["Company Invited", "Self Inquiry"])
CityTier = st.selectbox("City Tier", [1, 2, 3], index=1)
Occupation = st.selectbox("Occupation", ["Salaried", "Freelancer", "Business", "Other"])
Gender = st.selectbox("Gender", ["Male", "Female"])
NumberOfPersonVisiting = st.number_input("Number Of Person Visiting", min_value=0, value=2)
PreferredPropertyStar = st.number_input("Preferred Property Star", min_value=1, max_value=7, value=5)
MaritalStatus = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
NumberOfTrips = st.number_input("Number Of Trips (annual)", min_value=0, value=2)
Passport = st.selectbox("Passport (0=No,1=Yes)", [0,1], index=1)
OwnCar = st.selectbox("Own Car (0=No,1=Yes)", [0,1], index=1)
NumberOfChildrenVisiting = st.number_input("Number Of Children Visiting (below 5)", min_value=0, value=0)
Designation = st.text_input("Designation", value="Manager")
MonthlyIncome = st.number_input("Monthly Income", min_value=0, value=50000)
PitchSatisfactionScore = st.number_input("Pitch Satisfaction Score (1-10)", min_value=0, max_value=10, value=8)
ProductPitched = st.selectbox("Product Pitched", ["Wellness Package", "Family Package", "Other"])
NumberOfFollowups = st.number_input("Number Of Followups", min_value=0, value=1)
DurationOfPitch = st.number_input("Duration Of Pitch (minutes)", min_value=0, value=10)
submitted = st.form_submit_button("Predict")
# --------------------------
# Convert inputs to DataFrame
# --------------------------
def build_input_df():
row = {
"Age": Age,
"TypeofContact": TypeofContact,
"CityTier": CityTier,
"Occupation": Occupation,
"Gender": Gender,
"NumberOfPersonVisiting": NumberOfPersonVisiting,
"PreferredPropertyStar": PreferredPropertyStar,
"MaritalStatus": MaritalStatus,
"NumberOfTrips": NumberOfTrips,
"Passport": Passport,
"OwnCar": OwnCar,
"NumberOfChildrenVisiting": NumberOfChildrenVisiting,
"Designation": Designation,
"MonthlyIncome": MonthlyIncome,
"PitchSatisfactionScore": PitchSatisfactionScore,
"ProductPitched": ProductPitched,
"NumberOfFollowups": NumberOfFollowups,
"DurationOfPitch": DurationOfPitch
}
return pd.DataFrame([row])
# --------------------------
# Predict and display result
# --------------------------
if submitted:
input_df = build_input_df()
prediction = model.predict(input_df)
st.success(f"Predicted ProdTaken: {int(prediction[0])}")
|