Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
00825cb
1
Parent(s):
1ea7063
feat: generated files
Browse files- app.py +47 -50
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
-
import
|
|
|
5 |
|
6 |
# Configuración de la página principal
|
7 |
st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
|
@@ -15,6 +16,47 @@ df = df.iloc[:, :-2]
|
|
15 |
# Asegurarse de que el código del cliente sea una cadena (string)
|
16 |
df['CLIENTE'] = df['CLIENTE'].astype(str)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Diseño de la página principal
|
19 |
st.title("Welcome to Customer Insights App")
|
20 |
st.markdown("""
|
@@ -74,54 +116,9 @@ elif page == "Customer Analysis":
|
|
74 |
for manufacturer, value in zip(manufacturers, values):
|
75 |
st.write(f"{manufacturer} = {value:.4f}")
|
76 |
|
77 |
-
#
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
# Crear el gráfico de radar
|
82 |
-
fig = go.Figure()
|
83 |
-
|
84 |
-
# Add the data trace (pink line)
|
85 |
-
fig.add_trace(go.Scatterpolar(
|
86 |
-
r=values,
|
87 |
-
theta=manufacturers,
|
88 |
-
fill='toself',
|
89 |
-
fillcolor='rgba(255, 105, 180, 0.2)', # Light pink fill
|
90 |
-
line=dict(color='rgb(255, 105, 180)', width=2), # Pink line
|
91 |
-
mode='lines+markers',
|
92 |
-
marker=dict(size=8, color='rgb(255, 105, 180)') # Pink markers
|
93 |
-
))
|
94 |
-
|
95 |
-
# Add the outer boundary (blue line)
|
96 |
-
fig.add_trace(go.Scatterpolar(
|
97 |
-
r=[max(values) * 1.1] * len(manufacturers), # Slightly larger than the maximum value
|
98 |
-
theta=manufacturers,
|
99 |
-
mode='lines',
|
100 |
-
line=dict(color='rgb(100, 149, 237)', width=2), # Cornflower blue
|
101 |
-
showlegend=False
|
102 |
-
))
|
103 |
-
|
104 |
-
# Update the layout
|
105 |
-
fig.update_layout(
|
106 |
-
polar=dict(
|
107 |
-
radialaxis=dict(
|
108 |
-
visible=True,
|
109 |
-
range=[0, max(values) * 1.1],
|
110 |
-
showline=False,
|
111 |
-
showticklabels=True,
|
112 |
-
),
|
113 |
-
angularaxis=dict(
|
114 |
-
showline=True,
|
115 |
-
linecolor='rgb(192, 192, 192)', # Light gray
|
116 |
-
tickcolor='rgb(192, 192, 192)',
|
117 |
-
),
|
118 |
-
),
|
119 |
-
showlegend=False,
|
120 |
-
title=f'Radar Chart for Top 6 Manufacturers of Customer {customer_code}',
|
121 |
-
)
|
122 |
-
|
123 |
-
# Show the plot in Streamlit
|
124 |
-
st.plotly_chart(fig)
|
125 |
|
126 |
# Ventas del cliente 2021-2024 (si los datos existen)
|
127 |
if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
|
@@ -172,4 +169,4 @@ elif page == "Customer Recommendations":
|
|
172 |
# Aquí puedes reemplazar con la lógica del modelo de recomendación
|
173 |
st.write("Product A, Product B, Product C")
|
174 |
else:
|
175 |
-
st.warning(f"No data found for customer {customer_code}. Please check the code.")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import numpy as np
|
6 |
|
7 |
# Configuración de la página principal
|
8 |
st.set_page_config(page_title="Customer Insights App", page_icon=":bar_chart:")
|
|
|
16 |
# Asegurarse de que el código del cliente sea una cadena (string)
|
17 |
df['CLIENTE'] = df['CLIENTE'].astype(str)
|
18 |
|
19 |
+
# Función para crear el gráfico de radar
|
20 |
+
def radar_chart(categories, values, title):
|
21 |
+
# Número de variables
|
22 |
+
N = len(categories)
|
23 |
+
|
24 |
+
# Repetir el primer valor para cerrar el polígono
|
25 |
+
values += values[:1]
|
26 |
+
|
27 |
+
# Calcular los ángulos para cada punto
|
28 |
+
angles = [n / float(N) * 2 * np.pi for n in range(N)]
|
29 |
+
angles += angles[:1]
|
30 |
+
|
31 |
+
# Inicializar el gráfico
|
32 |
+
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(projection='polar'))
|
33 |
+
|
34 |
+
# Dibujar el polígono y rellenarlo
|
35 |
+
ax.plot(angles, values, 'o-', linewidth=2, color='pink')
|
36 |
+
ax.fill(angles, values, alpha=0.25, color='pink')
|
37 |
+
|
38 |
+
# Establecer las etiquetas y el título
|
39 |
+
ax.set_xticks(angles[:-1])
|
40 |
+
ax.set_xticklabels(categories)
|
41 |
+
ax.set_title(title)
|
42 |
+
|
43 |
+
# Configurar los ejes
|
44 |
+
ax.set_ylim(0, max(values))
|
45 |
+
|
46 |
+
# Dibujar círculos de referencia
|
47 |
+
circles = np.linspace(0, max(values), 5)
|
48 |
+
for circle in circles:
|
49 |
+
ax.plot(angles, [circle]*len(angles), '--', color='gray', linewidth=0.5)
|
50 |
+
|
51 |
+
# Eliminar las etiquetas radiales
|
52 |
+
ax.set_yticklabels([])
|
53 |
+
|
54 |
+
# Dibujar el borde exterior en azul
|
55 |
+
max_value = max(values)
|
56 |
+
ax.plot(angles, [max_value]*len(angles), '-', linewidth=2, color='blue')
|
57 |
+
|
58 |
+
return fig
|
59 |
+
|
60 |
# Diseño de la página principal
|
61 |
st.title("Welcome to Customer Insights App")
|
62 |
st.markdown("""
|
|
|
116 |
for manufacturer, value in zip(manufacturers, values):
|
117 |
st.write(f"{manufacturer} = {value:.4f}")
|
118 |
|
119 |
+
# Crear y mostrar el gráfico de radar
|
120 |
+
fig = radar_chart(manufacturers, values, f'Radar Chart for Top 6 Manufacturers of Customer {customer_code}')
|
121 |
+
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
# Ventas del cliente 2021-2024 (si los datos existen)
|
124 |
if 'VENTA_2021' in df.columns and 'VENTA_2022' in df.columns and 'VENTA_2023' in df.columns and 'VENTA_2024' in df.columns:
|
|
|
169 |
# Aquí puedes reemplazar con la lógica del modelo de recomendación
|
170 |
st.write("Product A, Product B, Product C")
|
171 |
else:
|
172 |
+
st.warning(f"No data found for customer {customer_code}. Please check the code.")
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
plotly
|
|
|
|
1 |
+
plotly
|
2 |
+
matplotlib
|