Yaswanth56 commited on
Commit
3f01465
·
verified ·
1 Parent(s): 503f29a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py CHANGED
@@ -2,6 +2,8 @@ from flask import Flask, render_template, send_from_directory, request, jsonify
2
  from simple_salesforce import Salesforce
3
  from dotenv import load_dotenv
4
  import os
 
 
5
 
6
  # Load environment variables from .env file
7
  load_dotenv()
@@ -61,5 +63,71 @@ def get_ingredients():
61
  except Exception as e:
62
  return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  if __name__ == '__main__':
65
  app.run(debug=True, host='0.0.0.0', port=7860)
 
2
  from simple_salesforce import Salesforce
3
  from dotenv import load_dotenv
4
  import os
5
+ import json
6
+ import requests
7
 
8
  # Load environment variables from .env file
9
  load_dotenv()
 
63
  except Exception as e:
64
  return jsonify({"error": f"Failed to fetch ingredients: {str(e)}"}), 500
65
 
66
+ # Mock endpoint to generate South Indian recipes (replace with ChatGPT API)
67
+ @app.route('/generate_recipes', methods=['POST'])
68
+ def generate_recipes():
69
+ data = request.json
70
+ selected_ingredients = data.get('ingredients', [])
71
+
72
+ # Mock response simulating ChatGPT (replace with real API call)
73
+ ingredients_str = ', '.join(selected_ingredients)
74
+ mock_response = {
75
+ "recipes": [
76
+ {
77
+ "name": "Pongal",
78
+ "image_url": "https://via.placeholder.com/100?text=Pongal",
79
+ "description": "A traditional Tamil Nadu dish made with rice and moong dal, seasoned with ghee, pepper, and cumin, reflecting the simplicity and warmth of South Indian breakfasts.",
80
+ "details": {
81
+ "preparation": "Cook rice and moong dal with water, temper with ghee, cumin, pepper, and cashews, and serve hot with chutney.",
82
+ "key_ingredients": ["rice", "moong dal", "ghee", "pepper", "cumin"]
83
+ }
84
+ },
85
+ {
86
+ "name": "Payasam",
87
+ "image_url": "https://via.placeholder.com/100?text=Payasam",
88
+ "description": "A creamy Kerala dessert made with milk, jaggery, and rice, enriched with cardamom and coconut, a staple in South Indian festivities.",
89
+ "details": {
90
+ "preparation": "Boil milk, add rice and jaggery, simmer until thick, and flavor with cardamom and coconut.",
91
+ "key_ingredients": ["milk", "jaggery", "rice", "cardamom", "coconut"]
92
+ }
93
+ },
94
+ {
95
+ "name": "Idli",
96
+ "image_url": "https://via.placeholder.com/100?text=Idli",
97
+ "description": "A fluffy steamed cake from Karnataka, made with fermented rice and urad dal, served with sambar and chutney, embodying South Indian comfort food.",
98
+ "details": {
99
+ "preparation": "Ferment rice and urad dal batter, steam in idli molds, and serve with sambar and coconut chutney.",
100
+ "key_ingredients": ["rice", "urad dal", "sambar", "chutney"]
101
+ }
102
+ },
103
+ {
104
+ "name": "Dosa",
105
+ "image_url": "https://via.placeholder.com/100?text=Dosa",
106
+ "description": "A crispy Andhra Pradesh crepe made from fermented rice and urad dal, often filled with potato masala, a versatile South Indian delight.",
107
+ "details": {
108
+ "preparation": "Spread fermented batter on a hot griddle, cook until crispy, add potato filling, and serve with chutney.",
109
+ "key_ingredients": ["rice", "urad dal", "potato", "chutney"]
110
+ }
111
+ },
112
+ {
113
+ "name": "Upma",
114
+ "image_url": "https://via.placeholder.com/100?text=Upma",
115
+ "description": "A savory Tamil Nadu porridge made with semolina, tempered with mustard seeds and curry leaves, a quick yet flavorful breakfast option.",
116
+ "details": {
117
+ "preparation": "Roast semolina, cook with water, and temper with mustard seeds, curry leaves, and vegetables.",
118
+ "key_ingredients": ["semolina", "mustard seeds", "curry leaves", "vegetables"]
119
+ }
120
+ }
121
+ ]
122
+ }
123
+
124
+ # Filter recipes based on selected ingredients (mock logic)
125
+ filtered_recipes = [
126
+ recipe for recipe in mock_response["recipes"]
127
+ if any(ing in ingredients_str.lower() for ing in recipe["details"]["key_ingredients"])
128
+ ][:5] # Limit to 5 recipes
129
+
130
+ return jsonify({"recipes": filtered_recipes})
131
+
132
  if __name__ == '__main__':
133
  app.run(debug=True, host='0.0.0.0', port=7860)