Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
# Author: Liam Grinstead | RFT Systems | All Rights Reserved
|
| 4 |
# ============================================================
|
| 5 |
|
| 6 |
-
import json,
|
| 7 |
from datetime import datetime
|
| 8 |
import numpy as np
|
| 9 |
import gradio as gr
|
|
@@ -18,13 +18,14 @@ LEGAL_NOTICE = (
|
|
| 18 |
|
| 19 |
# ------------------ System Profiles -------------------------
|
| 20 |
PROFILES = {
|
| 21 |
-
"AI / Neural":
|
| 22 |
-
"SpaceX / Aerospace":
|
| 23 |
-
"Energy / RHES":
|
| 24 |
"Extreme Perturbation": {"base": (0.82, 0.77), "w": (0.50, 0.50)},
|
| 25 |
}
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
return np.random.RandomState(seed)
|
| 29 |
|
| 30 |
def simulate_step(rng, profile, sigma, dist):
|
|
@@ -32,19 +33,22 @@ def simulate_step(rng, profile, sigma, dist):
|
|
| 32 |
wq, wz = PROFILES[profile]["w"]
|
| 33 |
if dist == "uniform":
|
| 34 |
qn = rng.uniform(-sigma, sigma)
|
| 35 |
-
zn = rng.uniform(-sigma*0.8, sigma*0.8)
|
| 36 |
else:
|
| 37 |
qn = rng.normal(0, sigma)
|
| 38 |
-
zn = rng.normal(0, sigma*0.8)
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
variance = abs(qn) + abs(zn)
|
|
|
|
| 42 |
if variance > 0.15:
|
| 43 |
status = "critical"
|
| 44 |
elif variance > 0.07:
|
| 45 |
status = "perturbed"
|
| 46 |
else:
|
| 47 |
status = "nominal"
|
|
|
|
| 48 |
return {"σ": round(sigma, 6), "QΩ": q, "ζ_sync": z, "status": status}
|
| 49 |
|
| 50 |
# ------------------ Simulation Runner -----------------------
|
|
@@ -53,8 +57,11 @@ def run(profile, dist, sigma, seed, samples):
|
|
| 53 |
results = [simulate_step(rng, profile, sigma, dist) for _ in range(samples)]
|
| 54 |
q_mean = np.mean([r["QΩ"] for r in results])
|
| 55 |
z_mean = np.mean([r["ζ_sync"] for r in results])
|
| 56 |
-
majority = max(
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
return {
|
| 59 |
"profile": profile,
|
| 60 |
"noise_scale": sigma,
|
|
@@ -63,17 +70,21 @@ def run(profile, dist, sigma, seed, samples):
|
|
| 63 |
"ζ_sync_mean": round(float(z_mean), 6),
|
| 64 |
"status_majority": majority,
|
| 65 |
"timestamp_utc": datetime.utcnow().isoformat() + "Z",
|
| 66 |
-
"rft_notice": LEGAL_NOTICE
|
| 67 |
}
|
| 68 |
|
| 69 |
# ------------------ Gradio Interface ------------------------
|
| 70 |
with gr.Blocks(title="RFT-Ω Total-Proof Kernel") as demo:
|
| 71 |
-
gr.Markdown(
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
|
| 74 |
with gr.Row():
|
| 75 |
-
profile = gr.Dropdown(
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
with gr.Row():
|
| 79 |
sigma = gr.Slider(0.0, 0.3, value=0.05, step=0.01, label="Noise Scale (σ)")
|
|
@@ -87,4 +98,5 @@ with gr.Blocks(title="RFT-Ω Total-Proof Kernel") as demo:
|
|
| 87 |
|
| 88 |
# ------------------ Launch -------------------------------
|
| 89 |
if __name__ == "__main__":
|
| 90 |
-
|
|
|
|
|
|
| 3 |
# Author: Liam Grinstead | RFT Systems | All Rights Reserved
|
| 4 |
# ============================================================
|
| 5 |
|
| 6 |
+
import json, random
|
| 7 |
from datetime import datetime
|
| 8 |
import numpy as np
|
| 9 |
import gradio as gr
|
|
|
|
| 18 |
|
| 19 |
# ------------------ System Profiles -------------------------
|
| 20 |
PROFILES = {
|
| 21 |
+
"AI / Neural": {"base": (0.86, 0.80), "w": (0.65, 0.35)},
|
| 22 |
+
"SpaceX / Aerospace": {"base": (0.84, 0.79), "w": (0.60, 0.40)},
|
| 23 |
+
"Energy / RHES": {"base": (0.83, 0.78), "w": (0.55, 0.45)},
|
| 24 |
"Extreme Perturbation": {"base": (0.82, 0.77), "w": (0.50, 0.50)},
|
| 25 |
}
|
| 26 |
|
| 27 |
+
# ------------------ Simulation Core -------------------------
|
| 28 |
+
def _rng(seed: int):
|
| 29 |
return np.random.RandomState(seed)
|
| 30 |
|
| 31 |
def simulate_step(rng, profile, sigma, dist):
|
|
|
|
| 33 |
wq, wz = PROFILES[profile]["w"]
|
| 34 |
if dist == "uniform":
|
| 35 |
qn = rng.uniform(-sigma, sigma)
|
| 36 |
+
zn = rng.uniform(-sigma * 0.8, sigma * 0.8)
|
| 37 |
else:
|
| 38 |
qn = rng.normal(0, sigma)
|
| 39 |
+
zn = rng.normal(0, sigma * 0.8)
|
| 40 |
+
|
| 41 |
+
q = float(np.clip(base_q + wq * qn, 0.0, 0.99))
|
| 42 |
+
z = float(np.clip(base_z + wz * zn, 0.0, 0.99))
|
| 43 |
variance = abs(qn) + abs(zn)
|
| 44 |
+
|
| 45 |
if variance > 0.15:
|
| 46 |
status = "critical"
|
| 47 |
elif variance > 0.07:
|
| 48 |
status = "perturbed"
|
| 49 |
else:
|
| 50 |
status = "nominal"
|
| 51 |
+
|
| 52 |
return {"σ": round(sigma, 6), "QΩ": q, "ζ_sync": z, "status": status}
|
| 53 |
|
| 54 |
# ------------------ Simulation Runner -----------------------
|
|
|
|
| 57 |
results = [simulate_step(rng, profile, sigma, dist) for _ in range(samples)]
|
| 58 |
q_mean = np.mean([r["QΩ"] for r in results])
|
| 59 |
z_mean = np.mean([r["ζ_sync"] for r in results])
|
| 60 |
+
majority = max(
|
| 61 |
+
["nominal", "perturbed", "critical"],
|
| 62 |
+
key=lambda s: sum(1 for r in results if r["status"] == s),
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
return {
|
| 66 |
"profile": profile,
|
| 67 |
"noise_scale": sigma,
|
|
|
|
| 70 |
"ζ_sync_mean": round(float(z_mean), 6),
|
| 71 |
"status_majority": majority,
|
| 72 |
"timestamp_utc": datetime.utcnow().isoformat() + "Z",
|
| 73 |
+
"rft_notice": LEGAL_NOTICE,
|
| 74 |
}
|
| 75 |
|
| 76 |
# ------------------ Gradio Interface ------------------------
|
| 77 |
with gr.Blocks(title="RFT-Ω Total-Proof Kernel") as demo:
|
| 78 |
+
gr.Markdown(
|
| 79 |
+
f"### RFT-Ω Total-Proof Kernel ({RFT_VERSION}) \n"
|
| 80 |
+
f"DOI: [{RFT_DOI}]({RFT_DOI}) \n{LEGAL_NOTICE}"
|
| 81 |
+
)
|
| 82 |
|
| 83 |
with gr.Row():
|
| 84 |
+
profile = gr.Dropdown(
|
| 85 |
+
list(PROFILES.keys()), label="System Profile", value="AI / Neural"
|
| 86 |
+
)
|
| 87 |
+
dist = gr.Radio(["gauss", "uniform"], label="Noise Distribution", value="gauss")
|
| 88 |
|
| 89 |
with gr.Row():
|
| 90 |
sigma = gr.Slider(0.0, 0.3, value=0.05, step=0.01, label="Noise Scale (σ)")
|
|
|
|
| 98 |
|
| 99 |
# ------------------ Launch -------------------------------
|
| 100 |
if __name__ == "__main__":
|
| 101 |
+
# Disable SSR for Hugging Face Spaces compatibility
|
| 102 |
+
demo.launch(server_name="0.0.0.0", share=False, ssr_mode=False)
|