Spaces:
Sleeping
Sleeping
Commit
路
ca8d4de
1
Parent(s):
88346bc
bugfix: Manufacturers Alerts
Browse files
app.py
CHANGED
@@ -325,6 +325,10 @@ elif page == "Customer Analysis":
|
|
325 |
customer_code_str = str(customer_code)
|
326 |
customer_data = predict_data[predict_data['cliente_id'] == customer_code_str]
|
327 |
|
|
|
|
|
|
|
|
|
328 |
with st.spinner("Generating sales predictions..."):
|
329 |
if not customer_data.empty:
|
330 |
# Define features consistently with the training process
|
@@ -348,6 +352,9 @@ elif page == "Customer Analysis":
|
|
348 |
|
349 |
# Load actual data from df_agg_2024
|
350 |
actual_sales = df_agg_2024[df_agg_2024['cliente_id'] == customer_code_str]
|
|
|
|
|
|
|
351 |
|
352 |
if not actual_sales.empty:
|
353 |
# Merge predictions with actual sales
|
@@ -362,6 +369,12 @@ elif page == "Customer Analysis":
|
|
362 |
# Ensure any missing sales data is filled with 0
|
363 |
results['ventas_reales'].fillna(0, inplace=True)
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
# Define the cutoff date for the last 12 months
|
366 |
fecha_inicio = pd.to_datetime("2023-01-01")
|
367 |
fecha_corte = pd.to_datetime("2024-09-01")
|
@@ -954,33 +967,31 @@ elif page == "Customer Analysis":
|
|
954 |
# st.warning("Sales data for 2021-2023 not available in the dataset.")
|
955 |
|
956 |
|
|
|
957 |
# Customer Recommendations Page
|
958 |
elif page == "Articles Recommendations":
|
959 |
st.title("Articles Recommendations")
|
960 |
-
|
961 |
st.markdown("""
|
962 |
Get tailored recommendations for your customers based on their basket.
|
963 |
""")
|
964 |
-
|
965 |
st.write("Select items and assign quantities for the basket:")
|
966 |
-
|
967 |
# Mostrar lista de art铆culos disponibles
|
968 |
available_articles = productos['ARTICULO'].unique()
|
969 |
selected_articles = st.multiselect("Select Articles", available_articles)
|
970 |
-
|
971 |
# Crear inputs para ingresar las cantidades de cada art铆culo seleccionado
|
972 |
quantities = {}
|
973 |
for article in selected_articles:
|
974 |
quantities[article] = st.number_input(f"Quantity for {article}", min_value=0, step=1)
|
975 |
-
|
976 |
if st.button("Calcular"): # A帽adimos el bot贸n "Calcular"
|
977 |
-
|
978 |
-
new_basket = [
|
979 |
-
|
|
|
|
|
|
|
980 |
if new_basket:
|
981 |
# Procesar la lista para recomendar
|
982 |
recommendations_df = recomienda_tfid(new_basket)
|
983 |
-
|
984 |
if not recommendations_df.empty:
|
985 |
st.write("### Recommendations based on the current basket:")
|
986 |
st.dataframe(recommendations_df)
|
|
|
325 |
customer_code_str = str(customer_code)
|
326 |
customer_data = predict_data[predict_data['cliente_id'] == customer_code_str]
|
327 |
|
328 |
+
# Apply filter for the selected manufacturer if not showing all manufacturers
|
329 |
+
if selected_manufacturer:
|
330 |
+
customer_data = customer_data[customer_data['marca_id_encoded'] == selected_manufacturer]
|
331 |
+
|
332 |
with st.spinner("Generating sales predictions..."):
|
333 |
if not customer_data.empty:
|
334 |
# Define features consistently with the training process
|
|
|
352 |
|
353 |
# Load actual data from df_agg_2024
|
354 |
actual_sales = df_agg_2024[df_agg_2024['cliente_id'] == customer_code_str]
|
355 |
+
|
356 |
+
if selected_manufacturer:
|
357 |
+
actual_sales = actual_sales[actual_sales['marca_id_encoded'] == selected_manufacturer]
|
358 |
|
359 |
if not actual_sales.empty:
|
360 |
# Merge predictions with actual sales
|
|
|
369 |
# Ensure any missing sales data is filled with 0
|
370 |
results['ventas_reales'].fillna(0, inplace=True)
|
371 |
|
372 |
+
# Filtrar los datos hist贸ricos por cliente y fabricante, si se ha seleccionado uno
|
373 |
+
filtered_historical_data = historical_data[
|
374 |
+
(historical_data['cliente_id'] == customer_code_str) &
|
375 |
+
(historical_data['marca_id_encoded'] == selected_manufacturer)
|
376 |
+
] if selected_manufacturer else historical_data[historical_data['cliente_id'] == customer_code_str]
|
377 |
+
|
378 |
# Define the cutoff date for the last 12 months
|
379 |
fecha_inicio = pd.to_datetime("2023-01-01")
|
380 |
fecha_corte = pd.to_datetime("2024-09-01")
|
|
|
967 |
# st.warning("Sales data for 2021-2023 not available in the dataset.")
|
968 |
|
969 |
|
970 |
+
# Customer Recommendations Page
|
971 |
# Customer Recommendations Page
|
972 |
elif page == "Articles Recommendations":
|
973 |
st.title("Articles Recommendations")
|
|
|
974 |
st.markdown("""
|
975 |
Get tailored recommendations for your customers based on their basket.
|
976 |
""")
|
|
|
977 |
st.write("Select items and assign quantities for the basket:")
|
|
|
978 |
# Mostrar lista de art铆culos disponibles
|
979 |
available_articles = productos['ARTICULO'].unique()
|
980 |
selected_articles = st.multiselect("Select Articles", available_articles)
|
|
|
981 |
# Crear inputs para ingresar las cantidades de cada art铆culo seleccionado
|
982 |
quantities = {}
|
983 |
for article in selected_articles:
|
984 |
quantities[article] = st.number_input(f"Quantity for {article}", min_value=0, step=1)
|
|
|
985 |
if st.button("Calcular"): # A帽adimos el bot贸n "Calcular"
|
986 |
+
# Crear una lista de art铆culos basada en la selecci贸n de c贸digos y cantidades
|
987 |
+
new_basket = []
|
988 |
+
for article in selected_articles:
|
989 |
+
quantity = quantities[article]
|
990 |
+
if quantity > 0:
|
991 |
+
new_basket.extend([article] * quantity) # A帽adir el c贸digo 'article' tantas veces como 'quantity'
|
992 |
if new_basket:
|
993 |
# Procesar la lista para recomendar
|
994 |
recommendations_df = recomienda_tfid(new_basket)
|
|
|
995 |
if not recommendations_df.empty:
|
996 |
st.write("### Recommendations based on the current basket:")
|
997 |
st.dataframe(recommendations_df)
|