RFT_Omega_API / app.py
RFTSystems's picture
Update app.py
e9b9fb9 verified
raw
history blame
3.76 kB
# ============================================================
# RFT-Ω FRAMEWORK — TOTAL-PROOF API (Gradio Stable Build)
# Author: Liam Grinstead | RFT Systems | All Rights Reserved
# ============================================================
import json, random
from datetime import datetime
import numpy as np
import gradio as gr
# ------------------ About / Legal ---------------------------
RFT_VERSION = "v4.0-total-proof-stable"
RFT_DOI = "https://doi.org/10.5281/zenodo.17466722"
LEGAL_NOTICE = (
"All Rights Reserved — RFT-IPURL v1.0 (UK / Berne). "
"Research validation use only. No reverse-engineering without written consent."
)
# ------------------ System Profiles -------------------------
PROFILES = {
"AI / Neural": {"base": (0.86, 0.80), "w": (0.65, 0.35)},
"SpaceX / Aerospace": {"base": (0.84, 0.79), "w": (0.60, 0.40)},
"Energy / RHES": {"base": (0.83, 0.78), "w": (0.55, 0.45)},
"Extreme Perturbation": {"base": (0.82, 0.77), "w": (0.50, 0.50)},
}
# ------------------ Simulation Core -------------------------
def _rng(seed: int):
return np.random.RandomState(seed)
def simulate_step(rng, profile, sigma, dist):
base_q, base_z = PROFILES[profile]["base"]
wq, wz = PROFILES[profile]["w"]
if dist == "uniform":
qn = rng.uniform(-sigma, sigma)
zn = rng.uniform(-sigma * 0.8, sigma * 0.8)
else:
qn = rng.normal(0, sigma)
zn = rng.normal(0, sigma * 0.8)
q = float(np.clip(base_q + wq * qn, 0.0, 0.99))
z = float(np.clip(base_z + wz * zn, 0.0, 0.99))
variance = abs(qn) + abs(zn)
if variance > 0.15:
status = "critical"
elif variance > 0.07:
status = "perturbed"
else:
status = "nominal"
return {"σ": round(sigma, 6), "QΩ": q, "ζ_sync": z, "status": status}
# ------------------ Simulation Runner -----------------------
def run(profile, dist, sigma, seed, samples):
rng = _rng(int(seed))
results = [simulate_step(rng, profile, sigma, dist) for _ in range(samples)]
q_mean = np.mean([r["QΩ"] for r in results])
z_mean = np.mean([r["ζ_sync"] for r in results])
majority = max(
["nominal", "perturbed", "critical"],
key=lambda s: sum(1 for r in results if r["status"] == s),
)
return {
"profile": profile,
"noise_scale": sigma,
"distribution": dist,
"QΩ_mean": round(float(q_mean), 6),
"ζ_sync_mean": round(float(z_mean), 6),
"status_majority": majority,
"timestamp_utc": datetime.utcnow().isoformat() + "Z",
"rft_notice": LEGAL_NOTICE,
}
# ------------------ Gradio Interface ------------------------
with gr.Blocks(title="RFT-Ω Total-Proof Kernel") as demo:
gr.Markdown(
f"### RFT-Ω Total-Proof Kernel ({RFT_VERSION}) \n"
f"DOI: [{RFT_DOI}]({RFT_DOI}) \n{LEGAL_NOTICE}"
)
with gr.Row():
profile = gr.Dropdown(
list(PROFILES.keys()), label="System Profile", value="AI / Neural"
)
dist = gr.Radio(["gauss", "uniform"], label="Noise Distribution", value="gauss")
with gr.Row():
sigma = gr.Slider(0.0, 0.3, value=0.05, step=0.01, label="Noise Scale (σ)")
seed = gr.Number(value=123, label="Seed (integer)")
samples = gr.Slider(1, 20, value=5, step=1, label="Samples per run")
run_btn = gr.Button("Run Simulation")
output = gr.JSON(label="Simulation Results")
run_btn.click(run, inputs=[profile, dist, sigma, seed, samples], outputs=[output])
# ------------------ Launch -------------------------------
if __name__ == "__main__":
# Disable SSR for Hugging Face Spaces compatibility
demo.launch(server_name="0.0.0.0", share=False, ssr_mode=False)