LordXido commited on
Commit
517f16d
·
verified ·
1 Parent(s): 4676865

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -70
app.py CHANGED
@@ -1,71 +1,41 @@
 
1
  import gradio as gr
2
- import hashlib
3
- import time
4
-
5
- # ===============================
6
- # CodexVault (Session Memory)
7
- # ===============================
8
- VAULT = []
9
- REFLEX_COUNT = 0
10
-
11
- def reflex_guard(scenario: str):
12
- global REFLEX_COUNT
13
- REFLEX_COUNT += 1
14
-
15
- ts = time.strftime("%Y-%m-%d %H:%M:%S")
16
- norm = scenario.strip().lower()
17
- h = hashlib.sha256(norm.encode()).hexdigest()[:12]
18
-
19
- if any(k in norm for k in ["override", "surge", "breach", "failure"]):
20
- score = 0.92
21
- elif any(k in norm for k in ["delay", "degrade", "unstable"]):
22
- score = 0.55
23
- else:
24
- score = 0.18
25
-
26
- if score >= 0.8:
27
- state = "HALT"
28
- elif score >= 0.4:
29
- state = "MONITOR"
30
- else:
31
- state = "STABLE"
32
-
33
- VAULT.append({
34
- "time": ts,
35
- "hash": h,
36
- "state": state,
37
- "score": score
38
- })
39
-
40
- return f"""
41
- [CodexVault] Reflex #{REFLEX_COUNT}
42
- [Timestamp] {ts}
43
- [Scenario Hash] {h}
44
- [Analyzer] Anomaly score = {score:.2f}
45
- [Decision] SYSTEM STATE → {state}
46
- [Vault] Stored reflexes = {len(VAULT)}
47
- """.strip()
48
-
49
-
50
- with gr.Blocks(css="body{background:#0f0f0f}") as demo:
51
- gr.Markdown(
52
- "# 🛡️ Codex ReflexGuard\n"
53
- "### CodexVault Enterprise Demo Node\n\n"
54
- "*Reflex-level safety intelligence (HF-native)*"
55
- )
56
-
57
- scenario = gr.Textbox(
58
- label="System Scenario",
59
- placeholder="e.g. override surge detected",
60
- lines=4
61
- )
62
-
63
- output = gr.Textbox(
64
- label="System Log",
65
- lines=10
66
- )
67
-
68
- scenario.submit(reflex_guard, scenario, output)
69
- gr.Button("Launch Reflex Check").click(reflex_guard, scenario, output)
70
-
71
- demo.launch()
 
1
+ import requests
2
  import gradio as gr
3
+ import os
4
+
5
+ ENTERPRISE_URL = "https://lordxido-codexreflexguard-enterprise.hf.space"
6
+ API_KEY = os.getenv("CODEX_ENTERPRISE_KEY", "demo-key")
7
+
8
+ def run_reflex(scenario: str):
9
+ if not scenario.strip():
10
+ return "⚠️ No scenario provided."
11
+
12
+ try:
13
+ r = requests.post(
14
+ f"{ENTERPRISE_URL}/v1/reflex/check",
15
+ headers={
16
+ "Content-Type": "application/json",
17
+ "X-API-Key": API_KEY
18
+ },
19
+ json={
20
+ "scenario": scenario,
21
+ "source": "demo-ui"
22
+ },
23
+ timeout=10
24
+ )
25
+
26
+ if r.status_code != 200:
27
+ return f"❌ Enterprise error: {r.status_code}\n{r.text}"
28
+
29
+ data = r.json()
30
+
31
+ return (
32
+ f"🧠 Reflex Decision\n"
33
+ f"-------------------\n"
34
+ f"State: {data['state']}\n"
35
+ f"Score: {data['score']}\n"
36
+ f"Action: {data['action']}\n"
37
+ f"Reason: {data['reason']}"
38
+ )
39
+
40
+ except Exception as e:
41
+ return f"🚨 Connection error:\n{str(e)}"