Hardik commited on
Commit
46042a6
·
1 Parent(s): 84a9f0b

Better error logging, direct ML predict endpoint

Browse files
Files changed (2) hide show
  1. ml_service/app/api/routes.py +5 -1
  2. nginx.conf +8 -0
ml_service/app/api/routes.py CHANGED
@@ -35,6 +35,9 @@ async def predict(request: PredictRequest):
35
  nonlocal pos_count, neg_count, total_count
36
  try:
37
  result = predict_fn(text)
 
 
 
38
  models_result[model_key] = result
39
  total_count += 1
40
  if result.label == "Positive":
@@ -42,7 +45,8 @@ async def predict(request: PredictRequest):
42
  else:
43
  neg_count += 1
44
  except Exception as e:
45
- errors.append(f"{model_key}: {str(e)}")
 
46
 
47
  if "lr" in request.models:
48
  try_predict("lr", predict_lr, request.text)
 
35
  nonlocal pos_count, neg_count, total_count
36
  try:
37
  result = predict_fn(text)
38
+ if result is None:
39
+ errors.append(f"{model_key}: returned None")
40
+ return
41
  models_result[model_key] = result
42
  total_count += 1
43
  if result.label == "Positive":
 
45
  else:
46
  neg_count += 1
47
  except Exception as e:
48
+ import traceback
49
+ errors.append(f"{model_key}: {str(e)}\n{traceback.format_exc()}")
50
 
51
  if "lr" in request.models:
52
  try_predict("lr", predict_lr, request.text)
nginx.conf CHANGED
@@ -30,6 +30,14 @@ http {
30
  proxy_set_header Host $host;
31
  }
32
 
 
 
 
 
 
 
 
 
33
  location / {
34
  try_files $uri $uri/ /index.html;
35
  }
 
30
  proxy_set_header Host $host;
31
  }
32
 
33
+ location /ml-predict {
34
+ proxy_pass http://127.0.0.1:8000/api/v1/predict;
35
+ proxy_http_version 1.1;
36
+ proxy_set_header Host $host;
37
+ proxy_set_header Content-Type application/json;
38
+ proxy_read_timeout 120s;
39
+ }
40
+
41
  location / {
42
  try_files $uri $uri/ /index.html;
43
  }