"""
page1_intro.py — Introduction, How to Use, Objectives, Architecture Diagram
"""
import streamlit as st
from styles import (inject_global_css, page_header, metric_row,
WCO_GOLD, WCO_BLUE, WCO_GREEN, WCO_RED, WCO_CARD_BG, WCO_BORDER, WCO_MUTED)
ARCH_SVG = """
"""
def show():
inject_global_css()
page_header("🛃", "No-CelH: Self-Learning RMS",
"WCO ACCREDITED · CUSTOMS RISK MANAGEMENT SYSTEM · ACTIVE LEARNING SIMULATION")
# ── KPI strip ─────────────────────────────────────────────────
metric_row([
("5", "Risk Areas", WCO_GOLD),
("1,000","Declarations / Run", WCO_BLUE),
("10%", "Interdiction Bandwidth", WCO_RED),
("0.82", "Target Efficiency Index", WCO_GREEN),
("2×", "Revenue vs Static", WCO_GOLD),
])
# ── Architecture SVG ──────────────────────────────────────────
st.markdown('
🏗️ System Architecture
', unsafe_allow_html=True)
st.markdown(ARCH_SVG, unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
# ── Three info columns ────────────────────────────────────────
c1, c2, c3 = st.columns(3)
with c1:
st.markdown("""
🎯 Objectives
- Demonstrate self-learning RMS vs static models
- Prove exploration + exploitation hybrid superiority
- Optimise 10% interdiction bandwidth dynamically
- Build offence database via Red/Yellow feedback
- Adapt to concept drift in real-time
- WCO compendium risk scoring with 5 risk areas
""", unsafe_allow_html=True)
with c2:
st.markdown("""
📖 How to Use This App
📋 Page 2 → Configure 5-area Risk Register, 3×3 Matrix, rules & annual weights
🔄 Page 3 → Run live simulation — watch 1,000 bills routed in real-time
📊 Page 4 → Analyse offence DB growth, exploration gains, rule hit tables
🏆 Page 5 → Optimisation report — efficiency, accuracy, bandwidth ROI
""", unsafe_allow_html=True)
with c3:
st.markdown("""
🔬 Recommended Exploration Strategy
bATE — Best for customs context
✅ Uncertainty-scaled gradient embeddings
✅ Revenue-weighted diversity (K-means++)
✅ Outperforms BADGE & random by large margin
✅ Anomaly + probability-based hybrid sampling
gATE adds gatekeeping randomness for adversarial robustness
""", unsafe_allow_html=True)
# ── How RMS works ─────────────────────────────────────────────
st.markdown('⚙️ How the Self-Learning Cycle Works
',
unsafe_allow_html=True)
steps = [
("1", "#C8A951", "📥 Ingest", "Batch of import declarations enters the scoring pipeline each week"),
("2", "#0066CC", "🧠 Score (DATE)", "Exploitation engine scores each bill: fraud probability ŷᶜˡˢ + revenue ŷʳᵉᵛ"),
("3", "#9933CC", "🔍 Explore (gATE)","Exploration engine identifies uncertain bills (unc_i near 0.5) for new knowledge"),
("4", "#C8A951", "⚖️ Hybrid Select", "10% bandwidth split: 90% exploitation + 10% exploration → RED/YELLOW/GREEN"),
("5", "#0066CC", "👮 Inspect", "Officers examine Red & Yellow — outcomes labelled (fraud / clean / doc-query)"),
("6", "#00843D", "🗄️ Feedback", "Confirmed frauds augment offence DB; rule weights auto-update → model retrains"),
]
cols = st.columns(6)
for i, (num, col, title, desc) in enumerate(steps):
with cols[i]:
st.markdown(f"""
""", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
# ── Scientific basis ──────────────────────────────────────────
with st.expander("📚 Scientific Basis & Mathematical Formulas"):
fc1, fc2 = st.columns(2)
with fc1:
st.markdown("""
DATE Exploitation Engine
Dual Attentive Tree-aware Embedding model optimises two objectives simultaneously:
- ŷᶜˡˢ — Probability of fraudulent transaction
- ŷʳᵉᵛ — Predicted additional revenue upon inspection
h_θ(x) = σ(W · z_φ(x))
""", unsafe_allow_html=True)
with fc2:
st.markdown("""
gATE Exploration Engine
Selects uncertain, high-revenue, diverse bills via:
- unc_i = −1.8 × |ŷᶜˡˢ − 0.5| + 1
- S_i = unc_i × log(ŷʳᵉᵛ + ε)
- K-means++ seeding for batch diversity
Efficiency Index = Detection Rate / Selection Rate
""", unsafe_allow_html=True)