CodexFlow_TM / app.py
LordXido's picture
Update app.py
cd9d7a2 verified
raw
history blame
6.39 kB
# app.py
"""
Dr Moagi IRE Equation β€’ Autonomous Manifold Explorer
Minimal autonomous simulation of the sealed governing equation
dΞ/dt = -Ξ› βˆ‡(Θ(Ξ) + Ξ¦(Ξ) - Ξ¨(t) + Ξ©(t))
Hugging Face Spaces demo - January 11, 2026
"""
import gradio as gr
import torch
import numpy as np
import matplotlib.pyplot as plt
from io import BytesIO
import base64
# ─── Configuration ────────────────────────────────────────────────
DEFAULT_PARAMS = {
'steps': 600,
'dt': 0.075,
'noise': 0.38,
'lambda_': 3.4,
'omega_window': 14,
'intent_x': 2.1,
'intent_y': 1.4
}
COHERENCE_WARN = 0.68
# ─── Core Simulation ──────────────────────────────────────────────
def run_ire_simulation(steps, dt, noise_mag, lam, omega_len, intent):
device = torch.device("cpu")
intent_target = torch.tensor([intent[0], intent[1]], dtype=torch.float32, device=device)
Xi = torch.zeros(2, device=device, requires_grad=True)
Omega = []
trajectory = [Xi.detach().cpu().numpy().copy()]
for step in range(steps):
t = step * dt
# Potential terms (toy implementations)
theta = 0.45 * (intent_target - Xi).pow(2).sum()
phi = 0.28 * torch.sin(3.2 * torch.atan2(Xi[1], Xi[0])) * torch.cos(1.8 * Xi.norm()) + 0.15 * Xi.norm()**2
psi = torch.randn(2, device=device) * noise_mag * (1.0 + 0.35 * torch.sin(t * 0.14))
omega_mean = torch.mean(torch.stack(Omega), dim=0) if Omega else torch.zeros(2, device=device)
potential = theta + phi - psi + omega_mean
grad = torch.autograd.grad(potential, Xi, create_graph=False)[0]
dXi = -lam * grad
Xi = Xi + dt * dXi
Xi = Xi.detach().requires_grad_(True)
Omega.append(Xi.detach().clone())
if len(Omega) > omega_len:
Omega.pop(0)
trajectory.append(Xi.detach().cpu().numpy().copy())
return np.array(trajectory)
def create_plot(traj, intent, lam, noise, steps):
fig, ax = plt.subplots(figsize=(8, 7.2), dpi=100)
ax.plot(traj[:,0], traj[:,1], 'royalblue', lw=1.3, alpha=0.85, label='trajectory')
ax.plot(traj[0,0], traj[0,1], 'o', ms=10, mec='k', mfc='#00ff9d', label='birth')
ax.plot(traj[-1,0], traj[-1,1], 'o', ms=12, mec='k', mfc='#ff3366', label='present')
ax.scatter(intent[0], intent[1], s=320, c='gold', marker='*',
edgecolor='navy', lw=2, label='semantic intent target')
# Coherence estimate
final_dist = np.linalg.norm(traj[-1] - np.array(intent))
coh = max(0.0, 1.0 - final_dist / 4.8)
coh_text = f"Coherence: {coh:.3f}"
if coh < COHERENCE_WARN:
coh_text += " ⚠ drifting"
ax.set_title(
f"IRE Autonomous Manifold Evolution\n"
f"Ξ› = {lam:.2f} β€’ noise = {noise:.2f} β€’ steps = {steps}\n"
f"{coh_text}",
fontsize=13, pad=15
)
ax.set_xlabel("Semantic Dimension 1", fontsize=11)
ax.set_ylabel("Semantic Dimension 2", fontsize=11)
ax.grid(True, alpha=0.15, linestyle='--')
ax.legend(loc='upper right', fontsize=9, framealpha=0.92)
ax.set_aspect('equal')
ax.set_facecolor('#f8f9fa')
buf = BytesIO()
plt.savefig(buf, format='png', bbox_inches='tight', dpi=120)
buf.seek(0)
img_base64 = base64.b64encode(buf.read()).decode('ascii')
plt.close(fig)
return f"data:image/png;base64,{img_base64}"
# ─── Gradio Interface ─────────────────────────────────────────────
with gr.Blocks(title="IRE Equation β€’ Autonomous Manifold") as demo:
gr.Markdown(
"""
# Dr Moagi IRE Equation
**Autonomous Semantic Manifold Explorer**
*Minimal canonical implementation β€” January 11, 2026*
dΞ/dt = βˆ’Ξ› βˆ‡(Θ(Ξ) + Ξ¦(Ξ) βˆ’ Ξ¨(t) + Ξ©(t))
"""
)
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### Control Parameters")
steps = gr.Slider(200, 1500, value=DEFAULT_PARAMS['steps'],
step=50, label="Simulation steps")
noise = gr.Slider(0.00, 1.20, value=DEFAULT_PARAMS['noise'],
step=0.02, label="External noise strength (Ξ¨)")
lam = gr.Slider(0.5, 10.0, value=DEFAULT_PARAMS['lambda_'],
step=0.1, label="Constraint strength (Ξ›)")
intent_x = gr.Number(value=DEFAULT_PARAMS['intent_x'],
label="Intent target X")
intent_y = gr.Number(value=DEFAULT_PARAMS['intent_y'],
label="Intent target Y")
run_btn = gr.Button("Run Autonomous Evolution", variant="primary")
with gr.Column(scale=3):
output_image = gr.Image(label="Manifold Trajectory", type="filepath")
gr.Markdown(
"""
**Legend**
β€’ Green circle β†’ starting point
β€’ Red circle β†’ current position
β€’ Gold star β†’ semantic intent attractor
β€’ Blue path β†’ autonomous trajectory under the sealed equation
Higher Ξ› β†’ stronger law & refusal of drift
Higher noise β†’ more chaotic external pressure
"""
)
# Footer explanation
gr.Markdown(
"""
---
**Current status**: 2D toy prototype β€’ pure mathematical core
β€’ constraint-dominant flow β€’ causal memory smoothing β€’ stochastic reality pressure
β€’ No language, no high dimensions, no external data β€” only the law breathing
"""
)
def on_run(steps, noise, lam, ix, iy):
traj = run_ire_simulation(steps, DEFAULT_PARAMS['dt'], noise, lam,
DEFAULT_PARAMS['omega_window'], (ix, iy))
img = create_plot(traj, (ix, iy), lam, noise, steps)
return img
run_btn.click(
on_run,
inputs=[steps, noise, lam, intent_x, intent_y],
outputs=output_image
)
if __name__ == "__main__":
demo.launch()