Update app.py
Browse files
app.py
CHANGED
|
@@ -371,16 +371,17 @@ def generate_action_timeline():
|
|
| 371 |
return fig
|
| 372 |
|
| 373 |
def refresh_dashboard():
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
|
|
|
| 384 |
return (
|
| 385 |
control_stats,
|
| 386 |
generate_risk_gauge(),
|
|
@@ -401,7 +402,7 @@ oss_caps = {
|
|
| 401 |
}
|
| 402 |
|
| 403 |
# ----------------------------------------------------------------------
|
| 404 |
-
# Health endpoint (
|
| 405 |
# ----------------------------------------------------------------------
|
| 406 |
async def health_endpoint():
|
| 407 |
return {"status": "healthy", "timestamp": datetime.utcnow().isoformat()}
|
|
@@ -540,12 +541,8 @@ with gr.Blocks(title="ARF v4 – Bayesian Risk Scoring Demo") as demo:
|
|
| 540 |
outputs=[hmc_summary, hmc_trace_plot, hmc_pair_plot]
|
| 541 |
)
|
| 542 |
|
| 543 |
-
# Add health endpoint
|
| 544 |
-
demo.
|
| 545 |
-
path="/health",
|
| 546 |
-
method="GET",
|
| 547 |
-
endpoint=health_endpoint
|
| 548 |
-
)
|
| 549 |
|
| 550 |
if __name__ == "__main__":
|
| 551 |
demo.queue()
|
|
|
|
| 371 |
return fig
|
| 372 |
|
| 373 |
def refresh_dashboard():
|
| 374 |
+
with history_lock:
|
| 375 |
+
total = len(decision_history)
|
| 376 |
+
approved = sum(1 for _, d, _ in decision_history if d.get("approved", False))
|
| 377 |
+
blocked = total - approved
|
| 378 |
+
avg_risk = np.mean([r for _, r in risk_history]) if risk_history else 0.5
|
| 379 |
+
control_stats = {
|
| 380 |
+
"total_decisions": total,
|
| 381 |
+
"approved_actions": approved,
|
| 382 |
+
"blocked_actions": blocked,
|
| 383 |
+
"average_risk": float(avg_risk)
|
| 384 |
+
}
|
| 385 |
return (
|
| 386 |
control_stats,
|
| 387 |
generate_risk_gauge(),
|
|
|
|
| 402 |
}
|
| 403 |
|
| 404 |
# ----------------------------------------------------------------------
|
| 405 |
+
# Health endpoint (async)
|
| 406 |
# ----------------------------------------------------------------------
|
| 407 |
async def health_endpoint():
|
| 408 |
return {"status": "healthy", "timestamp": datetime.utcnow().isoformat()}
|
|
|
|
| 541 |
outputs=[hmc_summary, hmc_trace_plot, hmc_pair_plot]
|
| 542 |
)
|
| 543 |
|
| 544 |
+
# Add health endpoint using the underlying FastAPI app
|
| 545 |
+
demo.fastapi_app.add_api_route("/health", health_endpoint, methods=["GET"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
|
| 547 |
if __name__ == "__main__":
|
| 548 |
demo.queue()
|