-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard.py
More file actions
205 lines (171 loc) · 6.65 KB
/
Copy pathdashboard.py
File metadata and controls
205 lines (171 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import streamlit as st
import pandas as pd
import numpy as np
import time
import random
from datetime import datetime, timezone
import altair as alt
from collections import deque
# -----------------------------------------------------------------------------
# 1. CONFIGURATION & CLASSIFICATION
# -----------------------------------------------------------------------------
st.set_page_config(
page_title="HELIX-TTD // WATCHTOWER",
page_icon="🦆",
layout="wide",
initial_sidebar_state="collapsed"
)
# MIL-SPEC CSS (V3.1 FIX: TARGETING MODERN STREAMLIT CLASSES)
st.markdown("""
<style>
/* FORCE DARK MODE BACKGROUND */
.stApp {
background-color: #0e1117;
color: #ffffff;
}
/* METRIC BOXES */
div[data-testid="stMetric"] {
background-color: #161b22;
border: 1px solid #30363d;
padding: 15px;
border-radius: 6px;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
/* METRIC LABELS (Top text) */
div[data-testid="stMetricLabel"] > div > p {
color: #8b949e !important;
font-family: 'Courier New', monospace;
font-size: 0.9em;
}
/* METRIC VALUES (Big numbers) */
div[data-testid="stMetricValue"] > div {
color: #00ffcc !important;
font-family: 'Courier New', monospace;
font-weight: bold;
}
/* HEADER TEXT */
h1, h2, h3 {
font-family: 'Courier New', monospace !important;
color: #00ffcc !important;
}
/* CODE BLOCKS */
.stCode {
background-color: #0d1117 !important;
font-family: 'Courier New', monospace;
}
/* BADGE */
.header-badge {
background-color: #21262d;
color: #c9d1d9;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.7em;
font-family: sans-serif;
border: 1px solid #30363d;
letter-spacing: 1px;
}
</style>
""", unsafe_allow_html=True)
# -----------------------------------------------------------------------------
# 2. SIMULATION ENGINE (STATEFUL PHYSICS)
# -----------------------------------------------------------------------------
class SimulationEngine:
def __init__(self):
if 'sim_state' not in st.session_state:
st.session_state.sim_state = {
'drift': 0.02,
'blocked': 1420,
'q3_lock': True,
'history': pd.DataFrame(columns=['timestamp', 'drift']),
'logs': deque(maxlen=8)
}
self._add_log("SYSTEM: Watchtower v2.1 Initialized")
self._add_log("ORACLE: Connection Established (NIST)")
def _add_log(self, message):
timestamp = datetime.now().strftime("%H:%M:%S")
st.session_state.sim_state['logs'].append(f"[{timestamp}] {message}")
def update(self):
state = st.session_state.sim_state
# Physics: Random Walk
delta = np.random.normal(0, 0.003)
state['drift'] = max(0, min(0.08, state['drift'] + delta))
# Defense: Random Attacks
if random.random() < 0.3:
state['blocked'] += 1
attack_type = random.choice([
"BLOCKED: Malformed Payload (IP: 10.2.4.X)",
"BLOCKED: Injection Attempt 'sudo rm -rf'",
"BLOCKED: High-Entropy Noise Packet",
"BLOCKED: Schema Violation (Missing 'drift')",
"BLOCKED: Replay Attack Detected"
])
self._add_log(attack_type)
# Harmony: Valid Signals
if random.random() < 0.2:
self._add_log(f"ACCEPTED: Signal 🦆 (Q1) - Drift {state['drift']*100:.2f}%")
# History for Chart
now = datetime.now()
new_row = pd.DataFrame({'timestamp': [now], 'drift': [state['drift']]})
state['history'] = pd.concat([state['history'], new_row]).tail(60)
return state
# -----------------------------------------------------------------------------
# 3. UI RENDERING
# -----------------------------------------------------------------------------
def render_dashboard():
sim = SimulationEngine()
data = sim.update()
# --- HEADER ---
c1, c2 = st.columns([3, 1])
with c1:
st.markdown("<span class='header-badge'>UNCLASSIFIED // FOUO</span>", unsafe_allow_html=True)
st.title("FEDERATION WATCHTOWER")
st.caption(f"Semantic Runtime Assurance (SRTA) | Session ID: {id(st.session_state)}")
with c2:
status_color = "🟢" if data['drift'] < 0.05 else "🟡"
st.markdown(f"### {status_color} SYSTEM ONLINE")
st.markdown("---")
# --- ROW 1: METRICS ---
m1, m2, m3, m4 = st.columns(4)
with m1:
q_state = "Q2" if data['drift'] < 0.035 else "Q1"
st.metric("HARMONY STATE", q_state, "LATTICE LOCK" if q_state == "Q2" else "QUIESCENT")
with m2:
st.metric("SEMANTIC DRIFT", f"{data['drift']*100:.2f}%")
with m3:
st.metric("THREATS BLOCKED", f"{data['blocked']:,}", "+ACTIVE")
with m4:
st.metric("Q3 ANCHOR", "LOCKED" if data['q3_lock'] else "SEARCHING", "24ms (NIST)")
# --- ROW 2: THE REEF (CHART) ---
st.markdown("### 🌊 SEMANTIC CURRENTS")
# Chart with explicit dark theme background
base = alt.Chart(data['history']).encode(
x=alt.X('timestamp:T', axis=alt.Axis(format='%H:%M:%S', title=None, labelColor='#8b949e')),
)
area = base.mark_area(
line={'color':'#00ffcc'},
color=alt.Gradient(
gradient='linear',
stops=[alt.GradientStop(color='#00ffcc', offset=0),
alt.GradientStop(color='rgba(0, 255, 204, 0.1)', offset=1)],
x1=1, x2=1, y1=1, y2=0
)
).encode(
y=alt.Y('drift:Q', scale=alt.Scale(domain=[0, 0.1]), axis=alt.Axis(labelColor='#8b949e'))
)
threshold = alt.Chart(pd.DataFrame({'y': [0.05]})).mark_rule(color='#ff4b4b', strokeDash=[4, 4]).encode(y='y')
st.altair_chart(area + threshold, use_container_width=True)
# --- ROW 3: INTELLIGENCE ---
c_log, c_oracle = st.columns([2, 1])
with c_log:
st.subheader("🛡️ DEFENSE LOG STREAM")
log_text = "\n".join(reversed(data['logs']))
st.code(log_text, language="bash")
with c_oracle:
st.subheader("📡 ORACLE STATUS")
st.info("SOURCE: NIST_BEACON_V2")
st.success("HASH: 5425edf6799e4397")
st.warning("NEXT SYNC: 0.8s")
time.sleep(1)
st.rerun()
if __name__ == "__main__":
render_dashboard()