Spaces:
Build error
Build error
update dashboard.py - overlap issue
Browse files- app.py +2 -2
- dashboard.py +40 -100
app.py
CHANGED
|
@@ -234,8 +234,8 @@ def create_interface():
|
|
| 234 |
theme=gr.themes.Soft(),
|
| 235 |
css="""
|
| 236 |
footer {visibility: hidden}
|
| 237 |
-
.plot-container {min-height:
|
| 238 |
-
.gradio-plot {min-height:
|
| 239 |
"""
|
| 240 |
) as demo:
|
| 241 |
|
|
|
|
| 234 |
theme=gr.themes.Soft(),
|
| 235 |
css="""
|
| 236 |
footer {visibility: hidden}
|
| 237 |
+
.plot-container {min-height: 1150px !important}
|
| 238 |
+
.gradio-plot {min-height: 1150px !important}
|
| 239 |
"""
|
| 240 |
) as demo:
|
| 241 |
|
dashboard.py
CHANGED
|
@@ -28,19 +28,19 @@ def create_sales_dashboard(sales_data: pd.DataFrame, period: str = "week") -> go
|
|
| 28 |
if sales_data.empty:
|
| 29 |
return create_empty_chart("No sales data available")
|
| 30 |
|
| 31 |
-
# Create subplot layout
|
| 32 |
fig = make_subplots(
|
| 33 |
-
rows=
|
| 34 |
subplot_titles=[
|
| 35 |
"π Daily Revenue Trend",
|
| 36 |
-
"π Top Products by Revenue",
|
| 37 |
-
"π Sales by Category"
|
| 38 |
-
"π° Revenue Distribution"
|
| 39 |
],
|
| 40 |
-
specs=[[{"secondary_y": True}
|
| 41 |
-
[{"type": "
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
)
|
| 45 |
|
| 46 |
try:
|
|
@@ -78,9 +78,9 @@ def create_sales_dashboard(sales_data: pd.DataFrame, period: str = "week") -> go
|
|
| 78 |
row=1, col=1, secondary_y=True
|
| 79 |
)
|
| 80 |
|
| 81 |
-
# 2. Top Products by Revenue (
|
| 82 |
if 'product_name' in sales_data.columns and 'total_price' in sales_data.columns:
|
| 83 |
-
top_products = sales_data.groupby('product_name')['total_price'].sum().nlargest(
|
| 84 |
|
| 85 |
fig.add_trace(
|
| 86 |
go.Bar(
|
|
@@ -91,10 +91,10 @@ def create_sales_dashboard(sales_data: pd.DataFrame, period: str = "week") -> go
|
|
| 91 |
marker_color='#A23B72',
|
| 92 |
hovertemplate='<b>%{y}</b><br>Revenue: β½%{x:,.0f}<extra></extra>'
|
| 93 |
),
|
| 94 |
-
row=
|
| 95 |
)
|
| 96 |
|
| 97 |
-
# 3. Sales by Category (
|
| 98 |
if 'category' in sales_data.columns and 'total_price' in sales_data.columns:
|
| 99 |
category_sales = sales_data.groupby('category')['total_price'].sum().reset_index()
|
| 100 |
|
|
@@ -106,20 +106,7 @@ def create_sales_dashboard(sales_data: pd.DataFrame, period: str = "week") -> go
|
|
| 106 |
hovertemplate='<b>%{label}</b><br>Revenue: β½%{value:,.0f}<br>Percent: %{percent}<extra></extra>',
|
| 107 |
marker_colors=px.colors.qualitative.Set3
|
| 108 |
),
|
| 109 |
-
row=
|
| 110 |
-
)
|
| 111 |
-
|
| 112 |
-
# 4. Revenue Distribution (Bottom Right)
|
| 113 |
-
if 'total_price' in sales_data.columns:
|
| 114 |
-
fig.add_trace(
|
| 115 |
-
go.Histogram(
|
| 116 |
-
x=sales_data['total_price'],
|
| 117 |
-
nbinsx=20,
|
| 118 |
-
name='Revenue Distribution',
|
| 119 |
-
marker_color='#F18F01',
|
| 120 |
-
hovertemplate='Range: β½%{x}<br>Count: %{y}<extra></extra>'
|
| 121 |
-
),
|
| 122 |
-
row=2, col=2
|
| 123 |
)
|
| 124 |
|
| 125 |
except Exception as e:
|
|
@@ -131,10 +118,10 @@ def create_sales_dashboard(sales_data: pd.DataFrame, period: str = "week") -> go
|
|
| 131 |
title=f"π Sales Analytics Dashboard - Last {period.title()}",
|
| 132 |
title_x=0.5,
|
| 133 |
showlegend=False,
|
| 134 |
-
height=
|
| 135 |
-
font=dict(size=
|
| 136 |
template="plotly_white",
|
| 137 |
-
margin=dict(t=
|
| 138 |
)
|
| 139 |
|
| 140 |
# Update axes labels
|
|
@@ -142,11 +129,8 @@ def create_sales_dashboard(sales_data: pd.DataFrame, period: str = "week") -> go
|
|
| 142 |
fig.update_yaxes(title_text="Revenue (β½)", row=1, col=1)
|
| 143 |
fig.update_yaxes(title_text="Quantity", secondary_y=True, row=1, col=1)
|
| 144 |
|
| 145 |
-
fig.update_xaxes(title_text="Revenue (β½)", row=
|
| 146 |
-
fig.update_yaxes(title_text="Products", row=
|
| 147 |
-
|
| 148 |
-
fig.update_xaxes(title_text="Order Value (β½)", row=2, col=2)
|
| 149 |
-
fig.update_yaxes(title_text="Frequency", row=2, col=2)
|
| 150 |
|
| 151 |
return fig
|
| 152 |
|
|
@@ -165,17 +149,17 @@ def create_inventory_dashboard(forecast_data: pd.DataFrame) -> go.Figure:
|
|
| 165 |
|
| 166 |
# Create subplot layout
|
| 167 |
fig = make_subplots(
|
| 168 |
-
rows=
|
| 169 |
subplot_titles=[
|
| 170 |
"π¨ Risk Level Distribution",
|
| 171 |
"β° Days Until Stockout",
|
| 172 |
-
"π¦ Current Stock Levels"
|
| 173 |
-
"π― Reorder Point Analysis"
|
| 174 |
],
|
| 175 |
-
specs=[[{"type": "pie"}
|
| 176 |
-
[{"type": "bar"}
|
| 177 |
-
|
| 178 |
-
|
|
|
|
| 179 |
)
|
| 180 |
|
| 181 |
try:
|
|
@@ -224,13 +208,13 @@ def create_inventory_dashboard(forecast_data: pd.DataFrame) -> go.Figure:
|
|
| 224 |
marker_color=bar_colors,
|
| 225 |
hovertemplate='<b>%{y}</b><br>Days: %{x:.1f}<extra></extra>'
|
| 226 |
),
|
| 227 |
-
row=
|
| 228 |
)
|
| 229 |
|
| 230 |
-
# 3. Current Stock Levels (
|
| 231 |
if 'current_stock' in forecast_data.columns and 'product_name' in forecast_data.columns:
|
| 232 |
-
# Take top
|
| 233 |
-
stock_data = forecast_data.nlargest(
|
| 234 |
|
| 235 |
fig.add_trace(
|
| 236 |
go.Bar(
|
|
@@ -240,50 +224,9 @@ def create_inventory_dashboard(forecast_data: pd.DataFrame) -> go.Figure:
|
|
| 240 |
marker_color='#2E86AB',
|
| 241 |
hovertemplate='<b>%{x}</b><br>Stock: %{y}<extra></extra>'
|
| 242 |
),
|
| 243 |
-
row=
|
| 244 |
-
)
|
| 245 |
-
|
| 246 |
-
# 4. Reorder Point Analysis (Bottom Right)
|
| 247 |
-
if all(col in forecast_data.columns for col in ['current_stock', 'recommended_reorder_point', 'product_name']):
|
| 248 |
-
# Take subset for readability
|
| 249 |
-
reorder_data = forecast_data.head(20)
|
| 250 |
-
|
| 251 |
-
# Current stock scatter
|
| 252 |
-
fig.add_trace(
|
| 253 |
-
go.Scatter(
|
| 254 |
-
x=reorder_data.index,
|
| 255 |
-
y=reorder_data['current_stock'],
|
| 256 |
-
mode='markers',
|
| 257 |
-
name='Current Stock',
|
| 258 |
-
marker=dict(
|
| 259 |
-
size=10,
|
| 260 |
-
color='#2E86AB',
|
| 261 |
-
symbol='circle'
|
| 262 |
-
),
|
| 263 |
-
hovertemplate='<b>%{text}</b><br>Current Stock: %{y}<extra></extra>',
|
| 264 |
-
text=reorder_data['product_name']
|
| 265 |
-
),
|
| 266 |
-
row=2, col=2
|
| 267 |
-
)
|
| 268 |
-
|
| 269 |
-
# Reorder point line
|
| 270 |
-
fig.add_trace(
|
| 271 |
-
go.Scatter(
|
| 272 |
-
x=reorder_data.index,
|
| 273 |
-
y=reorder_data['recommended_reorder_point'],
|
| 274 |
-
mode='markers+lines',
|
| 275 |
-
name='Reorder Point',
|
| 276 |
-
marker=dict(
|
| 277 |
-
size=8,
|
| 278 |
-
color='#A23B72',
|
| 279 |
-
symbol='diamond'
|
| 280 |
-
),
|
| 281 |
-
line=dict(color='#A23B72', dash='dash'),
|
| 282 |
-
hovertemplate='<b>%{text}</b><br>Reorder Point: %{y}<extra></extra>',
|
| 283 |
-
text=reorder_data['product_name']
|
| 284 |
-
),
|
| 285 |
-
row=2, col=2
|
| 286 |
)
|
|
|
|
| 287 |
|
| 288 |
except Exception as e:
|
| 289 |
logger.error(f"Error creating inventory dashboard: {str(e)}")
|
|
@@ -293,22 +236,19 @@ def create_inventory_dashboard(forecast_data: pd.DataFrame) -> go.Figure:
|
|
| 293 |
fig.update_layout(
|
| 294 |
title="π¦ Inventory Risk Analysis Dashboard",
|
| 295 |
title_x=0.5,
|
| 296 |
-
showlegend=
|
| 297 |
-
height=
|
| 298 |
-
font=dict(size=
|
| 299 |
template="plotly_white",
|
| 300 |
-
margin=dict(t=
|
| 301 |
)
|
| 302 |
|
| 303 |
# Update axes
|
| 304 |
-
fig.update_xaxes(title_text="Days", row=
|
| 305 |
-
fig.update_yaxes(title_text="Products", row=
|
| 306 |
-
|
| 307 |
-
fig.update_xaxes(title_text="Products", row=2, col=1, tickangle=45)
|
| 308 |
-
fig.update_yaxes(title_text="Stock Quantity", row=2, col=1)
|
| 309 |
|
| 310 |
-
fig.update_xaxes(title_text="
|
| 311 |
-
fig.update_yaxes(title_text="Quantity", row=
|
| 312 |
|
| 313 |
return fig
|
| 314 |
|
|
|
|
| 28 |
if sales_data.empty:
|
| 29 |
return create_empty_chart("No sales data available")
|
| 30 |
|
| 31 |
+
# Create subplot layout with better spacing
|
| 32 |
fig = make_subplots(
|
| 33 |
+
rows=3, cols=1,
|
| 34 |
subplot_titles=[
|
| 35 |
"π Daily Revenue Trend",
|
| 36 |
+
"π Top Products by Revenue",
|
| 37 |
+
"π Sales by Category"
|
|
|
|
| 38 |
],
|
| 39 |
+
specs=[[{"secondary_y": True}],
|
| 40 |
+
[{"type": "bar"}],
|
| 41 |
+
[{"type": "pie"}]],
|
| 42 |
+
vertical_spacing=0.15,
|
| 43 |
+
row_heights=[0.4, 0.35, 0.25]
|
| 44 |
)
|
| 45 |
|
| 46 |
try:
|
|
|
|
| 78 |
row=1, col=1, secondary_y=True
|
| 79 |
)
|
| 80 |
|
| 81 |
+
# 2. Top Products by Revenue (Second Row)
|
| 82 |
if 'product_name' in sales_data.columns and 'total_price' in sales_data.columns:
|
| 83 |
+
top_products = sales_data.groupby('product_name')['total_price'].sum().nlargest(8).reset_index()
|
| 84 |
|
| 85 |
fig.add_trace(
|
| 86 |
go.Bar(
|
|
|
|
| 91 |
marker_color='#A23B72',
|
| 92 |
hovertemplate='<b>%{y}</b><br>Revenue: β½%{x:,.0f}<extra></extra>'
|
| 93 |
),
|
| 94 |
+
row=2, col=1
|
| 95 |
)
|
| 96 |
|
| 97 |
+
# 3. Sales by Category (Third Row)
|
| 98 |
if 'category' in sales_data.columns and 'total_price' in sales_data.columns:
|
| 99 |
category_sales = sales_data.groupby('category')['total_price'].sum().reset_index()
|
| 100 |
|
|
|
|
| 106 |
hovertemplate='<b>%{label}</b><br>Revenue: β½%{value:,.0f}<br>Percent: %{percent}<extra></extra>',
|
| 107 |
marker_colors=px.colors.qualitative.Set3
|
| 108 |
),
|
| 109 |
+
row=3, col=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
)
|
| 111 |
|
| 112 |
except Exception as e:
|
|
|
|
| 118 |
title=f"π Sales Analytics Dashboard - Last {period.title()}",
|
| 119 |
title_x=0.5,
|
| 120 |
showlegend=False,
|
| 121 |
+
height=1100,
|
| 122 |
+
font=dict(size=12),
|
| 123 |
template="plotly_white",
|
| 124 |
+
margin=dict(t=120, b=80, l=80, r=80)
|
| 125 |
)
|
| 126 |
|
| 127 |
# Update axes labels
|
|
|
|
| 129 |
fig.update_yaxes(title_text="Revenue (β½)", row=1, col=1)
|
| 130 |
fig.update_yaxes(title_text="Quantity", secondary_y=True, row=1, col=1)
|
| 131 |
|
| 132 |
+
fig.update_xaxes(title_text="Revenue (β½)", row=2, col=1)
|
| 133 |
+
fig.update_yaxes(title_text="Products", row=2, col=1)
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
return fig
|
| 136 |
|
|
|
|
| 149 |
|
| 150 |
# Create subplot layout
|
| 151 |
fig = make_subplots(
|
| 152 |
+
rows=3, cols=1,
|
| 153 |
subplot_titles=[
|
| 154 |
"π¨ Risk Level Distribution",
|
| 155 |
"β° Days Until Stockout",
|
| 156 |
+
"π¦ Current Stock Levels"
|
|
|
|
| 157 |
],
|
| 158 |
+
specs=[[{"type": "pie"}],
|
| 159 |
+
[{"type": "bar"}],
|
| 160 |
+
[{"type": "bar"}]],
|
| 161 |
+
vertical_spacing=0.15,
|
| 162 |
+
row_heights=[0.35, 0.35, 0.30]
|
| 163 |
)
|
| 164 |
|
| 165 |
try:
|
|
|
|
| 208 |
marker_color=bar_colors,
|
| 209 |
hovertemplate='<b>%{y}</b><br>Days: %{x:.1f}<extra></extra>'
|
| 210 |
),
|
| 211 |
+
row=2, col=1
|
| 212 |
)
|
| 213 |
|
| 214 |
+
# 3. Current Stock Levels (Third Row)
|
| 215 |
if 'current_stock' in forecast_data.columns and 'product_name' in forecast_data.columns:
|
| 216 |
+
# Take top 10 products by stock level for better visibility
|
| 217 |
+
stock_data = forecast_data.nlargest(10, 'current_stock')
|
| 218 |
|
| 219 |
fig.add_trace(
|
| 220 |
go.Bar(
|
|
|
|
| 224 |
marker_color='#2E86AB',
|
| 225 |
hovertemplate='<b>%{x}</b><br>Stock: %{y}<extra></extra>'
|
| 226 |
),
|
| 227 |
+
row=3, col=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
)
|
| 229 |
+
|
| 230 |
|
| 231 |
except Exception as e:
|
| 232 |
logger.error(f"Error creating inventory dashboard: {str(e)}")
|
|
|
|
| 236 |
fig.update_layout(
|
| 237 |
title="π¦ Inventory Risk Analysis Dashboard",
|
| 238 |
title_x=0.5,
|
| 239 |
+
showlegend=False,
|
| 240 |
+
height=1100,
|
| 241 |
+
font=dict(size=12),
|
| 242 |
template="plotly_white",
|
| 243 |
+
margin=dict(t=120, b=80, l=80, r=80)
|
| 244 |
)
|
| 245 |
|
| 246 |
# Update axes
|
| 247 |
+
fig.update_xaxes(title_text="Days", row=2, col=1)
|
| 248 |
+
fig.update_yaxes(title_text="Products", row=2, col=1)
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
+
fig.update_xaxes(title_text="Products", row=3, col=1, tickangle=45)
|
| 251 |
+
fig.update_yaxes(title_text="Stock Quantity", row=3, col=1)
|
| 252 |
|
| 253 |
return fig
|
| 254 |
|