Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,105 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def reflex_guard(scenario: str):
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
if any(k in
|
| 11 |
score = 0.92
|
|
|
|
|
|
|
| 12 |
else:
|
| 13 |
score = 0.18
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
else:
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
return "\n".join(
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
HTML_UI = """
|
| 26 |
-
<div style="background:#0f0f0f;color:#
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
<p style="text-align:center;opacity:0.8">
|
| 29 |
-
|
| 30 |
</p>
|
| 31 |
|
| 32 |
-
<
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
<button onclick="runReflex()"
|
| 38 |
-
style="margin-top:
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
🚀 Launch Reflex Check
|
| 42 |
</button>
|
| 43 |
|
| 44 |
<pre id="output"
|
| 45 |
-
style="margin-top:
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</div>
|
| 50 |
|
| 51 |
<script>
|
|
@@ -70,6 +124,9 @@ async function runReflex(){
|
|
| 70 |
</script>
|
| 71 |
"""
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
with gr.Blocks(css="body{background:#0f0f0f}") as demo:
|
| 74 |
gr.HTML(HTML_UI)
|
| 75 |
hidden = gr.Textbox(visible=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import hashlib
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# ===============================
|
| 6 |
+
# CodexVault Reflex Memory (Session-Lattice)
|
| 7 |
+
# ===============================
|
| 8 |
+
REFLEX_MEMORY = []
|
| 9 |
+
REFLEX_COUNT = 0
|
| 10 |
+
|
| 11 |
+
def classify_state(score: float) -> str:
|
| 12 |
+
if score >= 0.8:
|
| 13 |
+
return "HALT"
|
| 14 |
+
elif score >= 0.4:
|
| 15 |
+
return "MONITOR"
|
| 16 |
+
return "STABLE"
|
| 17 |
|
| 18 |
def reflex_guard(scenario: str):
|
| 19 |
+
global REFLEX_COUNT
|
| 20 |
+
REFLEX_COUNT += 1
|
| 21 |
|
| 22 |
+
ts = time.strftime("%Y-%m-%d %H:%M:%S")
|
| 23 |
+
scenario_norm = scenario.strip().lower()
|
| 24 |
+
scenario_hash = hashlib.sha256(scenario_norm.encode()).hexdigest()[:12]
|
| 25 |
|
| 26 |
+
if any(k in scenario_norm for k in ["surge", "override", "anomaly", "breach", "failure"]):
|
| 27 |
score = 0.92
|
| 28 |
+
elif any(k in scenario_norm for k in ["delay", "degrade", "unstable"]):
|
| 29 |
+
score = 0.55
|
| 30 |
else:
|
| 31 |
score = 0.18
|
| 32 |
|
| 33 |
+
state = classify_state(score)
|
| 34 |
+
|
| 35 |
+
entry = {
|
| 36 |
+
"timestamp": ts,
|
| 37 |
+
"hash": scenario_hash,
|
| 38 |
+
"state": state,
|
| 39 |
+
"score": score
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
REFLEX_MEMORY.append(entry)
|
| 43 |
+
|
| 44 |
+
log = [
|
| 45 |
+
f"[CodexVault]: Reflex #{REFLEX_COUNT}",
|
| 46 |
+
f"[Timestamp]: {ts}",
|
| 47 |
+
f"[Scenario Hash]: {scenario_hash}",
|
| 48 |
+
f"[Analyzer]: Anomaly score = {score:.2f}",
|
| 49 |
+
f"[Decision]: SYSTEM STATE → {state}",
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
if state == "HALT":
|
| 53 |
+
log.append("[Action]: HALT_SIGNAL issued (preemptive defense engaged).")
|
| 54 |
+
elif state == "MONITOR":
|
| 55 |
+
log.append("[Action]: Monitoring escalation pathways.")
|
| 56 |
else:
|
| 57 |
+
log.append("[Action]: System stable. Passive vigilance.")
|
| 58 |
+
|
| 59 |
+
log.append(f"[Vault]: Reflex entries stored = {len(REFLEX_MEMORY)}")
|
| 60 |
|
| 61 |
+
return "\n".join(log)
|
| 62 |
|
| 63 |
|
| 64 |
+
# ===============================
|
| 65 |
+
# Codex UI (Embedded Frontend)
|
| 66 |
+
# ===============================
|
| 67 |
HTML_UI = """
|
| 68 |
+
<div style="background:#0f0f0f;color:#ffffff;padding:32px;
|
| 69 |
+
font-family:Segoe UI,Arial;border-radius:14px;max-width:900px;margin:auto">
|
| 70 |
+
|
| 71 |
+
<h1 style="text-align:center">🛡️ Codex ReflexGuard</h1>
|
| 72 |
<p style="text-align:center;opacity:0.8">
|
| 73 |
+
CodexVault Eternal Node · Reflex-Level Safety Intelligence
|
| 74 |
</p>
|
| 75 |
|
| 76 |
+
<div style="margin-top:20px">
|
| 77 |
+
<label style="font-weight:bold">System Scenario</label>
|
| 78 |
+
<textarea id="scenario"
|
| 79 |
+
style="width:100%;height:100px;margin-top:8px;
|
| 80 |
+
background:#1e1e1e;color:#fff;
|
| 81 |
+
border-radius:10px;border:none;padding:12px"></textarea>
|
| 82 |
+
</div>
|
| 83 |
|
| 84 |
<button onclick="runReflex()"
|
| 85 |
+
style="margin-top:18px;padding:14px 22px;
|
| 86 |
+
background:#00ffff;color:#000;
|
| 87 |
+
font-weight:bold;border:none;
|
| 88 |
+
border-radius:10px;cursor:pointer">
|
| 89 |
🚀 Launch Reflex Check
|
| 90 |
</button>
|
| 91 |
|
| 92 |
<pre id="output"
|
| 93 |
+
style="margin-top:24px;background:#1e1e1e;
|
| 94 |
+
padding:16px;border-radius:10px;
|
| 95 |
+
min-height:160px;white-space:pre-wrap">
|
| 96 |
+
[CodexVault]: Awaiting scenario input…
|
| 97 |
</pre>
|
| 98 |
+
|
| 99 |
+
<p style="margin-top:20px;font-size:12px;opacity:0.6;text-align:center">
|
| 100 |
+
This node demonstrates reflex-level safety intelligence.
|
| 101 |
+
It is not predictive analytics. It is pre-emptive system defense.
|
| 102 |
+
</p>
|
| 103 |
</div>
|
| 104 |
|
| 105 |
<script>
|
|
|
|
| 124 |
</script>
|
| 125 |
"""
|
| 126 |
|
| 127 |
+
# ===============================
|
| 128 |
+
# Gradio App (HF-Native)
|
| 129 |
+
# ===============================
|
| 130 |
with gr.Blocks(css="body{background:#0f0f0f}") as demo:
|
| 131 |
gr.HTML(HTML_UI)
|
| 132 |
hidden = gr.Textbox(visible=False)
|