petter2025 commited on
Commit
da7f2f6
·
verified ·
1 Parent(s): 67e6d4b

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +1 -19
hf_demo.py CHANGED
@@ -1,6 +1,4 @@
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
@@ -62,8 +60,6 @@ async def store_incident(event_data: dict, analysis: dict):
62
  Store an incident in memory.
63
  event_data should contain at least 'component', 'latency_p99', 'error_rate', etc.
64
  """
65
- # In a real implementation you would parse a ReliabilityEvent.
66
- # For simplicity, we pass a dict – you may need to adapt.
67
  try:
68
  incident_id = memory.store_incident(event_data, analysis)
69
  return {"incident_id": incident_id}
@@ -75,9 +71,7 @@ async def find_similar_incidents(action: str, k: int = 5):
75
  """
76
  Find incidents similar to the given action text.
77
  This uses a simple embedding fallback (random) for OSS.
78
- For production, integrate sentence-transformers.
79
  """
80
- # Create a dummy event from the action text
81
  class DummyEvent:
82
  def __init__(self, action):
83
  self.component = "user_action"
@@ -91,7 +85,6 @@ async def find_similar_incidents(action: str, k: int = 5):
91
  event = DummyEvent(action)
92
  analysis = {"action": action}
93
  similar = memory.find_similar(event, analysis, k=k)
94
- # Convert nodes to dict
95
  results = []
96
  for node in similar:
97
  results.append({
@@ -116,15 +109,4 @@ iface = gr.Interface(
116
  outputs="text",
117
  title="ARF v4 Demo"
118
  )
119
- app = gr.mount_gradio_app(app, iface, path="/")
120
-
121
- # ============== MAIN ENTRY POINT ==============
122
- if __name__ == "__main__":
123
- port = int(os.environ.get('PORT', 7860))
124
- uvicorn.run(
125
- "hf_demo:app",
126
- host="0.0.0.0",
127
- port=port,
128
- log_level="info",
129
- reload=False
130
- )
 
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
 
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}
 
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"
 
85
  event = DummyEvent(action)
86
  analysis = {"action": action}
87
  similar = memory.find_similar(event, analysis, k=k)
 
88
  results = []
89
  for node in similar:
90
  results.append({
 
109
  outputs="text",
110
  title="ARF v4 Demo"
111
  )
112
+ app = gr.mount_gradio_app(app, iface, path="/")