Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +617 -331
src/streamlit_app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
#Stable version for Yazaki India Ltd
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
@@ -18,6 +19,85 @@ st.set_page_config(
|
|
| 18 |
# Custom CSS (same as before)
|
| 19 |
st.markdown("""
|
| 20 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
</style>
|
| 22 |
""", unsafe_allow_html=True)
|
| 23 |
|
|
@@ -32,7 +112,7 @@ if 'external_signals' not in st.session_state:
|
|
| 32 |
def generate_8week_demand_data():
|
| 33 |
today = datetime(2025, 8, 4)
|
| 34 |
dates = [today + timedelta(days=x) for x in range(56)] # 8 weeks = 56 days
|
| 35 |
-
|
| 36 |
materials = [
|
| 37 |
'YAZ001-Wiring Harness',
|
| 38 |
'YAZ002-Connectors',
|
|
@@ -40,21 +120,21 @@ def generate_8week_demand_data():
|
|
| 40 |
'YAZ004-Sensors',
|
| 41 |
'YAZ005-Cable Assemblies'
|
| 42 |
]
|
| 43 |
-
|
| 44 |
all_data = []
|
| 45 |
-
|
| 46 |
for material in materials:
|
| 47 |
np.random.seed(hash(material) % 1000)
|
| 48 |
-
|
| 49 |
# Generate base demand patterns
|
| 50 |
base_demand = np.random.normal(150, 15, 56)
|
| 51 |
-
|
| 52 |
# First 14 days: FIRM DEMAND
|
| 53 |
firm_demand = np.clip(base_demand[:14], 100, 200).astype(int)
|
| 54 |
-
|
| 55 |
# Days 15-56: Customer shared demand (tentative)
|
| 56 |
customer_shared = np.clip(base_demand[14:] * (1 + 0.05 * np.sin(np.linspace(0, 3.14, 42))), 80, 220).astype(int)
|
| 57 |
-
|
| 58 |
# Days 15-56: AI-corrected demand (with external signals)
|
| 59 |
external_factors = np.zeros(42)
|
| 60 |
# Weather impact (weeks 3-4)
|
|
@@ -64,17 +144,17 @@ def generate_8week_demand_data():
|
|
| 64 |
external_factors[14:] += 10
|
| 65 |
# Festive season boost (weeks 6-7)
|
| 66 |
external_factors[28:42] += 8
|
| 67 |
-
|
| 68 |
corrected_demand = np.clip(customer_shared + external_factors, 60, 250).astype(int)
|
| 69 |
-
|
| 70 |
# Generate supply plan for 56 days
|
| 71 |
supply_capacity = np.random.normal(155, 12, 56)
|
| 72 |
supply_plan = np.clip(supply_capacity, 120, 220).astype(int)
|
| 73 |
-
|
| 74 |
# Apply disruptions to supply (weather impact on days 15-18)
|
| 75 |
supply_actual = supply_plan.copy()
|
| 76 |
supply_actual[15:19] = (supply_actual[15:19] * 0.8).astype(int)
|
| 77 |
-
|
| 78 |
for i, date in enumerate(dates):
|
| 79 |
# Determine which demand to use
|
| 80 |
if i < 14:
|
|
@@ -89,10 +169,10 @@ def generate_8week_demand_data():
|
|
| 89 |
customer_val = customer_shared[i-14]
|
| 90 |
corrected_val = corrected_demand[i-14]
|
| 91 |
demand_type = "AI-Corrected"
|
| 92 |
-
|
| 93 |
# Calculate shortfall
|
| 94 |
shortfall = max(0, demand_used - supply_actual[i])
|
| 95 |
-
|
| 96 |
all_data.append({
|
| 97 |
'Date': date,
|
| 98 |
'Week': f"Week {(i//7)+1}",
|
|
@@ -108,10 +188,10 @@ def generate_8week_demand_data():
|
|
| 108 |
'Demand_Type': demand_type,
|
| 109 |
'Gap': supply_actual[i] - demand_used
|
| 110 |
})
|
| 111 |
-
|
| 112 |
return pd.DataFrame(all_data)
|
| 113 |
|
| 114 |
-
#
|
| 115 |
@st.cache_data
|
| 116 |
def get_tier2_suppliers():
|
| 117 |
return {
|
|
@@ -141,23 +221,23 @@ def get_tier2_suppliers():
|
|
| 141 |
}
|
| 142 |
}
|
| 143 |
|
| 144 |
-
#
|
| 145 |
@st.cache_data
|
| 146 |
def generate_ecosystem_data():
|
| 147 |
today = datetime(2025, 8, 4)
|
| 148 |
dates = [today + timedelta(days=x) for x in range(14)]
|
|
|
|
| 149 |
suppliers = get_tier2_suppliers()
|
| 150 |
-
|
| 151 |
all_data = []
|
| 152 |
-
|
| 153 |
for supplier_name, supplier_info in suppliers.items():
|
| 154 |
for material in supplier_info['materials']:
|
| 155 |
np.random.seed(hash(supplier_name + material) % 1000)
|
| 156 |
-
|
| 157 |
base_capacity = supplier_info['capacity']
|
| 158 |
normal_supply = np.full(14, base_capacity, dtype=int)
|
| 159 |
disrupted_supply = normal_supply.copy()
|
| 160 |
-
|
| 161 |
if supplier_name == 'Electro Components Pvt Ltd':
|
| 162 |
disrupted_supply[3:7] = (disrupted_supply[3:7] * 0.3).astype(int)
|
| 163 |
disruption_cause = "Port delays in Chennai affecting imports"
|
|
@@ -173,16 +253,16 @@ def generate_ecosystem_data():
|
|
| 173 |
else:
|
| 174 |
disruption_cause = "No disruption"
|
| 175 |
disruption_days = []
|
| 176 |
-
|
| 177 |
lead_time = supplier_info['lead_time']
|
| 178 |
yazaki_supply = np.full(14, base_capacity, dtype=int)
|
| 179 |
-
|
| 180 |
for disruption_day in disruption_days:
|
| 181 |
arrival_day = disruption_day + lead_time
|
| 182 |
if arrival_day < 14:
|
| 183 |
reduction = normal_supply[disruption_day] - disrupted_supply[disruption_day]
|
| 184 |
yazaki_supply[arrival_day] = max(yazaki_supply[arrival_day] - reduction, 0)
|
| 185 |
-
|
| 186 |
for i, date in enumerate(dates):
|
| 187 |
all_data.append({
|
| 188 |
'Date': date,
|
|
@@ -199,10 +279,10 @@ def generate_ecosystem_data():
|
|
| 199 |
'Is_Disrupted': i in disruption_days,
|
| 200 |
'Is_Yazaki_Impacted': yazaki_supply[i] < normal_supply[i]
|
| 201 |
})
|
| 202 |
-
|
| 203 |
return pd.DataFrame(all_data)
|
| 204 |
|
| 205 |
-
#
|
| 206 |
@st.cache_data
|
| 207 |
def get_external_signals():
|
| 208 |
return [
|
|
@@ -217,43 +297,41 @@ def get_external_signals():
|
|
| 217 |
# UPDATED: Generate alerts for 8-week data
|
| 218 |
def generate_detailed_alerts(df):
|
| 219 |
alerts = []
|
| 220 |
-
|
| 221 |
for material in df['Material'].unique():
|
| 222 |
material_data = df[df['Material'] == material]
|
| 223 |
shortage_days = material_data[material_data['Shortfall'] > 5]
|
| 224 |
-
|
| 225 |
if not shortage_days.empty:
|
| 226 |
for _, row in shortage_days.iterrows():
|
| 227 |
root_causes = []
|
| 228 |
-
|
| 229 |
if row['Day'] > 14:
|
| 230 |
if row['Corrected_Demand'] and row['Customer_Demand']:
|
| 231 |
diff = row['Corrected_Demand'] - row['Customer_Demand']
|
| 232 |
if diff > 10:
|
| 233 |
root_causes.append(f"AI detected {diff} units additional demand from external signals")
|
| 234 |
-
|
| 235 |
if row['Day'] >= 15 and row['Day'] <= 18:
|
| 236 |
-
root_causes.append("Chennai
|
| 237 |
else:
|
| 238 |
root_causes.append("Firm demand exceeding supply capacity")
|
| 239 |
-
|
| 240 |
if not root_causes:
|
| 241 |
root_causes.append("Base demand exceeding current supply capacity")
|
| 242 |
-
|
| 243 |
mitigation_options = [
|
| 244 |
{"option": "Activate Pune backup production", "impact": "+30 units/day", "cost": "High", "timeline": "24 hours"},
|
| 245 |
{"option": "Expedite Tier-2 supplier shipments", "impact": "+15 units/day", "cost": "Medium", "timeline": "12 hours"},
|
| 246 |
{"option": "Emergency air freight from backup suppliers", "impact": "+40 units/day", "cost": "Very High", "timeline": "6 hours"},
|
| 247 |
{"option": "Reallocate inventory from other plants", "impact": "+20 units/day", "cost": "Low", "timeline": "18 hours"}
|
| 248 |
]
|
| 249 |
-
|
| 250 |
if row['Shortfall'] > 30:
|
| 251 |
best_option = mitigation_options[2]
|
| 252 |
elif row['Shortfall'] > 15:
|
| 253 |
best_option = mitigation_options[0]
|
| 254 |
else:
|
| 255 |
best_option = mitigation_options[1]
|
| 256 |
-
|
| 257 |
alerts.append({
|
| 258 |
'material': material,
|
| 259 |
'date': row['Date'].strftime('%Y-%m-%d'),
|
|
@@ -265,7 +343,7 @@ def generate_detailed_alerts(df):
|
|
| 265 |
'mitigation_options': mitigation_options,
|
| 266 |
'best_option': best_option
|
| 267 |
})
|
| 268 |
-
|
| 269 |
return alerts
|
| 270 |
|
| 271 |
# Keep mitigation strategies unchanged
|
|
@@ -296,14 +374,14 @@ def generate_mitigation_strategies(supplier, material, impact_amount, impact_day
|
|
| 296 |
'capacity': f'+{impact_amount * 0.6:.0f} units/day',
|
| 297 |
}
|
| 298 |
]
|
| 299 |
-
|
| 300 |
if impact_amount > 100:
|
| 301 |
recommended = [0, 1]
|
| 302 |
elif impact_amount > 50:
|
| 303 |
recommended = [0, 2]
|
| 304 |
else:
|
| 305 |
recommended = [2]
|
| 306 |
-
|
| 307 |
return base_strategies, recommended
|
| 308 |
|
| 309 |
# Load data
|
|
@@ -313,7 +391,7 @@ external_signals = get_external_signals()
|
|
| 313 |
suppliers = get_tier2_suppliers()
|
| 314 |
|
| 315 |
# Simple title (header removed as requested)
|
| 316 |
-
st.title("Supply Chain Command Center
|
| 317 |
|
| 318 |
# Tab Navigation (same as before)
|
| 319 |
st.sidebar.title("🎯 Dashboard Navigation")
|
|
@@ -325,332 +403,540 @@ dashboard_tab = st.sidebar.radio(
|
|
| 325 |
|
| 326 |
# UPDATED TAB 1: 8-WEEK DEMAND & SUPPLY FORECAST
|
| 327 |
if dashboard_tab == "📊 Demand & Supply Forecast":
|
| 328 |
-
|
| 329 |
st.markdown("""
|
| 330 |
-
<div
|
| 331 |
-
<
|
| 332 |
-
|
| 333 |
-
</h3>
|
| 334 |
</div>
|
| 335 |
""", unsafe_allow_html=True)
|
| 336 |
-
|
| 337 |
-
# Material
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
material_data = df_demand[df_demand['Material'] == selected_material].copy()
|
| 343 |
-
|
| 344 |
-
# Create forecast visualization
|
| 345 |
-
fig = go.Figure()
|
| 346 |
-
|
| 347 |
-
# Add firm demand (first 14 days)
|
| 348 |
-
firm_data = material_data[material_data['Day'] <= 14]
|
| 349 |
-
fig.add_trace(go.Scatter(
|
| 350 |
-
x=firm_data['Date'],
|
| 351 |
-
y=firm_data['Demand_Used'],
|
| 352 |
-
mode='lines+markers',
|
| 353 |
-
name='Firm Demand (Days 1-14)',
|
| 354 |
-
line=dict(color='#2E86AB', width=3),
|
| 355 |
-
marker=dict(size=8)
|
| 356 |
-
))
|
| 357 |
-
|
| 358 |
-
# Add customer shared demand (days 15-56)
|
| 359 |
-
future_data = material_data[material_data['Day'] > 14]
|
| 360 |
-
fig.add_trace(go.Scatter(
|
| 361 |
-
x=future_data['Date'],
|
| 362 |
-
y=future_data['Customer_Demand'],
|
| 363 |
-
mode='lines',
|
| 364 |
-
name='Customer Shared Demand',
|
| 365 |
-
line=dict(color='#F18F01', width=2, dash='dot'),
|
| 366 |
-
opacity=0.7
|
| 367 |
-
))
|
| 368 |
-
|
| 369 |
-
# Add AI-corrected demand (days 15-56)
|
| 370 |
-
fig.add_trace(go.Scatter(
|
| 371 |
-
x=future_data['Date'],
|
| 372 |
-
y=future_data['Corrected_Demand'],
|
| 373 |
-
mode='lines+markers',
|
| 374 |
-
name='AI-Corrected Demand',
|
| 375 |
-
line=dict(color='#C73E1D', width=3),
|
| 376 |
-
marker=dict(size=6)
|
| 377 |
-
))
|
| 378 |
-
|
| 379 |
-
# Add supply projection
|
| 380 |
-
fig.add_trace(go.Scatter(
|
| 381 |
-
x=material_data['Date'],
|
| 382 |
-
y=material_data['Supply_Projected'],
|
| 383 |
-
mode='lines',
|
| 384 |
-
name='Supply Projection',
|
| 385 |
-
line=dict(color='#4CAF50', width=2),
|
| 386 |
-
fill='tonexty',
|
| 387 |
-
fillcolor='rgba(76, 175, 80, 0.1)'
|
| 388 |
-
))
|
| 389 |
-
|
| 390 |
-
fig.update_layout(
|
| 391 |
-
title=f"📈 8-Week Demand vs Supply Forecast: {selected_material}",
|
| 392 |
-
xaxis_title="Date",
|
| 393 |
-
yaxis_title="Units",
|
| 394 |
-
height=500,
|
| 395 |
-
hovermode='x unified',
|
| 396 |
-
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
|
| 397 |
)
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
'Demand_Used': 'sum',
|
| 404 |
'Supply_Projected': 'sum',
|
| 405 |
'Shortfall': 'sum'
|
| 406 |
}).reset_index()
|
| 407 |
-
|
| 408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
col1, col2 = st.columns(2)
|
| 410 |
-
|
| 411 |
with col1:
|
| 412 |
-
st.
|
| 413 |
-
for
|
| 414 |
-
|
| 415 |
-
status = "✅ Surplus" if gap > 0 else "⚠️ Shortage" if gap < 0 else "⚖️ Balanced"
|
| 416 |
-
|
| 417 |
st.markdown(f"""
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
|
|
|
| 424 |
with col2:
|
| 425 |
-
st.
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
st.
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
""", unsafe_allow_html=True)
|
| 440 |
-
else:
|
| 441 |
-
st.success("✅ No shortages detected for this material!")
|
| 442 |
|
| 443 |
-
# TAB 2: ECOSYSTEM SUPPLIER IMPACT (updated variable names)
|
| 444 |
elif dashboard_tab == "🌐 Ecosystem Supplier Impact":
|
| 445 |
-
|
| 446 |
st.markdown("""
|
| 447 |
-
<div
|
| 448 |
-
<
|
| 449 |
-
|
| 450 |
-
</h3>
|
| 451 |
</div>
|
| 452 |
""", unsafe_allow_html=True)
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
st.markdown(f"""
|
| 473 |
-
<div
|
| 474 |
-
<h4
|
| 475 |
-
<p><
|
| 476 |
-
<p><
|
| 477 |
-
<p><strong>Yazaki Impact:</strong> {supplier['Total_Yazaki_Impact']} units</p>
|
| 478 |
-
<p><strong>Reliability:</strong> {supplier_info['reliability']}%</p>
|
| 479 |
</div>
|
| 480 |
""", unsafe_allow_html=True)
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
x=material_data['Date'],
|
| 505 |
y=material_data['Tier2_Disrupted_Supply'],
|
| 506 |
mode='lines+markers',
|
| 507 |
-
name=f'{
|
|
|
|
| 508 |
marker=dict(size=6)
|
| 509 |
))
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
)
|
| 517 |
-
|
| 518 |
-
st.plotly_chart(
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
disrupted_data = supplier_data[supplier_data['Is_Disrupted'] == True]
|
| 522 |
-
if not disrupted_data.empty:
|
| 523 |
-
st.subheader("⚠️ Disruption Details")
|
| 524 |
-
|
| 525 |
-
for material in disrupted_data['Material'].unique():
|
| 526 |
-
material_disruptions = disrupted_data[disrupted_data['Material'] == material]
|
| 527 |
-
if not material_disruptions.empty:
|
| 528 |
-
disruption_info = material_disruptions.iloc[0]
|
| 529 |
-
|
| 530 |
-
col1, col2 = st.columns(2)
|
| 531 |
-
with col1:
|
| 532 |
-
st.markdown(f"""
|
| 533 |
-
<div style='border-left: 4px solid #FF4444; padding: 15px; background: #f8f9fa; margin: 10px 0;'>
|
| 534 |
-
<strong>Supplier:</strong> {disruption_info['Supplier']}<br>
|
| 535 |
-
<strong>Material:</strong> {disruption_info['Material']}<br>
|
| 536 |
-
<strong>Root Cause:</strong> {disruption_info['Disruption_Cause']}<br>
|
| 537 |
-
<strong>Impact Duration:</strong> {len(material_disruptions)} days<br>
|
| 538 |
-
<strong>Total Impact:</strong> {material_disruptions['Tier2_Impact'].sum()} units
|
| 539 |
-
</div>
|
| 540 |
-
""", unsafe_allow_html=True)
|
| 541 |
-
|
| 542 |
-
with col2:
|
| 543 |
-
# Generate mitigation strategies
|
| 544 |
-
strategies, recommended = generate_mitigation_strategies(
|
| 545 |
-
disruption_info['Supplier'],
|
| 546 |
-
disruption_info['Material'],
|
| 547 |
-
material_disruptions['Tier2_Impact'].sum(),
|
| 548 |
-
len(material_disruptions)
|
| 549 |
-
)
|
| 550 |
-
|
| 551 |
-
st.markdown("**🛠️ Recommended Mitigation Strategies:**")
|
| 552 |
-
for idx in recommended:
|
| 553 |
-
strategy = strategies[idx]
|
| 554 |
-
st.markdown(f"""
|
| 555 |
-
**{strategy['strategy']}**
|
| 556 |
-
- {strategy['description']}
|
| 557 |
-
- Timeline: {strategy['timeline']}
|
| 558 |
-
- Cost: {strategy['cost']}
|
| 559 |
-
- Capacity: {strategy['capacity']}
|
| 560 |
-
""")
|
| 561 |
-
|
| 562 |
-
# TAB 3: BUFFER OPTIMIZER (unchanged)
|
| 563 |
elif dashboard_tab == "🛡️ Buffer Optimizer":
|
| 564 |
-
|
| 565 |
st.markdown("""
|
| 566 |
-
<div
|
| 567 |
-
<
|
| 568 |
-
|
| 569 |
-
</h3>
|
| 570 |
</div>
|
| 571 |
""", unsafe_allow_html=True)
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
st.
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
buffer_df =
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
))
|
| 623 |
-
|
| 624 |
-
fig_buffer.update_layout(
|
| 625 |
-
title='📊 Buffer Stock Analysis: Current vs Recommended',
|
| 626 |
-
xaxis_title='Material',
|
| 627 |
-
yaxis_title='Buffer Units',
|
| 628 |
-
barmode='group',
|
| 629 |
-
height=400
|
| 630 |
-
)
|
| 631 |
-
|
| 632 |
-
st.plotly_chart(fig_buffer, use_container_width=True)
|
| 633 |
-
|
| 634 |
-
# Buffer recommendations
|
| 635 |
-
st.subheader("💡 Buffer Optimization Recommendations")
|
| 636 |
-
|
| 637 |
for _, row in buffer_df.iterrows():
|
| 638 |
-
if row[
|
| 639 |
-
st.
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
|
| 645 |
# Footer
|
|
|
|
| 646 |
st.markdown("""
|
| 647 |
-
|
| 648 |
-
<
|
| 649 |
-
|
| 650 |
-
📊 <strong>Yazaki India Ltd 8-Week Supply Chain Command Center</strong> | Firm + AI-Corrected Demand | Ecosystem Intelligence + Buffer Optimization
|
| 651 |
-
</h3>
|
| 652 |
-
<p style='color: white; margin: 10px 0 0 0;'>
|
| 653 |
-
Powered by Agentic AI | 8-Week Planning Horizon | Comprehensive Supply Chain Resilience
|
| 654 |
-
</p>
|
| 655 |
</div>
|
| 656 |
""", unsafe_allow_html=True)
|
|
|
|
| 1 |
#Stable version for Yazaki India Ltd
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
|
|
|
| 19 |
# Custom CSS (same as before)
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
+
.tab-header {
|
| 23 |
+
background: linear-gradient(90deg, #059669, #10b981);
|
| 24 |
+
padding: 0.8rem;
|
| 25 |
+
border-radius: 8px;
|
| 26 |
+
color: white;
|
| 27 |
+
margin-bottom: 1rem;
|
| 28 |
+
}
|
| 29 |
+
.alert-card {
|
| 30 |
+
background: #fff5f5;
|
| 31 |
+
padding: 1rem;
|
| 32 |
+
border-radius: 8px;
|
| 33 |
+
border-left: 6px solid #e53e3e;
|
| 34 |
+
margin: 0.5rem 0;
|
| 35 |
+
}
|
| 36 |
+
.ecosystem-alert {
|
| 37 |
+
background: #fef2f2;
|
| 38 |
+
padding: 1rem;
|
| 39 |
+
border-radius: 8px;
|
| 40 |
+
border-left: 6px solid #dc2626;
|
| 41 |
+
margin: 0.5rem 0;
|
| 42 |
+
}
|
| 43 |
+
.root-cause {
|
| 44 |
+
background: #fef7e7;
|
| 45 |
+
padding: 0.8rem;
|
| 46 |
+
border-radius: 6px;
|
| 47 |
+
margin: 0.3rem 0;
|
| 48 |
+
border-left: 3px solid #f6ad55;
|
| 49 |
+
}
|
| 50 |
+
.mitigation {
|
| 51 |
+
background: #e6fffa;
|
| 52 |
+
padding: 0.8rem;
|
| 53 |
+
border-radius: 6px;
|
| 54 |
+
margin: 0.3rem 0;
|
| 55 |
+
border-left: 3px solid #4fd1c7;
|
| 56 |
+
}
|
| 57 |
+
.best-option {
|
| 58 |
+
background: #f0fff4;
|
| 59 |
+
padding: 0.8rem;
|
| 60 |
+
border-radius: 6px;
|
| 61 |
+
margin: 0.3rem 0;
|
| 62 |
+
border-left: 4px solid #48bb78;
|
| 63 |
+
border: 2px solid #48bb78;
|
| 64 |
+
}
|
| 65 |
+
.tier-impact {
|
| 66 |
+
background: #fff7ed;
|
| 67 |
+
padding: 0.8rem;
|
| 68 |
+
border-radius: 6px;
|
| 69 |
+
margin: 0.3rem 0;
|
| 70 |
+
border-left: 4px solid #f97316;
|
| 71 |
+
}
|
| 72 |
+
.mitigation-executed {
|
| 73 |
+
background: #ecfdf5;
|
| 74 |
+
padding: 0.8rem;
|
| 75 |
+
border-radius: 6px;
|
| 76 |
+
margin: 0.3rem 0;
|
| 77 |
+
border-left: 4px solid #10b981;
|
| 78 |
+
border: 2px solid #10b981;
|
| 79 |
+
}
|
| 80 |
+
.mitigation-recommended {
|
| 81 |
+
background: #eff6ff;
|
| 82 |
+
padding: 0.8rem;
|
| 83 |
+
border-radius: 6px;
|
| 84 |
+
margin: 0.3rem 0;
|
| 85 |
+
border-left: 4px solid #3b82f6;
|
| 86 |
+
}
|
| 87 |
+
.normal-status {
|
| 88 |
+
background: #f0fff4;
|
| 89 |
+
padding: 0.6rem;
|
| 90 |
+
border-radius: 6px;
|
| 91 |
+
border-left: 4px solid #48bb78;
|
| 92 |
+
margin: 0.2rem 0;
|
| 93 |
+
}
|
| 94 |
+
.external-signal {
|
| 95 |
+
background: #f3e5f5;
|
| 96 |
+
padding: 0.6rem;
|
| 97 |
+
border-radius: 6px;
|
| 98 |
+
border-left: 4px solid #9c27b0;
|
| 99 |
+
margin: 0.2rem 0;
|
| 100 |
+
}
|
| 101 |
</style>
|
| 102 |
""", unsafe_allow_html=True)
|
| 103 |
|
|
|
|
| 112 |
def generate_8week_demand_data():
|
| 113 |
today = datetime(2025, 8, 4)
|
| 114 |
dates = [today + timedelta(days=x) for x in range(56)] # 8 weeks = 56 days
|
| 115 |
+
|
| 116 |
materials = [
|
| 117 |
'YAZ001-Wiring Harness',
|
| 118 |
'YAZ002-Connectors',
|
|
|
|
| 120 |
'YAZ004-Sensors',
|
| 121 |
'YAZ005-Cable Assemblies'
|
| 122 |
]
|
| 123 |
+
|
| 124 |
all_data = []
|
| 125 |
+
|
| 126 |
for material in materials:
|
| 127 |
np.random.seed(hash(material) % 1000)
|
| 128 |
+
|
| 129 |
# Generate base demand patterns
|
| 130 |
base_demand = np.random.normal(150, 15, 56)
|
| 131 |
+
|
| 132 |
# First 14 days: FIRM DEMAND
|
| 133 |
firm_demand = np.clip(base_demand[:14], 100, 200).astype(int)
|
| 134 |
+
|
| 135 |
# Days 15-56: Customer shared demand (tentative)
|
| 136 |
customer_shared = np.clip(base_demand[14:] * (1 + 0.05 * np.sin(np.linspace(0, 3.14, 42))), 80, 220).astype(int)
|
| 137 |
+
|
| 138 |
# Days 15-56: AI-corrected demand (with external signals)
|
| 139 |
external_factors = np.zeros(42)
|
| 140 |
# Weather impact (weeks 3-4)
|
|
|
|
| 144 |
external_factors[14:] += 10
|
| 145 |
# Festive season boost (weeks 6-7)
|
| 146 |
external_factors[28:42] += 8
|
| 147 |
+
|
| 148 |
corrected_demand = np.clip(customer_shared + external_factors, 60, 250).astype(int)
|
| 149 |
+
|
| 150 |
# Generate supply plan for 56 days
|
| 151 |
supply_capacity = np.random.normal(155, 12, 56)
|
| 152 |
supply_plan = np.clip(supply_capacity, 120, 220).astype(int)
|
| 153 |
+
|
| 154 |
# Apply disruptions to supply (weather impact on days 15-18)
|
| 155 |
supply_actual = supply_plan.copy()
|
| 156 |
supply_actual[15:19] = (supply_actual[15:19] * 0.8).astype(int)
|
| 157 |
+
|
| 158 |
for i, date in enumerate(dates):
|
| 159 |
# Determine which demand to use
|
| 160 |
if i < 14:
|
|
|
|
| 169 |
customer_val = customer_shared[i-14]
|
| 170 |
corrected_val = corrected_demand[i-14]
|
| 171 |
demand_type = "AI-Corrected"
|
| 172 |
+
|
| 173 |
# Calculate shortfall
|
| 174 |
shortfall = max(0, demand_used - supply_actual[i])
|
| 175 |
+
|
| 176 |
all_data.append({
|
| 177 |
'Date': date,
|
| 178 |
'Week': f"Week {(i//7)+1}",
|
|
|
|
| 188 |
'Demand_Type': demand_type,
|
| 189 |
'Gap': supply_actual[i] - demand_used
|
| 190 |
})
|
| 191 |
+
|
| 192 |
return pd.DataFrame(all_data)
|
| 193 |
|
| 194 |
+
# UPDATED: Tier-2 suppliers for Yazaki India
|
| 195 |
@st.cache_data
|
| 196 |
def get_tier2_suppliers():
|
| 197 |
return {
|
|
|
|
| 221 |
}
|
| 222 |
}
|
| 223 |
|
| 224 |
+
# UPDATED: Ecosystem data with Yazaki-specific naming
|
| 225 |
@st.cache_data
|
| 226 |
def generate_ecosystem_data():
|
| 227 |
today = datetime(2025, 8, 4)
|
| 228 |
dates = [today + timedelta(days=x) for x in range(14)]
|
| 229 |
+
|
| 230 |
suppliers = get_tier2_suppliers()
|
|
|
|
| 231 |
all_data = []
|
| 232 |
+
|
| 233 |
for supplier_name, supplier_info in suppliers.items():
|
| 234 |
for material in supplier_info['materials']:
|
| 235 |
np.random.seed(hash(supplier_name + material) % 1000)
|
| 236 |
+
|
| 237 |
base_capacity = supplier_info['capacity']
|
| 238 |
normal_supply = np.full(14, base_capacity, dtype=int)
|
| 239 |
disrupted_supply = normal_supply.copy()
|
| 240 |
+
|
| 241 |
if supplier_name == 'Electro Components Pvt Ltd':
|
| 242 |
disrupted_supply[3:7] = (disrupted_supply[3:7] * 0.3).astype(int)
|
| 243 |
disruption_cause = "Port delays in Chennai affecting imports"
|
|
|
|
| 253 |
else:
|
| 254 |
disruption_cause = "No disruption"
|
| 255 |
disruption_days = []
|
| 256 |
+
|
| 257 |
lead_time = supplier_info['lead_time']
|
| 258 |
yazaki_supply = np.full(14, base_capacity, dtype=int)
|
| 259 |
+
|
| 260 |
for disruption_day in disruption_days:
|
| 261 |
arrival_day = disruption_day + lead_time
|
| 262 |
if arrival_day < 14:
|
| 263 |
reduction = normal_supply[disruption_day] - disrupted_supply[disruption_day]
|
| 264 |
yazaki_supply[arrival_day] = max(yazaki_supply[arrival_day] - reduction, 0)
|
| 265 |
+
|
| 266 |
for i, date in enumerate(dates):
|
| 267 |
all_data.append({
|
| 268 |
'Date': date,
|
|
|
|
| 279 |
'Is_Disrupted': i in disruption_days,
|
| 280 |
'Is_Yazaki_Impacted': yazaki_supply[i] < normal_supply[i]
|
| 281 |
})
|
| 282 |
+
|
| 283 |
return pd.DataFrame(all_data)
|
| 284 |
|
| 285 |
+
# External signals (unchanged)
|
| 286 |
@st.cache_data
|
| 287 |
def get_external_signals():
|
| 288 |
return [
|
|
|
|
| 297 |
# UPDATED: Generate alerts for 8-week data
|
| 298 |
def generate_detailed_alerts(df):
|
| 299 |
alerts = []
|
| 300 |
+
|
| 301 |
for material in df['Material'].unique():
|
| 302 |
material_data = df[df['Material'] == material]
|
| 303 |
shortage_days = material_data[material_data['Shortfall'] > 5]
|
| 304 |
+
|
| 305 |
if not shortage_days.empty:
|
| 306 |
for _, row in shortage_days.iterrows():
|
| 307 |
root_causes = []
|
|
|
|
| 308 |
if row['Day'] > 14:
|
| 309 |
if row['Corrected_Demand'] and row['Customer_Demand']:
|
| 310 |
diff = row['Corrected_Demand'] - row['Customer_Demand']
|
| 311 |
if diff > 10:
|
| 312 |
root_causes.append(f"AI detected {diff} units additional demand from external signals")
|
|
|
|
| 313 |
if row['Day'] >= 15 and row['Day'] <= 18:
|
| 314 |
+
root_causes.append("Chennai plant weather disruption reducing supply")
|
| 315 |
else:
|
| 316 |
root_causes.append("Firm demand exceeding supply capacity")
|
| 317 |
+
|
| 318 |
if not root_causes:
|
| 319 |
root_causes.append("Base demand exceeding current supply capacity")
|
| 320 |
+
|
| 321 |
mitigation_options = [
|
| 322 |
{"option": "Activate Pune backup production", "impact": "+30 units/day", "cost": "High", "timeline": "24 hours"},
|
| 323 |
{"option": "Expedite Tier-2 supplier shipments", "impact": "+15 units/day", "cost": "Medium", "timeline": "12 hours"},
|
| 324 |
{"option": "Emergency air freight from backup suppliers", "impact": "+40 units/day", "cost": "Very High", "timeline": "6 hours"},
|
| 325 |
{"option": "Reallocate inventory from other plants", "impact": "+20 units/day", "cost": "Low", "timeline": "18 hours"}
|
| 326 |
]
|
| 327 |
+
|
| 328 |
if row['Shortfall'] > 30:
|
| 329 |
best_option = mitigation_options[2]
|
| 330 |
elif row['Shortfall'] > 15:
|
| 331 |
best_option = mitigation_options[0]
|
| 332 |
else:
|
| 333 |
best_option = mitigation_options[1]
|
| 334 |
+
|
| 335 |
alerts.append({
|
| 336 |
'material': material,
|
| 337 |
'date': row['Date'].strftime('%Y-%m-%d'),
|
|
|
|
| 343 |
'mitigation_options': mitigation_options,
|
| 344 |
'best_option': best_option
|
| 345 |
})
|
| 346 |
+
|
| 347 |
return alerts
|
| 348 |
|
| 349 |
# Keep mitigation strategies unchanged
|
|
|
|
| 374 |
'capacity': f'+{impact_amount * 0.6:.0f} units/day',
|
| 375 |
}
|
| 376 |
]
|
| 377 |
+
|
| 378 |
if impact_amount > 100:
|
| 379 |
recommended = [0, 1]
|
| 380 |
elif impact_amount > 50:
|
| 381 |
recommended = [0, 2]
|
| 382 |
else:
|
| 383 |
recommended = [2]
|
| 384 |
+
|
| 385 |
return base_strategies, recommended
|
| 386 |
|
| 387 |
# Load data
|
|
|
|
| 391 |
suppliers = get_tier2_suppliers()
|
| 392 |
|
| 393 |
# Simple title (header removed as requested)
|
| 394 |
+
st.title("Supply Chain Command Center")
|
| 395 |
|
| 396 |
# Tab Navigation (same as before)
|
| 397 |
st.sidebar.title("🎯 Dashboard Navigation")
|
|
|
|
| 403 |
|
| 404 |
# UPDATED TAB 1: 8-WEEK DEMAND & SUPPLY FORECAST
|
| 405 |
if dashboard_tab == "📊 Demand & Supply Forecast":
|
|
|
|
| 406 |
st.markdown("""
|
| 407 |
+
<div class="tab-header">
|
| 408 |
+
<h2>📊 8-Week Demand & Supply Forecast Dashboard</h2>
|
| 409 |
+
<p>8-Week Planning Horizon | Firm Demand (Days 1-14) | AI-Corrected Demand (Days 15-56)</p>
|
|
|
|
| 410 |
</div>
|
| 411 |
""", unsafe_allow_html=True)
|
| 412 |
+
|
| 413 |
+
# Material selection
|
| 414 |
+
selected_materials_demand = st.sidebar.multiselect(
|
| 415 |
+
"Focus Materials:",
|
| 416 |
+
df_demand['Material'].unique(),
|
| 417 |
+
default=df_demand['Material'].unique()[:3]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
)
|
| 419 |
+
|
| 420 |
+
# Week filter
|
| 421 |
+
week_filter = st.sidebar.selectbox(
|
| 422 |
+
"Focus on Weeks:",
|
| 423 |
+
["All 8 Weeks", "Weeks 1-2 (Firm)", "Weeks 3-4", "Weeks 5-6", "Weeks 7-8"],
|
| 424 |
+
index=0
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
# Filter data
|
| 428 |
+
filtered_df_demand = df_demand[df_demand['Material'].isin(selected_materials_demand)]
|
| 429 |
+
|
| 430 |
+
if week_filter != "All 8 Weeks":
|
| 431 |
+
if week_filter == "Weeks 1-2 (Firm)":
|
| 432 |
+
filtered_df_demand = filtered_df_demand[filtered_df_demand['Day'] <= 14]
|
| 433 |
+
elif week_filter == "Weeks 3-4":
|
| 434 |
+
filtered_df_demand = filtered_df_demand[(filtered_df_demand['Day'] > 14) & (filtered_df_demand['Day'] <= 28)]
|
| 435 |
+
elif week_filter == "Weeks 5-6":
|
| 436 |
+
filtered_df_demand = filtered_df_demand[(filtered_df_demand['Day'] > 28) & (filtered_df_demand['Day'] <= 42)]
|
| 437 |
+
else: # Weeks 7-8
|
| 438 |
+
filtered_df_demand = filtered_df_demand[filtered_df_demand['Day'] > 42]
|
| 439 |
+
|
| 440 |
+
# Generate and display alerts
|
| 441 |
+
st.subheader("🚨 8-Week Supply Chain Alerts")
|
| 442 |
+
|
| 443 |
+
alerts = generate_detailed_alerts(filtered_df_demand)
|
| 444 |
+
|
| 445 |
+
if alerts:
|
| 446 |
+
for i, alert in enumerate(alerts[:3]):
|
| 447 |
+
st.markdown(f"""
|
| 448 |
+
<div class="alert-card">
|
| 449 |
+
<h4>⚠️ {alert['material']} - {alert['severity']} Shortage Alert</h4>
|
| 450 |
+
<p><b>Date:</b> {alert['date']} ({alert['week']}) | <b>Shortage:</b> {alert['shortage']} units | <b>Type:</b> {alert['demand_type']}</p>
|
| 451 |
+
</div>
|
| 452 |
+
""", unsafe_allow_html=True)
|
| 453 |
+
|
| 454 |
+
st.markdown("**🔍 Root Cause Analysis:**")
|
| 455 |
+
for cause in alert['root_causes']:
|
| 456 |
+
st.markdown(f"""
|
| 457 |
+
<div class="root-cause">
|
| 458 |
+
🎯 {cause}
|
| 459 |
+
</div>
|
| 460 |
+
""", unsafe_allow_html=True)
|
| 461 |
+
|
| 462 |
+
st.markdown("**⚡ Mitigation Options:**")
|
| 463 |
+
for option in alert['mitigation_options']:
|
| 464 |
+
is_best = option == alert['best_option']
|
| 465 |
+
option_class = "best-option" if is_best else "mitigation"
|
| 466 |
+
best_indicator = "🏆 **RECOMMENDED** " if is_best else ""
|
| 467 |
+
|
| 468 |
+
st.markdown(f"""
|
| 469 |
+
<div class="{option_class}">
|
| 470 |
+
{best_indicator}<b>{option['option']}</b><br>
|
| 471 |
+
📈 Impact: {option['impact']} | 💰 Cost: {option['cost']} | ⏱️ Timeline: {option['timeline']}
|
| 472 |
+
</div>
|
| 473 |
+
""", unsafe_allow_html=True)
|
| 474 |
+
|
| 475 |
+
col1, col2, col3 = st.columns([2, 1, 1])
|
| 476 |
+
with col1:
|
| 477 |
+
if st.button(f"✅ Implement Solution", key=f"demand_implement_{i}"):
|
| 478 |
+
st.success(f"Implementing: {alert['best_option']['option']}")
|
| 479 |
+
|
| 480 |
+
st.markdown("---")
|
| 481 |
+
else:
|
| 482 |
+
st.markdown("""
|
| 483 |
+
<div class="normal-status">
|
| 484 |
+
✅ <b>All Good!</b> No critical supply shortages detected in the 8-week horizon.
|
| 485 |
+
</div>
|
| 486 |
+
""", unsafe_allow_html=True)
|
| 487 |
+
|
| 488 |
+
# UPDATED: 8-Week Detailed Planning Table
|
| 489 |
+
st.subheader("📋 8-Week Demand-Supply Planning Table")
|
| 490 |
+
|
| 491 |
+
# Prepare display table
|
| 492 |
+
display_df = filtered_df_demand.copy()
|
| 493 |
+
display_df['Date_Display'] = display_df['Date'].dt.strftime('%m-%d')
|
| 494 |
+
|
| 495 |
+
# Create styled table
|
| 496 |
+
table_cols = ['Date_Display', 'Week', 'Material', 'Firm_Demand', 'Customer_Demand',
|
| 497 |
+
'Corrected_Demand', 'Supply_Projected', 'Shortfall']
|
| 498 |
+
|
| 499 |
+
table_data = display_df[table_cols].copy()
|
| 500 |
+
table_data.columns = ['Date', 'Week', 'Material', 'Firm Demand', 'Customer Demand',
|
| 501 |
+
'Corrected Demand', 'Supply Plan', 'Shortfall']
|
| 502 |
+
|
| 503 |
+
# Color coding function
|
| 504 |
+
def highlight_shortfall(val):
|
| 505 |
+
if pd.isna(val):
|
| 506 |
+
return ''
|
| 507 |
+
return 'background-color: #ffcccc' if val > 0 else ''
|
| 508 |
+
|
| 509 |
+
def highlight_firm_period(row):
|
| 510 |
+
if pd.notna(row['Firm Demand']):
|
| 511 |
+
return ['background-color: #e6f3ff'] * len(row)
|
| 512 |
+
return [''] * len(row)
|
| 513 |
+
|
| 514 |
+
# Apply styling
|
| 515 |
+
styled_table = table_data.style.applymap(highlight_shortfall, subset=['Shortfall'])
|
| 516 |
+
styled_table = styled_table.apply(highlight_firm_period, axis=1)
|
| 517 |
+
|
| 518 |
+
st.dataframe(styled_table, use_container_width=True, height=500)
|
| 519 |
+
|
| 520 |
+
# Weekly summary
|
| 521 |
+
st.subheader("📊 Weekly Summary")
|
| 522 |
+
|
| 523 |
+
weekly_summary = filtered_df_demand.groupby(['Week', 'Material']).agg({
|
| 524 |
'Demand_Used': 'sum',
|
| 525 |
'Supply_Projected': 'sum',
|
| 526 |
'Shortfall': 'sum'
|
| 527 |
}).reset_index()
|
| 528 |
+
|
| 529 |
+
weekly_summary['Balance'] = weekly_summary['Supply_Projected'] - weekly_summary['Demand_Used']
|
| 530 |
+
|
| 531 |
+
st.dataframe(weekly_summary, use_container_width=True)
|
| 532 |
+
|
| 533 |
+
# Enhanced visualization
|
| 534 |
+
st.subheader("📈 8-Week Demand vs Supply Outlook")
|
| 535 |
+
|
| 536 |
+
for material in selected_materials_demand:
|
| 537 |
+
material_data = filtered_df_demand[filtered_df_demand['Material'] == material]
|
| 538 |
+
|
| 539 |
+
st.markdown(f"**{material}**")
|
| 540 |
+
|
| 541 |
+
fig = go.Figure()
|
| 542 |
+
|
| 543 |
+
# Add demand used line
|
| 544 |
+
fig.add_trace(go.Scatter(
|
| 545 |
+
x=material_data['Date'],
|
| 546 |
+
y=material_data['Demand_Used'],
|
| 547 |
+
mode='lines+markers',
|
| 548 |
+
name='Demand Used',
|
| 549 |
+
line=dict(color='blue', width=3),
|
| 550 |
+
marker=dict(size=6)
|
| 551 |
+
))
|
| 552 |
+
|
| 553 |
+
# Add supply line
|
| 554 |
+
fig.add_trace(go.Scatter(
|
| 555 |
+
x=material_data['Date'],
|
| 556 |
+
y=material_data['Supply_Projected'],
|
| 557 |
+
mode='lines+markers',
|
| 558 |
+
name='Supply Projected',
|
| 559 |
+
line=dict(color='green', width=3),
|
| 560 |
+
marker=dict(size=6)
|
| 561 |
+
))
|
| 562 |
+
|
| 563 |
+
# Highlight shortfall areas
|
| 564 |
+
shortage_data = material_data[material_data['Shortfall'] > 0]
|
| 565 |
+
if not shortage_data.empty:
|
| 566 |
+
fig.add_trace(go.Scatter(
|
| 567 |
+
x=shortage_data['Date'],
|
| 568 |
+
y=shortage_data['Supply_Projected'],
|
| 569 |
+
mode='markers',
|
| 570 |
+
name='Shortage Days',
|
| 571 |
+
marker=dict(color='red', size=10, symbol='x'),
|
| 572 |
+
))
|
| 573 |
+
|
| 574 |
+
# Mark firm demand period
|
| 575 |
+
firm_data = material_data[material_data['Day'] <= 14]
|
| 576 |
+
if not firm_data.empty:
|
| 577 |
+
fig.add_vrect(
|
| 578 |
+
x0=firm_data['Date'].min(),
|
| 579 |
+
x1=firm_data['Date'].max(),
|
| 580 |
+
fillcolor="lightblue",
|
| 581 |
+
opacity=0.2,
|
| 582 |
+
line_width=0,
|
| 583 |
+
annotation_text="Firm Demand Period",
|
| 584 |
+
annotation_position="top left"
|
| 585 |
+
)
|
| 586 |
+
|
| 587 |
+
fig.update_layout(
|
| 588 |
+
title=f'{material} - 8-Week Supply vs Demand Forecast',
|
| 589 |
+
xaxis_title='Date',
|
| 590 |
+
yaxis_title='Units',
|
| 591 |
+
height=400,
|
| 592 |
+
showlegend=True,
|
| 593 |
+
hovermode='x unified'
|
| 594 |
+
)
|
| 595 |
+
|
| 596 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 597 |
+
|
| 598 |
+
# External demand sensing (same as before)
|
| 599 |
+
st.subheader("📡 Real-time External Demand Sensing")
|
| 600 |
+
|
| 601 |
col1, col2 = st.columns(2)
|
| 602 |
+
|
| 603 |
with col1:
|
| 604 |
+
st.write("**Active External Signals:**")
|
| 605 |
+
for signal in external_signals:
|
| 606 |
+
confidence_color = "🟢" if signal['Confidence'] > 90 else "🟡" if signal['Confidence'] > 80 else "🟠"
|
|
|
|
|
|
|
| 607 |
st.markdown(f"""
|
| 608 |
+
<div class="external-signal">
|
| 609 |
+
<b>{confidence_color} {signal['Source']}</b><br>
|
| 610 |
+
{signal['Signal']}<br>
|
| 611 |
+
<small>Impact: {signal['Impact']} | Confidence: {signal['Confidence']}%</small>
|
| 612 |
+
</div>
|
| 613 |
+
""", unsafe_allow_html=True)
|
| 614 |
+
|
| 615 |
with col2:
|
| 616 |
+
st.write("**8-Week Scenario Planning:**")
|
| 617 |
+
|
| 618 |
+
scenario = st.selectbox("Select Scenario to Test:",
|
| 619 |
+
["Base Case", "Extended Monsoon", "Sustained EV Boost", "Supply Chain Strike"])
|
| 620 |
+
|
| 621 |
+
if st.button("🎮 Run 8-Week Scenario", key="demand_scenario"):
|
| 622 |
+
if scenario == "Extended Monsoon":
|
| 623 |
+
st.error("Scenario: 30% supply reduction for 3 weeks. Activating multi-tier contingency plans...")
|
| 624 |
+
elif scenario == "Sustained EV Boost":
|
| 625 |
+
st.warning("Scenario: 25% demand increase for 6 weeks. Scaling ecosystem capacity...")
|
| 626 |
+
elif scenario == "Supply Chain Strike":
|
| 627 |
+
st.info("Scenario: Multi-supplier disruption. Implementing emergency protocols...")
|
| 628 |
+
|
| 629 |
+
# Keep TAB 2 and TAB 3 unchanged from previous version, but replace Rane with Yazaki in variables and text
|
|
|
|
|
|
|
|
|
|
| 630 |
|
|
|
|
| 631 |
elif dashboard_tab == "🌐 Ecosystem Supplier Impact":
|
|
|
|
| 632 |
st.markdown("""
|
| 633 |
+
<div class="tab-header">
|
| 634 |
+
<h2>🌐 Ecosystem Supplier Impact Dashboard</h2>
|
| 635 |
+
<p>Tier 2 Supplier Disruption Analysis | Cascading Impact Modeling | Automated Mitigation Response</p>
|
|
|
|
| 636 |
</div>
|
| 637 |
""", unsafe_allow_html=True)
|
| 638 |
+
|
| 639 |
+
selected_suppliers = st.sidebar.multiselect(
|
| 640 |
+
"Monitor Suppliers:",
|
| 641 |
+
list(suppliers.keys()),
|
| 642 |
+
default=list(suppliers.keys())
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
st.subheader("🚨 Live Ecosystem Supply Chain Alerts")
|
| 646 |
+
|
| 647 |
+
ecosystem_alerts = []
|
| 648 |
+
for supplier in selected_suppliers:
|
| 649 |
+
supplier_data = df_ecosystem[df_ecosystem['Supplier'] == supplier]
|
| 650 |
+
disrupted_data = supplier_data[supplier_data['Is_Disrupted'] == True]
|
| 651 |
+
|
| 652 |
+
if not disrupted_data.empty:
|
| 653 |
+
for material in disrupted_data['Material'].unique():
|
| 654 |
+
material_disruptions = disrupted_data[disrupted_data['Material'] == material]
|
| 655 |
+
|
| 656 |
+
total_impact = material_disruptions['Tier2_Impact'].sum()
|
| 657 |
+
impact_days = len(material_disruptions)
|
| 658 |
+
first_impact_date = material_disruptions['Date'].min()
|
| 659 |
+
|
| 660 |
+
yazaki_impacted = supplier_data[
|
| 661 |
+
(supplier_data['Material'] == material) &
|
| 662 |
+
(supplier_data['Is_Yazaki_Impacted'] == True)
|
| 663 |
+
]
|
| 664 |
+
|
| 665 |
+
if not yazaki_impacted.empty:
|
| 666 |
+
yazaki_impact_start = yazaki_impacted['Date'].min()
|
| 667 |
+
yazaki_impact_days = len(yazaki_impacted)
|
| 668 |
+
yazaki_total_impact = yazaki_impacted['Yazaki_Impact'].sum()
|
| 669 |
+
|
| 670 |
+
ecosystem_alerts.append({
|
| 671 |
+
'supplier': supplier,
|
| 672 |
+
'material': material,
|
| 673 |
+
'disruption_cause': material_disruptions.iloc[0]['Disruption_Cause'],
|
| 674 |
+
'tier2_impact_start': first_impact_date,
|
| 675 |
+
'tier2_impact_days': impact_days,
|
| 676 |
+
'tier2_total_impact': total_impact,
|
| 677 |
+
'yazaki_impact_start': yazaki_impact_start,
|
| 678 |
+
'yazaki_impact_days': yazaki_impact_days,
|
| 679 |
+
'yazaki_total_impact': yazaki_total_impact,
|
| 680 |
+
'lead_time': material_disruptions.iloc[0]['Lead_Time_Days']
|
| 681 |
+
})
|
| 682 |
+
|
| 683 |
+
if ecosystem_alerts:
|
| 684 |
+
for alert in ecosystem_alerts:
|
| 685 |
st.markdown(f"""
|
| 686 |
+
<div class="ecosystem-alert">
|
| 687 |
+
<h4>⚠️ Tier 2 Supplier Disruption Alert</h4>
|
| 688 |
+
<p><b>Supplier:</b> {alert['supplier']} | <b>Material:</b> {alert['material']}</p>
|
| 689 |
+
<p><b>Root Cause:</b> {alert['disruption_cause']}</p>
|
|
|
|
|
|
|
| 690 |
</div>
|
| 691 |
""", unsafe_allow_html=True)
|
| 692 |
+
|
| 693 |
+
col1, col2 = st.columns(2)
|
| 694 |
+
|
| 695 |
+
with col1:
|
| 696 |
+
st.markdown("**🏭 Tier 2 Supplier Impact:**")
|
| 697 |
+
st.markdown(f"""
|
| 698 |
+
<div class="tier-impact">
|
| 699 |
+
📅 <b>Impact Period:</b> {alert['tier2_impact_start'].strftime('%Y-%m-%d')} ({alert['tier2_impact_days']} days)<br>
|
| 700 |
+
📉 <b>Total Supply Lost:</b> {alert['tier2_total_impact']} units<br>
|
| 701 |
+
🎯 <b>Daily Impact:</b> {alert['tier2_total_impact'] // alert['tier2_impact_days']} units/day
|
| 702 |
+
</div>
|
| 703 |
+
""", unsafe_allow_html=True)
|
| 704 |
+
|
| 705 |
+
with col2:
|
| 706 |
+
st.markdown("**⚙️ Yazaki India Ltd Impact (with Lead Time):**")
|
| 707 |
+
st.markdown(f"""
|
| 708 |
+
<div class="tier-impact">
|
| 709 |
+
📅 <b>Impact Period:</b> {alert['yazaki_impact_start'].strftime('%Y-%m-%d')} ({alert['yazaki_impact_days']} days)<br>
|
| 710 |
+
📉 <b>Total Supply Lost:</b> {alert['yazaki_total_impact']} units<br>
|
| 711 |
+
⏱️ <b>Lead Time Delay:</b> {alert['lead_time']} days
|
| 712 |
+
</div>
|
| 713 |
+
""", unsafe_allow_html=True)
|
| 714 |
+
|
| 715 |
+
strategies, recommended_indices = generate_mitigation_strategies(
|
| 716 |
+
alert['supplier'],
|
| 717 |
+
alert['material'],
|
| 718 |
+
alert['yazaki_total_impact'] // alert['yazaki_impact_days'],
|
| 719 |
+
alert['yazaki_impact_days']
|
| 720 |
+
)
|
| 721 |
+
|
| 722 |
+
st.markdown("**🤖 Agentic AI Mitigation Strategies:**")
|
| 723 |
+
|
| 724 |
+
for i, strategy in enumerate(strategies):
|
| 725 |
+
is_recommended = i in recommended_indices
|
| 726 |
+
is_executed = f"eco_{alert['supplier']}_{alert['material']}_{i}" in st.session_state.executed_mitigations
|
| 727 |
+
|
| 728 |
+
if is_executed:
|
| 729 |
+
card_class = "mitigation-executed"
|
| 730 |
+
status_prefix = "✅ **EXECUTED** "
|
| 731 |
+
elif is_recommended:
|
| 732 |
+
card_class = "mitigation-recommended"
|
| 733 |
+
status_prefix = "🏆 **AI RECOMMENDED** "
|
| 734 |
+
else:
|
| 735 |
+
card_class = "mitigation-recommended"
|
| 736 |
+
status_prefix = ""
|
| 737 |
+
|
| 738 |
+
st.markdown(f"""
|
| 739 |
+
<div class="{card_class}">
|
| 740 |
+
{status_prefix}<b>{strategy['strategy']}</b><br>
|
| 741 |
+
📋 {strategy['description']}<br>
|
| 742 |
+
⏱️ <b>Timeline:</b> {strategy['timeline']} | 💰 <b>Cost:</b> {strategy['cost']}<br>
|
| 743 |
+
📈 <b>Effectiveness:</b> {strategy['effectiveness']} | 🚀 <b>Capacity:</b> {strategy['capacity']}
|
| 744 |
+
</div>
|
| 745 |
+
""", unsafe_allow_html=True)
|
| 746 |
+
|
| 747 |
+
strategy_key = f"eco_{alert['supplier']}_{alert['material']}_{i}"
|
| 748 |
+
|
| 749 |
+
col1, col2 = st.columns([2, 1])
|
| 750 |
+
|
| 751 |
+
with col1:
|
| 752 |
+
if not is_executed:
|
| 753 |
+
if st.button(f"🚀 Execute Strategy", key=f"execute_{strategy_key}"):
|
| 754 |
+
st.session_state.executed_mitigations.append(strategy_key)
|
| 755 |
+
st.success(f"Executing: {strategy['strategy']}")
|
| 756 |
+
st.rerun()
|
| 757 |
+
else:
|
| 758 |
+
st.success("Strategy Active")
|
| 759 |
+
|
| 760 |
+
with col2:
|
| 761 |
+
if is_recommended:
|
| 762 |
+
st.button("🏆 Recommended", key=f"rec_{strategy_key}", disabled=True)
|
| 763 |
+
|
| 764 |
+
st.markdown("---")
|
| 765 |
+
else:
|
| 766 |
+
st.markdown("""
|
| 767 |
+
<div class="normal-status">
|
| 768 |
+
✅ <b>Ecosystem Healthy!</b> No supplier disruptions detected in the current timeframe.
|
| 769 |
+
</div>
|
| 770 |
+
""", unsafe_allow_html=True)
|
| 771 |
+
|
| 772 |
+
st.subheader("📊 Ecosystem Supply Chain Flow Visualization")
|
| 773 |
+
|
| 774 |
+
fig = go.Figure()
|
| 775 |
+
|
| 776 |
+
for supplier in selected_suppliers:
|
| 777 |
+
supplier_data = df_ecosystem[df_ecosystem['Supplier'] == supplier]
|
| 778 |
+
sample_material = supplier_data['Material'].iloc[0]
|
| 779 |
+
material_data = supplier_data[supplier_data['Material'] == sample_material]
|
| 780 |
+
|
| 781 |
+
fig.add_trace(go.Scatter(
|
| 782 |
x=material_data['Date'],
|
| 783 |
y=material_data['Tier2_Disrupted_Supply'],
|
| 784 |
mode='lines+markers',
|
| 785 |
+
name=f'{supplier} (Tier 2)',
|
| 786 |
+
line=dict(width=2, dash='dash'),
|
| 787 |
marker=dict(size=6)
|
| 788 |
))
|
| 789 |
+
|
| 790 |
+
fig.add_trace(go.Scatter(
|
| 791 |
+
x=material_data['Date'],
|
| 792 |
+
y=material_data['Yazaki_Impacted_Supply'],
|
| 793 |
+
mode='lines+markers',
|
| 794 |
+
name=f'Yazaki Impact from {supplier}',
|
| 795 |
+
line=dict(width=3),
|
| 796 |
+
marker=dict(size=8)
|
| 797 |
+
))
|
| 798 |
+
|
| 799 |
+
fig.update_layout(
|
| 800 |
+
title='Tier 2 Supplier Disruptions → Yazaki India Ltd Supply Impact',
|
| 801 |
+
xaxis_title='Date',
|
| 802 |
+
yaxis_title='Supply Units',
|
| 803 |
+
height=500,
|
| 804 |
+
showlegend=True,
|
| 805 |
+
hovermode='x unified'
|
| 806 |
)
|
| 807 |
+
|
| 808 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 809 |
+
|
| 810 |
+
# TAB 3: BUFFER OPTIMIZER (same as before)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 811 |
elif dashboard_tab == "🛡️ Buffer Optimizer":
|
|
|
|
| 812 |
st.markdown("""
|
| 813 |
+
<div class="tab-header">
|
| 814 |
+
<h2>🛡️ Multi-Echelon Buffer Optimizer</h2>
|
| 815 |
+
<p>AI-driven safety-stock recommendations across the full network</p>
|
|
|
|
| 816 |
</div>
|
| 817 |
""", unsafe_allow_html=True)
|
| 818 |
+
|
| 819 |
+
service_level = st.slider("Target Service Level (%)", 90, 99, 95)
|
| 820 |
+
review_period = st.number_input("Inventory Review Period (days)", min_value=1, max_value=14, value=1)
|
| 821 |
+
|
| 822 |
+
z_factor = {90: 1.28, 92: 1.41, 95: 1.64, 97: 1.88, 98: 2.05, 99: 2.33}
|
| 823 |
+
Z = z_factor.get(service_level, 1.64)
|
| 824 |
+
|
| 825 |
+
# Use 8-week demand data for buffer calculation
|
| 826 |
+
demand_stats = (df_demand
|
| 827 |
+
.groupby("Material")
|
| 828 |
+
.agg(DailyMean=("Demand_Used", "mean"),
|
| 829 |
+
Sigma=("Demand_Used", "std"))
|
| 830 |
+
.reset_index())
|
| 831 |
+
|
| 832 |
+
lead_times = (df_ecosystem
|
| 833 |
+
.groupby("Material")
|
| 834 |
+
.agg(LeadTime=("Lead_Time_Days", "max"))
|
| 835 |
+
.reset_index())
|
| 836 |
+
|
| 837 |
+
current_buffers = (df_demand[df_demand["Day"] == 1]
|
| 838 |
+
.loc[:, ["Material", "Supply_Projected"]]
|
| 839 |
+
.rename(columns={"Supply_Projected": "OnHand"}))
|
| 840 |
+
|
| 841 |
+
buffer_df = (demand_stats.merge(lead_times, on="Material")
|
| 842 |
+
.merge(current_buffers, on="Material", how="left"))
|
| 843 |
+
|
| 844 |
+
buffer_df["RecommendedBuffer"] = (
|
| 845 |
+
Z * buffer_df["Sigma"] * np.sqrt(buffer_df["LeadTime"] + review_period)
|
| 846 |
+
).round()
|
| 847 |
+
|
| 848 |
+
buffer_df["Delta"] = buffer_df["RecommendedBuffer"] - buffer_df["OnHand"]
|
| 849 |
+
buffer_df["Action"] = np.where(buffer_df["Delta"] > 50,
|
| 850 |
+
"Increase buffer",
|
| 851 |
+
np.where(buffer_df["Delta"] < -50,
|
| 852 |
+
"Reduce buffer", "OK"))
|
| 853 |
+
|
| 854 |
+
st.subheader("📋 Buffer Recommendations")
|
| 855 |
+
display_cols = ["Material", "OnHand", "RecommendedBuffer", "Delta", "Action"]
|
| 856 |
+
st.dataframe(buffer_df[display_cols], use_container_width=True, height=300)
|
| 857 |
+
|
| 858 |
+
st.subheader("💰 Cost Impact Analysis")
|
| 859 |
+
carrying_cost = st.number_input("Annual Carrying Cost (% of unit cost)", min_value=0, max_value=50, value=20)
|
| 860 |
+
unit_cost = 100
|
| 861 |
+
|
| 862 |
+
buffer_df["CostImpact(₹)"] = (buffer_df["Delta"] * unit_cost * (carrying_cost/100) / 12)
|
| 863 |
+
|
| 864 |
+
cost_chart_data = buffer_df.set_index("Material")["CostImpact(₹)"]
|
| 865 |
+
st.bar_chart(cost_chart_data)
|
| 866 |
+
|
| 867 |
+
st.subheader("⚡ Execute AI Recommendations")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
for _, row in buffer_df.iterrows():
|
| 869 |
+
if row["Action"] != "OK":
|
| 870 |
+
if st.button(f"🚀 {row['Action']} for {row['Material']}", key=row["Material"]):
|
| 871 |
+
st.success(f"AI executed: {row['Action']} - Adjusting {int(row['Delta'])} units for {row['Material']}")
|
| 872 |
+
|
| 873 |
+
# Performance summary
|
| 874 |
+
st.subheader("📊 Performance Summary")
|
| 875 |
+
|
| 876 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 877 |
+
|
| 878 |
+
if dashboard_tab == "📊 Demand & Supply Forecast":
|
| 879 |
+
filtered_df = filtered_df_demand if 'filtered_df_demand' in locals() else df_demand
|
| 880 |
+
|
| 881 |
+
total_shortage_days = len(filtered_df[filtered_df['Shortfall'] > 0])
|
| 882 |
+
critical_shortage_days = len(filtered_df[filtered_df['Shortfall'] > 30])
|
| 883 |
+
materials_at_risk = len(filtered_df[filtered_df['Shortfall'] > 5]['Material'].unique())
|
| 884 |
+
avg_shortfall = filtered_df['Shortfall'].mean()
|
| 885 |
+
|
| 886 |
+
with col1:
|
| 887 |
+
st.metric("Days with Shortages", f"{total_shortage_days}")
|
| 888 |
+
|
| 889 |
+
with col2:
|
| 890 |
+
st.metric("Critical Days", f"{critical_shortage_days}")
|
| 891 |
+
|
| 892 |
+
with col3:
|
| 893 |
+
st.metric("Materials at Risk", f"{materials_at_risk}")
|
| 894 |
+
|
| 895 |
+
with col4:
|
| 896 |
+
st.metric("Avg Daily Shortfall", f"{avg_shortfall:.1f} units")
|
| 897 |
+
|
| 898 |
+
elif dashboard_tab == "🌐 Ecosystem Supplier Impact":
|
| 899 |
+
total_suppliers_disrupted = len(df_ecosystem[df_ecosystem['Is_Disrupted'] == True]['Supplier'].unique())
|
| 900 |
+
total_yazaki_impact_days = len(df_ecosystem[df_ecosystem['Is_Yazaki_Impacted'] == True])
|
| 901 |
+
total_mitigation_strategies = len([s for s in st.session_state.executed_mitigations if 'eco_' in s])
|
| 902 |
+
avg_lead_time = df_ecosystem['Lead_Time_Days'].mean()
|
| 903 |
+
|
| 904 |
+
with col1:
|
| 905 |
+
st.metric("Suppliers Disrupted", f"{total_suppliers_disrupted}")
|
| 906 |
+
|
| 907 |
+
with col2:
|
| 908 |
+
st.metric("Yazaki Impact Days", f"{total_yazaki_impact_days}")
|
| 909 |
+
|
| 910 |
+
with col3:
|
| 911 |
+
st.metric("Active Mitigations", f"{total_mitigation_strategies}")
|
| 912 |
+
|
| 913 |
+
with col4:
|
| 914 |
+
st.metric("Avg Lead Time", f"{avg_lead_time:.1f} days")
|
| 915 |
+
|
| 916 |
+
else: # Buffer Optimizer
|
| 917 |
+
if 'buffer_df' in locals():
|
| 918 |
+
total_materials = len(buffer_df)
|
| 919 |
+
materials_need_increase = len(buffer_df[buffer_df['Action'] == 'Increase buffer'])
|
| 920 |
+
materials_need_decrease = len(buffer_df[buffer_df['Action'] == 'Reduce buffer'])
|
| 921 |
+
total_cost_impact = buffer_df['CostImpact(₹)'].sum()
|
| 922 |
+
|
| 923 |
+
with col1:
|
| 924 |
+
st.metric("Total Materials", f"{total_materials}")
|
| 925 |
+
|
| 926 |
+
with col2:
|
| 927 |
+
st.metric("Need Buffer Increase", f"{materials_need_increase}")
|
| 928 |
+
|
| 929 |
+
with col3:
|
| 930 |
+
st.metric("Need Buffer Reduction", f"{materials_need_decrease}")
|
| 931 |
+
|
| 932 |
+
with col4:
|
| 933 |
+
st.metric("Monthly Cost Impact", f"₹{total_cost_impact:,.0f}")
|
| 934 |
|
| 935 |
# Footer
|
| 936 |
+
st.markdown("---")
|
| 937 |
st.markdown("""
|
| 938 |
+
<div style='text-align: center; color: #666;'>
|
| 939 |
+
<p>🌐 <b>Yazaki India Ltd 8-Week Supply Chain Command Center</b> | Firm + AI-Corrected Demand | Ecosystem Intelligence + Buffer Optimization<br>
|
| 940 |
+
Powered by Agentic AI | 8-Week Planning Horizon | Comprehensive Supply Chain Resilience</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 941 |
</div>
|
| 942 |
""", unsafe_allow_html=True)
|