Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
4d60872
1
Parent(s):
3fe0dd5
feat: updated location of files
Browse files
app.py
CHANGED
@@ -94,56 +94,123 @@ def radar_chart(categories, values, amounts, title):
|
|
94 |
|
95 |
return fig
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# Navigation menu
|
98 |
st.sidebar.title("DeepInsightz")
|
99 |
page = st.sidebar.selectbox("Select the tool you want to use", ["Home", "Customer Analysis", "Articles Recommendations"])
|
100 |
|
101 |
-
# Home Page
|
102 |
-
# Home Page Design
|
103 |
if page == "Home":
|
104 |
st.title("Welcome to DeepInsightz")
|
105 |
st.markdown("""
|
106 |
-
###
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
""")
|
109 |
|
110 |
-
|
111 |
-
st.subheader("Quick Overview")
|
112 |
-
col1, col2, col3 = st.columns(3)
|
113 |
-
col1.metric("Total Customers", "1,532", "+3.8%")
|
114 |
-
col2.metric("Total Sales (2023)", "€2.9M", "+4.2%")
|
115 |
-
col3.metric("Top Cluster", "Cluster 3", "+1.5%")
|
116 |
|
117 |
-
# 2.
|
118 |
-
st.subheader("Customer
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
np.random.seed(42)
|
123 |
-
|
124 |
-
'Cluster': np.random.choice(['Cluster 1', 'Cluster 2', 'Cluster 3', 'Cluster 4', 'Cluster 5'
|
125 |
'x': np.random.randn(100),
|
126 |
'y': np.random.randn(100),
|
127 |
'z': np.random.randn(100)
|
128 |
})
|
129 |
|
130 |
-
|
131 |
-
st.plotly_chart(
|
132 |
|
133 |
-
#
|
134 |
-
st.subheader("
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
138 |
}
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
142 |
|
143 |
-
#
|
144 |
st.markdown("""
|
145 |
-
## Ready to
|
146 |
-
- Use the tools in the sidebar to
|
147 |
""")
|
148 |
|
149 |
# Customer Analysis Page
|
|
|
94 |
|
95 |
return fig
|
96 |
|
97 |
+
# Custom CSS for dark theme and styling
|
98 |
+
st.markdown("""
|
99 |
+
<style>
|
100 |
+
body {
|
101 |
+
background-color: #121212;
|
102 |
+
color: white;
|
103 |
+
}
|
104 |
+
.stMetric {
|
105 |
+
background-color: #2E2E2E;
|
106 |
+
border-radius: 10px;
|
107 |
+
padding: 10px;
|
108 |
+
}
|
109 |
+
.stMetric > div {
|
110 |
+
color: white;
|
111 |
+
}
|
112 |
+
.stMetric > div > div {
|
113 |
+
color: white !important;
|
114 |
+
}
|
115 |
+
.custom-title {
|
116 |
+
color: white;
|
117 |
+
font-size: 36px;
|
118 |
+
margin-bottom: 20px;
|
119 |
+
}
|
120 |
+
.custom-metric-box {
|
121 |
+
background-color: #2E2E2E;
|
122 |
+
border-radius: 10px;
|
123 |
+
padding: 20px;
|
124 |
+
margin-bottom: 10px;
|
125 |
+
text-align: center;
|
126 |
+
color: white;
|
127 |
+
}
|
128 |
+
.up-arrow {
|
129 |
+
color: #00FF00; /* Green */
|
130 |
+
}
|
131 |
+
.down-arrow {
|
132 |
+
color: #FF0000; /* Red */
|
133 |
+
}
|
134 |
+
.container {
|
135 |
+
display: flex;
|
136 |
+
justify-content: space-between;
|
137 |
+
}
|
138 |
+
</style>
|
139 |
+
""", unsafe_allow_html=True)
|
140 |
+
|
141 |
# Navigation menu
|
142 |
st.sidebar.title("DeepInsightz")
|
143 |
page = st.sidebar.selectbox("Select the tool you want to use", ["Home", "Customer Analysis", "Articles Recommendations"])
|
144 |
|
|
|
|
|
145 |
if page == "Home":
|
146 |
st.title("Welcome to DeepInsightz")
|
147 |
st.markdown("""
|
148 |
+
### Data-driven Customer Clustering
|
149 |
+
At DeepInsightz, we analyzed 4,000 customers, 400 suppliers, and over 800,000 sales lines to help businesses make smarter sales decisions.
|
150 |
+
""")
|
151 |
+
|
152 |
+
# 1. Quick Metrics for Data Preparation
|
153 |
+
st.subheader("Data Preparation Overview")
|
154 |
+
st.write("""
|
155 |
+
- **Customers Analyzed**: 4,000
|
156 |
+
- **Suppliers Analyzed**: 400
|
157 |
+
- **Invoice Lines Processed**: 800,000
|
158 |
""")
|
159 |
|
160 |
+
st.info("The data was cleaned, duplicate entries were removed, and we standardized product codes and descriptions. We excluded customers with less than 12 purchases or total sales below €1,200 in 2024.")
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
+
# 2. Customer Distribution
|
163 |
+
st.subheader("Customer Distribution by Purchase Volume")
|
164 |
+
|
165 |
+
# Example data: distribution of customers by purchase volume
|
166 |
+
data = {
|
167 |
+
'Threshold (Items Purchased)': ['>1,000 items', '>5,000 items', '>10,000 items', '>20,000 items', '>50,000 items'],
|
168 |
+
'Number of Customers': [411, 180, 93, 47, 12],
|
169 |
+
'Percentage': [10, 4, 2, 1, 0.3]
|
170 |
+
}
|
171 |
+
df_customers = pd.DataFrame(data)
|
172 |
|
173 |
+
fig_customers = px.bar(df_customers, x='Threshold (Items Purchased)', y='Number of Customers',
|
174 |
+
title="Distribution of Customers by Purchase Volume")
|
175 |
+
st.plotly_chart(fig_customers)
|
176 |
+
|
177 |
+
# 3. Interactive Cluster Visualization (placeholder)
|
178 |
+
st.subheader("3D Cluster Visualization")
|
179 |
+
st.write("Explore the customer clusters and their product purchase behavior.")
|
180 |
+
|
181 |
+
# Sample random data for a 3D cluster (replace with actual cluster data)
|
182 |
np.random.seed(42)
|
183 |
+
df_cluster = pd.DataFrame({
|
184 |
+
'Cluster': np.random.choice(['Cluster 1', 'Cluster 2', 'Cluster 3', 'Cluster 4', 'Cluster 5'], 100),
|
185 |
'x': np.random.randn(100),
|
186 |
'y': np.random.randn(100),
|
187 |
'z': np.random.randn(100)
|
188 |
})
|
189 |
|
190 |
+
fig_cluster = px.scatter_3d(df_cluster, x='x', y='y', z='z', color='Cluster', title="Customer Clusters (3D View)")
|
191 |
+
st.plotly_chart(fig_cluster)
|
192 |
|
193 |
+
# 4. Product Groups vs Manufacturer
|
194 |
+
st.subheader("Product Group vs Manufacturer Distribution")
|
195 |
+
st.write("See how different manufacturers align with various product groups purchased by customers.")
|
196 |
+
|
197 |
+
# Example data for product groups vs manufacturers (replace with real data)
|
198 |
+
prod_data = {
|
199 |
+
'Product Group': ['Group A', 'Group B', 'Group C', 'Group D', 'Group E'],
|
200 |
+
'Manufacturer 1': [25, 40, 35, 30, 50],
|
201 |
+
'Manufacturer 2': [30, 35, 30, 45, 40],
|
202 |
+
'Manufacturer 3': [35, 25, 40, 25, 35]
|
203 |
}
|
204 |
+
df_prod_manu = pd.DataFrame(prod_data)
|
205 |
+
|
206 |
+
fig_prod_manu = px.bar(df_prod_manu, x='Product Group', y=['Manufacturer 1', 'Manufacturer 2', 'Manufacturer 3'],
|
207 |
+
title="Manufacturer Distribution Across Product Groups")
|
208 |
+
st.plotly_chart(fig_prod_manu)
|
209 |
|
210 |
+
# 5. Call to Action
|
211 |
st.markdown("""
|
212 |
+
## Ready to Explore the Customer Clusters Further?
|
213 |
+
- Use the tools in the sidebar to dive deeper into **Customer Analysis** or get **Product Recommendations**.
|
214 |
""")
|
215 |
|
216 |
# Customer Analysis Page
|