Download src/streamlit_app.py from MSK34/Mall-Customer-Segmentation: direct link, hf CLI and curl.
- Browser
- Download file 693 Bytes
-
https://huggingface.co/spaces/MSK34/Mall-Customer-Segmentation/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/MSK34/Mall-Customer-Segmentation/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/MSK34/Mall-Customer-Segmentation/resolve/main/src/streamlit_app.py
693 Bytes
| import streamlit as st | |
| import pandas as pd | |
| import joblib | |
| model = joblib.load("src/kmeans_model.pkl") | |
| scaler = joblib.load("src/scaler.pkl") | |
| st.title("Mall Customer Segmentation") | |
| st.write( | |
| "Customer segmentation using KMeans Clustering" | |
| ) | |
| income = st.slider( | |
| "Annual Income (k$)", | |
| 0, | |
| 150, | |
| 50 | |
| ) | |
| spending = st.slider( | |
| "Spending Score", | |
| 1, | |
| 100, | |
| 50 | |
| ) | |
| input_data = pd.DataFrame({ | |
| "Annual Income (k$)": [income], | |
| "Spending Score (1-100)": [spending] | |
| }) | |
| scaled_data = scaler.transform(input_data) | |
| prediction = model.predict(scaled_data)[0] | |
| if st.button("Predict Cluster"): | |
| st.success( | |
| f"Customer belongs to Cluster {prediction}" | |
| ) |