Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,30 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
log = []
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
if "surge" in scenario.lower() or "override" in scenario.lower():
|
| 8 |
anomaly_score = 0.92
|
| 9 |
else:
|
| 10 |
anomaly_score = 0.21
|
| 11 |
|
| 12 |
-
log.append("[Analyzer]: Anomaly score = {:.2f}"
|
| 13 |
if anomaly_score > 0.8:
|
| 14 |
log.append("[Decision]: HALT_SIGNAL issued due to risk threshold breach.")
|
| 15 |
else:
|
| 16 |
log.append("[Decision]: System stable. No action required.")
|
| 17 |
|
| 18 |
-
return {
|
| 19 |
-
|
| 20 |
-
demo = gr.Interface(fn=reflex_guard,
|
| 21 |
-
inputs=gr.Textbox(label="System Scenario"),
|
| 22 |
-
outputs="json",
|
| 23 |
-
live=False)
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import uvicorn
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.post("/run")
|
| 8 |
+
async def run_reflex(request: Request):
|
| 9 |
+
data = await request.json()
|
| 10 |
+
scenario = data.get("scenario", "")
|
| 11 |
log = []
|
| 12 |
+
|
| 13 |
+
log.append(f"[ReflexGuard]: Scenario received – '{scenario}'")
|
| 14 |
|
| 15 |
if "surge" in scenario.lower() or "override" in scenario.lower():
|
| 16 |
anomaly_score = 0.92
|
| 17 |
else:
|
| 18 |
anomaly_score = 0.21
|
| 19 |
|
| 20 |
+
log.append(f"[Analyzer]: Anomaly score = {anomaly_score:.2f}")
|
| 21 |
if anomaly_score > 0.8:
|
| 22 |
log.append("[Decision]: HALT_SIGNAL issued due to risk threshold breach.")
|
| 23 |
else:
|
| 24 |
log.append("[Decision]: System stable. No action required.")
|
| 25 |
|
| 26 |
+
return JSONResponse(content={"logs": log})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Only required for local dev; Hugging Face auto-detects app
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|