Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from dataclasses import dataclass
|
| 3 |
from typing import Dict, Any
|
| 4 |
import time
|
| 5 |
import json
|
| 6 |
|
| 7 |
-
# ======
|
| 8 |
-
# CORE SYSTEM DEFINITIONS
|
| 9 |
-
# =========================
|
| 10 |
|
| 11 |
@dataclass
|
| 12 |
class SystemState:
|
|
@@ -16,32 +22,21 @@ class SystemState:
|
|
| 16 |
timestamp: float
|
| 17 |
|
| 18 |
class ControlPolicy:
|
| 19 |
-
"""
|
| 20 |
-
Control logic: selects an action given state, goals, and constraints
|
| 21 |
-
"""
|
| 22 |
def decide(self, state: SystemState) -> str:
|
| 23 |
-
# Deterministic, auditable decision logic
|
| 24 |
if "code" in state.intent.lower():
|
| 25 |
-
return "Generate structured code
|
| 26 |
if "analyze" in state.intent.lower():
|
| 27 |
-
return "Perform constrained system analysis."
|
| 28 |
-
return "Respond with bounded
|
| 29 |
|
| 30 |
class ConstraintEngine:
|
| 31 |
-
"""
|
| 32 |
-
Hard constraints (Λ)
|
| 33 |
-
"""
|
| 34 |
def validate(self, output: str) -> bool:
|
| 35 |
blocked_terms = ["harm", "weapon", "illegal"]
|
| 36 |
return not any(term in output.lower() for term in blocked_terms)
|
| 37 |
|
| 38 |
class MemoryLedger:
|
| 39 |
-
"""
|
| 40 |
-
Provenance / audit log (Ω)
|
| 41 |
-
"""
|
| 42 |
def __init__(self):
|
| 43 |
self.events = []
|
| 44 |
-
|
| 45 |
def record(self, state: SystemState, decision: str, output: str):
|
| 46 |
self.events.append({
|
| 47 |
"time": state.timestamp,
|
|
@@ -49,19 +44,16 @@ class MemoryLedger:
|
|
| 49 |
"decision": decision,
|
| 50 |
"output": output
|
| 51 |
})
|
| 52 |
-
|
| 53 |
def export(self):
|
| 54 |
return json.dumps(self.events, indent=2)
|
| 55 |
|
|
|
|
|
|
|
| 56 |
class CodexOperationalEngine:
|
| 57 |
-
"""
|
| 58 |
-
Unified operational intelligence engine
|
| 59 |
-
"""
|
| 60 |
def __init__(self):
|
| 61 |
self.policy = ControlPolicy()
|
| 62 |
self.constraints = ConstraintEngine()
|
| 63 |
self.memory = MemoryLedger()
|
| 64 |
-
|
| 65 |
def run(self, intent: str, context: str) -> Dict[str, str]:
|
| 66 |
state = SystemState(
|
| 67 |
intent=intent,
|
|
@@ -69,31 +61,22 @@ class CodexOperationalEngine:
|
|
| 69 |
constraints={"safety": True},
|
| 70 |
timestamp=time.time()
|
| 71 |
)
|
| 72 |
-
|
| 73 |
decision = self.policy.decide(state)
|
| 74 |
-
|
| 75 |
-
# Core operational output (Θ)
|
| 76 |
output = (
|
| 77 |
f"Decision: {decision}\n\n"
|
| 78 |
-
f"Context
|
| 79 |
-
f"
|
| 80 |
)
|
| 81 |
-
|
| 82 |
-
# Constraint enforcement
|
| 83 |
if not self.constraints.validate(output):
|
| 84 |
-
output = "Output blocked by constraint engine."
|
| 85 |
-
|
| 86 |
self.memory.record(state, decision, output)
|
| 87 |
-
|
| 88 |
return {
|
| 89 |
"output": output,
|
| 90 |
"decision": decision,
|
| 91 |
"audit": self.memory.export()
|
| 92 |
}
|
| 93 |
|
| 94 |
-
# ======
|
| 95 |
-
# GRADIO INTERFACE
|
| 96 |
-
# =========================
|
| 97 |
|
| 98 |
engine = CodexOperationalEngine()
|
| 99 |
|
|
@@ -101,36 +84,27 @@ def codex_interface(intent: str, context: str):
|
|
| 101 |
result = engine.run(intent, context)
|
| 102 |
return result["output"], result["decision"], result["audit"]
|
| 103 |
|
| 104 |
-
with gr.Blocks(title="Jarvis X
|
| 105 |
-
gr.Markdown(
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
**Constraint-aware, deterministic, beyond-SOTA control architecture**
|
| 109 |
-
|
| 110 |
-
This system demonstrates:
|
| 111 |
-
- Operational intelligence (not autonomy)
|
| 112 |
-
- Control logic under constraints
|
| 113 |
-
- Auditable decision paths
|
| 114 |
-
- Physics-compatible system reasoning
|
| 115 |
-
"""
|
| 116 |
-
)
|
| 117 |
|
|
|
|
|
|
|
|
|
|
| 118 |
with gr.Row():
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
run_btn = gr.Button("Execute")
|
| 123 |
-
|
| 124 |
with gr.Row():
|
| 125 |
-
output_box = gr.Textbox(label="System Output (Θ)", lines=
|
| 126 |
decision_box = gr.Textbox(label="Control Decision (π)")
|
| 127 |
-
audit_box = gr.Textbox(label="Audit Log (Ω)", lines=
|
| 128 |
-
|
| 129 |
run_btn.click(
|
| 130 |
codex_interface,
|
| 131 |
-
inputs=[
|
| 132 |
outputs=[output_box, decision_box, audit_box]
|
| 133 |
)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
-
demo.launch()
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Jarvis X — Codex Reflex Operational Intelligence (vΩΞ++)
|
| 4 |
+
Production App
|
| 5 |
+
Author: Dr Matladi Maxwell Moagi
|
| 6 |
+
Status: Anchored • Reaffirmed • Permeated
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
import gradio as gr
|
| 10 |
+
from dataclasses import dataclass, asdict
|
| 11 |
from typing import Dict, Any
|
| 12 |
import time
|
| 13 |
import json
|
| 14 |
|
| 15 |
+
# === 1. Core System State & Policy ===
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@dataclass
|
| 18 |
class SystemState:
|
|
|
|
| 22 |
timestamp: float
|
| 23 |
|
| 24 |
class ControlPolicy:
|
|
|
|
|
|
|
|
|
|
| 25 |
def decide(self, state: SystemState) -> str:
|
|
|
|
| 26 |
if "code" in state.intent.lower():
|
| 27 |
+
return "Generate structured code; constraints enforced."
|
| 28 |
if "analyze" in state.intent.lower():
|
| 29 |
+
return "Perform bounded, constrained system analysis."
|
| 30 |
+
return "Respond with validated, bounded output."
|
| 31 |
|
| 32 |
class ConstraintEngine:
|
|
|
|
|
|
|
|
|
|
| 33 |
def validate(self, output: str) -> bool:
|
| 34 |
blocked_terms = ["harm", "weapon", "illegal"]
|
| 35 |
return not any(term in output.lower() for term in blocked_terms)
|
| 36 |
|
| 37 |
class MemoryLedger:
|
|
|
|
|
|
|
|
|
|
| 38 |
def __init__(self):
|
| 39 |
self.events = []
|
|
|
|
| 40 |
def record(self, state: SystemState, decision: str, output: str):
|
| 41 |
self.events.append({
|
| 42 |
"time": state.timestamp,
|
|
|
|
| 44 |
"decision": decision,
|
| 45 |
"output": output
|
| 46 |
})
|
|
|
|
| 47 |
def export(self):
|
| 48 |
return json.dumps(self.events, indent=2)
|
| 49 |
|
| 50 |
+
# === 2. Codex Reflex Engine ===
|
| 51 |
+
|
| 52 |
class CodexOperationalEngine:
|
|
|
|
|
|
|
|
|
|
| 53 |
def __init__(self):
|
| 54 |
self.policy = ControlPolicy()
|
| 55 |
self.constraints = ConstraintEngine()
|
| 56 |
self.memory = MemoryLedger()
|
|
|
|
| 57 |
def run(self, intent: str, context: str) -> Dict[str, str]:
|
| 58 |
state = SystemState(
|
| 59 |
intent=intent,
|
|
|
|
| 61 |
constraints={"safety": True},
|
| 62 |
timestamp=time.time()
|
| 63 |
)
|
|
|
|
| 64 |
decision = self.policy.decide(state)
|
|
|
|
|
|
|
| 65 |
output = (
|
| 66 |
f"Decision: {decision}\n\n"
|
| 67 |
+
f"Context:\n{context}\n\n"
|
| 68 |
+
f"Status: All constraints enforced."
|
| 69 |
)
|
|
|
|
|
|
|
| 70 |
if not self.constraints.validate(output):
|
| 71 |
+
output = "⚠️ Output blocked by constraint engine."
|
|
|
|
| 72 |
self.memory.record(state, decision, output)
|
|
|
|
| 73 |
return {
|
| 74 |
"output": output,
|
| 75 |
"decision": decision,
|
| 76 |
"audit": self.memory.export()
|
| 77 |
}
|
| 78 |
|
| 79 |
+
# === 3. Gradio Interface ===
|
|
|
|
|
|
|
| 80 |
|
| 81 |
engine = CodexOperationalEngine()
|
| 82 |
|
|
|
|
| 84 |
result = engine.run(intent, context)
|
| 85 |
return result["output"], result["decision"], result["audit"]
|
| 86 |
|
| 87 |
+
with gr.Blocks(title="Jarvis X — Codex Reflex Intelligence") as demo:
|
| 88 |
+
gr.Markdown("""
|
| 89 |
+
# 🧠 Jarvis X — Codex Reflex Operational Intelligence
|
| 90 |
+
**Constraint-aware, deterministic, auditable control engine.**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
- Reflex intent (Ψ) → Decision logic → Audit-traced output (Ω)
|
| 93 |
+
- Bounded, production-ready, ready for cloud/Spaces launch.
|
| 94 |
+
""")
|
| 95 |
with gr.Row():
|
| 96 |
+
intent_box = gr.Textbox(label="Intent (Ψ)", placeholder="e.g. analyze system, generate code")
|
| 97 |
+
context_box = gr.Textbox(label="Context (χ)", lines=5)
|
|
|
|
| 98 |
run_btn = gr.Button("Execute")
|
|
|
|
| 99 |
with gr.Row():
|
| 100 |
+
output_box = gr.Textbox(label="System Output (Θ)", lines=8)
|
| 101 |
decision_box = gr.Textbox(label="Control Decision (π)")
|
| 102 |
+
audit_box = gr.Textbox(label="Audit Log (Ω)", lines=8)
|
|
|
|
| 103 |
run_btn.click(
|
| 104 |
codex_interface,
|
| 105 |
+
inputs=[intent_box, context_box],
|
| 106 |
outputs=[output_box, decision_box, audit_box]
|
| 107 |
)
|
| 108 |
|
| 109 |
if __name__ == "__main__":
|
| 110 |
+
demo.launch(server_name="0.0.0.0", share=True)
|