GMARTINEZMILLA commited on
Commit
e51f0f6
·
1 Parent(s): 1255914

feat: updated app script

Browse files
Files changed (1) hide show
  1. app.py +58 -70
app.py CHANGED
@@ -10,61 +10,60 @@ from sklearn.metrics import mean_absolute_error, mean_squared_error
10
  from joblib import dump, load
11
  from utils import recomienda_tfid
12
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Page configuration
15
  st.set_page_config(page_title="DeepInsightz", page_icon=":bar_chart:", layout="wide")
16
 
17
- # Custom CSS for styling similar to the inspiration
18
- st.markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  <style>
20
- /* General Page Background */
21
- body {
22
- background-color: #282828;
23
- color: white;
24
- }
25
-
26
- /* Container styling for metric boxes */
27
- [data-testid="stMetric"] {
28
- background-color: #4f4f4f;
29
  border-radius: 10px;
30
  text-align: center;
31
  padding: 15px 0;
32
  margin-bottom: 20px;
33
- }
34
-
35
- [data-testid="stMetricLabel"] {
36
- display: flex;
37
- justify-content: center;
38
- align-items: center;
39
- color: white;
40
- }
41
-
42
- [data-testid="stMetricDeltaIcon-Up"] {
43
- position: relative;
44
- left: 38%;
45
- transform: translateX(-50%);
46
- color: #00FF00; /* Green for positive delta */
47
- }
48
-
49
- [data-testid="stMetricDeltaIcon-Down"] {
50
- position: relative;
51
- left: 38%;
52
- transform: translateX(-50%);
53
- color: #FF0000; /* Red for negative delta */
54
- }
55
-
56
- /* Customize the sidebar background */
57
- [data-testid="stSidebar"] {
58
- background-color: #282828;
59
- }
60
-
61
- /* General container for charts and boxes */
62
- .container {
63
  display: flex;
64
- justify-content: space-between;
65
- background-color: #282828;
66
- }
67
-
 
 
 
68
  </style>
69
  """, unsafe_allow_html=True)
70
 
@@ -109,30 +108,25 @@ def create_donut_chart(values, labels, color_scheme, title):
109
  fig = px.pie(
110
  values=values,
111
  names=labels,
112
- hole=0.7, # Adjusting the hole size for a modern look
113
- color_discrete_sequence=color_scheme # Set color scheme
114
  )
115
-
116
- # Styling adjustments to center the percentage
117
- fig.update_traces(
118
- textinfo='percent+label',
119
- hoverinfo='label+percent',
120
- textposition='inside',
121
- showlegend=False
122
- )
123
-
124
- # Layout adjustments
125
  fig.update_layout(
126
- annotations=[dict(text=f"{int(values[1])}%", x=0.5, y=0.5, font_size=40, showarrow=False)], # Center percentage text
127
  title=title,
128
- height=300, # Adjust the size
129
  margin=dict(t=30, b=10, l=10, r=10),
130
- paper_bgcolor="rgba(0, 0, 0, 0)", # Background color transparent
131
- plot_bgcolor="rgba(0, 0, 0, 0)"
132
  )
133
-
134
  return fig
135
 
 
 
 
 
 
136
  # Function to create radar chart with square root transformation
137
  def radar_chart(categories, values, amounts, title):
138
  N = len(categories)
@@ -177,11 +171,6 @@ def radar_chart(categories, values, amounts, title):
177
 
178
  return fig
179
 
180
- # Navigation menu
181
- with st.sidebar:
182
- st.sidebar.title("DeepInsightz")
183
- page = st.sidebar.selectbox("Select the tool you want to use", ["Summary", "Customer Analysis", "Articles Recommendations"])
184
-
185
 
186
 
187
  if page == "Summary":
@@ -205,12 +194,10 @@ if page == "Summary":
205
  # Create a placeholder for your own donut charts with Plotly
206
  inbound_values = [23, 77] # Adjust the values
207
  labels = ['Outbound', 'Inbound']
208
- color_scheme = ['#155F7A', '#29b5e8']
209
 
210
- donut_fig = create_donut_chart(inbound_values, labels, color_scheme, title="")
211
  st.plotly_chart(donut_fig, use_container_width=True)
212
 
213
-
214
  # Middle Column (White): 3D Cluster Model and Bar Chart
215
  with col2:
216
  st.markdown('#### 3D Customer Clusters')
@@ -238,6 +225,7 @@ if page == "Summary":
238
  'Sales': [400000, 600000, 500000, 300000]}
239
  df_sales = pd.DataFrame(sales_data)
240
  fig_sales = px.bar(df_sales, x='Cluster', y='Sales')
 
241
  st.plotly_chart(fig_sales, use_container_width=True)
242
 
243
  # Right Column (Blue): Key Metrics Overview and Data Preparation Summary
 
10
  from joblib import dump, load
11
  from utils import recomienda_tfid
12
 
13
+ # Navigation menu
14
+ with st.sidebar:
15
+ st.sidebar.title("DeepInsightz")
16
+
17
+ # Theme toggle for light/dark mode
18
+ theme_toggle = st.sidebar.selectbox('Select Theme', ['Light', 'Dark'])
19
+
20
+ # Existing tool selection
21
+ page = st.sidebar.selectbox("Select the tool you want to use", ["Summary", "Customer Analysis", "Articles Recommendations"])
22
 
23
  # Page configuration
24
  st.set_page_config(page_title="DeepInsightz", page_icon=":bar_chart:", layout="wide")
25
 
26
+ # Custom CSS for dynamic theme styling
27
+ # Define light and dark theme specific colors and styles
28
+ if theme_toggle == 'Dark':
29
+ background_color = "#282828"
30
+ text_color = "white"
31
+ metric_box_color = "#4f4f4f"
32
+ sidebar_color = "#282828"
33
+ plot_bgcolor = "rgba(0, 0, 0, 0)"
34
+ primary_color = '#00FF00' # for positive delta
35
+ negative_color = '#FF0000' # for negative delta
36
+ else:
37
+ background_color = "white"
38
+ text_color = "black"
39
+ metric_box_color = "#f5f5f5"
40
+ sidebar_color = "#f0f0f0"
41
+ plot_bgcolor = "rgba(255, 255, 255, 1)"
42
+ primary_color = '#228B22' # for positive delta in light mode
43
+ negative_color = '#8B0000' # for negative delta in light mode
44
+
45
+ st.markdown(f"""
46
  <style>
47
+ body {{
48
+ background-color: {background_color};
49
+ color: {text_color};
50
+ }}
51
+ [data-testid="stMetric"] {{
52
+ background-color: {metric_box_color};
 
 
 
53
  border-radius: 10px;
54
  text-align: center;
55
  padding: 15px 0;
56
  margin-bottom: 20px;
57
+ }}
58
+ [data-testid="stMetricLabel"] {{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  display: flex;
60
+ justify-content: center;
61
+ align-items: center;
62
+ color: {text_color};
63
+ }}
64
+ [data-testid="stSidebar"] {{
65
+ background-color: {sidebar_color};
66
+ }}
67
  </style>
68
  """, unsafe_allow_html=True)
69
 
 
108
  fig = px.pie(
109
  values=values,
110
  names=labels,
111
+ hole=0.7,
112
+ color_discrete_sequence=color_scheme
113
  )
114
+ fig.update_traces(textinfo='percent+label', hoverinfo='label+percent', textposition='inside', showlegend=False)
 
 
 
 
 
 
 
 
 
115
  fig.update_layout(
116
+ annotations=[dict(text=f"{int(values[1])}%", x=0.5, y=0.5, font_size=40, showarrow=False)],
117
  title=title,
118
+ height=300,
119
  margin=dict(t=30, b=10, l=10, r=10),
120
+ paper_bgcolor=plot_bgcolor, # Use theme-dependent background color
121
+ plot_bgcolor=plot_bgcolor
122
  )
 
123
  return fig
124
 
125
+ if theme_toggle == 'Dark':
126
+ donut_color_scheme = ['#155F7A', '#29b5e8'] # Example colors for dark mode
127
+ else:
128
+ donut_color_scheme = ['#007BFF', '#66b5ff'] # Example colors for light mode
129
+
130
  # Function to create radar chart with square root transformation
131
  def radar_chart(categories, values, amounts, title):
132
  N = len(categories)
 
171
 
172
  return fig
173
 
 
 
 
 
 
174
 
175
 
176
  if page == "Summary":
 
194
  # Create a placeholder for your own donut charts with Plotly
195
  inbound_values = [23, 77] # Adjust the values
196
  labels = ['Outbound', 'Inbound']
 
197
 
198
+ donut_fig = create_donut_chart(inbound_values, labels, donut_color_scheme, title="")
199
  st.plotly_chart(donut_fig, use_container_width=True)
200
 
 
201
  # Middle Column (White): 3D Cluster Model and Bar Chart
202
  with col2:
203
  st.markdown('#### 3D Customer Clusters')
 
225
  'Sales': [400000, 600000, 500000, 300000]}
226
  df_sales = pd.DataFrame(sales_data)
227
  fig_sales = px.bar(df_sales, x='Cluster', y='Sales')
228
+ fig_sales.update_layout(paper_bgcolor=plot_bgcolor, plot_bgcolor=plot_bgcolor)
229
  st.plotly_chart(fig_sales, use_container_width=True)
230
 
231
  # Right Column (Blue): Key Metrics Overview and Data Preparation Summary