nagasurendra commited on
Commit
787225f
·
verified ·
1 Parent(s): 1ff5a7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -35,19 +35,19 @@ def serve_static(filename):
35
 
36
  @app.route('/get_ingredients', methods=['POST'])
37
  def get_ingredients():
38
- global sf
39
- if not sf:
40
- sf = get_salesforce_connection()
41
- if not sf:
42
- return jsonify({"error": "Failed to connect to Salesforce"}), 500
43
-
44
  dietary_preference = request.json.get('dietary_preference', '').strip().lower()
45
 
 
 
 
46
  if dietary_preference == 'veg':
 
47
  soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Veg' LIMIT 200"
48
- elif dietary_preference in ['non-vegetarian', 'non veg', 'nonveg']:
 
49
  soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Non-Veg' LIMIT 200"
50
  else:
 
51
  return jsonify({"error": "Invalid dietary preference."}), 400
52
 
53
  try:
@@ -56,9 +56,12 @@ def get_ingredients():
56
  {"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
57
  for record in result['records'] if 'Name' in record
58
  ]
 
59
  return jsonify({"ingredients": ingredients})
60
  except Exception as e:
 
61
  return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
62
 
 
63
  if __name__ == '__main__':
64
  app.run(debug=True, host='0.0.0.0', port=7860)
 
35
 
36
  @app.route('/get_ingredients', methods=['POST'])
37
  def get_ingredients():
 
 
 
 
 
 
38
  dietary_preference = request.json.get('dietary_preference', '').strip().lower()
39
 
40
+ # Debugging: print the received dietary preference
41
+ print(f"Received dietary preference: {dietary_preference}")
42
+
43
  if dietary_preference == 'veg':
44
+ print("Fetching ingredients for Vegetarian...") # Debug when fetching vegetarian ingredients
45
  soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Veg' LIMIT 200"
46
+ elif dietary_preference == 'non-vegetarian':
47
+ print("Fetching ingredients for Non-Vegetarian...") # Debug when fetching non-vegetarian ingredients
48
  soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE Category__c = 'Non-Veg' LIMIT 200"
49
  else:
50
+ print("Invalid dietary preference received.") # Debug for invalid dietary preference
51
  return jsonify({"error": "Invalid dietary preference."}), 400
52
 
53
  try:
 
56
  {"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
57
  for record in result['records'] if 'Name' in record
58
  ]
59
+ print(f"Fetched {len(ingredients)} ingredients.") # Debug: print how many ingredients were fetched
60
  return jsonify({"ingredients": ingredients})
61
  except Exception as e:
62
+ print(f"Error while fetching ingredients: {str(e)}") # Debug error
63
  return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
64
 
65
+
66
  if __name__ == '__main__':
67
  app.run(debug=True, host='0.0.0.0', port=7860)