Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505118 unmodified lines707172737475import gradio as grimport jsondef reflex_guard(scenario: str):logs = []logs.append(f"[ReflexGuard]: Scenario received – '{scenario}'")scenario_l = scenario.lower()if any(k in scenario_l for k in ["surge", "override", "anomaly", "breach"]):score = 0.92else:score = 0.18logs.append(f"[Analyzer]: Anomaly score = {score:.2f}")if score > 0.8:logs.append("[Decision]: HALT_SIGNAL issued (risk threshold exceeded).")else:logs.append("[Decision]: System stable. Monitoring continues.")return "\n".join(logs)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><p style="text-align:center;opacity:0.8">Live Reflex Intelligence System (Codex vΩΞ)</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><button onclick="runReflex()"style="margin-top:15px;padding:12px 20px;background:#00ffff;border:none;font-weight:bold;border-radius:8px;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...</pre></div><script>18 unmodified lines</script>"""with gr.Blocks(css="body{background:#0f0f0f}") as demo:gr.HTML(HTML_UI)hidden = gr.Textbox(visible=False)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410518 unmodified lines124125126127128129130131132import gradio as grimport hashlibimport time# ===============================# CodexVault Reflex Memory (Session-Lattice)# ===============================REFLEX_MEMORY = []REFLEX_COUNT = 0def classify_state(score: float) -> str:if score >= 0.8:return "HALT"elif score >= 0.4:return "MONITOR"return "STABLE"def reflex_guard(scenario: str):global REFLEX_COUNTREFLEX_COUNT += 1ts = 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_norm for k in ["surge", "override", "anomaly", "breach", "failure"]):score = 0.92elif any(k in scenario_norm for k in ["delay", "degrade", "unstable"]):score = 0.55else:score = 0.18state = 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:log.append("[Action]: System stable. Passive vigilance.")log.append(f"[Vault]: Reflex entries stored = {len(REFLEX_MEMORY)}")return "\n".join(log)# ===============================# Codex UI (Embedded Frontend)# ===============================HTML_UI = """<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">CodexVault Eternal Node · Reflex-Level Safety Intelligence</p><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: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: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