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("ruta_del_archivo.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.")