GMARTINEZMILLA commited on
Commit
02c25ad
·
1 Parent(s): 862597e

feat: updated version app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -9,20 +9,20 @@ from sklearn.metrics.pairwise import cosine_similarity
9
  # Page configuration
10
  st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
11
 
12
- # Load CSV files
13
  df = pd.read_csv("df_clean.csv")
14
  nombres_proveedores = pd.read_csv("nombres_proveedores.csv", sep=';')
15
  euros_proveedor = pd.read_csv("euros_proveedor.csv", sep=',')
16
  ventas_clientes = pd.read_csv("ventas_clientes.csv", sep=',')
 
17
 
18
  # Ensure customer codes are strings
19
  df['CLIENTE'] = df['CLIENTE'].astype(str)
20
  nombres_proveedores['codigo'] = nombres_proveedores['codigo'].astype(str)
21
  euros_proveedor['CLIENTE'] = euros_proveedor['CLIENTE'].astype(str)
 
22
  fieles_df = pd.read_csv("clientes_relevantes.csv")
23
- # Cargo csv del histórico de cestas
24
  cestas = pd.read_csv("cestas.csv")
25
- # Cargo csv de productos y descripcion
26
  productos = pd.read_csv("productos.csv")
27
 
28
  # Convert all columns except 'CLIENTE' to float in euros_proveedor
@@ -124,10 +124,15 @@ elif page == "Customer Analysis":
124
  if not customer_data.empty and not customer_euros.empty:
125
  st.write(f"### Analysis for Customer {customer_code}")
126
 
127
- # **Step 1: Find Customer's Cluster**
128
- customer_clusters = pd.read_csv('predicts/customer_clusters.csv')
129
- cluster = customer_clusters[customer_clusters['cliente_id'] == customer_code]['cluster_id'].values[0]
130
- st.write(f"Customer {customer_code} belongs to cluster {cluster}")
 
 
 
 
 
131
 
132
  # **Step 2: Load the Corresponding Model**
133
  model_path = f'models/modelo_cluster_{cluster}.txt'
@@ -378,4 +383,4 @@ elif page == "Articles Recommendations":
378
  else:
379
  st.warning("No recommendations found for the provided basket.")
380
  else:
381
- st.warning("Please select at least one article and set its quantity.")
 
9
  # Page configuration
10
  st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
11
 
12
+ # Load CSV files at the top, only once
13
  df = pd.read_csv("df_clean.csv")
14
  nombres_proveedores = pd.read_csv("nombres_proveedores.csv", sep=';')
15
  euros_proveedor = pd.read_csv("euros_proveedor.csv", sep=',')
16
  ventas_clientes = pd.read_csv("ventas_clientes.csv", sep=',')
17
+ customer_clusters = pd.read_csv('predicts/customer_clusters.csv') # Load the customer clusters here
18
 
19
  # Ensure customer codes are strings
20
  df['CLIENTE'] = df['CLIENTE'].astype(str)
21
  nombres_proveedores['codigo'] = nombres_proveedores['codigo'].astype(str)
22
  euros_proveedor['CLIENTE'] = euros_proveedor['CLIENTE'].astype(str)
23
+ customer_clusters['cliente_id'] = customer_clusters['cliente_id'].astype(str) # Ensure customer IDs are strings
24
  fieles_df = pd.read_csv("clientes_relevantes.csv")
 
25
  cestas = pd.read_csv("cestas.csv")
 
26
  productos = pd.read_csv("productos.csv")
27
 
28
  # Convert all columns except 'CLIENTE' to float in euros_proveedor
 
124
  if not customer_data.empty and not customer_euros.empty:
125
  st.write(f"### Analysis for Customer {customer_code}")
126
 
127
+ # **Find Customer's Cluster**
128
+ customer_match = customer_clusters[customer_clusters['cliente_id'] == customer_code]
129
+
130
+ if not customer_match.empty:
131
+ cluster = customer_match['cluster_id'].values[0]
132
+ st.write(f"Customer {customer_code} belongs to cluster {cluster}")
133
+ else:
134
+ st.error(f"Customer {customer_code} not found in customer_clusters.")
135
+ return # Stop further execution if no cluster is found
136
 
137
  # **Step 2: Load the Corresponding Model**
138
  model_path = f'models/modelo_cluster_{cluster}.txt'
 
383
  else:
384
  st.warning("No recommendations found for the provided basket.")
385
  else:
386
+ st.warning("Please select at least one article and set its quantity.")