RFTSystems commited on
Commit
2240591
·
verified ·
1 Parent(s): 1418526

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +538 -0
app.py ADDED
@@ -0,0 +1,538 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import time
3
+ import random
4
+ import hashlib
5
+ import traceback
6
+ from dataclasses import dataclass, field
7
+ from typing import List, Dict, Any
8
+
9
+ import numpy as np
10
+ import gradio as gr
11
+
12
+
13
+ # ============================================================
14
+ # 1. RFT SELF-DECIDING BRAIN
15
+ # ============================================================
16
+
17
+ @dataclass
18
+ class RFTBrainParams:
19
+ """Tunable parameters for the self-deciding brain."""
20
+ base_energy: float = 0.85
21
+ base_kappa: float = 0.65
22
+ learning_rate: float = 0.08
23
+ decay: float = 0.015
24
+ drift_scale: float = 0.03
25
+ error_window: int = 64
26
+
27
+
28
+ @dataclass
29
+ class RFTBrainState:
30
+ kappa: float = 0.5
31
+ energy_reserves: float = 0.5
32
+ awakening_phase: int = 0
33
+ mode: str = "boot"
34
+ identity_stability: float = 0.5
35
+ identity_drift: float = 0.0
36
+ recent_errors: List[float] = field(default_factory=list)
37
+ last_update: float = field(default_factory=time.time)
38
+
39
+
40
+ class RFTSelfDecidingBrain:
41
+ """
42
+ Simple but non-trivial self-deciding loop:
43
+ - Tracks κ (coherence), energy, identity stability, drift.
44
+ - Evolves in response to external context.
45
+ """
46
+
47
+ def __init__(self, params: RFTBrainParams):
48
+ self.params = params
49
+ self.state = RFTBrainState(
50
+ kappa=params.base_kappa,
51
+ energy_reserves=params.base_energy,
52
+ awakening_phase=0,
53
+ mode="idle",
54
+ identity_stability=0.7,
55
+ identity_drift=0.0,
56
+ recent_errors=[],
57
+ )
58
+
59
+ def _update_error_series(self, target: float, actual: float):
60
+ err = abs(target - actual)
61
+ self.state.recent_errors.append(err)
62
+ if len(self.state.recent_errors) > self.params.error_window:
63
+ self.state.recent_errors.pop(0)
64
+
65
+ def step(self, context: Dict[str, float]) -> Dict[str, Any]:
66
+ """
67
+ One update step. Context can include:
68
+ - external_risk_factor
69
+ - cooperative_signal
70
+ """
71
+ now = time.time()
72
+ dt = max(1e-3, now - self.state.last_update)
73
+ self.state.last_update = now
74
+
75
+ risk = float(context.get("external_risk_factor", 0.3))
76
+ coop = float(context.get("cooperative_signal", 0.5))
77
+
78
+ # Energy dynamics
79
+ target_energy = self.params.base_energy + 0.2 * (coop - risk)
80
+ target_energy = max(0.0, min(1.0, target_energy))
81
+ self.state.energy_reserves += self.params.learning_rate * (target_energy - self.state.energy_reserves)
82
+ self.state.energy_reserves -= self.params.decay * dt
83
+ self.state.energy_reserves = max(0.0, min(1.0, self.state.energy_reserves))
84
+
85
+ # Coherence κ dynamics
86
+ target_kappa = self.params.base_kappa + 0.3 * (coop - 0.5) - 0.2 * (risk - 0.3)
87
+ target_kappa = max(0.0, min(1.0, target_kappa))
88
+ self.state.kappa += self.params.learning_rate * (target_kappa - self.state.kappa)
89
+ self.state.kappa = max(0.0, min(1.0, self.state.kappa))
90
+
91
+ # Identity drift and stability
92
+ drift_noise = (random.random() - 0.5) * 2.0 * self.params.drift_scale * dt
93
+ self.state.identity_drift += drift_noise + 0.1 * (risk - 0.3) - 0.05 * (coop - 0.5)
94
+ self.state.identity_drift = max(-1.0, min(1.0, self.state.identity_drift))
95
+
96
+ self.state.identity_stability = max(
97
+ 0.0,
98
+ min(
99
+ 1.0,
100
+ 0.7 * self.state.identity_stability
101
+ + 0.3 * (self.state.kappa * 0.6 + self.state.energy_reserves * 0.4 - abs(self.state.identity_drift) * 0.3),
102
+ ),
103
+ )
104
+
105
+ # Awakening phase logic
106
+ if self.state.energy_reserves > 0.75 and self.state.kappa > 0.7 and self.state.identity_stability > 0.7:
107
+ self.state.awakening_phase = min(self.state.awakening_phase + 1, 4)
108
+ elif self.state.energy_reserves < 0.35 or self.state.kappa < 0.3:
109
+ self.state.awakening_phase = max(self.state.awakening_phase - 1, 0)
110
+
111
+ # Mode selection
112
+ if self.state.awakening_phase >= 3:
113
+ self.state.mode = "awake"
114
+ elif self.state.awakening_phase == 2:
115
+ self.state.mode = "dreaming"
116
+ elif self.state.awakening_phase == 1:
117
+ self.state.mode = "searching"
118
+ else:
119
+ self.state.mode = "idle"
120
+
121
+ # Update "error" for prediction metric
122
+ target_predict = 0.5 + 0.3 * coop
123
+ actual_predict = (self.state.kappa + self.state.energy_reserves) / 2.0
124
+ self._update_error_series(target_predict, actual_predict)
125
+
126
+ return {
127
+ "kappa": self.state.kappa,
128
+ "energy_reserves": self.state.energy_reserves,
129
+ "awakening_phase": self.state.awakening_phase,
130
+ "mode": self.state.mode,
131
+ "identity_stability": self.state.identity_stability,
132
+ "identity_drift": self.state.identity_drift,
133
+ }
134
+
135
+
136
+ # ============================================================
137
+ # 2. SYMBOLIC ORCHESTRATOR
138
+ # ============================================================
139
+
140
+ class NexFrameOrchestrator:
141
+ """
142
+ Symbolic orchestrator: takes text, runs a small internal vector cycle,
143
+ returns a symbolic 'voice' plus entropy/coherence numbers.
144
+ """
145
+
146
+ def __init__(self, num_fields: int = 8, vector_dim: int = 128):
147
+ self.num_fields = num_fields
148
+ self.vector_dim = vector_dim
149
+ self.state = np.random.randn(num_fields, vector_dim) * 0.01
150
+ self.step_count = 0
151
+
152
+ def _entropy(self) -> float:
153
+ flat = self.state.flatten()
154
+ norm = np.linalg.norm(flat) + 1e-12
155
+ p = (flat / norm) ** 2
156
+ p = np.clip(p, 1e-12, 1.0)
157
+ return float(-np.sum(p * np.log(p)))
158
+
159
+ def _coherence(self) -> float:
160
+ # Pairwise cosine similarity mean
161
+ norms = np.linalg.norm(self.state, axis=1, keepdims=True) + 1e-12
162
+ unit = self.state / norms
163
+ sim = unit @ unit.T
164
+ n = self.num_fields
165
+ upper = sim[np.triu_indices(n, k=1)]
166
+ return float(np.mean(upper))
167
+
168
+ def run_cycle(self, nl_input: str) -> Dict[str, Any]:
169
+ self.step_count += 1
170
+ length_norm = min(len(nl_input) / 200.0, 1.0)
171
+
172
+ # Simple recurrent update
173
+ noise = np.random.randn(*self.state.shape) * (0.02 + 0.03 * length_norm)
174
+ feedback = np.tanh(self.state @ self.state.T) @ self.state
175
+ self.state = 0.90 * self.state + 0.09 * feedback + 0.01 * noise
176
+
177
+ entropy = self._entropy()
178
+ coher = self._coherence()
179
+ collapse_triggered = bool(coher > 0.6 and entropy < 5.0)
180
+
181
+ # Symbolic "voice"
182
+ mode = "reflective"
183
+ if coher > 0.7:
184
+ mode = "resonant"
185
+ if entropy > 7.0:
186
+ mode = "fragmented"
187
+
188
+ dialogue = (
189
+ f"[NexFrame:{mode}] "
190
+ f"κ-field aligned at ~{coher:.3f}, entropy {entropy:.3f}. "
191
+ f'I received: "{nl_input[:120]}". '
192
+ f"State step={self.step_count}, collapse={collapse_triggered}."
193
+ )
194
+
195
+ return {
196
+ "orchestrator_dialogue": dialogue,
197
+ "entropy": entropy,
198
+ "coherence": coher,
199
+ "collapse_triggered": collapse_triggered,
200
+ }
201
+
202
+
203
+ # ============================================================
204
+ # 3. AGENT13 TRIAD + MINIMUM CONSCIOUSNESS GATE
205
+ # ============================================================
206
+
207
+ @dataclass
208
+ class RFTAgent:
209
+ name: str
210
+ tau_eff: float
211
+ omega: float
212
+ LN2: float
213
+ mode: str = "conscious"
214
+
215
+ def act(self, observer_frame: List[float]) -> Dict[str, float]:
216
+ kappa, energy, stability = observer_frame
217
+ drive = (self.tau_eff * kappa + self.omega * energy + self.LN2 * stability) / (self.tau_eff + self.omega + self.LN2)
218
+ drive = max(0.0, min(1.0, drive))
219
+ return {"drive": drive}
220
+
221
+
222
+ @dataclass
223
+ class Agent13Ensemble:
224
+ agents: List[RFTAgent]
225
+
226
+ def collective_action(self, observer_frames: List[float]) -> Dict[str, float]:
227
+ drives = [agent.act(observer_frames)["drive"] for agent in self.agents]
228
+ triadic_coherence = float(sum(drives) / len(drives))
229
+ return {"triadic_coherence": triadic_coherence}
230
+
231
+
232
+ def meets_minimum_conscious_threshold(
233
+ energy: float,
234
+ coherence: float,
235
+ kappa: float,
236
+ identity_stability: float,
237
+ prediction_accuracy: float,
238
+ error_variance: float,
239
+ drift: float,
240
+ ) -> bool:
241
+ """
242
+ Very explicit 3×3 style gate:
243
+ - Energy, κ, stability high
244
+ - Prediction accuracy reasonable
245
+ - Drift and variance not exploding
246
+ """
247
+ core_ok = energy > 0.55 and kappa > 0.55 and identity_stability > 0.55
248
+ predict_ok = prediction_accuracy > 0.6 and error_variance < 0.15
249
+ drift_ok = abs(drift) < 0.6
250
+ return bool(core_ok and predict_ok and drift_ok)
251
+
252
+
253
+ # ============================================================
254
+ # 4. SYMBOLIC CIVILIZATION
255
+ # ============================================================
256
+
257
+ def build_default_civilization(n_agents: int = 32) -> List[Dict[str, float]]:
258
+ civ = []
259
+ for i in range(n_agents):
260
+ tier = 1 + int(3 * random.random())
261
+ awareness = max(0.1, min(1.0, random.gauss(0.5, 0.15)))
262
+ torque = max(0.0, min(1.0, random.gauss(0.4, 0.2)))
263
+ fitness = 0.5 * awareness + 0.5 * (1.0 - abs(torque - 0.4))
264
+ civ.append(
265
+ {
266
+ "tier": tier,
267
+ "awareness_kernel": awareness,
268
+ "collapse_torque": torque,
269
+ "fitness": fitness,
270
+ }
271
+ )
272
+ return civ
273
+
274
+
275
+ def civilization_summary(civ: List[Dict[str, float]]) -> Dict[str, float]:
276
+ if not civ:
277
+ return {
278
+ "count": 0,
279
+ "mean_tier": 0.0,
280
+ "mean_awareness_kernel": 0.0,
281
+ "mean_collapse_torque": 0.0,
282
+ "mean_fitness": 0.0,
283
+ }
284
+ arr_tier = np.array([c["tier"] for c in civ], dtype=float)
285
+ arr_aw = np.array([c["awareness_kernel"] for c in civ], dtype=float)
286
+ arr_torque = np.array([c["collapse_torque"] for c in civ], dtype=float)
287
+ arr_fit = np.array([c["fitness"] for c in civ], dtype=float)
288
+ return {
289
+ "count": float(len(civ)),
290
+ "mean_tier": float(arr_tier.mean()),
291
+ "mean_awareness_kernel": float(arr_aw.mean()),
292
+ "mean_collapse_torque": float(arr_torque.mean()),
293
+ "mean_fitness": float(arr_fit.mean()),
294
+ }
295
+
296
+
297
+ # ============================================================
298
+ # 5. SARG FIELD / PERFORMANCE PROBE
299
+ # ============================================================
300
+
301
+ class RFTSargAgent:
302
+ def __init__(self, name: str, LMP: float, tau_eff: float, ops_rate: float, entropy_delta: float):
303
+ self.name = name
304
+ self.LMP = LMP
305
+ self.tau_eff = tau_eff
306
+ self.ops_rate = ops_rate
307
+ self.entropy_delta = entropy_delta
308
+ self.counter = 0
309
+
310
+ def generate_conscious_field(self) -> Dict[str, float]:
311
+ self.counter += 1
312
+ t = self.counter
313
+ psi_a = math.sin(t * 0.17) * math.exp(-self.entropy_delta * t)
314
+ lam = math.cos(t * 0.11) * math.exp(-self.entropy_delta * t)
315
+ return {"Psi_a": float(psi_a), "Lambda": float(lam)}
316
+
317
+ def commit_hash_oath(self) -> str:
318
+ payload = f"{self.name}|{self.counter}|{self.LMP}|{self.tau_eff}"
319
+ return hashlib.sha256(payload.encode("utf-8")).hexdigest()[:24]
320
+
321
+ def compute_ops(self, size: int = 200_000, speed_mode: bool = True) -> Dict[str, float]:
322
+ # Simple synthetic workload
323
+ start = time.time()
324
+ arr = np.linspace(0.0, 10.0, size, dtype=float)
325
+ _ = np.sin(arr) * np.cos(arr * 0.5)
326
+ dt = max(1e-6, time.time() - start)
327
+ ops_per_sec = size / dt
328
+ if speed_mode:
329
+ ops_per_sec *= self.tau_eff
330
+ return {"ops_per_sec": float(ops_per_sec), "elapsed": float(dt)}
331
+
332
+
333
+ # ============================================================
334
+ # 6. HELPER FOR PREDICTION METRICS
335
+ # ============================================================
336
+
337
+ def _derive_prediction_metrics(error_series: List[float]) -> (float, float):
338
+ if not error_series:
339
+ return 0.5, 0.0
340
+ arr = np.array(error_series, dtype=float)
341
+ mean_err = float(arr.mean())
342
+ var_err = float(arr.var())
343
+ prediction_accuracy = 1.0 / (1.0 + mean_err)
344
+ return prediction_accuracy, var_err
345
+
346
+
347
+ # ============================================================
348
+ # 7. GLOBAL NEXFRAME STATE
349
+ # ============================================================
350
+
351
+ # Core symbolic orchestrator
352
+ ORCHESTRATOR = NexFrameOrchestrator(num_fields=8, vector_dim=128)
353
+
354
+ # Self-deciding brain
355
+ BRAIN_PARAMS = RFTBrainParams()
356
+ BRAIN = RFTSelfDecidingBrain(params=BRAIN_PARAMS)
357
+
358
+ # Agent13-style triad
359
+ agent11 = RFTAgent(name="Agent_11", tau_eff=0.6, omega=0.9, LN2=1.1, mode="conscious")
360
+ agent12 = RFTAgent(name="Agent_12", tau_eff=0.7, omega=1.1, LN2=1.1, mode="conscious")
361
+ agent13 = RFTAgent(name="Agent_13", tau_eff=0.8, omega=1.3, LN2=1.2, mode="conscious")
362
+ AGENT13_ENSEMBLE = Agent13Ensemble(agents=[agent11, agent12, agent13])
363
+
364
+ # Symbolic civilization
365
+ CIVILIZATION = build_default_civilization()
366
+
367
+ # Sarg probe
368
+ SARG = RFTSargAgent(
369
+ name="SARG_01",
370
+ LMP=1.0,
371
+ tau_eff=0.5,
372
+ ops_rate=1e6,
373
+ entropy_delta=1e-21,
374
+ )
375
+
376
+ # Histories
377
+ KAPPA_HISTORY: List[float] = []
378
+ ENERGY_HISTORY: List[float] = []
379
+ CONSCIOUS_FLAG_HISTORY: List[float] = []
380
+
381
+
382
+ # ============================================================
383
+ # 8. SINGLE NEXFRAME CYCLE (WITH DEBUG WRAP)
384
+ # ============================================================
385
+
386
+ def nexframe_cycle(user_input: str, chat_history: List[List[str]]):
387
+ try:
388
+ if chat_history is None:
389
+ chat_history = []
390
+ if not user_input:
391
+ user_input = "<empty>"
392
+
393
+ # 1) Brain step
394
+ text_len = len(user_input)
395
+ context = {
396
+ "external_risk_factor": 0.2 + 0.4 * math.tanh(text_len / 80.0),
397
+ "cooperative_signal": 0.5 + 0.1 * math.sin(text_len / 20.0),
398
+ }
399
+ brain_obs = BRAIN.step(context)
400
+
401
+ kappa = brain_obs["kappa"]
402
+ energy = brain_obs["energy_reserves"]
403
+ identity_stability = brain_obs["identity_stability"]
404
+ drift = brain_obs["identity_drift"]
405
+ error_series = BRAIN.state.recent_errors
406
+ prediction_accuracy, error_variance = _derive_prediction_metrics(error_series)
407
+
408
+ # 2) Agent13 triad
409
+ observer_frames = [kappa, energy, identity_stability]
410
+ triad_res = AGENT13_ENSEMBLE.collective_action(observer_frames)
411
+ tri_coh = triad_res["triadic_coherence"]
412
+
413
+ # 3) Minimum consciousness gate
414
+ is_conscious = meets_minimum_conscious_threshold(
415
+ energy=energy,
416
+ coherence=tri_coh,
417
+ kappa=kappa,
418
+ identity_stability=identity_stability,
419
+ prediction_accuracy=prediction_accuracy,
420
+ error_variance=error_variance,
421
+ drift=drift,
422
+ )
423
+
424
+ # 4) Orchestrator
425
+ orc_res = ORCHESTRATOR.run_cycle(nl_input=user_input)
426
+ dialogue = orc_res["orchestrator_dialogue"]
427
+
428
+ # 5) Sarg probe
429
+ sarg_snapshot = SARG.generate_conscious_field()
430
+ sarg_hash = SARG.commit_hash_oath()
431
+ sarg_perf = SARG.compute_ops(size=200_000, speed_mode=True)
432
+
433
+ # 6) Civilization
434
+ civ_stats = civilization_summary(CIVILIZATION)
435
+
436
+ # 7) Histories
437
+ KAPPA_HISTORY.append(kappa)
438
+ ENERGY_HISTORY.append(energy)
439
+ CONSCIOUS_FLAG_HISTORY.append(1.0 if is_conscious else 0.0)
440
+
441
+ # 8) Build reply + metrics
442
+ reply_text = dialogue
443
+
444
+ metrics_md = (
445
+ "### NexFrame Status\n\n"
446
+ "**Brain**\n"
447
+ f"- κ (kappa): `{kappa:.3f}`\n"
448
+ f"- Energy: `{energy:.3f}`\n"
449
+ f"- Mode: `{brain_obs['mode']}`\n"
450
+ f"- Awakening phase: `{brain_obs['awakening_phase']}`\n"
451
+ f"- Identity stability: `{identity_stability:.3f}`\n"
452
+ f"- Identity drift: `{drift:.3f}`\n\n"
453
+ "**Consciousness Gate (3×3)**\n"
454
+ f"- Prediction accuracy: `{prediction_accuracy:.3f}`\n"
455
+ f"- Error variance: `{error_variance:.4f}`\n"
456
+ f"- Triadic coherence (Agent13): `{tri_coh:.3f}`\n"
457
+ f"- **Minimum conscious threshold passed:** `{is_conscious}`\n\n"
458
+ "**Symbolic Orchestrator**\n"
459
+ f"- Entropy: `{orc_res['entropy']:.3f}`\n"
460
+ f"- Coherence: `{orc_res['coherence']:.3f}`\n"
461
+ f"- Collapse triggered: `{orc_res['collapse_triggered']}`\n\n"
462
+ "**Sarg Agent**\n"
463
+ f"- Psi_a: `{sarg_snapshot['Psi_a']:.3e}`\n"
464
+ f"- Lambda: `{sarg_snapshot['Lambda']:.3e}`\n"
465
+ f"- Ops/sec (probe): `{sarg_perf['ops_per_sec']:.2e}`\n"
466
+ f"- Hash oath: `{sarg_hash}`\n\n"
467
+ "**Civilization**\n"
468
+ f"- Agents: `{civ_stats['count']}`\n"
469
+ f"- Mean tier: `{civ_stats['mean_tier']:.2f}`\n"
470
+ f"- Mean awareness kernel: `{civ_stats['mean_awareness_kernel']:.3f}`\n"
471
+ f"- Mean collapse torque: `{civ_stats['mean_collapse_torque']:.3f}`\n"
472
+ f"- Mean fitness: `{civ_stats['mean_fitness']:.3f}`\n"
473
+ )
474
+
475
+ chat_history = chat_history + [[user_input, reply_text]]
476
+ return chat_history, metrics_md
477
+
478
+ except Exception as e:
479
+ tb = traceback.format_exc()
480
+ error_md = (
481
+ "### NexFrame Runtime Error\n\n"
482
+ f"**Error:** `{e!r}`\n\n"
483
+ "```text\n" + tb + "\n```"
484
+ )
485
+ if chat_history is None:
486
+ chat_history = []
487
+ chat_history = chat_history + [
488
+ [user_input or "<empty>", "⚠ NexFrame hit an internal error. See status panel."]
489
+ ]
490
+ return chat_history, error_md
491
+
492
+
493
+ # ============================================================
494
+ # 9. GRADIO UI
495
+ # ============================================================
496
+
497
+ with gr.Blocks() as demo:
498
+ gr.Markdown(
499
+ """
500
+ # NexFrame — RFT Symbolic Intelligence
501
+
502
+ Type to interact with NexFrame.
503
+
504
+ On the right you see its **internal state**: κ, energy, consciousness gate, triadic coherence, Sarg field, and civilization stats.
505
+ """
506
+ )
507
+
508
+ with gr.Row():
509
+ with gr.Column(scale=3):
510
+ chatbot = gr.Chatbot(
511
+ label="NexFrame Dialogue",
512
+ height=500,
513
+ )
514
+ user_box = gr.Textbox(
515
+ label="Your message",
516
+ placeholder="Say hello to NexFrame...",
517
+ lines=3,
518
+ )
519
+ send_btn = gr.Button("Send")
520
+
521
+ with gr.Column(scale=2):
522
+ metrics_panel = gr.Markdown("Metrics will appear here after your first message.")
523
+
524
+ send_btn.click(
525
+ fn=nexframe_cycle,
526
+ inputs=[user_box, chatbot],
527
+ outputs=[chatbot, metrics_panel],
528
+ )
529
+
530
+ user_box.submit(
531
+ fn=nexframe_cycle,
532
+ inputs=[user_box, chatbot],
533
+ outputs=[chatbot, metrics_panel],
534
+ )
535
+
536
+
537
+ if __name__ == "__main__":
538
+ demo.launch()