Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
515f7b7
1
Parent(s):
2d063f3
feat: Translated Summary to Spanish
Browse files
app.py
CHANGED
@@ -219,9 +219,9 @@ if page == "Resumen":
|
|
219 |
with col1:
|
220 |
st.markdown('#### Información General')
|
221 |
st.metric(label="Rango de fechas", value="2021-2023")
|
222 |
-
st.metric(label="Clientes
|
223 |
-
st.metric(label="Productos
|
224 |
-
st.metric(label="Líneas de
|
225 |
|
226 |
|
227 |
|
@@ -272,14 +272,13 @@ elif page == "Análisis de Cliente":
|
|
272 |
st.markdown("""
|
273 |
<h2 style='text-align: center; font-size: 2.5rem;'>Análisis de Cliente</h2>
|
274 |
<p style='text-align: center; font-size: 1.2rem; color: gray;'>
|
275 |
-
|
276 |
-
including past sales, predictions for the current year, and manufacturer-specific information.
|
277 |
</p>
|
278 |
""", unsafe_allow_html=True)
|
279 |
|
280 |
# Combine text input and dropdown into a single searchable selectbox
|
281 |
customer_code = st.selectbox(
|
282 |
-
"
|
283 |
df['CLIENTE'].unique(), # All customer codes
|
284 |
|
285 |
format_func=lambda x: str(x), # Ensures the values are displayed as strings
|
@@ -288,7 +287,7 @@ elif page == "Análisis de Cliente":
|
|
288 |
|
289 |
if st.button("Calcular"):
|
290 |
if customer_code:
|
291 |
-
with st.spinner("
|
292 |
# Find Customer's Cluster
|
293 |
customer_match = customer_clusters[customer_clusters['cliente_id'] == customer_code]
|
294 |
time.sleep(1)
|
@@ -296,24 +295,24 @@ elif page == "Análisis de Cliente":
|
|
296 |
if not customer_match.empty:
|
297 |
cluster = customer_match['cluster_id'].values[0]
|
298 |
|
299 |
-
with st.spinner(f"
|
300 |
# Load the Corresponding Model
|
301 |
model_path = f'models/modelo_cluster_{cluster}.txt'
|
302 |
gbm = lgb.Booster(model_file=model_path)
|
303 |
|
304 |
-
with st.spinner("
|
305 |
# Load predict data for that cluster
|
306 |
predict_data = pd.read_csv(f'predicts/predict_cluster_{cluster}.csv')
|
307 |
|
308 |
# Convert cliente_id to string
|
309 |
predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
|
310 |
|
311 |
-
with st.spinner("
|
312 |
# Filter for the specific customer
|
313 |
customer_code_str = str(customer_code)
|
314 |
customer_data = predict_data[predict_data['cliente_id'] == customer_code_str]
|
315 |
|
316 |
-
with st.spinner("
|
317 |
if not customer_data.empty:
|
318 |
# Define features consistently with the training process
|
319 |
lag_features = [f'precio_total_lag_{lag}' for lag in range(1, 25)]
|
@@ -476,8 +475,8 @@ elif page == "Análisis de Cliente":
|
|
476 |
|
477 |
# Column 1: Radar chart for top manufacturers
|
478 |
with col1:
|
479 |
-
st.subheader("
|
480 |
-
st.info("
|
481 |
|
482 |
# Group results by manufacturer to calculate the total predicted and actual sales
|
483 |
grouped_results = results.groupby('marca_id_encoded').agg({
|
@@ -559,13 +558,13 @@ elif page == "Análisis de Cliente":
|
|
559 |
manufacturers = [get_supplier_name(m) for m in manufacturers_to_show.index]
|
560 |
|
561 |
if manufacturers:
|
562 |
-
fig = radar_chart(manufacturers, values, amounts, f'
|
563 |
st.pyplot(fig)
|
564 |
|
565 |
# Column 2: Alerts and additional analysis
|
566 |
with col2:
|
567 |
-
st.subheader("
|
568 |
-
st.warning("
|
569 |
|
570 |
# Group results by manufacturer to calculate the total predicted and actual sales
|
571 |
grouped_results = results.groupby('marca_id_encoded').agg({
|
@@ -683,7 +682,7 @@ elif page == "Análisis de Cliente":
|
|
683 |
|
684 |
# Customize layout
|
685 |
fig_sales_bar.update_layout(
|
686 |
-
title=f"
|
687 |
xaxis_title="Year",
|
688 |
yaxis_title="Sales (€)",
|
689 |
barmode='group',
|
|
|
219 |
with col1:
|
220 |
st.markdown('#### Información General')
|
221 |
st.metric(label="Rango de fechas", value="2021-2023")
|
222 |
+
st.metric(label="Clientes analizados", value="3.000")
|
223 |
+
st.metric(label="Productos únicos vendidos", value="10.702")
|
224 |
+
st.metric(label="Líneas de venta totales", value="764.396")
|
225 |
|
226 |
|
227 |
|
|
|
272 |
st.markdown("""
|
273 |
<h2 style='text-align: center; font-size: 2.5rem;'>Análisis de Cliente</h2>
|
274 |
<p style='text-align: center; font-size: 1.2rem; color: gray;'>
|
275 |
+
Introduce el código del cliente para explorar información detallada del mismo, incluyendo ventas anteriores, predicciones para el año actual e información específica por fabricante.
|
|
|
276 |
</p>
|
277 |
""", unsafe_allow_html=True)
|
278 |
|
279 |
# Combine text input and dropdown into a single searchable selectbox
|
280 |
customer_code = st.selectbox(
|
281 |
+
"Escribe o selecciona el código de tu cliente",
|
282 |
df['CLIENTE'].unique(), # All customer codes
|
283 |
|
284 |
format_func=lambda x: str(x), # Ensures the values are displayed as strings
|
|
|
287 |
|
288 |
if st.button("Calcular"):
|
289 |
if customer_code:
|
290 |
+
with st.spinner("Estamos identificando el grupo del cliente..."):
|
291 |
# Find Customer's Cluster
|
292 |
customer_match = customer_clusters[customer_clusters['cliente_id'] == customer_code]
|
293 |
time.sleep(1)
|
|
|
295 |
if not customer_match.empty:
|
296 |
cluster = customer_match['cluster_id'].values[0]
|
297 |
|
298 |
+
with st.spinner(f"Seleccionando el modelo predictivo..."):
|
299 |
# Load the Corresponding Model
|
300 |
model_path = f'models/modelo_cluster_{cluster}.txt'
|
301 |
gbm = lgb.Booster(model_file=model_path)
|
302 |
|
303 |
+
with st.spinner("Preparando los datos..."):
|
304 |
# Load predict data for that cluster
|
305 |
predict_data = pd.read_csv(f'predicts/predict_cluster_{cluster}.csv')
|
306 |
|
307 |
# Convert cliente_id to string
|
308 |
predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
|
309 |
|
310 |
+
with st.spinner("Filtrando data..."):
|
311 |
# Filter for the specific customer
|
312 |
customer_code_str = str(customer_code)
|
313 |
customer_data = predict_data[predict_data['cliente_id'] == customer_code_str]
|
314 |
|
315 |
+
with st.spinner("Geneerando predicciones de venta..."):
|
316 |
if not customer_data.empty:
|
317 |
# Define features consistently with the training process
|
318 |
lag_features = [f'precio_total_lag_{lag}' for lag in range(1, 25)]
|
|
|
475 |
|
476 |
# Column 1: Radar chart for top manufacturers
|
477 |
with col1:
|
478 |
+
st.subheader("¡Esto tiene buena pinta!")
|
479 |
+
st.info("Su cliente ha superado las ventas predichas de las siguientes marcas:")
|
480 |
|
481 |
# Group results by manufacturer to calculate the total predicted and actual sales
|
482 |
grouped_results = results.groupby('marca_id_encoded').agg({
|
|
|
558 |
manufacturers = [get_supplier_name(m) for m in manufacturers_to_show.index]
|
559 |
|
560 |
if manufacturers:
|
561 |
+
fig = radar_chart(manufacturers, values, amounts, f'Gráfico de radar para los {len(manufacturers)} principales fabricantes del cliente {customer_code}')
|
562 |
st.pyplot(fig)
|
563 |
|
564 |
# Column 2: Alerts and additional analysis
|
565 |
with col2:
|
566 |
+
st.subheader("¡Puede que tengas que revisar esto!")
|
567 |
+
st.warning("Se esperaba que tu cliente comprara más productos de las siguientes marcas:")
|
568 |
|
569 |
# Group results by manufacturer to calculate the total predicted and actual sales
|
570 |
grouped_results = results.groupby('marca_id_encoded').agg({
|
|
|
682 |
|
683 |
# Customize layout
|
684 |
fig_sales_bar.update_layout(
|
685 |
+
title=f"Ventas anuales de tu cliente",
|
686 |
xaxis_title="Year",
|
687 |
yaxis_title="Sales (€)",
|
688 |
barmode='group',
|