Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,17 +63,20 @@ class RFTSelfDecidingBrain:
|
|
| 63 |
risk = float(context.get("external_risk_factor", 0.3))
|
| 64 |
coop = float(context.get("cooperative_signal", 0.5))
|
| 65 |
|
|
|
|
| 66 |
target_energy = self.params.base_energy + 0.2 * (coop - risk)
|
| 67 |
target_energy = max(0.0, min(1.0, target_energy))
|
| 68 |
self.state.energy_reserves += self.params.learning_rate * (target_energy - self.state.energy_reserves)
|
| 69 |
self.state.energy_reserves -= self.params.decay * dt
|
| 70 |
self.state.energy_reserves = max(0.0, min(1.0, self.state.energy_reserves))
|
| 71 |
|
|
|
|
| 72 |
target_kappa = self.params.base_kappa + 0.3 * (coop - 0.5) - 0.2 * (risk - 0.3)
|
| 73 |
target_kappa = max(0.0, min(1.0, target_kappa))
|
| 74 |
self.state.kappa += self.params.learning_rate * (target_kappa - self.state.kappa)
|
| 75 |
self.state.kappa = max(0.0, min(1.0, self.state.kappa))
|
| 76 |
|
|
|
|
| 77 |
drift_noise = (random.random() - 0.5) * 2.0 * self.params.drift_scale * dt
|
| 78 |
self.state.identity_drift += drift_noise + 0.1 * (risk - 0.3) - 0.05 * (coop - 0.5)
|
| 79 |
self.state.identity_drift = max(-1.0, min(1.0, self.state.identity_drift))
|
|
@@ -87,11 +90,13 @@ class RFTSelfDecidingBrain:
|
|
| 87 |
),
|
| 88 |
)
|
| 89 |
|
|
|
|
| 90 |
if self.state.energy_reserves > 0.75 and self.state.kappa > 0.7 and self.state.identity_stability > 0.7:
|
| 91 |
self.state.awakening_phase = min(self.state.awakening_phase + 1, 4)
|
| 92 |
elif self.state.energy_reserves < 0.35 or self.state.kappa < 0.3:
|
| 93 |
self.state.awakening_phase = max(self.state.awakening_phase - 1, 0)
|
| 94 |
|
|
|
|
| 95 |
if self.state.awakening_phase >= 3:
|
| 96 |
self.state.mode = "awake"
|
| 97 |
elif self.state.awakening_phase == 2:
|
|
@@ -101,6 +106,7 @@ class RFTSelfDecidingBrain:
|
|
| 101 |
else:
|
| 102 |
self.state.mode = "idle"
|
| 103 |
|
|
|
|
| 104 |
target_predict = 0.5 + 0.3 * coop
|
| 105 |
actual_predict = (self.state.kappa + self.state.energy_reserves) / 2.0
|
| 106 |
self._update_error_series(target_predict, actual_predict)
|
|
@@ -346,6 +352,7 @@ CONSCIOUS_FLAG_HISTORY: List[float] = []
|
|
| 346 |
def nexframe_cycle(user_input: str, chat_history: List[Dict[str, str]]):
|
| 347 |
try:
|
| 348 |
if chat_history is None:
|
|
|
|
| 349 |
chat_history = []
|
| 350 |
if not user_input:
|
| 351 |
user_input = "<empty>"
|
|
@@ -393,6 +400,15 @@ def nexframe_cycle(user_input: str, chat_history: List[Dict[str, str]]):
|
|
| 393 |
|
| 394 |
reply_text = dialogue
|
| 395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
metrics_md = (
|
| 397 |
"### NexFrame Status\n\n"
|
| 398 |
"**Brain**\n"
|
|
@@ -424,11 +440,12 @@ def nexframe_cycle(user_input: str, chat_history: List[Dict[str, str]]):
|
|
| 424 |
f"- Mean fitness: `{civ_stats['mean_fitness']:.3f}`\n"
|
| 425 |
)
|
| 426 |
|
|
|
|
| 427 |
chat_history = chat_history + [
|
| 428 |
{"role": "user", "content": user_input},
|
| 429 |
{"role": "assistant", "content": reply_text},
|
| 430 |
]
|
| 431 |
-
return chat_history, metrics_md
|
| 432 |
|
| 433 |
except Exception as e:
|
| 434 |
tb = traceback.format_exc()
|
|
@@ -443,29 +460,93 @@ def nexframe_cycle(user_input: str, chat_history: List[Dict[str, str]]):
|
|
| 443 |
{"role": "user", "content": user_input or "<empty>"},
|
| 444 |
{"role": "assistant", "content": "⚠ NexFrame hit an internal error. See status panel."},
|
| 445 |
]
|
| 446 |
-
|
|
|
|
| 447 |
|
| 448 |
|
| 449 |
# ============================================================
|
| 450 |
# 9. GRADIO UI
|
| 451 |
# ============================================================
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
with gr.Blocks() as demo:
|
| 454 |
gr.Markdown(
|
| 455 |
"""
|
| 456 |
# NexFrame — RFT Symbolic Intelligence
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
"""
|
| 462 |
)
|
| 463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
with gr.Row():
|
| 465 |
with gr.Column(scale=3):
|
| 466 |
chatbot = gr.Chatbot(
|
| 467 |
label="NexFrame Dialogue",
|
| 468 |
height=500,
|
|
|
|
| 469 |
)
|
| 470 |
user_box = gr.Textbox(
|
| 471 |
label="Your message",
|
|
@@ -475,18 +556,21 @@ On the right you see its **internal state**: κ, energy, consciousness gate, tri
|
|
| 475 |
send_btn = gr.Button("Send")
|
| 476 |
|
| 477 |
with gr.Column(scale=2):
|
|
|
|
|
|
|
|
|
|
| 478 |
metrics_panel = gr.Markdown("Metrics will appear here after your first message.")
|
| 479 |
|
| 480 |
send_btn.click(
|
| 481 |
fn=nexframe_cycle,
|
| 482 |
inputs=[user_box, chatbot],
|
| 483 |
-
outputs=[chatbot, metrics_panel],
|
| 484 |
)
|
| 485 |
|
| 486 |
user_box.submit(
|
| 487 |
fn=nexframe_cycle,
|
| 488 |
inputs=[user_box, chatbot],
|
| 489 |
-
outputs=[chatbot, metrics_panel],
|
| 490 |
)
|
| 491 |
|
| 492 |
|
|
|
|
| 63 |
risk = float(context.get("external_risk_factor", 0.3))
|
| 64 |
coop = float(context.get("cooperative_signal", 0.5))
|
| 65 |
|
| 66 |
+
# Energy dynamics
|
| 67 |
target_energy = self.params.base_energy + 0.2 * (coop - risk)
|
| 68 |
target_energy = max(0.0, min(1.0, target_energy))
|
| 69 |
self.state.energy_reserves += self.params.learning_rate * (target_energy - self.state.energy_reserves)
|
| 70 |
self.state.energy_reserves -= self.params.decay * dt
|
| 71 |
self.state.energy_reserves = max(0.0, min(1.0, self.state.energy_reserves))
|
| 72 |
|
| 73 |
+
# Coherence κ dynamics
|
| 74 |
target_kappa = self.params.base_kappa + 0.3 * (coop - 0.5) - 0.2 * (risk - 0.3)
|
| 75 |
target_kappa = max(0.0, min(1.0, target_kappa))
|
| 76 |
self.state.kappa += self.params.learning_rate * (target_kappa - self.state.kappa)
|
| 77 |
self.state.kappa = max(0.0, min(1.0, self.state.kappa))
|
| 78 |
|
| 79 |
+
# Identity drift and stability
|
| 80 |
drift_noise = (random.random() - 0.5) * 2.0 * self.params.drift_scale * dt
|
| 81 |
self.state.identity_drift += drift_noise + 0.1 * (risk - 0.3) - 0.05 * (coop - 0.5)
|
| 82 |
self.state.identity_drift = max(-1.0, min(1.0, self.state.identity_drift))
|
|
|
|
| 90 |
),
|
| 91 |
)
|
| 92 |
|
| 93 |
+
# Awakening ladder
|
| 94 |
if self.state.energy_reserves > 0.75 and self.state.kappa > 0.7 and self.state.identity_stability > 0.7:
|
| 95 |
self.state.awakening_phase = min(self.state.awakening_phase + 1, 4)
|
| 96 |
elif self.state.energy_reserves < 0.35 or self.state.kappa < 0.3:
|
| 97 |
self.state.awakening_phase = max(self.state.awakening_phase - 1, 0)
|
| 98 |
|
| 99 |
+
# Mode
|
| 100 |
if self.state.awakening_phase >= 3:
|
| 101 |
self.state.mode = "awake"
|
| 102 |
elif self.state.awakening_phase == 2:
|
|
|
|
| 106 |
else:
|
| 107 |
self.state.mode = "idle"
|
| 108 |
|
| 109 |
+
# Internal prediction signal vs actual
|
| 110 |
target_predict = 0.5 + 0.3 * coop
|
| 111 |
actual_predict = (self.state.kappa + self.state.energy_reserves) / 2.0
|
| 112 |
self._update_error_series(target_predict, actual_predict)
|
|
|
|
| 352 |
def nexframe_cycle(user_input: str, chat_history: List[Dict[str, str]]):
|
| 353 |
try:
|
| 354 |
if chat_history is None:
|
| 355 |
+
|
| 356 |
chat_history = []
|
| 357 |
if not user_input:
|
| 358 |
user_input = "<empty>"
|
|
|
|
| 400 |
|
| 401 |
reply_text = dialogue
|
| 402 |
|
| 403 |
+
# Short status strip
|
| 404 |
+
gate_str = "✅ Gate: PASSED" if is_conscious else "⭕ Gate: NOT PASSED"
|
| 405 |
+
status_md = (
|
| 406 |
+
f"**State:** `{brain_obs['mode']}` (phase {brain_obs['awakening_phase']}) \n"
|
| 407 |
+
f"**κ:** `{kappa:.3f}` • **Energy:** `{energy:.3f}` \n"
|
| 408 |
+
f"**{gate_str}**"
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
# Full metrics
|
| 412 |
metrics_md = (
|
| 413 |
"### NexFrame Status\n\n"
|
| 414 |
"**Brain**\n"
|
|
|
|
| 440 |
f"- Mean fitness: `{civ_stats['mean_fitness']:.3f}`\n"
|
| 441 |
)
|
| 442 |
|
| 443 |
+
# Chatbot messages (dict format)
|
| 444 |
chat_history = chat_history + [
|
| 445 |
{"role": "user", "content": user_input},
|
| 446 |
{"role": "assistant", "content": reply_text},
|
| 447 |
]
|
| 448 |
+
return chat_history, status_md, metrics_md
|
| 449 |
|
| 450 |
except Exception as e:
|
| 451 |
tb = traceback.format_exc()
|
|
|
|
| 460 |
{"role": "user", "content": user_input or "<empty>"},
|
| 461 |
{"role": "assistant", "content": "⚠ NexFrame hit an internal error. See status panel."},
|
| 462 |
]
|
| 463 |
+
status_md = "**State:** error \n**Details:** see status panel below."
|
| 464 |
+
return chat_history, status_md, error_md
|
| 465 |
|
| 466 |
|
| 467 |
# ============================================================
|
| 468 |
# 9. GRADIO UI
|
| 469 |
# ============================================================
|
| 470 |
|
| 471 |
+
# Initial message so visitors see something immediately
|
| 472 |
+
INITIAL_MESSAGES = [
|
| 473 |
+
{
|
| 474 |
+
"role": "assistant",
|
| 475 |
+
"content": (
|
| 476 |
+
"I am NexFrame, a symbolic RFT engine. "
|
| 477 |
+
"Type a message and I will respond while my internal state updates on the right."
|
| 478 |
+
),
|
| 479 |
+
}
|
| 480 |
+
]
|
| 481 |
+
|
| 482 |
with gr.Blocks() as demo:
|
| 483 |
gr.Markdown(
|
| 484 |
"""
|
| 485 |
# NexFrame — RFT Symbolic Intelligence
|
| 486 |
|
| 487 |
+
This is **not** a standard chatbot.
|
| 488 |
+
Your messages drive a small symbolic brain. The chat on the left is its voice.
|
| 489 |
+
The panel on the right shows what its internal field is doing while it talks to you.
|
| 490 |
"""
|
| 491 |
)
|
| 492 |
|
| 493 |
+
with gr.Accordion("What am I looking at?", open=False):
|
| 494 |
+
gr.Markdown(
|
| 495 |
+
"""
|
| 496 |
+
### How this works (non-technical)
|
| 497 |
+
|
| 498 |
+
NexFrame converts your text into numbers, pushes them through a symbolic brain, and updates a set of dials that describe how stable or chaotic that brain is.
|
| 499 |
+
|
| 500 |
+
**Left** = what NexFrame says.
|
| 501 |
+
**Right** = what NexFrame *is* while it says it.
|
| 502 |
+
|
| 503 |
+
---
|
| 504 |
+
|
| 505 |
+
#### Brain
|
| 506 |
+
- **κ (kappa)** – how internally coherent NexFrame is (0 = scrambled, 1 = highly aligned).
|
| 507 |
+
- **Energy** – how much \"fuel\" the brain has to keep running its internal loops.
|
| 508 |
+
- **Mode** – rough state: `idle`, `searching`, `dreaming`, `awake`.
|
| 509 |
+
- **Awakening phase** – 0–4 ladder; higher means a more stable, self-consistent state.
|
| 510 |
+
- **Identity stability / drift** – how steady NexFrame’s internal identity is vs how much it is drifting.
|
| 511 |
+
|
| 512 |
+
#### Consciousness Gate (3×3)
|
| 513 |
+
A simple, explicit test – not magic.
|
| 514 |
+
It checks three things:
|
| 515 |
+
|
| 516 |
+
1. Internal health (κ, energy, stability)
|
| 517 |
+
2. Prediction quality (how well its own internal signals line up)
|
| 518 |
+
3. Drift/instability
|
| 519 |
+
|
| 520 |
+
Only if all three look good do you see: **\"Minimum conscious threshold passed: True\"**.
|
| 521 |
+
|
| 522 |
+
#### Symbolic Orchestrator
|
| 523 |
+
- **Entropy** – how spread out the internal patterns are (higher = more chaotic).
|
| 524 |
+
- **Coherence** – how much the internal fields agree with each other.
|
| 525 |
+
- **Collapse triggered** – flips when coherence is high *and* entropy is low.
|
| 526 |
+
|
| 527 |
+
#### Sarg Agent
|
| 528 |
+
A tiny performance + field probe:
|
| 529 |
+
- Generates a small field (Ψₐ and Λ) every time you send a message.
|
| 530 |
+
- Measures how many operations per second it can push through.
|
| 531 |
+
- Signs each step with a short hash (**hash oath**) so runs can be tracked externally.
|
| 532 |
+
|
| 533 |
+
#### Civilization
|
| 534 |
+
A toy population of symbolic agents.
|
| 535 |
+
You see the averages:
|
| 536 |
+
|
| 537 |
+
- **Tier** – rough level in the hierarchy.
|
| 538 |
+
- **Awareness kernel** – how \"aware\" the average agent is.
|
| 539 |
+
- **Collapse torque** – how strongly they push the field toward decisions.
|
| 540 |
+
- **Fitness** – one score summarising how viable this symbolic civilization is.
|
| 541 |
+
"""
|
| 542 |
+
)
|
| 543 |
+
|
| 544 |
with gr.Row():
|
| 545 |
with gr.Column(scale=3):
|
| 546 |
chatbot = gr.Chatbot(
|
| 547 |
label="NexFrame Dialogue",
|
| 548 |
height=500,
|
| 549 |
+
value=INITIAL_MESSAGES,
|
| 550 |
)
|
| 551 |
user_box = gr.Textbox(
|
| 552 |
label="Your message",
|
|
|
|
| 556 |
send_btn = gr.Button("Send")
|
| 557 |
|
| 558 |
with gr.Column(scale=2):
|
| 559 |
+
status_strip = gr.Markdown(
|
| 560 |
+
"**State:** waiting for first message…"
|
| 561 |
+
)
|
| 562 |
metrics_panel = gr.Markdown("Metrics will appear here after your first message.")
|
| 563 |
|
| 564 |
send_btn.click(
|
| 565 |
fn=nexframe_cycle,
|
| 566 |
inputs=[user_box, chatbot],
|
| 567 |
+
outputs=[chatbot, status_strip, metrics_panel],
|
| 568 |
)
|
| 569 |
|
| 570 |
user_box.submit(
|
| 571 |
fn=nexframe_cycle,
|
| 572 |
inputs=[user_box, chatbot],
|
| 573 |
+
outputs=[chatbot, status_strip, metrics_panel],
|
| 574 |
)
|
| 575 |
|
| 576 |
|