nbroad HF staff commited on
Commit
8bb57b2
·
verified ·
1 Parent(s): 1b75c1f

plot failures separately

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -28,8 +28,7 @@ models = [
28
  "mistralai/Mistral-7B-Instruct-v0.3",
29
  "mistralai/Mixtral-8x7B-Instruct-v0.1",
30
  ]
31
- LOG_FILE = "api_logs.json"
32
- CHECK_INTERVAL = 30 # 1 minute
33
 
34
 
35
  client = AsyncInferenceClient(token=os.environ["HF_INFERENCE_API_TOKEN"])
@@ -75,7 +74,7 @@ async def check_apis():
75
  @app.on_event("startup")
76
  async def start_scheduler():
77
  scheduler = AsyncIOScheduler()
78
- scheduler.add_job(check_apis, 'interval', minutes=1)
79
  scheduler.start()
80
 
81
  @app.get("/")
@@ -88,7 +87,7 @@ async def get_logs():
88
  logs = json.load(f)
89
  return logs
90
 
91
- @app.get("/api/chart-data", response_model=Dict[str, Dict[str, List]])
92
  async def get_chart_data():
93
  with open(LOG_FILE, "r") as f:
94
  logs = json.load(f)
@@ -97,9 +96,14 @@ async def get_chart_data():
97
  for log in logs:
98
  model = log['model']
99
  if model not in chart_data:
100
- chart_data[model] = {'x': [], 'y': []}
101
- chart_data[model]['x'].append(log['timestamp'])
102
- chart_data[model]['y'].append(1 if log['success'] else 0)
 
 
 
 
 
103
 
104
  return chart_data
105
 
 
28
  "mistralai/Mistral-7B-Instruct-v0.3",
29
  "mistralai/Mixtral-8x7B-Instruct-v0.1",
30
  ]
31
+ LOG_FILE = "/data/api_logs.json"
 
32
 
33
 
34
  client = AsyncInferenceClient(token=os.environ["HF_INFERENCE_API_TOKEN"])
 
74
  @app.on_event("startup")
75
  async def start_scheduler():
76
  scheduler = AsyncIOScheduler()
77
+ scheduler.add_job(check_apis, 'interval', minutes=10)
78
  scheduler.start()
79
 
80
  @app.get("/")
 
87
  logs = json.load(f)
88
  return logs
89
 
90
+ @app.get("/api/chart-data", response_model=Dict[str, Dict[str, Dict[str, List]]])
91
  async def get_chart_data():
92
  with open(LOG_FILE, "r") as f:
93
  logs = json.load(f)
 
96
  for log in logs:
97
  model = log['model']
98
  if model not in chart_data:
99
+ chart_data[model] = {
100
+ 'success': {'x': [], 'y': []},
101
+ 'failure': {'x': [], 'y': []}
102
+ }
103
+
104
+ status = 'success' if log['success'] else 'failure'
105
+ chart_data[model][status]['x'].append(log['timestamp'])
106
+ chart_data[model][status]['y'].append(1)
107
 
108
  return chart_data
109