aman-s-affinsys commited on
Commit
64f6827
·
1 Parent(s): 5867cf7

fix: predict intent

Browse files
Files changed (1) hide show
  1. main.py +5 -5
main.py CHANGED
@@ -26,9 +26,7 @@ except Exception as e:
26
  text_classifier = None
27
 
28
 
29
- # Define Request Model
30
- class PredictionRequest(BaseModel):
31
- text: str
32
 
33
  @app.get("/")
34
  def hello():
@@ -36,10 +34,12 @@ def hello():
36
  "Status":"Healthy"}
37
  # Prediction Endpoint
38
  @app.post("/predict")
39
- def predict_intent(request: PredictionRequest):
40
  if text_classifier is None:
41
  return {"error": "Model not found"}
42
- preds_list = text_classifier(request.text)
 
 
43
  best_pred = max(preds_list[0], key=lambda x: x["score"]) # Get highest-scoring intent
44
  return {"intent": best_pred["label"], "confidence": best_pred["score"]}
45
 
 
26
  text_classifier = None
27
 
28
 
29
+
 
 
30
 
31
  @app.get("/")
32
  def hello():
 
34
  "Status":"Healthy"}
35
  # Prediction Endpoint
36
  @app.post("/predict")
37
+ def predict_intent(request):
38
  if text_classifier is None:
39
  return {"error": "Model not found"}
40
+ sentence=request.data.get("sentence", "").strip()
41
+ preds_list = text_classifier(sentence)
42
+ print(preds_list)
43
  best_pred = max(preds_list[0], key=lambda x: x["score"]) # Get highest-scoring intent
44
  return {"intent": best_pred["label"], "confidence": best_pred["score"]}
45