petter2025 commited on
Commit
6d534a4
·
verified ·
1 Parent(s): a607b7f

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +4 -14
hf_demo.py CHANGED
@@ -1,7 +1,6 @@
1
  # hf_demo.py – ARF v4 API with Gradio frontend (optional)
2
  import logging
3
  import uuid
4
- import os
5
  from datetime import datetime, timezone
6
  from typing import Dict, Any, Optional
7
 
@@ -89,7 +88,7 @@ async def get_risk():
89
  "decision_id": decision_id,
90
  "timestamp": datetime.now(timezone.utc).isoformat(),
91
  "risk_score": float(risk_value),
92
- "outcome": None, # will be filled when feedback is given
93
  })
94
 
95
  return {
@@ -113,7 +112,6 @@ async def evaluate_incident(request: EvaluateRequest):
113
  Evaluate an incident and return a risk score with explainability.
114
  This is a placeholder – replace with actual call to your risk engine.
115
  """
116
- # For now, return a dummy response
117
  return EvaluateResponse(
118
  risk_score=0.23,
119
  base_risk=0.15,
@@ -129,7 +127,6 @@ async def record_outcome(decision_id: str, success: bool):
129
  for dec in decision_history:
130
  if dec["decision_id"] == decision_id:
131
  dec["outcome"] = "success" if success else "failure"
132
- # Update the risk engine (optional)
133
  intent = _DemoIntent()
134
  try:
135
  risk_engine.update_outcome(intent, success)
@@ -139,7 +136,7 @@ async def record_outcome(decision_id: str, success: bool):
139
  return {"error": "decision not found"}
140
 
141
  # ========================= GRADIO UI (Optional) =========================
142
- # This mounts the Gradio interface at the root path ("/").
143
 
144
  def get_risk_snapshot():
145
  try:
@@ -218,12 +215,5 @@ with gr.Blocks(title="ARF v4 Demo") as demo:
218
  memory_btn.click(fn=get_memory_snapshot, outputs=memory_output)
219
  history_btn.click(fn=lambda: decision_history[-10:], outputs=decision_output)
220
 
221
- # Mount Gradio app at the root path
222
- app = gr.mount_gradio_app(app, demo, path="/")
223
-
224
- # ========================= ENTRY POINT =========================
225
- # This ensures the server starts and stays alive when the script is run directly.
226
- if __name__ == "__main__":
227
- import uvicorn
228
- port = int(os.environ.get("PORT", 7860))
229
- uvicorn.run(app, host="0.0.0.0", port=port)
 
1
  # hf_demo.py – ARF v4 API with Gradio frontend (optional)
2
  import logging
3
  import uuid
 
4
  from datetime import datetime, timezone
5
  from typing import Dict, Any, Optional
6
 
 
88
  "decision_id": decision_id,
89
  "timestamp": datetime.now(timezone.utc).isoformat(),
90
  "risk_score": float(risk_value),
91
+ "outcome": None,
92
  })
93
 
94
  return {
 
112
  Evaluate an incident and return a risk score with explainability.
113
  This is a placeholder – replace with actual call to your risk engine.
114
  """
 
115
  return EvaluateResponse(
116
  risk_score=0.23,
117
  base_risk=0.15,
 
127
  for dec in decision_history:
128
  if dec["decision_id"] == decision_id:
129
  dec["outcome"] = "success" if success else "failure"
 
130
  intent = _DemoIntent()
131
  try:
132
  risk_engine.update_outcome(intent, success)
 
136
  return {"error": "decision not found"}
137
 
138
  # ========================= GRADIO UI (Optional) =========================
139
+ # Mount the Gradio interface at the root path.
140
 
141
  def get_risk_snapshot():
142
  try:
 
215
  memory_btn.click(fn=get_memory_snapshot, outputs=memory_output)
216
  history_btn.click(fn=lambda: decision_history[-10:], outputs=decision_output)
217
 
218
+ # Mount Gradio app at the root path – the Hugging Face platform will serve this FastAPI app.
219
+ app = gr.mount_gradio_app(app, demo, path="/")