Update hf_demo.py
Browse files- hf_demo.py +8 -10
hf_demo.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 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
|
|
@@ -47,7 +49,6 @@ async def health():
|
|
| 47 |
|
| 48 |
@app.get("/api/v1/get_risk")
|
| 49 |
async def get_risk():
|
| 50 |
-
# Get current system risk (this method exists in v4)
|
| 51 |
risk_score = risk_engine.get_current_risk()
|
| 52 |
return {
|
| 53 |
"system_risk": risk_score.mean,
|
|
@@ -56,10 +57,6 @@ async def get_risk():
|
|
| 56 |
|
| 57 |
@app.post("/api/v1/incident")
|
| 58 |
async def store_incident(event_data: dict, analysis: dict):
|
| 59 |
-
"""
|
| 60 |
-
Store an incident in memory.
|
| 61 |
-
event_data should contain at least 'component', 'latency_p99', 'error_rate', etc.
|
| 62 |
-
"""
|
| 63 |
try:
|
| 64 |
incident_id = memory.store_incident(event_data, analysis)
|
| 65 |
return {"incident_id": incident_id}
|
|
@@ -68,10 +65,6 @@ async def store_incident(event_data: dict, analysis: dict):
|
|
| 68 |
|
| 69 |
@app.get("/api/v1/memory/similar")
|
| 70 |
async def find_similar_incidents(action: str, k: int = 5):
|
| 71 |
-
"""
|
| 72 |
-
Find incidents similar to the given action text.
|
| 73 |
-
This uses a simple embedding fallback (random) for OSS.
|
| 74 |
-
"""
|
| 75 |
class DummyEvent:
|
| 76 |
def __init__(self, action):
|
| 77 |
self.component = "user_action"
|
|
@@ -109,4 +102,9 @@ iface = gr.Interface(
|
|
| 109 |
outputs="text",
|
| 110 |
title="ARF v4 Demo"
|
| 111 |
)
|
| 112 |
-
app = gr.mount_gradio_app(app, iface, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# hf_demo.py – ARF v4 API with Memory
|
| 2 |
+
import os
|
| 3 |
+
import uvicorn
|
| 4 |
from fastapi import FastAPI, HTTPException
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
import gradio as gr
|
|
|
|
| 49 |
|
| 50 |
@app.get("/api/v1/get_risk")
|
| 51 |
async def get_risk():
|
|
|
|
| 52 |
risk_score = risk_engine.get_current_risk()
|
| 53 |
return {
|
| 54 |
"system_risk": risk_score.mean,
|
|
|
|
| 57 |
|
| 58 |
@app.post("/api/v1/incident")
|
| 59 |
async def store_incident(event_data: dict, analysis: dict):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
try:
|
| 61 |
incident_id = memory.store_incident(event_data, analysis)
|
| 62 |
return {"incident_id": incident_id}
|
|
|
|
| 65 |
|
| 66 |
@app.get("/api/v1/memory/similar")
|
| 67 |
async def find_similar_incidents(action: str, k: int = 5):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
class DummyEvent:
|
| 69 |
def __init__(self, action):
|
| 70 |
self.component = "user_action"
|
|
|
|
| 102 |
outputs="text",
|
| 103 |
title="ARF v4 Demo"
|
| 104 |
)
|
| 105 |
+
app = gr.mount_gradio_app(app, iface, path="/")
|
| 106 |
+
|
| 107 |
+
# ============== MAIN ENTRY POINT ==============
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
port = int(os.environ.get('PORT', 7860))
|
| 110 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|