Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
586b580
1
Parent(s):
efe8a71
feat: updated website
Browse files
app.py
CHANGED
@@ -59,10 +59,6 @@ st.markdown(f"""
|
|
59 |
</style>
|
60 |
""", unsafe_allow_html=True)
|
61 |
|
62 |
-
# Navigation menu
|
63 |
-
with st.sidebar:
|
64 |
-
st.sidebar.title("DeepInsightz")
|
65 |
-
page = st.sidebar.selectbox("Select the tool you want to use", ["Summary", "Customer Analysis", "Articles Recommendations"])
|
66 |
|
67 |
# Load CSV files at the top
|
68 |
df = pd.read_csv("df_clean.csv")
|
@@ -72,6 +68,23 @@ ventas_clientes = pd.read_csv("ventas_clientes.csv", sep=',')
|
|
72 |
customer_clusters = pd.read_csv('predicts/customer_clusters.csv') # Load the customer clusters here
|
73 |
df_agg_2024 = pd.read_csv('predicts/df_agg_2024.csv')
|
74 |
pca_data_5 = pd.read_csv('pca_data.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
# Generamos la columna total_sales
|
77 |
ventas_clientes['total_sales'] = ventas_clientes[['VENTA_2021', 'VENTA_2022', 'VENTA_2023']].sum(axis=1)
|
@@ -280,6 +293,7 @@ elif page == "Customer Analysis":
|
|
280 |
customer_code = st.selectbox(
|
281 |
"Search and Select Customer Code",
|
282 |
df['CLIENTE'].unique(), # All customer codes
|
|
|
283 |
format_func=lambda x: str(x), # Ensures the values are displayed as strings
|
284 |
help="Start typing to search for a specific customer code"
|
285 |
)
|
@@ -348,6 +362,57 @@ elif page == "Customer Analysis":
|
|
348 |
# Ensure any missing sales data is filled with 0
|
349 |
results['ventas_reales'].fillna(0, inplace=True)
|
350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
# Split space into two columns
|
352 |
col1, col2 = st.columns(2)
|
353 |
|
|
|
59 |
</style>
|
60 |
""", unsafe_allow_html=True)
|
61 |
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Load CSV files at the top
|
64 |
df = pd.read_csv("df_clean.csv")
|
|
|
68 |
customer_clusters = pd.read_csv('predicts/customer_clusters.csv') # Load the customer clusters here
|
69 |
df_agg_2024 = pd.read_csv('predicts/df_agg_2024.csv')
|
70 |
pca_data_5 = pd.read_csv('pca_data.csv')
|
71 |
+
historical_data = pd.read_csv('historical_data.csv')
|
72 |
+
|
73 |
+
with st.sidebar:
|
74 |
+
st.sidebar.title("DeepInsightz")
|
75 |
+
page = st.sidebar.selectbox("Select the tool you want to use", ["Summary", "Customer Analysis", "Articles Recommendations"])
|
76 |
+
|
77 |
+
# If the user selects "Customer Analysis," show filter options in the sidebar
|
78 |
+
if page == "Customer Analysis":
|
79 |
+
st.sidebar.title("Filter Options")
|
80 |
+
show_all = st.sidebar.checkbox('Show All Manufacturers', value=True)
|
81 |
+
|
82 |
+
# If not showing all, allow filtering by manufacturer code
|
83 |
+
if not show_all:
|
84 |
+
selected_manufacturer = st.sidebar.selectbox(
|
85 |
+
'Select Manufacturer Code',
|
86 |
+
historical_data['marca_id_encoded'].unique()
|
87 |
+
)
|
88 |
|
89 |
# Generamos la columna total_sales
|
90 |
ventas_clientes['total_sales'] = ventas_clientes[['VENTA_2021', 'VENTA_2022', 'VENTA_2023']].sum(axis=1)
|
|
|
293 |
customer_code = st.selectbox(
|
294 |
"Search and Select Customer Code",
|
295 |
df['CLIENTE'].unique(), # All customer codes
|
296 |
+
|
297 |
format_func=lambda x: str(x), # Ensures the values are displayed as strings
|
298 |
help="Start typing to search for a specific customer code"
|
299 |
)
|
|
|
362 |
# Ensure any missing sales data is filled with 0
|
363 |
results['ventas_reales'].fillna(0, inplace=True)
|
364 |
|
365 |
+
st.markdown("### Sales History, Predictions, and Real Sales")
|
366 |
+
fechas = pd.to_datetime(results['fecha_mes']) # Extract the date
|
367 |
+
|
368 |
+
# Extract the actual data for the plot
|
369 |
+
ventas_historicas = customer_data['precio_total'].values[:12] # Historical sales (first 12 months)
|
370 |
+
ventas_predichas = results['ventas_predichas'].values # Predicted sales (next months)
|
371 |
+
ventas_reales = results['ventas_reales'].values # Real sales (next months)
|
372 |
+
|
373 |
+
# Create the figure using Plotly
|
374 |
+
fig = go.Figure()
|
375 |
+
|
376 |
+
# Plot historical sales
|
377 |
+
fig.add_trace(go.Scatter(
|
378 |
+
x=fechas[:12], # First 12 months
|
379 |
+
y=ventas_historicas,
|
380 |
+
mode='lines+markers',
|
381 |
+
name='Ventas Históricas',
|
382 |
+
line=dict(color='blue')
|
383 |
+
))
|
384 |
+
|
385 |
+
# Plot predicted sales
|
386 |
+
fig.add_trace(go.Scatter(
|
387 |
+
x=fechas[12:], # Remaining months
|
388 |
+
y=ventas_predichas,
|
389 |
+
mode='lines+markers',
|
390 |
+
name='Ventas Predichas',
|
391 |
+
line=dict(color='orange')
|
392 |
+
))
|
393 |
+
|
394 |
+
# Plot real sales
|
395 |
+
fig.add_trace(go.Scatter(
|
396 |
+
x=fechas[12:], # Remaining months
|
397 |
+
y=ventas_reales,
|
398 |
+
mode='lines+markers',
|
399 |
+
name='Ventas Reales',
|
400 |
+
line=dict(color='green')
|
401 |
+
))
|
402 |
+
|
403 |
+
# Customize the layout
|
404 |
+
fig.update_layout(
|
405 |
+
title=f"Ventas Históricas, Predichas y Reales para Cliente {customer_code}",
|
406 |
+
xaxis_title="Fecha",
|
407 |
+
yaxis_title="Ventas (€)",
|
408 |
+
height=600,
|
409 |
+
legend_title="Tipo de Ventas",
|
410 |
+
hovermode="x unified"
|
411 |
+
)
|
412 |
+
|
413 |
+
# Display the Plotly figure
|
414 |
+
st.plotly_chart(fig)
|
415 |
+
|
416 |
# Split space into two columns
|
417 |
col1, col2 = st.columns(2)
|
418 |
|