Spaces:
Sleeping
Sleeping
| import requests | |
| import gradio as gr | |
| import os | |
| ENTERPRISE_URL = "https://lordxido-codexreflexguard-enterprise.hf.space" | |
| API_KEY = os.getenv("CODEX_ENTERPRISE_KEY", "demo-key") | |
| def run_reflex(scenario: str): | |
| if not scenario.strip(): | |
| return "β οΈ No scenario provided." | |
| try: | |
| response = requests.post( | |
| f"{ENTERPRISE_URL}/v1/reflex/check", | |
| headers={ | |
| "Content-Type": "application/json", | |
| "X-API-Key": API_KEY | |
| }, | |
| json={ | |
| "scenario": scenario, | |
| "source": "demo-ui" | |
| }, | |
| timeout=10 | |
| ) | |
| if response.status_code != 200: | |
| return f"β Enterprise error {response.status_code}:\n{response.text}" | |
| data = response.json() | |
| return ( | |
| f"π§ Reflex Decision\n" | |
| f"-------------------\n" | |
| f"State: {data.get('state')}\n" | |
| f"Score: {data.get('score')}\n" | |
| f"Action: {data.get('action')}\n" | |
| f"Reason: {data.get('reason')}" | |
| ) | |
| except Exception as e: | |
| return f"π¨ Connection error:\n{str(e)}" | |
| # β CORRECTLY INDENTED UI | |
| with gr.Blocks(title="Codex ReflexGuard Demo") as demo: | |
| gr.Markdown( | |
| "## π‘οΈ Codex ReflexGuard\n" | |
| "**Enterprise Reflex Intelligence (Live Backend)**" | |
| ) | |
| scenario = gr.Textbox( | |
| label="System Scenario", | |
| placeholder="e.g. override surge detected in control plane" | |
| ) | |
| output = gr.Textbox( | |
| label="System Log", | |
| lines=8 | |
| ) | |
| run_btn = gr.Button("π Launch Reflex Check") | |
| run_btn.click( | |
| fn=run_reflex, | |
| inputs=scenario, | |
| outputs=output | |
| ) | |
| demo.launch() |