shivanis14
commited on
Commit
•
75a7d9b
1
Parent(s):
5b0b86e
Update rda.py
Browse files
rda.py
CHANGED
@@ -59,12 +59,14 @@ def process_nutrition_data(nutrition_per_serving, user_serving_size):
|
|
59 |
|
60 |
def find_nutrition(data):
|
61 |
#data is a dict. See https://github.com/ConsumeWise123/rda1/blob/main/clientp.py
|
|
|
|
|
62 |
try:
|
63 |
nutrition_per_serving = data['nutritionPerServing']
|
64 |
user_serving_size = float(data['userServingSize'])
|
65 |
|
66 |
if not nutrition_per_serving or user_serving_size <= 0:
|
67 |
-
return {"error": "Invalid nutrition data or serving size"}
|
68 |
|
69 |
# Process and respond with scaled values and daily percentages
|
70 |
scaled_nutrition, percentage_daily_values = process_nutrition_data(nutrition_per_serving, user_serving_size)
|
@@ -75,4 +77,4 @@ def find_nutrition(data):
|
|
75 |
return rda_analysis_str
|
76 |
|
77 |
except Exception as e:
|
78 |
-
return {"error": "Invalid JSON or input"}
|
|
|
59 |
|
60 |
def find_nutrition(data):
|
61 |
#data is a dict. See https://github.com/ConsumeWise123/rda1/blob/main/clientp.py
|
62 |
+
if not data:
|
63 |
+
return ""
|
64 |
try:
|
65 |
nutrition_per_serving = data['nutritionPerServing']
|
66 |
user_serving_size = float(data['userServingSize'])
|
67 |
|
68 |
if not nutrition_per_serving or user_serving_size <= 0:
|
69 |
+
return json.dumps({"error": "Invalid nutrition data or serving size"})
|
70 |
|
71 |
# Process and respond with scaled values and daily percentages
|
72 |
scaled_nutrition, percentage_daily_values = process_nutrition_data(nutrition_per_serving, user_serving_size)
|
|
|
77 |
return rda_analysis_str
|
78 |
|
79 |
except Exception as e:
|
80 |
+
return json.dumps({"error" : "Invalid JSON or input"})
|