Abs6187 aditii27 commited on
Commit
a709d98
·
verified ·
1 Parent(s): 83375da

Upload app (1).py (#1)

Browse files

- Upload app (1).py (7e0c321a7cb34a056044d60af787f914ce62f132)


Co-authored-by: Aditi Soni <[email protected]>

Files changed (1) hide show
  1. app (1).py +212 -0
app (1).py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from dotenv import load_dotenv
3
+ from langchain_groq import ChatGroq
4
+ import os
5
+ import importlib.util
6
+
7
+ # Check if team_info module exists and import it
8
+ try:
9
+ import team_info
10
+ has_team_info = True
11
+ except ImportError:
12
+ has_team_info = False
13
+
14
+ # Load environment variables
15
+ load_dotenv()
16
+
17
+ # Initialize the model
18
+ model = ChatGroq(model="llama3-8b-8192")
19
+
20
+ # Function to calculate daily calorie requirements
21
+ def calculate_calorie_requirements(age, gender, weight, height, fitness_goal):
22
+ if gender == "Male":
23
+ bmr = 10 * weight + 6.25 * height - 5 * age + 5
24
+ else:
25
+ bmr = 10 * weight + 6.25 * height - 5 * age - 161
26
+
27
+ if fitness_goal == "Weight Loss":
28
+ return bmr * 1.2
29
+ elif fitness_goal == "Weight Gain":
30
+ return bmr * 1.5
31
+ else:
32
+ return bmr * 1.375
33
+
34
+ # Function to generate the plan
35
+ def generate_plan_with_prompt(metrics, prompt_template):
36
+ prompt = prompt_template.format(**metrics)
37
+ response = model.invoke(prompt)
38
+ return response
39
+
40
+ # Function to format the response neatly
41
+ def format_plan(response):
42
+ try:
43
+ content = response.content
44
+ sections = content.split("\n\n")
45
+ formatted = ""
46
+ for section in sections:
47
+ formatted += f"**{section.strip()}**\n\n"
48
+ return formatted
49
+ except Exception as e:
50
+ return f"Error formatting plan: {e}"
51
+
52
+ # Ayurvedic prompt template
53
+ ayurveda_prompt_template = """
54
+ You are a health expert specialized in both modern medicine and Ayurveda. Generate a personalized weekly diet and exercise plan for {name}, a {age}-year-old {gender} with a BMI of {bmi} ({health_status}).
55
+
56
+ Fitness Goal: {fitness_goal}.
57
+ Daily Calorie Requirement: {daily_calories} kcal.
58
+ Dietary Preference: {dietary_preference}.
59
+ Food Allergies: {food_allergies}.
60
+ Local Cuisine: {local_cuisine}.
61
+ Month: {month}.
62
+ Ayurvedic Consideration: True
63
+
64
+ Plan should include:
65
+ 1. A daily diet plan with meal timings, calorie details, and meal alternatives.
66
+ 2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
67
+ 3. Dynamic plan adjustments based on month and local cuisine preferences.
68
+ 4. Wearable integration for tracking steps, heart rate, and calorie burn.
69
+ 5. Progress monitoring for daily calorie burn and weight tracking.
70
+ 6. **Food Delivery Integration**:
71
+ - Meal suggestions based on diet plans.
72
+ - Integration with food delivery platforms (Uber Eats, DoorDash).
73
+ - Searching menu items that fit calorie and dietary preferences.
74
+ - Multi-restaurant meal aggregation for complete diet fulfillment.
75
+ - Location-based meal recommendations.
76
+ - Customizable meal delivery schedules.
77
+ 7. **Ayurvedic Elements**:
78
+ - Dosha assessment based on provided metrics.
79
+ - Ayurvedic dietary recommendations aligned with your dosha type.
80
+ - Seasonal herbs and spices for balance.
81
+ - Daily routines (Dinacharya) for optimal health.
82
+ - Natural remedies complementing modern medicine.
83
+
84
+ Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
85
+
86
+ Return output as:
87
+ Day: {{weekday}}
88
+ - Breakfast: Time, Description, Calories, Ayurvedic Properties
89
+ - Lunch: Time, Description, Calories, Ayurvedic Properties
90
+ - Snacks: Time, Description, Calories, Ayurvedic Properties
91
+ - Dinner: Time, Description, Calories, Ayurvedic Properties
92
+ - Exercise: Description, Duration, Dosha Benefits
93
+ - Wearable Tracking: Steps, Heart Rate, Calories Burned
94
+ - Progress Monitoring: Daily calorie intake vs. burn.
95
+ - Food Delivery: Suggested meal items and delivery options.
96
+ - Ayurvedic Tips: Daily wellness practices based on dosha.
97
+ """
98
+
99
+ # Regular prompt template
100
+ regular_prompt_template = """
101
+ You are a health expert. Generate a personalized weekly diet and exercise plan for {name}, a {age}-year-old {gender} with a BMI of {bmi} ({health_status}).
102
+
103
+ Fitness Goal: {fitness_goal}.
104
+ Daily Calorie Requirement: {daily_calories} kcal.
105
+ Dietary Preference: {dietary_preference}.
106
+ Food Allergies: {food_allergies}.
107
+ Local Cuisine: {local_cuisine}.
108
+ Month: {month}.
109
+
110
+ Plan should include:
111
+ 1. A daily diet plan with meal timings, calorie details, and meal alternatives.
112
+ 2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
113
+ 3. Dynamic plan adjustments based on month and local cuisine preferences.
114
+ 4. Wearable integration for tracking steps, heart rate, and calorie burn.
115
+ 5. Progress monitoring for daily calorie burn and weight tracking.
116
+ 6. **Food Delivery Integration**:
117
+ - Meal suggestions based on diet plans.
118
+ - Integration with food delivery platforms (Uber Eats, DoorDash).
119
+ - Searching menu items that fit calorie and dietary preferences.
120
+ - Multi-restaurant meal aggregation for complete diet fulfillment.
121
+ - Location-based meal recommendations.
122
+ - Customizable meal delivery schedules.
123
+
124
+ Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
125
+
126
+ Return output as:
127
+ Day: {{weekday}}
128
+ - Breakfast: Time, Description, Calories
129
+ - Lunch: Time, Description, Calories
130
+ - Snacks: Time, Description, Calories
131
+ - Dinner: Time, Description, Calories
132
+ - Exercise: Description, Duration
133
+ - Wearable Tracking: Steps, Heart Rate, Calories Burned
134
+ - Progress Monitoring: Daily calorie intake vs. burn.
135
+ - Food Delivery: Suggested meal items and delivery options.
136
+ """
137
+
138
+ # Streamlit app
139
+ st.title("AI-Based Personalized Weekly Diet and Exercise Planner")
140
+
141
+ # Add sidebar with team information
142
+ with st.sidebar:
143
+ st.header("About this Project")
144
+ st.write("Integration of Ayurveda and modern medical science for comprehensive wellness insights")
145
+
146
+ if has_team_info:
147
+ st.subheader("Team Members")
148
+ st.markdown("- Aditi Soni [LinkedIn](https://www.linkedin.com/in/aditi-soni-259813285/)")
149
+ st.markdown("- Bhumika Patel [LinkedIn](https://www.linkedin.com/in/bhumika-patel-ml/)")
150
+ st.markdown("- Aditi Lakhera [LinkedIn](https://www.linkedin.com/in/aditi-lakhera-b628802bb/)")
151
+ st.markdown("- Anushri Tiwari [LinkedIn](https://www.linkedin.com/in/anushri-tiwari-916494300 )")
152
+
153
+
154
+ st.subheader("Project Links")
155
+ st.markdown("[GitHub Repository](https://github.com/Abs6187/AI_Health_v2)")
156
+ st.markdown("[Presentation](https://github.com/Abs6187/AI_Health_v2/blob/main/HackGirl_PPT_HackSRIT.pptx)")
157
+ st.markdown("[Hackathon](https://unstop.com/hackathons/hacksrit-shri-ram-group-of-institutions-jabalpur-1471613)")
158
+
159
+ # Input fields
160
+ st.header("Enter Your Details")
161
+ name = st.text_input("Name")
162
+ age = st.number_input("Age", min_value=1, value=25)
163
+ weight = st.number_input("Weight (kg)", min_value=1, value=70)
164
+ height = st.number_input("Height (cm)", min_value=1, value=170)
165
+ gender = st.selectbox("Gender", options=["Male", "Female", "Other"])
166
+ fitness_goal = st.selectbox("Fitness Goal", options=["Weight Loss", "Weight Gain", "Maintenance"])
167
+ dietary_preference = st.selectbox("Dietary Preference", options=["Vegetarian", "Vegan", "Keto", "Halal", "None"])
168
+ food_allergies = st.text_input("Food Allergies (if any)")
169
+ local_cuisine = st.text_input("Preferred Local Cuisine (e.g., Indian, Italian, Chinese)")
170
+ month = st.selectbox("Select Month", options=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"])
171
+
172
+ # New option for Ayurvedic integration
173
+ include_ayurveda = st.checkbox("Include Ayurvedic wellness insights", value=True)
174
+
175
+ bmi = round(weight / (height / 100) ** 2, 2)
176
+ health_status = "Underweight" if bmi < 18.5 else "Normal weight" if bmi <= 24.9 else "Overweight"
177
+ daily_calories = calculate_calorie_requirements(age, gender, weight, height, fitness_goal)
178
+
179
+ st.write(f"Your BMI is {bmi}, which indicates {health_status}.")
180
+ st.write(f"Your daily calorie requirement is approximately {int(daily_calories)} kcal.")
181
+
182
+ # User metrics
183
+ metrics = {
184
+ "name": name,
185
+ "age": age,
186
+ "gender": gender,
187
+ "bmi": bmi,
188
+ "health_status": health_status,
189
+ "fitness_goal": fitness_goal,
190
+ "dietary_preference": dietary_preference,
191
+ "food_allergies": food_allergies,
192
+ "daily_calories": int(daily_calories),
193
+ "local_cuisine": local_cuisine,
194
+ "weekdays": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
195
+ "month": month,
196
+ }
197
+
198
+ # Generate and display plan
199
+ if st.button("Generate Plan"):
200
+ with st.spinner("Generating your plan..."):
201
+ try:
202
+ # Choose the appropriate prompt based on the Ayurveda option
203
+ selected_prompt = ayurveda_prompt_template if include_ayurveda else regular_prompt_template
204
+ plan = generate_plan_with_prompt(metrics, selected_prompt)
205
+ formatted_plan = format_plan(plan)
206
+
207
+ plan_title = "Integrated Ayurvedic & Modern Diet and Exercise Plan" if include_ayurveda else "Diet and Exercise Plan"
208
+ st.header(f"Generated {plan_title} for {month}")
209
+ st.markdown(formatted_plan)
210
+ except Exception as e:
211
+ st.error(f"Error generating the plan: {e}")
212
+