└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # a-balanced-daily-diet-for-middle-aged-women 2 | # app.py 3 | from flask import Flask, request, render_template 4 | import random 5 | 6 | app = Flask(__name__) 7 | 8 | # Example food items with their nutritional content (calories, protein, fat, carbs) 9 | FOOD_ITEMS = [ 10 | {"name": "Chicken Breast", "calories": 165, "protein": 31, "fat": 3.6, "carbs": 0}, 11 | {"name": "Broccoli", "calories": 55, "protein": 3.7, "fat": 0.6, "carbs": 11}, 12 | {"name": "Almonds", "calories": 575, "protein": 21, "fat": 49, "carbs": 22}, 13 | {"name": "Oatmeal", "calories": 150, "protein": 5, "fat": 3, "carbs": 27}, 14 | {"name": "Salmon", "calories": 208, "protein": 20, "fat": 13, "carbs": 0}, 15 | {"name": "Apple", "calories": 95, "protein": 0.5, "fat": 0.3, "carbs": 25}, 16 | ] 17 | 18 | # Example nutritional requirements for middle-aged women 19 | DAILY_REQUIREMENTS = { 20 | "calories": 2000, 21 | "protein": 46, # in grams 22 | "fat": 70, # in grams 23 | "carbs": 250, # in grams 24 | } 25 | 26 | def generate_meal_plan(): 27 | meal_plan = [] 28 | total_nutrition = {"calories": 0, "protein": 0, "fat": 0, "carbs": 0} 29 | 30 | while total_nutrition["calories"] < DAILY_REQUIREMENTS["calories"]: 31 | food_item = random.choice(FOOD_ITEMS) 32 | meal_plan.append(food_item) 33 | 34 | for nutrient in total_nutrition: 35 | total_nutrition[nutrient] += food_item[nutrient] 36 | 37 | if len(meal_plan) > 20: # Prevent infinite loop 38 | break 39 | 40 | return meal_plan, total_nutrition 41 | 42 | @app.route('/') 43 | def index(): 44 | return render_template('index.html') 45 | 46 | @app.route('/generate', methods=['POST']) 47 | def generate(): 48 | meal_plan, total_nutrition = generate_meal_plan() 49 | return render_template('meal_plan.html', meal_plan=meal_plan, total_nutrition=total_nutrition) 50 | 51 | if __name__ == '__main__': 52 | app.run(debug=True) 53 | 54 | 55 |
56 |Calories: {{ total_nutrition.calories }}
79 |Protein: {{ total_nutrition.protein }}g
80 |Fat: {{ total_nutrition.fat }}g
81 |Carbs: {{ total_nutrition.carbs }}g
82 | 83 | 84 | 85 | Creating a balanced daily diet application involves several steps, including defining the nutritional requirements for middle-aged women, generating meal plans, and ensuring the diet meets these requirements. The application will include a backend to handle the logic and a simple front end to interact with the user. 86 | 87 | Here's an outline of the necessary code, including a simple frontend and backend using Python (Flask for the backend and HTML/CSS for the frontend): 88 | 89 | Running the Application. 90 | 1 Save the backend code to a file named app.py. 91 | 2 Create a directory named templates in the same directory as app.py. 92 | 3 Save index.html and meal_plan.html inside the templates directory. 93 | 4 Install Flask if you haven't already by running pip install Flask. 94 | 5 Run the Flask application by executing python app.py. 95 | This application will generate a simple balanced daily meal plan based on predefined nutritional requirements for middle-aged women. You can expand the FOOD_ITEMS list and improve the logic for generating meal plans to make it more robust and tailored to individual preferences and dietary restrictions. 96 | --------------------------------------------------------------------------------