Spaces:
Sleeping
Sleeping
Commit
·
ff3d566
1
Parent(s):
44c5a0b
feat: updated website
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
import matplotlib.pyplot as plt
|
@@ -259,34 +260,29 @@ elif page == "Customer Analysis":
|
|
259 |
|
260 |
if st.button("Calcular"):
|
261 |
if customer_code:
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
cluster = customer_match['cluster_id'].values[0]
|
267 |
-
st.write(f"Customer {customer_code} belongs to cluster {cluster}")
|
268 |
|
|
|
|
|
|
|
|
|
|
|
269 |
# Load the Corresponding Model
|
270 |
model_path = f'models/modelo_cluster_{cluster}.txt'
|
271 |
gbm = lgb.Booster(model_file=model_path)
|
272 |
-
st.
|
273 |
-
|
274 |
-
# Inspect the model
|
275 |
-
st.write("### Model Information:")
|
276 |
-
st.write(f"Number of trees: {gbm.num_trees()}")
|
277 |
-
st.write(f"Number of features: {gbm.num_feature()}")
|
278 |
-
st.write("Feature names:")
|
279 |
-
st.write(gbm.feature_name())
|
280 |
|
|
|
281 |
# Load predict data for that cluster
|
282 |
predict_data = pd.read_csv(f'predicts/predict_cluster_{cluster}.csv')
|
283 |
|
284 |
# Convert cliente_id to string
|
285 |
predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
|
286 |
-
|
287 |
-
|
288 |
-
st.write(predict_data.head())
|
289 |
-
st.write(f"Shape: {predict_data.shape}")
|
290 |
|
291 |
# Filter for the specific customer
|
292 |
customer_code_str = str(customer_code)
|
|
|
1 |
import streamlit as st
|
2 |
+
import time
|
3 |
import pandas as pd
|
4 |
import plotly.express as px
|
5 |
import matplotlib.pyplot as plt
|
|
|
260 |
|
261 |
if st.button("Calcular"):
|
262 |
if customer_code:
|
263 |
+
with st.spinner("We are identifying the customer's cluster..."):
|
264 |
+
# Find Customer's Cluster
|
265 |
+
customer_match = customer_clusters[customer_clusters['cliente_id'] == customer_code]
|
266 |
+
|
|
|
|
|
267 |
|
268 |
+
if not customer_match.empty:
|
269 |
+
cluster = customer_match['cluster_id'].values[0]
|
270 |
+
st.success(f"Customer {customer_code} belongs to cluster {cluster}")
|
271 |
+
|
272 |
+
with st.spinner(f"Loading customer model for cluster {cluster}..."):
|
273 |
# Load the Corresponding Model
|
274 |
model_path = f'models/modelo_cluster_{cluster}.txt'
|
275 |
gbm = lgb.Booster(model_file=model_path)
|
276 |
+
st.success(f"Loaded model for cluster {cluster}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
+
with st.spinner("Getting the data ready..."):
|
279 |
# Load predict data for that cluster
|
280 |
predict_data = pd.read_csv(f'predicts/predict_cluster_{cluster}.csv')
|
281 |
|
282 |
# Convert cliente_id to string
|
283 |
predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
|
284 |
+
|
285 |
+
with st.spinner("Filtering for your customer..."):
|
|
|
|
|
286 |
|
287 |
# Filter for the specific customer
|
288 |
customer_code_str = str(customer_code)
|