Dineflow commited on
Commit
4c04edc
·
verified ·
1 Parent(s): 8dafdc5

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +19 -15
handler.py CHANGED
@@ -13,22 +13,26 @@ 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
- response = {
27
- "review": review,
28
- "predicted_rating": int(predicted_rating)
29
- }
30
- return json.dumps(response)
31
 
32
- except json.JSONDecodeError:
33
- return json.dumps({"error": "Invalid JSON format"})
 
 
 
 
 
 
34
 
 
13
  predicted_rating = self.model.predict(review_tfidf)[0]
14
  return predicted_rating
15
 
16
+ def __call__(self, inputs):
17
+ try:
18
+ if isinstance(inputs, dict):
19
+ data = inputs # Directly use the dictionary
20
+ else:
21
+ data = json.loads(inputs) # Parse the JSON string
22
 
23
+ review = data.get("inputs")
 
24
 
25
+ if not review:
26
+ return json.dumps({"error": "No review provided"})
27
+
28
+ predicted_rating = self.predict_rating(review)
 
 
 
29
 
30
+ response = {
31
+ "review": review,
32
+ "predicted_rating": int(predicted_rating)
33
+ }
34
+ return json.dumps(response)
35
+
36
+ except json.JSONDecodeError:
37
+ return json.dumps({"error": "Invalid JSON format"})
38