Dineflow commited on
Commit
ae2af9c
·
verified ·
1 Parent(s): 7111e22

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +6 -4
handler.py CHANGED
@@ -13,23 +13,25 @@ class EndpointHandler:
13
  predicted_rating = self.model.predict(review_tfidf)[0]
14
  return predicted_rating
15
 
16
- def __call__(self, inputs):
17
  try:
 
18
  data = json.loads(inputs)
19
- review = data.get("review")
20
 
21
  if not review:
22
  return json.dumps({"error": "No review provided"})
23
 
 
24
  predicted_rating = self.predict_rating(review)
25
 
26
-
27
  response = {
28
  "review": review,
29
  "predicted_rating": int(predicted_rating)
30
-
31
  }
32
  return json.dumps(response)
33
 
34
  except json.JSONDecodeError:
35
  return json.dumps({"error": "Invalid JSON format"})
 
 
13
  predicted_rating = self.model.predict(review_tfidf)[0]
14
  return predicted_rating
15
 
16
+ def __call__(self, inputs):
17
  try:
18
+ # Parse the input string to a dictionary
19
  data = json.loads(inputs)
20
+ review = data.get("inputs")
21
 
22
  if not review:
23
  return json.dumps({"error": "No review provided"})
24
 
25
+ # Call the prediction method
26
  predicted_rating = self.predict_rating(review)
27
 
28
+ # Prepare the response
29
  response = {
30
  "review": review,
31
  "predicted_rating": int(predicted_rating)
 
32
  }
33
  return json.dumps(response)
34
 
35
  except json.JSONDecodeError:
36
  return json.dumps({"error": "Invalid JSON format"})
37
+