Spaces:
Build error
Build error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,62 +1,50 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
)
|
| 12 |
model = joblib.load(model_path)
|
| 13 |
|
| 14 |
-
st.title("
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
owncar = st.selectbox("Own Car", [0, 1])
|
| 32 |
-
children = st.number_input("Number of Children Visiting", min_value=0, max_value=5, value=1)
|
| 33 |
-
designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager", "AVP", "VP"])
|
| 34 |
-
product = st.selectbox("Product Pitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"])
|
| 35 |
-
|
| 36 |
-
# Prediction
|
| 37 |
-
if st.button("Predict"):
|
| 38 |
input_df = pd.DataFrame([{
|
| 39 |
"Age": age,
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"NumberOfPersonVisiting": num_persons,
|
| 44 |
-
"NumberOfFollowups": followups,
|
| 45 |
-
"PreferredPropertyStar": star,
|
| 46 |
-
"MaritalStatus": marital,
|
| 47 |
-
"NumberOfTrips": trips,
|
| 48 |
-
"Passport": passport,
|
| 49 |
"MonthlyIncome": income,
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
}])
|
| 56 |
|
| 57 |
prediction = model.predict(input_df)[0]
|
| 58 |
if prediction == 1:
|
| 59 |
-
st.success("✅
|
| 60 |
else:
|
| 61 |
-
st.error("❌
|
|
|
|
| 62 |
|
|
|
|
| 1 |
+
# week_3_mls/deployment/app.py
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import joblib
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
+
# Load model from HF Hub
|
| 8 |
+
MODEL_REPO = "roshra/machine-failure-prediction"
|
| 9 |
+
MODEL_FILE = "tourism_clean_model.joblib"
|
| 10 |
+
|
| 11 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, repo_type="space")
|
|
|
|
| 12 |
model = joblib.load(model_path)
|
| 13 |
|
| 14 |
+
st.title("🧳 Tourism Package Purchase Prediction App")
|
| 15 |
+
st.write("Fill in details to predict if the customer will purchase the package.")
|
| 16 |
+
|
| 17 |
+
# UI inputs
|
| 18 |
+
age = st.number_input("Age", 18, 100, 30)
|
| 19 |
+
duration = st.number_input("Trip Duration (days)", 1, 30, 5)
|
| 20 |
+
adults = st.number_input("Number of Adults", 1, 10, 2)
|
| 21 |
+
children = st.number_input("Number of Children", 0, 10, 0)
|
| 22 |
+
income = st.number_input("Monthly Income", 1000, 200000, 30000)
|
| 23 |
+
|
| 24 |
+
prop = st.selectbox("Preferred Property", ["Hotel", "Resort", "Guest House", "Other"])
|
| 25 |
+
travel = st.selectbox("Mode of Travel", ["Air", "Train", "Car", "Bus"])
|
| 26 |
+
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
| 27 |
+
occupation = st.selectbox("Occupation", ["Salaried", "Self-Employed", "Business", "Other"])
|
| 28 |
+
marital = st.selectbox("Marital Status", ["Single", "Married", "Divorced", "Other"])
|
| 29 |
+
|
| 30 |
+
if st.button("Predict Purchase"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
input_df = pd.DataFrame([{
|
| 32 |
"Age": age,
|
| 33 |
+
"Duration": duration,
|
| 34 |
+
"NumberOfAdults": adults,
|
| 35 |
+
"NumberOfChildren": children,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
"MonthlyIncome": income,
|
| 37 |
+
"PreferredProperty": prop,
|
| 38 |
+
"ModeOfTravel": travel,
|
| 39 |
+
"Gender": gender,
|
| 40 |
+
"Occupation": occupation,
|
| 41 |
+
"MaritalStatus": marital
|
| 42 |
}])
|
| 43 |
|
| 44 |
prediction = model.predict(input_df)[0]
|
| 45 |
if prediction == 1:
|
| 46 |
+
st.success("✅ Customer is likely to purchase the package!")
|
| 47 |
else:
|
| 48 |
+
st.error("❌ Customer is unlikely to purchase the package.")
|
| 49 |
+
|
| 50 |
|