Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +155 -662
src/streamlit_app.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
#Stable version for Yazaki India Ltd
|
| 2 |
-
|
| 3 |
import streamlit as st
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
|
@@ -18,92 +16,12 @@ st.set_page_config(
|
|
| 18 |
|
| 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 |
|
| 104 |
# Initialize session state
|
| 105 |
if 'executed_mitigations' not in st.session_state:
|
| 106 |
st.session_state.executed_mitigations = []
|
|
|
|
| 107 |
if 'external_signals' not in st.session_state:
|
| 108 |
st.session_state.external_signals = []
|
| 109 |
|
|
@@ -114,19 +32,16 @@ def generate_8week_demand_data():
|
|
| 114 |
dates = [today + timedelta(days=x) for x in range(56)] # 8 weeks = 56 days
|
| 115 |
|
| 116 |
materials = [
|
| 117 |
-
'
|
| 118 |
-
'
|
| 119 |
-
'
|
| 120 |
-
'
|
| 121 |
-
'
|
| 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
|
|
@@ -139,9 +54,8 @@ def generate_8week_demand_data():
|
|
| 139 |
external_factors = np.zeros(42)
|
| 140 |
# Weather impact (weeks 3-4)
|
| 141 |
external_factors[0:14] += np.random.normal(0, 5, 14)
|
| 142 |
-
# EV policy impact (weeks 5-8)
|
| 143 |
-
|
| 144 |
-
external_factors[14:] += 10
|
| 145 |
# Festive season boost (weeks 6-7)
|
| 146 |
external_factors[28:42] += 8
|
| 147 |
|
|
@@ -156,7 +70,6 @@ def generate_8week_demand_data():
|
|
| 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:
|
| 161 |
demand_used = firm_demand[i]
|
| 162 |
firm_val = firm_demand[i]
|
|
@@ -170,12 +83,11 @@ def generate_8week_demand_data():
|
|
| 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}",
|
| 179 |
'Day': i + 1,
|
| 180 |
'Material': material,
|
| 181 |
'Firm_Demand': firm_val,
|
|
@@ -188,65 +100,62 @@ def generate_8week_demand_data():
|
|
| 188 |
'Demand_Type': demand_type,
|
| 189 |
'Gap': supply_actual[i] - demand_used
|
| 190 |
})
|
| 191 |
-
|
| 192 |
return pd.DataFrame(all_data)
|
| 193 |
|
| 194 |
-
#
|
| 195 |
@st.cache_data
|
| 196 |
def get_tier2_suppliers():
|
| 197 |
return {
|
| 198 |
-
'
|
| 199 |
-
'location': '
|
| 200 |
-
'materials': ['
|
| 201 |
-
'capacity':
|
| 202 |
-
'reliability':
|
| 203 |
-
'lead_time': 2,
|
| 204 |
-
'risk_factors': ['Monsoon flooding', 'Labor strikes', 'Power outages']
|
| 205 |
-
},
|
| 206 |
-
'Precision Components': {
|
| 207 |
-
'location': 'Bangalore',
|
| 208 |
-
'materials': ['STG003-Power Steering', 'BRK001-Brake Pads'],
|
| 209 |
-
'capacity': 180,
|
| 210 |
-
'reliability': 92,
|
| 211 |
'lead_time': 3,
|
| 212 |
-
'risk_factors': ['
|
| 213 |
},
|
| 214 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
'location': 'Pune',
|
| 216 |
-
'materials': ['
|
| 217 |
-
'capacity':
|
| 218 |
-
'reliability':
|
| 219 |
'lead_time': 1,
|
| 220 |
-
'risk_factors': ['Quality
|
| 221 |
}
|
| 222 |
}
|
| 223 |
|
| 224 |
-
#
|
| 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 == '
|
| 242 |
disrupted_supply[3:7] = (disrupted_supply[3:7] * 0.3).astype(int)
|
| 243 |
-
disruption_cause = "
|
| 244 |
disruption_days = list(range(3, 7))
|
| 245 |
-
elif supplier_name == '
|
| 246 |
disrupted_supply[5:8] = (disrupted_supply[5:8] * 0.5).astype(int)
|
| 247 |
disruption_cause = "Critical equipment failure"
|
| 248 |
disruption_days = list(range(5, 8))
|
| 249 |
-
elif supplier_name == '
|
| 250 |
disrupted_supply[8:11] = (disrupted_supply[8:11] * 0.2).astype(int)
|
| 251 |
disruption_cause = "Labor strike at Pune facility"
|
| 252 |
disruption_days = list(range(8, 11))
|
|
@@ -255,13 +164,13 @@ def generate_ecosystem_data():
|
|
| 255 |
disruption_days = []
|
| 256 |
|
| 257 |
lead_time = supplier_info['lead_time']
|
| 258 |
-
|
| 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 |
-
|
| 265 |
|
| 266 |
for i, date in enumerate(dates):
|
| 267 |
all_data.append({
|
|
@@ -271,37 +180,34 @@ def generate_ecosystem_data():
|
|
| 271 |
'Tier2_Normal_Supply': int(normal_supply[i]),
|
| 272 |
'Tier2_Disrupted_Supply': int(disrupted_supply[i]),
|
| 273 |
'Tier2_Impact': int(normal_supply[i] - disrupted_supply[i]),
|
| 274 |
-
'
|
| 275 |
-
'
|
| 276 |
-
'
|
| 277 |
'Disruption_Cause': disruption_cause if i in disruption_days else "Normal Operations",
|
| 278 |
'Lead_Time_Days': lead_time,
|
| 279 |
'Is_Disrupted': i in disruption_days,
|
| 280 |
-
'
|
| 281 |
})
|
| 282 |
-
|
| 283 |
return pd.DataFrame(all_data)
|
| 284 |
|
| 285 |
-
#
|
| 286 |
@st.cache_data
|
| 287 |
def get_external_signals():
|
| 288 |
return [
|
| 289 |
{'Source': 'Weather API', 'Signal': 'Heavy rains forecasted in Chennai for next 3 days', 'Impact': 'Supply Risk', 'Confidence': 95},
|
| 290 |
{'Source': 'Market Intelligence', 'Signal': 'EV sales up 25% this quarter', 'Impact': 'Demand Increase', 'Confidence': 88},
|
| 291 |
{'Source': 'News Analytics', 'Signal': 'Upcoming festive season - historically 15% demand spike', 'Impact': 'Demand Surge', 'Confidence': 92},
|
| 292 |
-
{'Source': 'Supplier Network', 'Signal': 'Tier-
|
| 293 |
-
{'Source': 'Social Media', 'Signal': 'Positive sentiment around new
|
| 294 |
{'Source': 'Government Portal', 'Signal': 'New EV subsidy policy effective next week', 'Impact': 'Market Expansion', 'Confidence': 100}
|
| 295 |
]
|
| 296 |
|
| 297 |
-
#
|
| 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 = []
|
|
@@ -310,11 +216,10 @@ def generate_detailed_alerts(df):
|
|
| 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
|
| 314 |
root_causes.append("Chennai plant weather disruption reducing supply")
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
if not root_causes:
|
| 319 |
root_causes.append("Base demand exceeding current supply capacity")
|
| 320 |
|
|
@@ -343,10 +248,9 @@ def generate_detailed_alerts(df):
|
|
| 343 |
'mitigation_options': mitigation_options,
|
| 344 |
'best_option': best_option
|
| 345 |
})
|
| 346 |
-
|
| 347 |
return alerts
|
| 348 |
|
| 349 |
-
#
|
| 350 |
def generate_mitigation_strategies(supplier, material, impact_amount, impact_days):
|
| 351 |
base_strategies = [
|
| 352 |
{
|
|
@@ -374,14 +278,12 @@ def generate_mitigation_strategies(supplier, material, impact_amount, impact_day
|
|
| 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
|
|
@@ -390,10 +292,10 @@ df_ecosystem = generate_ecosystem_data()
|
|
| 390 |
external_signals = get_external_signals()
|
| 391 |
suppliers = get_tier2_suppliers()
|
| 392 |
|
| 393 |
-
# Simple title
|
| 394 |
-
st.title("Supply Chain Command Center")
|
| 395 |
|
| 396 |
-
# Tab Navigation
|
| 397 |
st.sidebar.title("🎯 Dashboard Navigation")
|
| 398 |
dashboard_tab = st.sidebar.radio(
|
| 399 |
"Select Dashboard:",
|
|
@@ -401,541 +303,132 @@ dashboard_tab = st.sidebar.radio(
|
|
| 401 |
index=0
|
| 402 |
)
|
| 403 |
|
| 404 |
-
#
|
| 405 |
if dashboard_tab == "📊 Demand & Supply Forecast":
|
| 406 |
st.markdown("""
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
"""
|
| 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 |
-
#
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
)
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 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 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
""
|
| 453 |
-
|
| 454 |
-
st.markdown("**🔍 Root Cause Analysis:**")
|
| 455 |
for cause in alert['root_causes']:
|
| 456 |
-
st.markdown(f""
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
"
|
| 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.
|
| 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 |
-
#
|
| 630 |
elif dashboard_tab == "🌐 Ecosystem Supplier Impact":
|
| 631 |
st.markdown("""
|
| 632 |
-
|
| 633 |
-
<h2>🌐 Ecosystem Supplier Impact Dashboard</h2>
|
| 634 |
-
<p>Tier 2 Supplier Disruption Analysis | Cascading Impact Modeling | Automated Mitigation Response</p>
|
| 635 |
-
</div>
|
| 636 |
-
""", unsafe_allow_html=True)
|
| 637 |
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
list(suppliers.keys()),
|
| 641 |
-
default=list(suppliers.keys())
|
| 642 |
-
)
|
| 643 |
|
| 644 |
-
|
| 645 |
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
supplier_data = df_ecosystem[df_ecosystem['Supplier'] == supplier]
|
| 649 |
-
disrupted_data = supplier_data[supplier_data['Is_Disrupted'] == True]
|
| 650 |
-
|
| 651 |
-
if not disrupted_data.empty:
|
| 652 |
-
for material in disrupted_data['Material'].unique():
|
| 653 |
-
material_disruptions = disrupted_data[disrupted_data['Material'] == material]
|
| 654 |
-
|
| 655 |
-
total_impact = material_disruptions['Tier2_Impact'].sum()
|
| 656 |
-
impact_days = len(material_disruptions)
|
| 657 |
-
first_impact_date = material_disruptions['Date'].min()
|
| 658 |
-
|
| 659 |
-
Yazaki India Ltd_impacted = supplier_data[
|
| 660 |
-
(supplier_data['Material'] == material) &
|
| 661 |
-
(supplier_data['Is_Yazaki India Ltd_Impacted'] == True)
|
| 662 |
-
]
|
| 663 |
-
|
| 664 |
-
if not Yazaki India Ltd_impacted.empty:
|
| 665 |
-
Yazaki India Ltd_impact_start = Yazaki India Ltd_impacted['Date'].min()
|
| 666 |
-
Yazaki India Ltd_impact_days = len(Yazaki India Ltd_impacted)
|
| 667 |
-
Yazaki India Ltd_total_impact = Yazaki India Ltd_impacted['Yazaki India Ltd_Impact'].sum()
|
| 668 |
-
|
| 669 |
-
ecosystem_alerts.append({
|
| 670 |
-
'supplier': supplier,
|
| 671 |
-
'material': material,
|
| 672 |
-
'disruption_cause': material_disruptions.iloc[0]['Disruption_Cause'],
|
| 673 |
-
'tier2_impact_start': first_impact_date,
|
| 674 |
-
'tier2_impact_days': impact_days,
|
| 675 |
-
'tier2_total_impact': total_impact,
|
| 676 |
-
'Yazaki India Ltd_impact_start': Yazaki India Ltd_impact_start,
|
| 677 |
-
'Yazaki India Ltd_impact_days': Yazaki India Ltd_impact_days,
|
| 678 |
-
'Yazaki India Ltd_total_impact': Yazaki India Ltd_total_impact,
|
| 679 |
-
'lead_time': material_disruptions.iloc[0]['Lead_Time_Days']
|
| 680 |
-
})
|
| 681 |
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
<h4>⚠️ Tier 2 Supplier Disruption Alert</h4>
|
| 687 |
-
<p><b>Supplier:</b> {alert['supplier']} | <b>Material:</b> {alert['material']}</p>
|
| 688 |
-
<p><b>Root Cause:</b> {alert['disruption_cause']}</p>
|
| 689 |
-
</div>
|
| 690 |
-
""", unsafe_allow_html=True)
|
| 691 |
-
|
| 692 |
-
col1, col2 = st.columns(2)
|
| 693 |
-
|
| 694 |
-
with col1:
|
| 695 |
-
st.markdown("**🏭 Tier 2 Supplier Impact:**")
|
| 696 |
-
st.markdown(f"""
|
| 697 |
-
<div class="tier-impact">
|
| 698 |
-
📅 <b>Impact Period:</b> {alert['tier2_impact_start'].strftime('%Y-%m-%d')} ({alert['tier2_impact_days']} days)<br>
|
| 699 |
-
📉 <b>Total Supply Lost:</b> {alert['tier2_total_impact']} units<br>
|
| 700 |
-
🎯 <b>Daily Impact:</b> {alert['tier2_total_impact'] // alert['tier2_impact_days']} units/day
|
| 701 |
-
</div>
|
| 702 |
-
""", unsafe_allow_html=True)
|
| 703 |
-
|
| 704 |
-
with col2:
|
| 705 |
-
st.markdown("**⚙️ Yazaki India Ltd Impact (with Lead Time):**")
|
| 706 |
-
st.markdown(f"""
|
| 707 |
-
<div class="tier-impact">
|
| 708 |
-
📅 <b>Impact Period:</b> {alert['Yazaki India Ltd_impact_start'].strftime('%Y-%m-%d')} ({alert['Yazaki India Ltd_impact_days']} days)<br>
|
| 709 |
-
📉 <b>Total Supply Lost:</b> {alert['Yazaki India Ltd_total_impact']} units<br>
|
| 710 |
-
⏱️ <b>Lead Time Delay:</b> {alert['lead_time']} days
|
| 711 |
-
</div>
|
| 712 |
-
""", unsafe_allow_html=True)
|
| 713 |
-
|
| 714 |
-
strategies, recommended_indices = generate_mitigation_strategies(
|
| 715 |
-
alert['supplier'],
|
| 716 |
-
alert['material'],
|
| 717 |
-
alert['Yazaki India Ltd_total_impact'] // alert['Yazaki India Ltd_impact_days'],
|
| 718 |
-
alert['Yazaki India Ltd_impact_days']
|
| 719 |
-
)
|
| 720 |
-
|
| 721 |
-
st.markdown("**🤖 Agentic AI Mitigation Strategies:**")
|
| 722 |
-
|
| 723 |
-
for i, strategy in enumerate(strategies):
|
| 724 |
-
is_recommended = i in recommended_indices
|
| 725 |
-
is_executed = f"eco_{alert['supplier']}_{alert['material']}_{i}" in st.session_state.executed_mitigations
|
| 726 |
-
|
| 727 |
-
if is_executed:
|
| 728 |
-
card_class = "mitigation-executed"
|
| 729 |
-
status_prefix = "✅ **EXECUTED** "
|
| 730 |
-
elif is_recommended:
|
| 731 |
-
card_class = "mitigation-recommended"
|
| 732 |
-
status_prefix = "🏆 **AI RECOMMENDED** "
|
| 733 |
-
else:
|
| 734 |
-
card_class = "mitigation-recommended"
|
| 735 |
-
status_prefix = ""
|
| 736 |
-
|
| 737 |
-
st.markdown(f"""
|
| 738 |
-
<div class="{card_class}">
|
| 739 |
-
{status_prefix}<b>{strategy['strategy']}</b><br>
|
| 740 |
-
📋 {strategy['description']}<br>
|
| 741 |
-
⏱️ <b>Timeline:</b> {strategy['timeline']} | 💰 <b>Cost:</b> {strategy['cost']}<br>
|
| 742 |
-
📈 <b>Effectiveness:</b> {strategy['effectiveness']} | 🚀 <b>Capacity:</b> {strategy['capacity']}
|
| 743 |
-
</div>
|
| 744 |
-
""", unsafe_allow_html=True)
|
| 745 |
-
|
| 746 |
-
strategy_key = f"eco_{alert['supplier']}_{alert['material']}_{i}"
|
| 747 |
-
|
| 748 |
-
col1, col2 = st.columns([2, 1])
|
| 749 |
-
|
| 750 |
-
with col1:
|
| 751 |
-
if not is_executed:
|
| 752 |
-
if st.button(f"🚀 Execute Strategy", key=f"execute_{strategy_key}"):
|
| 753 |
-
st.session_state.executed_mitigations.append(strategy_key)
|
| 754 |
-
st.success(f"Executing: {strategy['strategy']}")
|
| 755 |
-
st.rerun()
|
| 756 |
-
else:
|
| 757 |
-
st.success("Strategy Active")
|
| 758 |
-
|
| 759 |
-
with col2:
|
| 760 |
-
if is_recommended:
|
| 761 |
-
st.button("🏆 Recommended", key=f"rec_{strategy_key}", disabled=True)
|
| 762 |
-
|
| 763 |
-
st.markdown("---")
|
| 764 |
-
else:
|
| 765 |
-
st.markdown("""
|
| 766 |
-
<div class="normal-status">
|
| 767 |
-
✅ <b>Ecosystem Healthy!</b> No supplier disruptions detected in the current timeframe.
|
| 768 |
-
</div>
|
| 769 |
-
""", unsafe_allow_html=True)
|
| 770 |
-
|
| 771 |
-
st.subheader("📊 Ecosystem Supply Chain Flow Visualization")
|
| 772 |
-
|
| 773 |
-
fig = go.Figure()
|
| 774 |
-
|
| 775 |
-
for supplier in selected_suppliers:
|
| 776 |
-
supplier_data = df_ecosystem[df_ecosystem['Supplier'] == supplier]
|
| 777 |
-
sample_material = supplier_data['Material'].iloc[0]
|
| 778 |
-
material_data = supplier_data[supplier_data['Material'] == sample_material]
|
| 779 |
-
|
| 780 |
-
fig.add_trace(go.Scatter(
|
| 781 |
-
x=material_data['Date'],
|
| 782 |
-
y=material_data['Tier2_Disrupted_Supply'],
|
| 783 |
-
mode='lines+markers',
|
| 784 |
-
name=f'{supplier} (Tier 2)',
|
| 785 |
-
line=dict(width=2, dash='dash'),
|
| 786 |
-
marker=dict(size=6)
|
| 787 |
-
))
|
| 788 |
-
|
| 789 |
-
fig.add_trace(go.Scatter(
|
| 790 |
-
x=material_data['Date'],
|
| 791 |
-
y=material_data['Yazaki India Ltd_Impacted_Supply'],
|
| 792 |
-
mode='lines+markers',
|
| 793 |
-
name=f'Yazaki India Ltd Impact from {supplier}',
|
| 794 |
-
line=dict(width=3),
|
| 795 |
-
marker=dict(size=8)
|
| 796 |
-
))
|
| 797 |
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
)
|
| 806 |
-
|
| 807 |
-
st.plotly_chart(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
|
| 809 |
-
# TAB 3: BUFFER OPTIMIZER
|
| 810 |
elif dashboard_tab == "🛡️ Buffer Optimizer":
|
| 811 |
st.markdown("""
|
| 812 |
-
|
| 813 |
-
<h2>🛡️ Multi-Echelon Buffer Optimizer</h2>
|
| 814 |
-
<p>AI-driven safety-stock recommendations across the full network</p>
|
| 815 |
-
</div>
|
| 816 |
-
""", unsafe_allow_html=True)
|
| 817 |
-
|
| 818 |
-
service_level = st.slider("Target Service Level (%)", 90, 99, 95)
|
| 819 |
-
review_period = st.number_input("Inventory Review Period (days)", min_value=1, max_value=14, value=1)
|
| 820 |
-
|
| 821 |
-
z_factor = {90: 1.28, 92: 1.41, 95: 1.64, 97: 1.88, 98: 2.05, 99: 2.33}
|
| 822 |
-
Z = z_factor.get(service_level, 1.64)
|
| 823 |
-
|
| 824 |
-
# Use 8-week demand data for buffer calculation
|
| 825 |
-
demand_stats = (df_demand
|
| 826 |
-
.groupby("Material")
|
| 827 |
-
.agg(DailyMean=("Demand_Used", "mean"),
|
| 828 |
-
Sigma=("Demand_Used", "std"))
|
| 829 |
-
.reset_index())
|
| 830 |
-
|
| 831 |
-
lead_times = (df_ecosystem
|
| 832 |
-
.groupby("Material")
|
| 833 |
-
.agg(LeadTime=("Lead_Time_Days", "max"))
|
| 834 |
-
.reset_index())
|
| 835 |
-
|
| 836 |
-
current_buffers = (df_demand[df_demand["Day"] == 1]
|
| 837 |
-
.loc[:, ["Material", "Supply_Projected"]]
|
| 838 |
-
.rename(columns={"Supply_Projected": "OnHand"}))
|
| 839 |
-
|
| 840 |
-
buffer_df = (demand_stats.merge(lead_times, on="Material")
|
| 841 |
-
.merge(current_buffers, on="Material", how="left"))
|
| 842 |
-
|
| 843 |
-
buffer_df["RecommendedBuffer"] = (
|
| 844 |
-
Z * buffer_df["Sigma"] * np.sqrt(buffer_df["LeadTime"] + review_period)
|
| 845 |
-
).round()
|
| 846 |
-
|
| 847 |
-
buffer_df["Delta"] = buffer_df["RecommendedBuffer"] - buffer_df["OnHand"]
|
| 848 |
-
buffer_df["Action"] = np.where(buffer_df["Delta"] > 50,
|
| 849 |
-
"Increase buffer",
|
| 850 |
-
np.where(buffer_df["Delta"] < -50,
|
| 851 |
-
"Reduce buffer", "OK"))
|
| 852 |
-
|
| 853 |
-
st.subheader("📋 Buffer Recommendations")
|
| 854 |
-
display_cols = ["Material", "OnHand", "RecommendedBuffer", "Delta", "Action"]
|
| 855 |
-
st.dataframe(buffer_df[display_cols], use_container_width=True, height=300)
|
| 856 |
-
|
| 857 |
-
st.subheader("💰 Cost Impact Analysis")
|
| 858 |
-
carrying_cost = st.number_input("Annual Carrying Cost (% of unit cost)", min_value=0, max_value=50, value=20)
|
| 859 |
-
unit_cost = 100
|
| 860 |
-
|
| 861 |
-
buffer_df["CostImpact(₹)"] = (buffer_df["Delta"] * unit_cost * (carrying_cost/100) / 12)
|
| 862 |
-
|
| 863 |
-
cost_chart_data = buffer_df.set_index("Material")["CostImpact(₹)"]
|
| 864 |
-
st.bar_chart(cost_chart_data)
|
| 865 |
-
|
| 866 |
-
st.subheader("⚡ Execute AI Recommendations")
|
| 867 |
-
for _, row in buffer_df.iterrows():
|
| 868 |
-
if row["Action"] != "OK":
|
| 869 |
-
if st.button(f"🚀 {row['Action']} for {row['Material']}", key=row["Material"]):
|
| 870 |
-
st.success(f"AI executed: {row['Action']} - Adjusting {int(row['Delta'])} units for {row['Material']}")
|
| 871 |
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
col1, col2, col3, col4 = st.columns(4)
|
| 876 |
-
|
| 877 |
-
if dashboard_tab == "📊 Demand & Supply Forecast":
|
| 878 |
-
filtered_df = filtered_df_demand if 'filtered_df_demand' in locals() else df_demand
|
| 879 |
-
|
| 880 |
-
total_shortage_days = len(filtered_df[filtered_df['Shortfall'] > 0])
|
| 881 |
-
critical_shortage_days = len(filtered_df[filtered_df['Shortfall'] > 30])
|
| 882 |
-
materials_at_risk = len(filtered_df[filtered_df['Shortfall'] > 5]['Material'].unique())
|
| 883 |
-
avg_shortfall = filtered_df['Shortfall'].mean()
|
| 884 |
-
|
| 885 |
-
with col1:
|
| 886 |
-
st.metric("Days with Shortages", f"{total_shortage_days}")
|
| 887 |
-
|
| 888 |
-
with col2:
|
| 889 |
-
st.metric("Critical Days", f"{critical_shortage_days}")
|
| 890 |
-
|
| 891 |
-
with col3:
|
| 892 |
-
st.metric("Materials at Risk", f"{materials_at_risk}")
|
| 893 |
-
|
| 894 |
-
with col4:
|
| 895 |
-
st.metric("Avg Daily Shortfall", f"{avg_shortfall:.1f} units")
|
| 896 |
-
|
| 897 |
-
elif dashboard_tab == "🌐 Ecosystem Supplier Impact":
|
| 898 |
-
total_suppliers_disrupted = len(df_ecosystem[df_ecosystem['Is_Disrupted'] == True]['Supplier'].unique())
|
| 899 |
-
total_Yazaki India Ltd_impact_days = len(df_ecosystem[df_ecosystem['Is_Yazaki India Ltd_Impacted'] == True])
|
| 900 |
-
total_mitigation_strategies = len([s for s in st.session_state.executed_mitigations if 'eco_' in s])
|
| 901 |
-
avg_lead_time = df_ecosystem['Lead_Time_Days'].mean()
|
| 902 |
-
|
| 903 |
-
with col1:
|
| 904 |
-
st.metric("Suppliers Disrupted", f"{total_suppliers_disrupted}")
|
| 905 |
|
| 906 |
-
|
| 907 |
-
|
| 908 |
|
| 909 |
-
|
| 910 |
-
|
| 911 |
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
else: # Buffer Optimizer
|
| 916 |
-
if 'buffer_df' in locals():
|
| 917 |
-
total_materials = len(buffer_df)
|
| 918 |
-
materials_need_increase = len(buffer_df[buffer_df['Action'] == 'Increase buffer'])
|
| 919 |
-
materials_need_decrease = len(buffer_df[buffer_df['Action'] == 'Reduce buffer'])
|
| 920 |
-
total_cost_impact = buffer_df['CostImpact(₹)'].sum()
|
| 921 |
-
|
| 922 |
-
with col1:
|
| 923 |
-
st.metric("Total Materials", f"{total_materials}")
|
| 924 |
-
|
| 925 |
-
with col2:
|
| 926 |
-
st.metric("Need Buffer Increase", f"{materials_need_increase}")
|
| 927 |
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 933 |
|
| 934 |
-
# Footer
|
| 935 |
-
st.markdown("---")
|
| 936 |
-
st.markdown("""
|
| 937 |
-
<div style='text-align: center; color: #666;'>
|
| 938 |
-
<p>🌐 <b>Yazaki India Ltd 8-Week Supply Chain Command Center</b> | Firm + AI-Corrected Demand | Ecosystem Intelligence + Buffer Optimization<br>
|
| 939 |
-
Powered by Agentic AI | 8-Week Planning Horizon | Comprehensive Supply Chain Resilience</p>
|
| 940 |
-
</div>
|
| 941 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
|
|
|
| 16 |
|
| 17 |
# Custom CSS (same as before)
|
| 18 |
st.markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
""", unsafe_allow_html=True)
|
| 20 |
|
| 21 |
# Initialize session state
|
| 22 |
if 'executed_mitigations' not in st.session_state:
|
| 23 |
st.session_state.executed_mitigations = []
|
| 24 |
+
|
| 25 |
if 'external_signals' not in st.session_state:
|
| 26 |
st.session_state.external_signals = []
|
| 27 |
|
|
|
|
| 32 |
dates = [today + timedelta(days=x) for x in range(56)] # 8 weeks = 56 days
|
| 33 |
|
| 34 |
materials = [
|
| 35 |
+
'YAZ001-Wiring Harness',
|
| 36 |
+
'YAZ002-Connectors',
|
| 37 |
+
'YAZ003-Terminals',
|
| 38 |
+
'YAZ004-Sensors',
|
| 39 |
+
'YAZ005-Cable Assemblies'
|
| 40 |
]
|
| 41 |
|
| 42 |
all_data = []
|
|
|
|
| 43 |
for material in materials:
|
| 44 |
np.random.seed(hash(material) % 1000)
|
|
|
|
|
|
|
| 45 |
base_demand = np.random.normal(150, 15, 56)
|
| 46 |
|
| 47 |
# First 14 days: FIRM DEMAND
|
|
|
|
| 54 |
external_factors = np.zeros(42)
|
| 55 |
# Weather impact (weeks 3-4)
|
| 56 |
external_factors[0:14] += np.random.normal(0, 5, 14)
|
| 57 |
+
# EV policy impact (weeks 5-8), considering Yazaki is in automotive electronics
|
| 58 |
+
external_factors[14:] += 10
|
|
|
|
| 59 |
# Festive season boost (weeks 6-7)
|
| 60 |
external_factors[28:42] += 8
|
| 61 |
|
|
|
|
| 70 |
supply_actual[15:19] = (supply_actual[15:19] * 0.8).astype(int)
|
| 71 |
|
| 72 |
for i, date in enumerate(dates):
|
|
|
|
| 73 |
if i < 14:
|
| 74 |
demand_used = firm_demand[i]
|
| 75 |
firm_val = firm_demand[i]
|
|
|
|
| 83 |
corrected_val = corrected_demand[i-14]
|
| 84 |
demand_type = "AI-Corrected"
|
| 85 |
|
|
|
|
| 86 |
shortfall = max(0, demand_used - supply_actual[i])
|
| 87 |
|
| 88 |
all_data.append({
|
| 89 |
'Date': date,
|
| 90 |
+
'Week': f"Week {(i // 7) + 1}",
|
| 91 |
'Day': i + 1,
|
| 92 |
'Material': material,
|
| 93 |
'Firm_Demand': firm_val,
|
|
|
|
| 100 |
'Demand_Type': demand_type,
|
| 101 |
'Gap': supply_actual[i] - demand_used
|
| 102 |
})
|
|
|
|
| 103 |
return pd.DataFrame(all_data)
|
| 104 |
|
| 105 |
+
# Updated ecosystem Tier-2 suppliers for Yazaki India Ltd
|
| 106 |
@st.cache_data
|
| 107 |
def get_tier2_suppliers():
|
| 108 |
return {
|
| 109 |
+
'Electro Components Pvt Ltd': {
|
| 110 |
+
'location': 'Chennai',
|
| 111 |
+
'materials': ['YAZ001-Wiring Harness', 'YAZ002-Connectors'],
|
| 112 |
+
'capacity': 210,
|
| 113 |
+
'reliability': 93,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
'lead_time': 3,
|
| 115 |
+
'risk_factors': ['Port delays', 'Power outages', 'Labor strikes']
|
| 116 |
},
|
| 117 |
+
'Connectix Solutions': {
|
| 118 |
+
'location': 'Ahmedabad',
|
| 119 |
+
'materials': ['YAZ003-Terminals', 'YAZ004-Sensors'],
|
| 120 |
+
'capacity': 190,
|
| 121 |
+
'reliability': 90,
|
| 122 |
+
'lead_time': 2,
|
| 123 |
+
'risk_factors': ['Raw material shortage', 'Transportation issues', 'Equipment failure']
|
| 124 |
+
},
|
| 125 |
+
'WireCraft Industries': {
|
| 126 |
'location': 'Pune',
|
| 127 |
+
'materials': ['YAZ005-Cable Assemblies', 'YAZ001-Wiring Harness'],
|
| 128 |
+
'capacity': 230,
|
| 129 |
+
'reliability': 87,
|
| 130 |
'lead_time': 1,
|
| 131 |
+
'risk_factors': ['Quality checks', 'Capacity limits', 'Supplier disputes']
|
| 132 |
}
|
| 133 |
}
|
| 134 |
|
| 135 |
+
# Updated ecosystem data generation function for Yazaki
|
| 136 |
@st.cache_data
|
| 137 |
def generate_ecosystem_data():
|
| 138 |
today = datetime(2025, 8, 4)
|
| 139 |
dates = [today + timedelta(days=x) for x in range(14)]
|
|
|
|
| 140 |
suppliers = get_tier2_suppliers()
|
|
|
|
| 141 |
|
| 142 |
+
all_data = []
|
| 143 |
for supplier_name, supplier_info in suppliers.items():
|
| 144 |
for material in supplier_info['materials']:
|
| 145 |
np.random.seed(hash(supplier_name + material) % 1000)
|
|
|
|
| 146 |
base_capacity = supplier_info['capacity']
|
| 147 |
normal_supply = np.full(14, base_capacity, dtype=int)
|
| 148 |
disrupted_supply = normal_supply.copy()
|
| 149 |
|
| 150 |
+
if supplier_name == 'Electro Components Pvt Ltd':
|
| 151 |
disrupted_supply[3:7] = (disrupted_supply[3:7] * 0.3).astype(int)
|
| 152 |
+
disruption_cause = "Port delays in Chennai"
|
| 153 |
disruption_days = list(range(3, 7))
|
| 154 |
+
elif supplier_name == 'Connectix Solutions':
|
| 155 |
disrupted_supply[5:8] = (disrupted_supply[5:8] * 0.5).astype(int)
|
| 156 |
disruption_cause = "Critical equipment failure"
|
| 157 |
disruption_days = list(range(5, 8))
|
| 158 |
+
elif supplier_name == 'WireCraft Industries':
|
| 159 |
disrupted_supply[8:11] = (disrupted_supply[8:11] * 0.2).astype(int)
|
| 160 |
disruption_cause = "Labor strike at Pune facility"
|
| 161 |
disruption_days = list(range(8, 11))
|
|
|
|
| 164 |
disruption_days = []
|
| 165 |
|
| 166 |
lead_time = supplier_info['lead_time']
|
| 167 |
+
yazaki_supply = np.full(14, base_capacity, dtype=int)
|
| 168 |
|
| 169 |
for disruption_day in disruption_days:
|
| 170 |
arrival_day = disruption_day + lead_time
|
| 171 |
if arrival_day < 14:
|
| 172 |
reduction = normal_supply[disruption_day] - disrupted_supply[disruption_day]
|
| 173 |
+
yazaki_supply[arrival_day] = max(yazaki_supply[arrival_day] - reduction, 0)
|
| 174 |
|
| 175 |
for i, date in enumerate(dates):
|
| 176 |
all_data.append({
|
|
|
|
| 180 |
'Tier2_Normal_Supply': int(normal_supply[i]),
|
| 181 |
'Tier2_Disrupted_Supply': int(disrupted_supply[i]),
|
| 182 |
'Tier2_Impact': int(normal_supply[i] - disrupted_supply[i]),
|
| 183 |
+
'Yazaki_Normal_Supply': int(normal_supply[i]),
|
| 184 |
+
'Yazaki_Impacted_Supply': int(yazaki_supply[i]),
|
| 185 |
+
'Yazaki_Impact': int(normal_supply[i] - yazaki_supply[i]),
|
| 186 |
'Disruption_Cause': disruption_cause if i in disruption_days else "Normal Operations",
|
| 187 |
'Lead_Time_Days': lead_time,
|
| 188 |
'Is_Disrupted': i in disruption_days,
|
| 189 |
+
'Is_Yazaki_Impacted': yazaki_supply[i] < normal_supply[i]
|
| 190 |
})
|
|
|
|
| 191 |
return pd.DataFrame(all_data)
|
| 192 |
|
| 193 |
+
# External signals unchanged
|
| 194 |
@st.cache_data
|
| 195 |
def get_external_signals():
|
| 196 |
return [
|
| 197 |
{'Source': 'Weather API', 'Signal': 'Heavy rains forecasted in Chennai for next 3 days', 'Impact': 'Supply Risk', 'Confidence': 95},
|
| 198 |
{'Source': 'Market Intelligence', 'Signal': 'EV sales up 25% this quarter', 'Impact': 'Demand Increase', 'Confidence': 88},
|
| 199 |
{'Source': 'News Analytics', 'Signal': 'Upcoming festive season - historically 15% demand spike', 'Impact': 'Demand Surge', 'Confidence': 92},
|
| 200 |
+
{'Source': 'Supplier Network', 'Signal': 'Tier-2 supplier capacity increased by 20%', 'Impact': 'Supply Boost', 'Confidence': 98},
|
| 201 |
+
{'Source': 'Social Media', 'Signal': 'Positive sentiment around new EV models', 'Impact': 'Demand Growth', 'Confidence': 75},
|
| 202 |
{'Source': 'Government Portal', 'Signal': 'New EV subsidy policy effective next week', 'Impact': 'Market Expansion', 'Confidence': 100}
|
| 203 |
]
|
| 204 |
|
| 205 |
+
# Generate alerts for 8-week data — with Yazaki references and unchanged logic
|
| 206 |
def generate_detailed_alerts(df):
|
| 207 |
alerts = []
|
|
|
|
| 208 |
for material in df['Material'].unique():
|
| 209 |
material_data = df[df['Material'] == material]
|
| 210 |
shortage_days = material_data[material_data['Shortfall'] > 5]
|
|
|
|
| 211 |
if not shortage_days.empty:
|
| 212 |
for _, row in shortage_days.iterrows():
|
| 213 |
root_causes = []
|
|
|
|
| 216 |
diff = row['Corrected_Demand'] - row['Customer_Demand']
|
| 217 |
if diff > 10:
|
| 218 |
root_causes.append(f"AI detected {diff} units additional demand from external signals")
|
| 219 |
+
if 15 <= row['Day'] <= 18:
|
| 220 |
root_causes.append("Chennai plant weather disruption reducing supply")
|
| 221 |
+
else:
|
| 222 |
+
root_causes.append("... Firm demand exceeding supply capacity")
|
|
|
|
| 223 |
if not root_causes:
|
| 224 |
root_causes.append("Base demand exceeding current supply capacity")
|
| 225 |
|
|
|
|
| 248 |
'mitigation_options': mitigation_options,
|
| 249 |
'best_option': best_option
|
| 250 |
})
|
|
|
|
| 251 |
return alerts
|
| 252 |
|
| 253 |
+
# Mitigation strategies unchanged but updated for Yazaki naming
|
| 254 |
def generate_mitigation_strategies(supplier, material, impact_amount, impact_days):
|
| 255 |
base_strategies = [
|
| 256 |
{
|
|
|
|
| 278 |
'capacity': f'+{impact_amount * 0.6:.0f} units/day',
|
| 279 |
}
|
| 280 |
]
|
|
|
|
| 281 |
if impact_amount > 100:
|
| 282 |
recommended = [0, 1]
|
| 283 |
elif impact_amount > 50:
|
| 284 |
recommended = [0, 2]
|
| 285 |
else:
|
| 286 |
recommended = [2]
|
|
|
|
| 287 |
return base_strategies, recommended
|
| 288 |
|
| 289 |
# Load data
|
|
|
|
| 292 |
external_signals = get_external_signals()
|
| 293 |
suppliers = get_tier2_suppliers()
|
| 294 |
|
| 295 |
+
# Simple title
|
| 296 |
+
st.title("Supply Chain Command Center - Yazaki India Ltd")
|
| 297 |
|
| 298 |
+
# Tab Navigation
|
| 299 |
st.sidebar.title("🎯 Dashboard Navigation")
|
| 300 |
dashboard_tab = st.sidebar.radio(
|
| 301 |
"Select Dashboard:",
|
|
|
|
| 303 |
index=0
|
| 304 |
)
|
| 305 |
|
| 306 |
+
# TAB 1: 8-WEEK DEMAND & SUPPLY FORECAST
|
| 307 |
if dashboard_tab == "📊 Demand & Supply Forecast":
|
| 308 |
st.markdown("""
|
| 309 |
+
# 8-Week Demand & Supply Forecast for Yazaki India Ltd
|
| 310 |
+
|
| 311 |
+
This dashboard provides firm and AI-corrected demand forecasts along with supply projections for critical Yazaki materials.
|
| 312 |
+
|
| 313 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
+
# Select material filter
|
| 316 |
+
material_selected = st.selectbox("Select Material", df_demand['Material'].unique())
|
| 317 |
+
|
| 318 |
+
demand_data = df_demand[df_demand['Material'] == material_selected]
|
| 319 |
+
|
| 320 |
+
fig = go.Figure()
|
| 321 |
+
fig.add_trace(go.Scatter(
|
| 322 |
+
x=demand_data['Date'], y=demand_data['Firm_Demand'], mode='lines+markers',
|
| 323 |
+
name='Firm Demand (Days 1-14)'
|
| 324 |
+
))
|
| 325 |
+
fig.add_trace(go.Scatter(
|
| 326 |
+
x=demand_data['Date'], y=demand_data['Corrected_Demand'], mode='lines+markers',
|
| 327 |
+
name='AI-Corrected Demand (Days 15-56)'
|
| 328 |
+
))
|
| 329 |
+
fig.add_trace(go.Scatter(
|
| 330 |
+
x=demand_data['Date'], y=demand_data['Supply_Projected'], mode='lines+markers',
|
| 331 |
+
name='Projected Supply'
|
| 332 |
+
))
|
| 333 |
+
fig.update_layout(
|
| 334 |
+
yaxis_title='Units',
|
| 335 |
+
xaxis_title='Date',
|
| 336 |
+
legend_title='Legend',
|
| 337 |
+
height=400
|
| 338 |
)
|
| 339 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 340 |
+
|
| 341 |
+
# Display alerts if any
|
| 342 |
+
alerts = generate_detailed_alerts(demand_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
if alerts:
|
| 344 |
+
st.markdown("### Supply Shortage Alerts")
|
| 345 |
+
for alert in alerts:
|
| 346 |
+
st.markdown(f"**Date:** {alert['date']} ({alert['week']})")
|
| 347 |
+
st.markdown(f"**Material:** {alert['material']}")
|
| 348 |
+
st.markdown(f"**Severity:** {alert['severity']}")
|
| 349 |
+
st.markdown(f"**Shortage:** {alert['shortage']} units")
|
| 350 |
+
st.markdown(f"**Demand Type:** {alert['demand_type']}")
|
| 351 |
+
st.markdown("**Root Causes:**")
|
|
|
|
| 352 |
for cause in alert['root_causes']:
|
| 353 |
+
st.markdown(f"- {cause}")
|
| 354 |
+
st.markdown("**Recommended Mitigation Options:**")
|
| 355 |
+
for idx, option in enumerate(alert['mitigation_options']):
|
| 356 |
+
recommended_marker = "✅" if option == alert['best_option'] else ""
|
| 357 |
+
st.markdown(f"{recommended_marker} {option['option']} - Impact: {option['impact']}, Cost: {option['cost']}, Timeline: {option['timeline']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
st.markdown("---")
|
| 359 |
else:
|
| 360 |
+
st.success("No significant shortages detected for selected material in the next 8 weeks.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
+
# TAB 2: ECOSYSTEM SUPPLIER IMPACT
|
| 363 |
elif dashboard_tab == "🌐 Ecosystem Supplier Impact":
|
| 364 |
st.markdown("""
|
| 365 |
+
# Tier-2 Supplier Supply Impact and Risk Analysis for Yazaki India Ltd
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
+
This dashboard visualizes the supply disruptions and cascading impacts within the Yazaki supply chain ecosystem.
|
| 368 |
+
""")
|
|
|
|
|
|
|
|
|
|
| 369 |
|
| 370 |
+
df_tier2 = df_ecosystem.copy()
|
| 371 |
|
| 372 |
+
supplier_filter = st.multiselect("Select Supplier(s)", options=df_tier2['Supplier'].unique(), default=df_tier2['Supplier'].unique())
|
| 373 |
+
material_filter = st.multiselect("Select Material(s)", options=df_tier2['Material'].unique(), default=df_tier2['Material'].unique())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
+
filtered_data = df_tier2[
|
| 376 |
+
(df_tier2['Supplier'].isin(supplier_filter)) &
|
| 377 |
+
(df_tier2['Material'].isin(material_filter))
|
| 378 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
+
fig2 = px.line(
|
| 381 |
+
filtered_data,
|
| 382 |
+
x='Date',
|
| 383 |
+
y=['Yazaki_Normal_Supply', 'Yazaki_Impacted_Supply'],
|
| 384 |
+
color='Material',
|
| 385 |
+
line_dash='Supplier',
|
| 386 |
+
title='Supply Levels - Normal vs Impacted'
|
| 387 |
)
|
| 388 |
+
fig2.update_layout(yaxis_title='Units', height=450)
|
| 389 |
+
st.plotly_chart(fig2, use_container_width=True)
|
| 390 |
+
|
| 391 |
+
# Show table of risk factors and disruption causes
|
| 392 |
+
st.markdown("### Supplier Disruption Details")
|
| 393 |
+
for supplier in supplier_filter:
|
| 394 |
+
if supplier in suppliers:
|
| 395 |
+
info = suppliers[supplier]
|
| 396 |
+
st.markdown(f"**{supplier}** (Location: {info['location']})")
|
| 397 |
+
st.markdown(f"- Materials Supplied: {', '.join(info['materials'])}")
|
| 398 |
+
st.markdown(f"- Capacity: {info['capacity']}")
|
| 399 |
+
st.markdown(f"- Reliability: {info['reliability']}%")
|
| 400 |
+
st.markdown(f"- Lead Time (days): {info['lead_time']}")
|
| 401 |
+
st.markdown(f"- Risk Factors:")
|
| 402 |
+
for factor in info['risk_factors']:
|
| 403 |
+
st.markdown(f" - {factor}")
|
| 404 |
+
st.markdown("---")
|
| 405 |
|
| 406 |
+
# TAB 3: BUFFER OPTIMIZER
|
| 407 |
elif dashboard_tab == "🛡️ Buffer Optimizer":
|
| 408 |
st.markdown("""
|
| 409 |
+
# Dynamic Buffer Stock Optimization for Yazaki India Ltd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
+
This dashboard provides suggested mitigation strategies to address supply risks and optimize inventory buffers.
|
| 412 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
+
supplier_selected = st.selectbox("Select Tier-2 Supplier", options=suppliers.keys())
|
| 415 |
+
material_selected = st.selectbox("Select Material", options=suppliers[supplier_selected]['materials'])
|
| 416 |
|
| 417 |
+
impact_amount = st.number_input("Estimated Impact Amount (units/day)", min_value=0, max_value=500, value=50)
|
| 418 |
+
impact_days = st.number_input("Impact Duration (days)", min_value=1, max_value=30, value=7)
|
| 419 |
|
| 420 |
+
if st.button("Generate Mitigation Strategies"):
|
| 421 |
+
strategies, recommended_idxs = generate_mitigation_strategies(supplier_selected, material_selected, impact_amount, impact_days)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
|
| 423 |
+
st.markdown(f"### Mitigation Strategies for {material_selected} from {supplier_selected}")
|
| 424 |
+
for i, strat in enumerate(strategies):
|
| 425 |
+
recommended_mark = "✅ Recommended" if i in recommended_idxs else ""
|
| 426 |
+
st.markdown(f"**{strat['strategy']}** {recommended_mark}")
|
| 427 |
+
st.markdown(f"- Description: {strat['description']}")
|
| 428 |
+
st.markdown(f"- Timeline: {strat['timeline']}")
|
| 429 |
+
st.markdown(f"- Cost: {strat['cost']}")
|
| 430 |
+
st.markdown(f"- Effectiveness: {strat['effectiveness']}")
|
| 431 |
+
st.markdown(f"- Capacity Gain: {strat['capacity']}")
|
| 432 |
+
st.markdown("---")
|
| 433 |
|
| 434 |
+
# Footer or Additional Info can be added here if needed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|