File size: 4,248 Bytes
89e696a
36f3034
 
d496756
89e696a
36f3034
2c1bfb4
 
45bb8a5
 
6012e5e
45bb8a5
ab9c8b0
2c1bfb4
 
 
 
 
 
ab9c8b0
3a7c531
2c1bfb4
36f3034
b6148e0
ab9c8b0
 
36f3034
 
ab9c8b0
36f3034
 
 
 
 
45bb8a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36f3034
 
ab9c8b0
36f3034
 
 
 
 
45bb8a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

# Configuración de la página principal
st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")

# Cargar el archivo CSV que ya está disponible en la web
# Asegúrate de que el archivo esté en el mismo directorio o en una ubicación accesible
df = pd.read_csv("info.csv")  # Actualiza "ruta_del_archivo.csv" con la ruta correcta

# Diseño de la página principal
st.title("Welcome to Customer Insights App")
st.markdown("""
    This app helps businesses analyze customer behaviors and provide personalized recommendations based on purchase history. 
    Use the tools below to dive deeper into your customer data.
""")

# Menú de navegación
page = st.selectbox("Selecciona la herramienta que quieres utilizar", ["", "Customer Analysis", "Customer Recommendations"])

# Página Home
if page == "":
    st.markdown("## Welcome to the Customer Insights App")
    st.write("Use the dropdown menu to navigate between the different sections.")

# Página Customer Analysis
elif page == "Customer Analysis":
    st.title("Customer Analysis")
    st.markdown("""
        Use the tools below to explore your customer data.
    """)

    # Input para código de cliente
    customer_code = st.text_input("Enter Customer Code")

    if customer_code:
        # Filtrar datos para el cliente seleccionado
        customer_data = df[df["CLIENTE"] == customer_code]

        if not customer_data.empty:
            st.write(f"### Analysis for Customer {customer_code}")
            
            # Generar un gráfico spider (radar chart)
            categories = ['Variable1', 'Variable2', 'Variable3', 'Variable4']  # Aquí puedes incluir tus variables específicas
            customer_values = [customer_data[category].values[0] for category in categories]
            
            fig_spider = go.Figure()
            fig_spider.add_trace(go.Scatterpolar(
                r=customer_values,
                theta=categories,
                fill='toself',
                name=f'Customer {customer_code}'
            ))
            fig_spider.update_layout(
                polar=dict(
                    radialaxis=dict(
                        visible=True,
                        range=[0, max(customer_values) + 1]
                    )),
                showlegend=False,
                title=f'Spider Chart for Customer {customer_code}'
            )
            st.plotly_chart(fig_spider)

            # Ventas del cliente 2021-2024
            years = ['2021', '2022', '2023', '2024']
            sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024']  # Nombres de las columnas para ventas por año
            customer_sales = [customer_data[col].values[0] for col in sales_columns]
            
            fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
            fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
            st.plotly_chart(fig_sales)

        else:
            st.warning(f"No data found for customer {customer_code}. Please check the code.")

# Página Customer Recommendations
elif page == "Customer Recommendations":
    st.title("Customer Recommendations")
    st.markdown("""
        Get tailored recommendations for your customers based on their purchasing history.
    """)

    # Input para código de cliente
    customer_code = st.text_input("Enter Customer Code for Recommendations")

    if customer_code:
        customer_data = df[df["CLIENTE"] == customer_code]
        
        if not customer_data.empty:
            # Mostrar historial de compras del cliente seleccionado
            st.write(f"### Purchase History for Customer {customer_code}")
            st.write(customer_data)

            # Generar recomendaciones (placeholder)
            st.write(f"### Recommended Products for Customer {customer_code}")
            # Aquí puedes reemplazar con la lógica del modelo de recomendación
            st.write("Product A, Product B, Product C")
        else:
            st.warning(f"No data found for customer {customer_code}. Please check the code.")