GMARTINEZMILLA commited on
Commit
45bb8a5
1 Parent(s): d496756

feat: generated files

Browse files
Files changed (1) hide show
  1. app.py +64 -66
app.py CHANGED
@@ -6,6 +6,10 @@ import plotly.graph_objects as go
6
  # Configuración de la página principal
7
  st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
8
 
 
 
 
 
9
  # Diseño de la página principal
10
  st.title("Welcome to Customer Insights App")
11
  st.markdown("""
@@ -28,55 +32,49 @@ elif page == "Customer Analysis":
28
  Use the tools below to explore your customer data.
29
  """)
30
 
31
- # Cargar y visualizar datos
32
- uploaded_file = st.file_uploader("Upload your CSV file", type="csv")
33
- if uploaded_file:
34
- df = pd.read_csv(uploaded_file)
35
- st.write("## Dataset Overview", df.head())
36
-
37
- # Input para código de cliente
38
- customer_code = st.text_input("Enter Customer Code")
39
-
40
- if customer_code:
41
- # Filtrar datos para el cliente seleccionado
42
- customer_data = df[df["CLIENTE"] == customer_code]
43
-
44
- if not customer_data.empty:
45
- st.write(f"### Analysis for Customer {customer_code}")
46
-
47
- # Generar un gráfico spider (radar chart)
48
- categories = ['Variable1', 'Variable2', 'Variable3', 'Variable4'] # Aquí puedes incluir tus variables específicas
49
- customer_values = [customer_data[category].values[0] for category in categories]
50
-
51
- fig_spider = go.Figure()
52
- fig_spider.add_trace(go.Scatterpolar(
53
- r=customer_values,
54
- theta=categories,
55
- fill='toself',
56
- name=f'Customer {customer_code}'
57
- ))
58
- fig_spider.update_layout(
59
- polar=dict(
60
- radialaxis=dict(
61
- visible=True,
62
- range=[0, max(customer_values) + 1]
63
- )),
64
- showlegend=False,
65
- title=f'Spider Chart for Customer {customer_code}'
66
- )
67
- st.plotly_chart(fig_spider)
68
-
69
- # Ventas del cliente 2021-2024
70
- years = ['2021', '2022', '2023', '2024']
71
- sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024'] # Nombres de las columnas para ventas por año
72
- customer_sales = [customer_data[col].values[0] for col in sales_columns]
73
-
74
- fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
75
- fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
76
- st.plotly_chart(fig_sales)
77
-
78
- else:
79
- st.warning(f"No data found for customer {customer_code}. Please check the code.")
80
 
81
  # Página Customer Recommendations
82
  elif page == "Customer Recommendations":
@@ -85,20 +83,20 @@ elif page == "Customer Recommendations":
85
  Get tailored recommendations for your customers based on their purchasing history.
86
  """)
87
 
88
- # Cargar los datos
89
- uploaded_file = st.file_uploader("Upload your CSV file", type="csv")
90
- if uploaded_file:
91
- df = pd.read_csv(uploaded_file)
92
-
93
- # Selección de cliente
94
- customer_id = st.selectbox("Select a Customer", df["CLIENTE"].unique())
95
-
96
- # Mostrar historial de compras del cliente seleccionado
97
- st.write(f"### Purchase History for Customer {customer_id}")
98
- customer_data = df[df["CLIENTE"] == customer_id]
99
- st.write(customer_data)
100
-
101
- # Generar recomendaciones (placeholder)
102
- st.write(f"### Recommended Products for Customer {customer_id}")
103
- # Aquí puedes reemplazar con la lógica del modelo de recomendación
104
- st.write("Product A, Product B, Product C")
 
6
  # Configuración de la página principal
7
  st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
8
 
9
+ # Cargar el archivo CSV que ya está disponible en la web
10
+ # Asegúrate de que el archivo esté en el mismo directorio o en una ubicación accesible
11
+ df = pd.read_csv("ruta_del_archivo.csv") # Actualiza "ruta_del_archivo.csv" con la ruta correcta
12
+
13
  # Diseño de la página principal
14
  st.title("Welcome to Customer Insights App")
15
  st.markdown("""
 
32
  Use the tools below to explore your customer data.
33
  """)
34
 
35
+ # Input para código de cliente
36
+ customer_code = st.text_input("Enter Customer Code")
37
+
38
+ if customer_code:
39
+ # Filtrar datos para el cliente seleccionado
40
+ customer_data = df[df["CLIENTE"] == customer_code]
41
+
42
+ if not customer_data.empty:
43
+ st.write(f"### Analysis for Customer {customer_code}")
44
+
45
+ # Generar un gráfico spider (radar chart)
46
+ categories = ['Variable1', 'Variable2', 'Variable3', 'Variable4'] # Aquí puedes incluir tus variables específicas
47
+ customer_values = [customer_data[category].values[0] for category in categories]
48
+
49
+ fig_spider = go.Figure()
50
+ fig_spider.add_trace(go.Scatterpolar(
51
+ r=customer_values,
52
+ theta=categories,
53
+ fill='toself',
54
+ name=f'Customer {customer_code}'
55
+ ))
56
+ fig_spider.update_layout(
57
+ polar=dict(
58
+ radialaxis=dict(
59
+ visible=True,
60
+ range=[0, max(customer_values) + 1]
61
+ )),
62
+ showlegend=False,
63
+ title=f'Spider Chart for Customer {customer_code}'
64
+ )
65
+ st.plotly_chart(fig_spider)
66
+
67
+ # Ventas del cliente 2021-2024
68
+ years = ['2021', '2022', '2023', '2024']
69
+ sales_columns = ['VENTA_2021', 'VENTA_2022', 'VENTA_2023', 'VENTA_2024'] # Nombres de las columnas para ventas por año
70
+ customer_sales = [customer_data[col].values[0] for col in sales_columns]
71
+
72
+ fig_sales = px.line(x=years, y=customer_sales, markers=True, title=f'Sales Over the Years for Customer {customer_code}')
73
+ fig_sales.update_layout(xaxis_title="Year", yaxis_title="Sales")
74
+ st.plotly_chart(fig_sales)
75
+
76
+ else:
77
+ st.warning(f"No data found for customer {customer_code}. Please check the code.")
 
 
 
 
 
 
78
 
79
  # Página Customer Recommendations
80
  elif page == "Customer Recommendations":
 
83
  Get tailored recommendations for your customers based on their purchasing history.
84
  """)
85
 
86
+ # Input para código de cliente
87
+ customer_code = st.text_input("Enter Customer Code for Recommendations")
88
+
89
+ if customer_code:
90
+ customer_data = df[df["CLIENTE"] == customer_code]
91
+
92
+ if not customer_data.empty:
93
+ # Mostrar historial de compras del cliente seleccionado
94
+ st.write(f"### Purchase History for Customer {customer_code}")
95
+ st.write(customer_data)
96
+
97
+ # Generar recomendaciones (placeholder)
98
+ st.write(f"### Recommended Products for Customer {customer_code}")
99
+ # Aquí puedes reemplazar con la lógica del modelo de recomendación
100
+ st.write("Product A, Product B, Product C")
101
+ else:
102
+ st.warning(f"No data found for customer {customer_code}. Please check the code.")