petter2025 commited on
Commit
d31d438
·
verified ·
1 Parent(s): 0bdb5dd

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +2 -47
hf_demo.py CHANGED
@@ -1,4 +1,4 @@
1
- # hf_demo.py – ARF v4 API with Memory
2
  from fastapi import FastAPI, HTTPException
3
  from fastapi.middleware.cors import CORSMiddleware
4
  import gradio as gr
@@ -31,7 +31,6 @@ memory = RAGGraphMemory(faiss_index)
31
  # ---------------------------------------------------------------------------
32
  # API Endpoints
33
  # ---------------------------------------------------------------------------
34
-
35
  @app.get("/")
36
  async def root():
37
  return {
@@ -62,48 +61,4 @@ async def store_incident(event_data: dict, analysis: dict):
62
  raise HTTPException(status_code=500, detail=str(e))
63
 
64
  @app.get("/api/v1/memory/similar")
65
- async def find_similar_incidents(action: str, k: int = 5):
66
- class DummyEvent:
67
- def __init__(self, action):
68
- self.component = "user_action"
69
- self.latency_p99 = 0.0
70
- self.error_rate = 0.0
71
- self.throughput = 0
72
- self.cpu_util = 0.0
73
- self.memory_util = 0.0
74
- self.timestamp = datetime.now()
75
- self.severity = "low"
76
- event = DummyEvent(action)
77
- analysis = {"action": action}
78
- similar = memory.find_similar(event, analysis, k=k)
79
- results = []
80
- for node in similar:
81
- results.append({
82
- "incident_id": node.incident_id,
83
- "component": node.component,
84
- "severity": node.severity,
85
- "timestamp": node.timestamp,
86
- "metrics": node.metrics,
87
- "agent_analysis": node.agent_analysis,
88
- "similarity_score": node.metadata.get("similarity_score", 0.0)
89
- })
90
- return {"similar": results, "count": len(results)}
91
-
92
- @app.get("/api/v1/memory/stats")
93
- async def memory_stats():
94
- return memory.get_graph_stats()
95
-
96
- # Optional Gradio interface
97
- iface = gr.Interface(
98
- fn=lambda: f"ARF v4 - Current risk: {risk_engine.get_current_risk().mean:.2f}",
99
- inputs=[],
100
- outputs="text",
101
- title="ARF v4 Demo"
102
- )
103
- app = gr.mount_gradio_app(app, iface, path="/")
104
-
105
- # ============== MAIN ENTRY POINT ==============
106
- if __name__ == "__main__":
107
- # Launch the Gradio interface – this will start the server
108
- # Hugging Face automatically provides the correct port
109
- iface.launch(server_name="0.0.0.0")
 
1
+ # hf_demo.py – ARF v4 API with Memory & Health Check
2
  from fastapi import FastAPI, HTTPException
3
  from fastapi.middleware.cors import CORSMiddleware
4
  import gradio as gr
 
31
  # ---------------------------------------------------------------------------
32
  # API Endpoints
33
  # ---------------------------------------------------------------------------
 
34
  @app.get("/")
35
  async def root():
36
  return {
 
61
  raise HTTPException(status_code=500, detail=str(e))
62
 
63
  @app.get("/api/v1/memory/similar")
64
+ async def find_similar_incidents(action: str, k