Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +73 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,75 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Download and load the model
|
| 7 |
+
model_path = hf_hub_download(repo_id="PSstark/Machine-Learning-Prediction", filename="best_prediction_model_v1.joblib")
|
| 8 |
+
model = joblib.load(model_path)
|
| 9 |
+
|
| 10 |
+
# Streamlit UI for Machine Failure Prediction
|
| 11 |
+
st.title("Tourism Product Purchase Prediction App")
|
| 12 |
+
st.write("""
|
| 13 |
+
Welcome to the **Tourism Product Purchase Prediction App**! 🌍✨
|
| 14 |
+
|
| 15 |
+
This tool predicts whether a customer is likely to purchase a tourism product based on their personal details, preferences, and interaction history.
|
| 16 |
+
|
| 17 |
+
Please provide the customer information below, and the model will estimate the likelihood of them taking the product.
|
| 18 |
+
""")
|
| 19 |
+
|
| 20 |
+
# Basic demographic info
|
| 21 |
+
age = st.number_input("Customer Age", min_value=18, max_value=80, value=35)
|
| 22 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
| 23 |
+
marital_status = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
|
| 24 |
+
|
| 25 |
+
# Contact and occupation info
|
| 26 |
+
typeof_contact = st.selectbox("Type of Contact", ["Self Enquiry", "Company Invited"])
|
| 27 |
+
occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"])
|
| 28 |
+
|
| 29 |
+
# Travel and product preferences
|
| 30 |
+
city_tier = st.selectbox("City Tier", [1, 2, 3])
|
| 31 |
+
product_pitched = st.selectbox("Product Pitched", ["Basic", "Deluxe", "Standard", "Super Deluxe", "King"])
|
| 32 |
+
designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager", "AVP", "VP"])
|
| 33 |
+
|
| 34 |
+
# Numeric customer interaction details
|
| 35 |
+
duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0.0, max_value=100.0, value=10.0)
|
| 36 |
+
number_of_person_visiting = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=2)
|
| 37 |
+
number_of_followups = st.number_input("Number of Follow-ups", min_value=0, max_value=20, value=2)
|
| 38 |
+
preferred_property_star = st.selectbox("Preferred Property Star", [1, 2, 3, 4, 5])
|
| 39 |
+
number_of_trips = st.number_input("Number of Trips Taken", min_value=0, max_value=50, value=5)
|
| 40 |
+
pitch_satisfaction_score = st.slider("Pitch Satisfaction Score", min_value=1, max_value=5, value=3)
|
| 41 |
+
|
| 42 |
+
# Additional info
|
| 43 |
+
passport = st.selectbox("Passport", [0, 1])
|
| 44 |
+
own_car = st.selectbox("Own Car", [0, 1,2,3])
|
| 45 |
+
number_of_children_visiting = st.number_input("Number of Children Visiting", min_value=0, max_value=10, value=0)
|
| 46 |
+
monthly_income = st.number_input("Monthly Income", min_value=0.0, max_value=1000000.0, value=25000.0)
|
| 47 |
+
|
| 48 |
+
# 📊 Assemble all inputs into a DataFrame
|
| 49 |
+
input_data = pd.DataFrame([{
|
| 50 |
+
'Age': age,
|
| 51 |
+
'TypeofContact': typeof_contact,
|
| 52 |
+
'CityTier': city_tier,
|
| 53 |
+
'DurationOfPitch': duration_of_pitch,
|
| 54 |
+
'Occupation': occupation,
|
| 55 |
+
'Gender': gender,
|
| 56 |
+
'NumberOfPersonVisiting': number_of_person_visiting,
|
| 57 |
+
'NumberOfFollowups': number_of_followups,
|
| 58 |
+
'ProductPitched': product_pitched,
|
| 59 |
+
'PreferredPropertyStar': preferred_property_star,
|
| 60 |
+
'MaritalStatus': marital_status,
|
| 61 |
+
'NumberOfTrips': number_of_trips,
|
| 62 |
+
'Passport': passport,
|
| 63 |
+
'PitchSatisfactionScore': pitch_satisfaction_score,
|
| 64 |
+
'OwnCar': own_car,
|
| 65 |
+
'NumberOfChildrenVisiting': number_of_children_visiting,
|
| 66 |
+
'Designation': designation,
|
| 67 |
+
'MonthlyIncome': monthly_income
|
| 68 |
+
}])
|
| 69 |
|
| 70 |
+
# 🔮 Make prediction
|
| 71 |
+
if st.button("Predict Purchase"):
|
| 72 |
+
prediction = model.predict(input_data)[0]
|
| 73 |
+
result = "✅ Customer is Likely to Purchase the Product" if prediction == 1 else "❌ Customer is Unlikely to Purchase the Product"
|
| 74 |
+
st.subheader("Prediction Result:")
|
| 75 |
+
st.success(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|