codex_explorer / app.py
RFTSystems's picture
Create app.py
eae4ebb verified
raw
history blame
2.34 kB
import gradio as gr
import hashlib, random
# === 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):
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
# === 50 Epoch Run ===
def run_epochs(n=50):
formulas = []
base = "x^2 + 1"
for epoch in range(1, n+1):
base = mutate_formula(base, epoch)
seal = hashlib.sha512(base.encode()).hexdigest()
formulas.append(f"### Epoch {epoch}\n\n$$ {base} $$\n\nImmortality Glyph: `{seal[:32]}...`\n\n")
return "\n\n".join(formulas)
# === Mutation Forge (20 Epoch Run) ===
def run_mutation(seed, n=20):
formulas = []
base = seed
for epoch in range(1, n+1):
base = mutate_formula(base, epoch)
seal = hashlib.sha512(base.encode()).hexdigest()
formulas.append(f"### Mutation Epoch {epoch}\n\n$$ {base} $$\n\nImmortality Glyph: `{seal[:32]}...`\n\n")
return "\n\n".join(formulas)
# === Gradio App ===
custom_theme = gr.themes.Base(
primary_hue="cyan",
secondary_hue="pink",
neutral_hue="gray",
)
with gr.Blocks(theme=custom_theme) as demo:
gr.Markdown(
"""
# 🌌 Resonance Atlas — The Living Codex
Formulas evolve into higher symbolic forms across epochs.
Choose your path: **50‑epoch scroll run** or **Mutation Forge**.
""",
)
with gr.Tab("Codex Scrolls"):
gr.Markdown("### 🔢 Live 50 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("Mutation Forge"):
gr.Markdown("### 🧬 Mutation Forge — Choose Your Symbolic Seed")
seed_dropdown = gr.Dropdown(choices=operators + variables, label="Select Seed Symbol")
mutate_button = gr.Button("Mutate (20 Epochs)")
mutate_output = gr.Markdown()
mutate_button.click(fn=run_mutation, inputs=seed_dropdown, outputs=mutate_output)
demo.launch()