Spaces:
Running
Running
plot failures separately
Browse files
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=
|
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] = {
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
|