Spaces:
Sleeping
Sleeping
Update app.py
Browse files1223456789101112131415161718561920218222324251026272829303132151617183334353637383940414243444546474849505152535455562057585960226162636465666726276869707172297374753233343576777879808182838438394085868788899091924546479394959697989910010110210310410518 unmodified lines124125126127128129130131132import gradio as grimport jsonimport hashlibimport time
# ===============================# CodexVault Reflex Memory (Session-Lattice)# ===============================REFLEX_MEMORY = []REFLEX_COUNT = 0
def classify_state(score: float) -> str: if score >= 0.8: return "HALT" elif score >= 0.4: return "MONITOR" return "STABLE"
def reflex_guard(scenario: str): logs = [] logs.append(f"[ReflexGuard]: Scenario received – '{scenario}'") global REFLEX_COUNT REFLEX_COUNT += 1
scenario_l = scenario.lower() ts = time.strftime("%Y-%m-%d %H:%M:%S") scenario_norm = scenario.strip().lower() scenario_hash = hashlib.sha256(scenario_norm.encode()).hexdigest()[:12]
if any(k in scenario_l for k in ["surge", "override", "anomaly", "breach"]): if any(k in scenario_norm for k in ["surge", "override", "anomaly", "breach", "failure"]): score = 0.92 elif any(k in scenario_norm for k in ["delay", "degrade", "unstable"]): score = 0.55 else: score = 0.18
logs.append(f"[Analyzer]: Anomaly score = {score:.2f}")
if score > 0.8: logs.append("[Decision]: HALT_SIGNAL issued (risk threshold exceeded).") state = classify_state(score)
entry = { "timestamp": ts, "hash": scenario_hash, "state": state, "score": score }
REFLEX_MEMORY.append(entry)
log = [ f"[CodexVault]: Reflex #{REFLEX_COUNT}", f"[Timestamp]: {ts}", f"[Scenario Hash]: {scenario_hash}", f"[Analyzer]: Anomaly score = {score:.2f}", f"[Decision]: SYSTEM STATE → {state}", ]
if state == "HALT": log.append("[Action]: HALT_SIGNAL issued (preemptive defense engaged).") elif state == "MONITOR": log.append("[Action]: Monitoring escalation pathways.") else: logs.append("[Decision]: System stable. Monitoring continues.") log.append("[Action]: System stable. Passive vigilance.")
log.append(f"[Vault]: Reflex entries stored = {len(REFLEX_MEMORY)}")
return "\n".join(logs) return "\n".join(log)
# ===============================# Codex UI (Embedded Frontend)# ===============================HTML_UI = """<div style="background:#0f0f0f;color:#fff;padding:30px;font-family:Segoe UI;border-radius:12px"> <h1 style="text-align:center">🛡️ Codex ReflexGuard Dashboard</h1><div style="background:#0f0f0f;color:#ffffff;padding:32px; font-family:Segoe UI,Arial;border-radius:14px;max-width:900px;margin:auto">
<h1 style="text-align:center">🛡️ Codex ReflexGuard</h1> <p style="text-align:center;opacity:0.8"> Live Reflex Intelligence System (Codex vΩΞ) CodexVault Eternal Node · Reflex-Level Safety Intelligence </p>
<label style="font-weight:bold">System Scenario</label> <textarea id="scenario" style="width:100%;height:90px; background:#1e1e1e;color:white;border-radius:8px; border:none;padding:10px;margin-top:8px"></textarea> <div style="margin-top:20px"> <label style="font-weight:bold">System Scenario</label> <textarea id="scenario" style="width:100%;height:100px;margin-top:8px; background:#1e1e1e;color:#fff; border-radius:10px;border:none;padding:12px"></textarea> </div>
<button onclick="runReflex()" style="margin-top:15px;padding:12px 20px; background:#00ffff;border:none; font-weight:bold;border-radius:8px;cursor:pointer"> style="margin-top:18px;padding:14px 22px; background:#00ffff;color:#000; font-weight:bold;border:none; border-radius:10px;cursor:pointer"> 🚀 Launch Reflex Check </button>
<pre id="output" style="margin-top:20px;background:#1e1e1e; padding:15px;border-radius:8px;min-height:120px">[ReflexGuard]: Awaiting input... style="margin-top:24px;background:#1e1e1e; padding:16px;border-radius:10px; min-height:160px;white-space:pre-wrap">[CodexVault]: Awaiting scenario input… </pre>
<p style="margin-top:20px;font-size:12px;opacity:0.6;text-align:center"> This node demonstrates reflex-level safety intelligence. It is not predictive analytics. It is pre-emptive system defense. </p></div>
<script>18 unmodified lines</script>"""
# ===============================# Gradio App (HF-Native)# ===============================with gr.Blocks(css="body{background:#0f0f0f}") as demo: gr.HTML(HTML_UI) hidden = gr.Textbox(visible=False)app.py+81-24