Spaces:
No application file
No application file
Upload folder using huggingface_hub
Browse files- app.py +16 -27
- requirements.txt +5 -1
app.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Set the title of the Streamlit app
|
| 6 |
st.title("ExtraaLearn Customer Predictor")
|
| 7 |
st.subheader("Online Prediction")
|
| 8 |
|
|
|
|
| 9 |
# Collect user input for property features
|
| 10 |
age = st.number_input("age", min_value=5, max_value=90, step=1, value=30)
|
| 11 |
website_visits = st.number_input("website_visits", min_value=0, step=1, value=1)
|
|
@@ -38,28 +42,13 @@ input_data = pd.DataFrame([{
|
|
| 38 |
'referral' : 'referral'
|
| 39 |
}])
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
response = requests.post("https://<username>-<repo_id>.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 44 |
-
if response.status_code == 200:
|
| 45 |
-
prediction = response.json()['Predicted Price (in dollars)']
|
| 46 |
-
st.success(f"Predicted Rental Price (in dollars): {prediction}")
|
| 47 |
-
else:
|
| 48 |
-
st.error("Error making prediction.")
|
| 49 |
-
|
| 50 |
-
# Section for batch prediction
|
| 51 |
-
st.subheader("Batch Prediction")
|
| 52 |
-
|
| 53 |
-
# Allow users to upload a CSV file for batch prediction
|
| 54 |
-
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
if
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
st.write(predictions) # Display the predictions
|
| 64 |
-
else:
|
| 65 |
-
st.error("Error making batch prediction.")
|
|
|
|
| 1 |
+
|
| 2 |
+
# Load the trained model
|
| 3 |
+
def load_model():
|
| 4 |
+
return joblib.load("backend_files/customer_prediction_model_v1_0.joblib")
|
| 5 |
+
|
| 6 |
+
model = load_model()
|
| 7 |
|
| 8 |
# Set the title of the Streamlit app
|
| 9 |
st.title("ExtraaLearn Customer Predictor")
|
| 10 |
st.subheader("Online Prediction")
|
| 11 |
|
| 12 |
+
# Collect user input based on dataset columns
|
| 13 |
# Collect user input for property features
|
| 14 |
age = st.number_input("age", min_value=5, max_value=90, step=1, value=30)
|
| 15 |
website_visits = st.number_input("website_visits", min_value=0, step=1, value=1)
|
|
|
|
| 42 |
'referral' : 'referral'
|
| 43 |
}])
|
| 44 |
|
| 45 |
+
# Set classification threshold
|
| 46 |
+
classification_threshold = 0.5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# Predict button
|
| 49 |
+
if st.button("Predict"):
|
| 50 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 51 |
+
prediction = (prediction_proba >= classification_threshold).astype(int)
|
| 52 |
+
result = "Join" if prediction == 1 else "not join"
|
| 53 |
+
st.write(f"Prediction: The customer is likely to **{result}**.")
|
| 54 |
+
st.write(f"Churn Probability: {prediction_proba:.2f}")
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
| 1 |
pandas==2.2.2
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
streamlit==1.43.2
|
|
|
|
| 1 |
+
|
| 2 |
pandas==2.2.2
|
| 3 |
+
numpy==2.0.2
|
| 4 |
+
scikit-learn==1.6.1
|
| 5 |
+
xgboost==2.1.4
|
| 6 |
+
joblib==1.4.2
|
| 7 |
streamlit==1.43.2
|