codex_explorer / app.py
RFTSystems's picture
Update app.py
1496c17 verified
raw
history blame
2.5 kB
import gradio as gr
import hashlib, random, matplotlib.pyplot as plt
# === Mutation Engine ===
operators = ["\\sin", "\\cos", "\\exp", "\\log", "\\nabla", "\\int", "\\frac{\\partial}{\\partial t}"]
variables = ["x", "y", "t", "\\xi_1", "dP", "d\\Psi", "dT"]
def mutate_formula(base, epoch):
# Structural mutation rules
if epoch % 5 == 0:
base = f"\\int ({base}) \\, dx"
elif epoch % 7 == 0:
base = f"\\nabla \\cdot ({base})"
else:
new_term = random.choice(operators) + "(" + random.choice(variables) + ")"
base = base + " + " + new_term
return base
def run_epochs(n=50):
formulas = []
base = "x^2 + 1" # starting point
for epoch in range(1, n+1):
base = mutate_formula(base, epoch)
seal = hashlib.sha512(base.encode()).hexdigest()
complexity = base.count("\\") + base.count("+")
formulas.append(f"**Epoch {epoch}**\n\n$$ {base} $$\n\nImmortality Glyph: `{seal[:32]}...`")
return "\n\n---\n\n".join(formulas)
# === Complexity Plot ===
def plot_complexity(n=50):
base = "x^2 + 1"
complexities = []
epochs = list(range(1, n+1))
for epoch in epochs:
base = mutate_formula(base, epoch)
complexity = base.count("\\") + base.count("+")
complexities.append(complexity)
plt.figure(figsize=(8,5), facecolor="black")
plt.plot(epochs, complexities, color="cyan", marker="o", linestyle="--")
plt.title("Symbolic Complexity Growth Across Epochs", color="white")
plt.xlabel("Epoch"); plt.ylabel("Complexity Score")
plt.grid(alpha=0.3); plt.gca().set_facecolor("black")
return plt.gcf()
# === Gradio App ===
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
gr.Markdown("# 🌌 Resonance Atlas — The Living Codex")
gr.Markdown("Watch formulas evolve into higher symbolic forms across epochs. Each scroll is sealed with an Immortality Glyph.")
with gr.Tab("Codex Scrolls"):
run_button = gr.Button("Run 50 Epochs")
output = gr.Markdown()
run_button.click(fn=run_epochs, inputs=None, outputs=output)
with gr.Tab("Complexity Timeline"):
plot_button = gr.Button("Show Complexity Growth")
plot_output = gr.Plot()
plot_button.click(fn=plot_complexity, inputs=None, outputs=plot_output)
with gr.Tab("Immersion Mode"):
gr.Markdown("### Full‑screen dynamic visualization coming soon…")
gr.Markdown("Formulas pulse, glyphs glow, epochs unfold.")
demo.launch()