Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -4,20 +4,26 @@ import joblib
|
|
| 4 |
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
-
|
| 8 |
MODEL_REPO_ID = "bhumitps/tourism_model"
|
| 9 |
-
MODEL_FILENAME = "
|
| 10 |
|
| 11 |
|
| 12 |
@st.cache_resource
|
| 13 |
def load_model():
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
model = load_model()
|
|
@@ -60,7 +66,6 @@ with col2:
|
|
| 60 |
st.markdown("---")
|
| 61 |
|
| 62 |
if st.button("Predict"):
|
| 63 |
-
# Build a single-row DataFrame. Column names must match training features.
|
| 64 |
input_data = pd.DataFrame([{
|
| 65 |
"Age": Age,
|
| 66 |
"TypeofContact": TypeofContact,
|
|
@@ -82,8 +87,6 @@ if st.button("Predict"):
|
|
| 82 |
"MonthlyIncome": MonthlyIncome,
|
| 83 |
}])
|
| 84 |
|
| 85 |
-
# The training pipeline (data_prep + train.py) used label encoding and scaling.
|
| 86 |
-
# This app relies on the model pipeline's own preprocessing, so we pass raw values.
|
| 87 |
pred_proba = model.predict_proba(input_data)[0][1]
|
| 88 |
pred_label = model.predict(input_data)[0]
|
| 89 |
|
|
|
|
| 4 |
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
|
|
|
| 7 |
MODEL_REPO_ID = "bhumitps/tourism_model"
|
| 8 |
+
MODEL_FILENAME = "best_tourism_model_v2.joblib"
|
| 9 |
|
| 10 |
|
| 11 |
@st.cache_resource
|
| 12 |
def load_model():
|
| 13 |
+
st.write("Loading model from Hugging Face Hub...") # simple log in UI
|
| 14 |
+
try:
|
| 15 |
+
model_path = hf_hub_download(
|
| 16 |
+
repo_id=MODEL_REPO_ID,
|
| 17 |
+
filename=MODEL_FILENAME,
|
| 18 |
+
repo_type="model",
|
| 19 |
+
force_download=True,
|
| 20 |
+
)
|
| 21 |
+
model = joblib.load(model_path)
|
| 22 |
+
st.write("Model loaded successfully.")
|
| 23 |
+
return model
|
| 24 |
+
except Exception as e:
|
| 25 |
+
st.error(f"Error loading model: {e}")
|
| 26 |
+
raise
|
| 27 |
|
| 28 |
|
| 29 |
model = load_model()
|
|
|
|
| 66 |
st.markdown("---")
|
| 67 |
|
| 68 |
if st.button("Predict"):
|
|
|
|
| 69 |
input_data = pd.DataFrame([{
|
| 70 |
"Age": Age,
|
| 71 |
"TypeofContact": TypeofContact,
|
|
|
|
| 87 |
"MonthlyIncome": MonthlyIncome,
|
| 88 |
}])
|
| 89 |
|
|
|
|
|
|
|
| 90 |
pred_proba = model.predict_proba(input_data)[0][1]
|
| 91 |
pred_label = model.predict(input_data)[0]
|
| 92 |
|