Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,78 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import uvicorn
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
async def run_reflex(request: Request):
|
| 9 |
-
data = await request.json()
|
| 10 |
-
scenario = data.get("scenario", "")
|
| 11 |
-
log = []
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
if "surge" in scenario.lower() or "override" in scenario.lower():
|
| 16 |
-
anomaly_score = 0.92
|
| 17 |
else:
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
log.append("[Decision]: HALT_SIGNAL issued due to risk threshold breach.")
|
| 23 |
else:
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
if __name__ == "__main__":
|
| 30 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
|
|
|
| 3 |
|
| 4 |
+
def reflex_guard(scenario: str):
|
| 5 |
+
logs = []
|
| 6 |
+
logs.append(f"[ReflexGuard]: Scenario received – '{scenario}'")
|
| 7 |
|
| 8 |
+
scenario_l = scenario.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
if any(k in scenario_l for k in ["surge", "override", "anomaly", "breach"]):
|
| 11 |
+
score = 0.92
|
|
|
|
|
|
|
| 12 |
else:
|
| 13 |
+
score = 0.18
|
| 14 |
+
|
| 15 |
+
logs.append(f"[Analyzer]: Anomaly score = {score:.2f}")
|
| 16 |
|
| 17 |
+
if score > 0.8:
|
| 18 |
+
logs.append("[Decision]: HALT_SIGNAL issued (risk threshold exceeded).")
|
|
|
|
| 19 |
else:
|
| 20 |
+
logs.append("[Decision]: System stable. Monitoring continues.")
|
| 21 |
+
|
| 22 |
+
return "\n".join(logs)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
HTML_UI = """
|
| 26 |
+
<div style="background:#0f0f0f;color:#fff;padding:30px;font-family:Segoe UI;border-radius:12px">
|
| 27 |
+
<h1 style="text-align:center">🛡️ Codex ReflexGuard Dashboard</h1>
|
| 28 |
+
<p style="text-align:center;opacity:0.8">
|
| 29 |
+
Live Reflex Intelligence System (Codex vΩΞ)
|
| 30 |
+
</p>
|
| 31 |
+
|
| 32 |
+
<label style="font-weight:bold">System Scenario</label>
|
| 33 |
+
<textarea id="scenario" style="width:100%;height:90px;
|
| 34 |
+
background:#1e1e1e;color:white;border-radius:8px;
|
| 35 |
+
border:none;padding:10px;margin-top:8px"></textarea>
|
| 36 |
+
|
| 37 |
+
<button onclick="runReflex()"
|
| 38 |
+
style="margin-top:15px;padding:12px 20px;
|
| 39 |
+
background:#00ffff;border:none;
|
| 40 |
+
font-weight:bold;border-radius:8px;cursor:pointer">
|
| 41 |
+
🚀 Launch Reflex Check
|
| 42 |
+
</button>
|
| 43 |
+
|
| 44 |
+
<pre id="output"
|
| 45 |
+
style="margin-top:20px;background:#1e1e1e;
|
| 46 |
+
padding:15px;border-radius:8px;min-height:120px">
|
| 47 |
+
[ReflexGuard]: Awaiting input...
|
| 48 |
+
</pre>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<script>
|
| 52 |
+
async function runReflex(){
|
| 53 |
+
const scenario = document.getElementById("scenario").value;
|
| 54 |
+
const output = document.getElementById("output");
|
| 55 |
+
|
| 56 |
+
if(!scenario){
|
| 57 |
+
output.textContent += "\\n[Error]: No scenario provided.";
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
const res = await fetch("/run/predict", {
|
| 62 |
+
method: "POST",
|
| 63 |
+
headers: {"Content-Type":"application/json"},
|
| 64 |
+
body: JSON.stringify({data:[scenario]})
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const data = await res.json();
|
| 68 |
+
output.textContent = data.data[0];
|
| 69 |
+
}
|
| 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)
|
| 76 |
+
hidden.change(reflex_guard, hidden, hidden, api_name="run")
|
| 77 |
|
| 78 |
+
demo.launch()
|
|
|
|
|
|