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]}...`\n\n") return "\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", color="white"); plt.ylabel("Complexity Score", color="white") plt.grid(alpha=0.3); plt.gca().set_facecolor("black") plt.tick_params(colors="white") return plt.gcf() # === Gradio App === custom_theme = gr.themes.Base( primary_hue="cyan", # supported hue secondary_hue="pink", # supported hue neutral_hue="gray", # supported hue ) with gr.Blocks(theme=custom_theme) as demo: gr.Markdown( """ # 🌌 Resonance Atlas — The Living Codex Immerse yourself in evolving scrolls of mathematics. Formulas mutate into higher symbolic forms across epochs, sealed with Immortality Glyphs. """, ) with gr.Tab("Codex Scrolls"): gr.Markdown("### 🔢 Live Epoch Run") 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"): gr.Markdown("### 📈 Complexity Growth") 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("### 🌠 Immersion Mode") gr.Markdown("Formulas pulse, glyphs glow, epochs unfold in full-screen dynamic visualization.") demo.launch()