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

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +15 -18
handler.py CHANGED
@@ -14,25 +14,22 @@ class EndpointHandler:
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
-
 
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"})