Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,144 +2,100 @@ import streamlit as st
|
|
2 |
from dotenv import load_dotenv
|
3 |
from langchain_groq import ChatGroq
|
4 |
import os
|
5 |
-
import
|
6 |
-
import altair as alt
|
7 |
-
import datetime
|
8 |
-
import random
|
9 |
|
10 |
-
# Set page configuration
|
11 |
st.set_page_config(
|
12 |
-
page_title="
|
13 |
page_icon="🌿",
|
14 |
layout="wide",
|
15 |
initial_sidebar_state="expanded"
|
16 |
)
|
17 |
|
18 |
-
#
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
.main {
|
|
|
|
|
|
|
22 |
background-color: #f8f9fa;
|
23 |
}
|
|
|
|
|
|
|
24 |
.stTabs [data-baseweb="tab-list"] {
|
25 |
-
gap:
|
26 |
}
|
27 |
.stTabs [data-baseweb="tab"] {
|
28 |
height: 50px;
|
29 |
white-space: pre-wrap;
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
}
|
34 |
.stTabs [aria-selected="true"] {
|
35 |
-
background-color: #
|
36 |
-
|
37 |
}
|
38 |
-
.stButton>button {
|
39 |
-
|
40 |
-
border-radius: 8px;
|
41 |
-
height: 3em;
|
42 |
-
background-color: #4361ee;
|
43 |
color: white;
|
44 |
-
font-weight:
|
|
|
|
|
|
|
45 |
}
|
46 |
-
.stButton>button:hover {
|
47 |
-
background-color: #
|
48 |
-
|
49 |
}
|
50 |
-
.
|
51 |
background-color: white;
|
52 |
-
|
53 |
-
|
54 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
55 |
-
text-align: center;
|
56 |
-
}
|
57 |
-
.input-section {
|
58 |
-
background-color: white;
|
59 |
-
border-radius: 8px;
|
60 |
-
padding: 20px;
|
61 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
62 |
-
margin-bottom: 20px;
|
63 |
}
|
64 |
-
.
|
65 |
-
|
66 |
-
padding:
|
67 |
-
border-radius:
|
68 |
-
|
69 |
-
font-weight: 600;
|
70 |
-
margin-right: 5px;
|
71 |
}
|
72 |
-
|
73 |
-
|
74 |
-
color: #065f46;
|
75 |
-
}
|
76 |
-
.badge-yellow {
|
77 |
-
background-color: #fef3c7;
|
78 |
-
color: #92400e;
|
79 |
-
}
|
80 |
-
.badge-red {
|
81 |
-
background-color: #fee2e2;
|
82 |
-
color: #b91c1c;
|
83 |
-
}
|
84 |
-
.badge-blue {
|
85 |
-
background-color: #dbeafe;
|
86 |
-
color: #1e40af;
|
87 |
}
|
88 |
</style>
|
89 |
""", unsafe_allow_html=True)
|
90 |
|
91 |
-
# Check
|
92 |
try:
|
93 |
import team_info
|
94 |
has_team_info = True
|
95 |
except ImportError:
|
96 |
has_team_info = False
|
97 |
|
98 |
-
# Load environment variables
|
99 |
load_dotenv()
|
|
|
|
|
100 |
model = ChatGroq(model="llama3-8b-8192")
|
101 |
|
102 |
-
# Function to calculate daily calorie requirements
|
103 |
-
def calculate_calorie_requirements(age, gender, weight, height, fitness_goal
|
104 |
if gender == "Male":
|
105 |
bmr = 10 * weight + 6.25 * height - 5 * age + 5
|
106 |
else:
|
107 |
bmr = 10 * weight + 6.25 * height - 5 * age - 161
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
"Moderately active (moderate exercise/sports 3-5 days/week)": 1.55,
|
114 |
-
"Very active (hard exercise/sports 6-7 days/week)": 1.725,
|
115 |
-
"Super active (very hard exercise & physical job or 2x training)": 1.9
|
116 |
-
}
|
117 |
-
|
118 |
-
# Goal adjustments
|
119 |
-
goal_adjustments = {
|
120 |
-
"Weight Loss": 0.8, # 20% calorie deficit
|
121 |
-
"Weight Gain": 1.15, # 15% calorie surplus
|
122 |
-
"Maintenance": 1.0 # No adjustment
|
123 |
-
}
|
124 |
-
|
125 |
-
return bmr * activity_multipliers[activity_level] * goal_adjustments[fitness_goal]
|
126 |
-
|
127 |
-
# Function to determine BMI category with detailed breakdown
|
128 |
-
def get_bmi_category(bmi):
|
129 |
-
if bmi < 16:
|
130 |
-
return "Severely Underweight", "red"
|
131 |
-
elif 16 <= bmi < 18.5:
|
132 |
-
return "Underweight", "yellow"
|
133 |
-
elif 18.5 <= bmi < 25:
|
134 |
-
return "Normal weight", "green"
|
135 |
-
elif 25 <= bmi < 30:
|
136 |
-
return "Overweight", "yellow"
|
137 |
-
elif 30 <= bmi < 35:
|
138 |
-
return "Obesity Class I", "red"
|
139 |
-
elif 35 <= bmi < 40:
|
140 |
-
return "Obesity Class II", "red"
|
141 |
else:
|
142 |
-
return
|
143 |
|
144 |
# Function to generate the plan
|
145 |
def generate_plan_with_prompt(metrics, prompt_template):
|
@@ -147,57 +103,22 @@ def generate_plan_with_prompt(metrics, prompt_template):
|
|
147 |
response = model.invoke(prompt)
|
148 |
return response
|
149 |
|
150 |
-
# Function to format the response
|
151 |
def format_plan(response):
|
152 |
try:
|
153 |
content = response.content
|
154 |
-
|
155 |
-
|
156 |
-
for
|
157 |
-
|
158 |
-
|
159 |
-
formatted_content += f"<div class='plan-intro'>{day.strip()}</div>"
|
160 |
-
continue
|
161 |
-
# Create a card for each day
|
162 |
-
formatted_content += f"""
|
163 |
-
<div style='background-color: white; border-radius: 8px; padding: 15px; margin-bottom: 15px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);'>
|
164 |
-
<h3 style='color: #4361ee; border-bottom: 1px solid #e5e7eb; padding-bottom: 10px;'>Day: {day.split('\n', 1)[0].strip()}</h3>
|
165 |
-
<div style='padding: 10px 0;'>
|
166 |
-
"""
|
167 |
-
# Process each line of the day's content
|
168 |
-
sections = day.split('\n', 1)[1].split('\n - ')
|
169 |
-
for section in sections:
|
170 |
-
if not section.strip():
|
171 |
-
continue
|
172 |
-
# Add special formatting for each type of entry
|
173 |
-
if "Breakfast:" in section:
|
174 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🍳 Breakfast:</strong> {section.replace('Breakfast:', '').strip()}</div>"
|
175 |
-
elif "Lunch:" in section:
|
176 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🍲 Lunch:</strong> {section.replace('Lunch:', '').strip()}</div>"
|
177 |
-
elif "Snacks:" in section:
|
178 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🥨 Snacks:</strong> {section.replace('Snacks:', '').strip()}</div>"
|
179 |
-
elif "Dinner:" in section:
|
180 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🍽️ Dinner:</strong> {section.replace('Dinner:', '').strip()}</div>"
|
181 |
-
elif "Exercise:" in section:
|
182 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🏋️ Exercise:</strong> {section.replace('Exercise:', '').strip()}</div>"
|
183 |
-
elif "Wearable Tracking:" in section:
|
184 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>⌚ Wearable Tracking:</strong> {section.replace('Wearable Tracking:', '').strip()}</div>"
|
185 |
-
elif "Progress Monitoring:" in section:
|
186 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>📊 Progress Monitoring:</strong> {section.replace('Progress Monitoring:', '').strip()}</div>"
|
187 |
-
elif "Food Delivery:" in section:
|
188 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🚚 Food Delivery:</strong> {section.replace('Food Delivery:', '').strip()}</div>"
|
189 |
-
elif "Ayurvedic Tips:" in section:
|
190 |
-
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🌿 Ayurvedic Tips:</strong> {section.replace('Ayurvedic Tips:', '').strip()}</div>"
|
191 |
-
else:
|
192 |
-
formatted_content += f"<div style='margin-bottom: 10px;'>{section.strip()}</div>"
|
193 |
-
formatted_content += "</div></div>"
|
194 |
-
return formatted_content
|
195 |
except Exception as e:
|
196 |
-
return f"
|
197 |
|
198 |
-
#
|
199 |
ayurveda_prompt_template = """
|
200 |
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}).
|
|
|
201 |
Fitness Goal: {fitness_goal}.
|
202 |
Daily Calorie Requirement: {daily_calories} kcal.
|
203 |
Dietary Preference: {dietary_preference}.
|
@@ -205,6 +126,7 @@ Food Allergies: {food_allergies}.
|
|
205 |
Local Cuisine: {local_cuisine}.
|
206 |
Month: {month}.
|
207 |
Ayurvedic Consideration: True
|
|
|
208 |
Plan should include:
|
209 |
1. A daily diet plan with meal timings, calorie details, and meal alternatives.
|
210 |
2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
|
@@ -224,7 +146,9 @@ Plan should include:
|
|
224 |
- Seasonal herbs and spices for balance.
|
225 |
- Daily routines (Dinacharya) for optimal health.
|
226 |
- Natural remedies complementing modern medicine.
|
|
|
227 |
Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
|
|
|
228 |
Return output as:
|
229 |
Day: {{weekday}}
|
230 |
- Breakfast: Time, Description, Calories, Ayurvedic Properties
|
@@ -238,14 +162,17 @@ Day: {{weekday}}
|
|
238 |
- Ayurvedic Tips: Daily wellness practices based on dosha.
|
239 |
"""
|
240 |
|
|
|
241 |
regular_prompt_template = """
|
242 |
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}).
|
|
|
243 |
Fitness Goal: {fitness_goal}.
|
244 |
Daily Calorie Requirement: {daily_calories} kcal.
|
245 |
Dietary Preference: {dietary_preference}.
|
246 |
Food Allergies: {food_allergies}.
|
247 |
Local Cuisine: {local_cuisine}.
|
248 |
Month: {month}.
|
|
|
249 |
Plan should include:
|
250 |
1. A daily diet plan with meal timings, calorie details, and meal alternatives.
|
251 |
2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
|
@@ -259,7 +186,9 @@ Plan should include:
|
|
259 |
- Multi-restaurant meal aggregation for complete diet fulfillment.
|
260 |
- Location-based meal recommendations.
|
261 |
- Customizable meal delivery schedules.
|
|
|
262 |
Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
|
|
|
263 |
Return output as:
|
264 |
Day: {{weekday}}
|
265 |
- Breakfast: Time, Description, Calories
|
@@ -272,367 +201,208 @@ Day: {{weekday}}
|
|
272 |
- Food Delivery: Suggested meal items and delivery options.
|
273 |
"""
|
274 |
|
275 |
-
#
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
st.session_state.daily_calories = 0
|
280 |
-
if 'health_status' not in st.session_state:
|
281 |
-
st.session_state.health_status = ""
|
282 |
-
if 'status_color' not in st.session_state:
|
283 |
-
st.session_state.status_color = ""
|
284 |
-
if 'metrics' not in st.session_state:
|
285 |
-
st.session_state.metrics = {}
|
286 |
-
if 'plan_generated' not in st.session_state:
|
287 |
-
st.session_state.plan_generated = False
|
288 |
-
if 'plan_content' not in st.session_state:
|
289 |
-
st.session_state.plan_content = ""
|
290 |
-
|
291 |
-
# Generate sample progress data for demo purposes
|
292 |
-
def generate_sample_data(days=30):
|
293 |
-
start_date = datetime.datetime.now() - datetime.timedelta(days=days)
|
294 |
-
dates = [start_date + datetime.timedelta(days=i) for i in range(days)]
|
295 |
-
# Generate weight data with a slight downward trend
|
296 |
-
initial_weight = 75
|
297 |
-
weights = [initial_weight - 0.1 * i + random.uniform(-0.5, 0.5) for i in range(days)]
|
298 |
-
# Generate calorie data with weekly patterns
|
299 |
-
calories = []
|
300 |
-
for i in range(days):
|
301 |
-
# Weekends tend to have higher calorie intake
|
302 |
-
if i % 7 >= 5: # Saturday and Sunday
|
303 |
-
calories.append(2200 + random.uniform(-200, 300))
|
304 |
-
else:
|
305 |
-
calories.append(1800 + random.uniform(-100, 200))
|
306 |
-
# Generate steps data
|
307 |
-
steps = [random.randint(6000, 12000) for _ in range(days)]
|
308 |
-
# Create a DataFrame
|
309 |
-
data = pd.DataFrame({
|
310 |
-
'date': dates,
|
311 |
-
'weight': weights,
|
312 |
-
'calories': calories,
|
313 |
-
'steps': steps
|
314 |
-
})
|
315 |
-
return data
|
316 |
-
|
317 |
-
# Create a responsive header
|
318 |
-
st.markdown("""
|
319 |
-
<div class="header-section">
|
320 |
-
<h1 style="color: #4361ee;">AI-Based Personalized Health & Wellness Planner</h1>
|
321 |
-
<p style="font-size: 18px;">Integrating modern science with Ayurvedic wisdom for holistic health</p>
|
322 |
-
</div>
|
323 |
-
""", unsafe_allow_html=True)
|
324 |
-
|
325 |
-
# Create tabs for different sections of the app
|
326 |
-
tabs = st.tabs(["📋 Profile & Plan", "📊 Analytics", "ℹ️ About"])
|
327 |
-
|
328 |
-
with tabs[0]:
|
329 |
-
# Create a two-column layout for input form and results
|
330 |
-
col1, col2 = st.columns([3, 2])
|
331 |
with col1:
|
332 |
-
st.
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
age = st.number_input("Age", min_value=1, max_value=120, value=25)
|
339 |
gender = st.selectbox("Gender", options=["Male", "Female", "Other"])
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
with
|
|
|
346 |
fitness_goal = st.selectbox("Fitness Goal", options=["Weight Loss", "Weight Gain", "Maintenance"])
|
347 |
-
dietary_preference = st.selectbox("Dietary Preference",
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
])
|
356 |
include_ayurveda = st.checkbox("Include Ayurvedic wellness insights", value=True)
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
"
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
try:
|
392 |
# Choose the appropriate prompt based on the Ayurveda option
|
393 |
selected_prompt = ayurveda_prompt_template if include_ayurveda else regular_prompt_template
|
394 |
-
plan = generate_plan_with_prompt(
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
st.
|
400 |
-
|
401 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
except Exception as e:
|
403 |
st.error(f"Error generating the plan: {e}")
|
404 |
-
|
405 |
-
with
|
406 |
-
|
407 |
-
|
408 |
-
st.markdown("""
|
409 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); text-align: center; margin-bottom: 20px;">
|
410 |
-
<h3 style="margin-bottom: 20px;">Your Health Metrics</h3>
|
411 |
-
""", unsafe_allow_html=True)
|
412 |
-
metric_col1, metric_col2 = st.columns(2)
|
413 |
-
with metric_col1:
|
414 |
-
st.markdown(f"""
|
415 |
-
<div class="metric-card">
|
416 |
-
<h4>BMI</h4>
|
417 |
-
<h2 style="font-size: 2.5rem; margin: 10px 0;">{st.session_state.bmi}</h2>
|
418 |
-
<span class="badge badge-{st.session_state.status_color}">{st.session_state.health_status}</span>
|
419 |
-
</div>
|
420 |
-
""", unsafe_allow_html=True)
|
421 |
-
with metric_col2:
|
422 |
-
st.markdown(f"""
|
423 |
-
<div class="metric-card">
|
424 |
-
<h4>Daily Calories</h4>
|
425 |
-
<h2 style="font-size: 2.5rem; margin: 10px 0;">{st.session_state.daily_calories}</h2>
|
426 |
-
<span class="badge badge-blue">kcal</span>
|
427 |
-
</div>
|
428 |
-
""", unsafe_allow_html=True)
|
429 |
-
st.markdown("""</div>""", unsafe_allow_html=True)
|
430 |
-
# Display recommendations based on health status
|
431 |
-
st.markdown("""
|
432 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); margin-bottom: 20px;">
|
433 |
-
<h3>Health Recommendations</h3>
|
434 |
-
""", unsafe_allow_html=True)
|
435 |
-
if st.session_state.status_color == "green":
|
436 |
-
st.markdown("""
|
437 |
-
<p>✅ Your BMI is in the healthy range!</p>
|
438 |
-
<p>🔍 Focus on maintaining your current weight with a balanced diet and regular exercise.</p>
|
439 |
-
<p>💪 Strength training 2-3 times per week is recommended for muscle maintenance.</p>
|
440 |
-
<p>🥗 Continue eating a variety of nutritious foods to maintain your overall health.</p>
|
441 |
-
""", unsafe_allow_html=True)
|
442 |
-
elif st.session_state.status_color == "yellow":
|
443 |
-
st.markdown("""
|
444 |
-
<p>⚠️ Your BMI indicates you may benefit from some adjustments to your lifestyle.</p>
|
445 |
-
<p>🏃♂️ Regular cardio exercise (30-45 minutes, 4-5 days per week) is recommended.</p>
|
446 |
-
<p>🍽️ Focus on portion control and balanced nutrition.</p>
|
447 |
-
<p>📱 Consider tracking your food intake and exercise for better awareness.</p>
|
448 |
-
""", unsafe_allow_html=True)
|
449 |
-
elif st.session_state.status_color == "red":
|
450 |
-
st.markdown("""
|
451 |
-
<p>❗ Your BMI suggests you may benefit from consulting with a healthcare professional.</p>
|
452 |
-
<p>👨⚕️ Consider seeking advice from a physician or registered dietitian.</p>
|
453 |
-
<p>👣 Start with gentle, low-impact exercise like walking or swimming.</p>
|
454 |
-
<p>🥦 Focus on whole, unprocessed foods rich in nutrients.</p>
|
455 |
-
<p>🧘♀️ Stress management techniques may also support your health journey.</p>
|
456 |
-
""", unsafe_allow_html=True)
|
457 |
-
st.markdown("""</div>""", unsafe_allow_html=True)
|
458 |
-
# Display tips based on fitness goal
|
459 |
-
st.markdown(f"""
|
460 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);">
|
461 |
-
<h3>{st.session_state.metrics.get('fitness_goal', '')} Tips</h3>
|
462 |
-
""", unsafe_allow_html=True)
|
463 |
-
if st.session_state.metrics.get('fitness_goal') == "Weight Loss":
|
464 |
-
st.markdown("""
|
465 |
-
<p>🔻 Focus on creating a moderate calorie deficit (500-750 kcal/day).</p>
|
466 |
-
<p>⏱️ Consider intermittent fasting methods like 16:8 that may support your goals.</p>
|
467 |
-
<p>🚶♀️ Increase NEAT (Non-Exercise Activity Thermogenesis) through daily movement.</p>
|
468 |
-
<p>🧠 Manage stress as it can contribute to weight gain.</p>
|
469 |
-
""", unsafe_allow_html=True)
|
470 |
-
elif st.session_state.metrics.get('fitness_goal') == "Weight Gain":
|
471 |
-
st.markdown("""
|
472 |
-
<p>🔺 Aim for a calorie surplus of 300-500 kcal/day.</p>
|
473 |
-
<p>🏋️ Focus on progressive overload in strength training to build muscle.</p>
|
474 |
-
<p>🥛 Include protein-rich foods and consider protein supplementation if needed.</p>
|
475 |
-
<p>😴 Prioritize quality sleep as it's essential for muscle recovery and growth.</p>
|
476 |
-
""", unsafe_allow_html=True)
|
477 |
-
elif st.session_state.metrics.get('fitness_goal') == "Maintenance":
|
478 |
-
st.markdown("""
|
479 |
-
<p>⚖️ Monitor your weight weekly to ensure you're maintaining.</p>
|
480 |
-
<p>🏃♂️ Mix up your exercise routine to prevent plateaus and maintain interest.</p>
|
481 |
-
<p>🥗 Practice the 80/20 rule: 80% nutritious foods, 20% treats in moderation.</p>
|
482 |
-
<p>📊 Adjust calorie intake based on activity levels throughout the week.</p>
|
483 |
-
""", unsafe_allow_html=True)
|
484 |
-
st.markdown("""</div>""", unsafe_allow_html=True)
|
485 |
-
else:
|
486 |
-
# Display a welcome message if no metrics have been calculated yet
|
487 |
-
st.markdown("""
|
488 |
-
<div style="background-color: white; border-radius: 8px; padding: 30px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); text-align: center; height: 100%;">
|
489 |
-
<img src="https://www.svgrepo.com/show/513354/yoga.svg" width="100">
|
490 |
-
<h2 style="margin: 20px 0;">Welcome to Your Health Journey</h2>
|
491 |
-
<p style="font-size: 16px; margin-bottom: 20px;">Fill in your details and click 'Calculate Health Metrics' to start your personalized wellness plan.</p>
|
492 |
-
<p style="font-style: italic;">"The greatest wealth is health." - Virgil</p>
|
493 |
-
</div>
|
494 |
-
""", unsafe_allow_html=True)
|
495 |
-
# Display the generated plan if available
|
496 |
-
if st.session_state.plan_generated:
|
497 |
-
st.markdown("""
|
498 |
-
<div class="plan-section">
|
499 |
-
<h2 style="text-align: center; margin-bottom: 20px;">Your Personalized Health Plan</h2>
|
500 |
-
""", unsafe_allow_html=True)
|
501 |
-
st.markdown(st.session_state.plan_content, unsafe_allow_html=True)
|
502 |
-
st.markdown("""</div>""", unsafe_allow_html=True)
|
503 |
-
|
504 |
-
with tabs[1]:
|
505 |
-
st.markdown("""
|
506 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin-bottom: 20px;">
|
507 |
-
<h2 style="text-align: center;">Health Progress Analytics</h2>
|
508 |
-
</div>
|
509 |
-
""", unsafe_allow_html=True)
|
510 |
-
# Generate sample data for demo purposes
|
511 |
-
sample_data = generate_sample_data()
|
512 |
-
# Choose analysis timeframe
|
513 |
-
timeframe = st.radio("Select Timeframe", options=["7 Days", "14 Days", "30 Days"], horizontal=True)
|
514 |
-
days = int(timeframe.split()[0])
|
515 |
-
filtered_data = sample_data.iloc[-days:]
|
516 |
-
# Create multiple charts
|
517 |
-
chart_col1, chart_col2 = st.columns(2)
|
518 |
-
with chart_col1:
|
519 |
-
st.subheader("Weight Progress")
|
520 |
-
weight_chart = alt.Chart(filtered_data).mark_line(point=True).encode(
|
521 |
-
x=alt.X('date:T', title='Date'),
|
522 |
-
y=alt.Y('weight:Q', title='Weight (kg)', scale=alt.Scale(zero=False)),
|
523 |
-
tooltip=['date:T', 'weight:Q']
|
524 |
-
).properties(height=300).interactive()
|
525 |
-
st.altair_chart(weight_chart, use_container_width=True)
|
526 |
-
with chart_col2:
|
527 |
-
st.subheader("Daily Calorie Intake")
|
528 |
-
calorie_chart = alt.Chart(filtered_data).mark_bar().encode(
|
529 |
-
x=alt.X('date:T', title='Date'),
|
530 |
-
y=alt.Y('calories:Q', title='Calories (kcal)'),
|
531 |
-
color=alt.condition(
|
532 |
-
alt.datum.calories > 2000,
|
533 |
-
alt.value('#ffaa00'),
|
534 |
-
alt.value('#4361ee')
|
535 |
-
),
|
536 |
-
tooltip=['date:T', 'calories:Q']
|
537 |
-
).properties(height=300).interactive()
|
538 |
-
st.altair_chart(calorie_chart, use_container_width=True)
|
539 |
-
st.subheader("Daily Steps")
|
540 |
-
steps_chart = alt.Chart(filtered_data).mark_area(
|
541 |
-
line={'color':'#4361ee'},
|
542 |
-
color=alt.Gradient(
|
543 |
-
gradient='linear',
|
544 |
-
stops=[alt.GradientStop(color='white', offset=0),
|
545 |
-
alt.GradientStop(color='#dbeafe', offset=1)],
|
546 |
-
x1=1,
|
547 |
-
x2=1,
|
548 |
-
y1=1,
|
549 |
-
y2=0
|
550 |
-
)
|
551 |
-
).encode(
|
552 |
-
x=alt.X('date:T', title='Date'),
|
553 |
-
y=alt.Y('steps:Q', title='Steps'),
|
554 |
-
tooltip=['date:T', 'steps:Q']
|
555 |
-
).properties(height=250).interactive()
|
556 |
-
st.altair_chart(steps_chart, use_container_width=True)
|
557 |
-
# Display key metrics
|
558 |
-
metric_cols = st.columns(4)
|
559 |
-
with metric_cols[0]:
|
560 |
-
st.metric("Average Weight", f"{filtered_data['weight'].mean():.1f} kg", f"{filtered_data['weight'].iloc[-1] - filtered_data['weight'].iloc[0]:.1f} kg")
|
561 |
-
with metric_cols[1]:
|
562 |
-
st.metric("Average Calories", f"{int(filtered_data['calories'].mean())} kcal")
|
563 |
-
with metric_cols[2]:
|
564 |
-
st.metric("Average Steps", f"{int(filtered_data['steps'].mean())}", f"{int(filtered_data['steps'].iloc[-1] - filtered_data['steps'].iloc[0])}")
|
565 |
-
with metric_cols[3]:
|
566 |
-
if st.session_state.daily_calories > 0:
|
567 |
-
calorie_diff = int(filtered_data['calories'].mean() - st.session_state.daily_calories)
|
568 |
-
st.metric("vs. Target Calories", f"{int(st.session_state.daily_calories)} kcal", f"{calorie_diff} kcal")
|
569 |
-
else:
|
570 |
-
st.metric("Calorie Goal Status", "Not set")
|
571 |
-
|
572 |
-
with tabs[2]:
|
573 |
-
st.markdown("""
|
574 |
-
<div style="background-color: white; border-radius: 8px; padding: 30px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin-bottom: 20px;">
|
575 |
-
<h2 style="text-align: center;">About This Project</h2>
|
576 |
-
<p style="font-size: 16px; margin: 20px 0;">
|
577 |
-
The AI-Based Personalized Health & Wellness Planner is a cutting-edge application that integrates modern scientific knowledge with traditional Ayurvedic wisdom to create comprehensive, personalized wellness plans.
|
578 |
-
</p>
|
579 |
-
<ul style="margin-left: 20px; font-size: 16px;">
|
580 |
-
<li>Personalized diet and exercise recommendations based on your unique profile</li>
|
581 |
-
<li>Optional Ayurvedic insights tailored to your body type (dosha)</li>
|
582 |
-
<li>Integration with food delivery platforms for convenient meal ordering</li>
|
583 |
-
<li>Wearable device tracking to monitor your progress</li>
|
584 |
-
<li>Adaptive recommendations based on seasonal factors</li>
|
585 |
-
</ul>
|
586 |
-
</div>
|
587 |
-
""", unsafe_allow_html=True)
|
588 |
-
# Display team information if available
|
589 |
-
if has_team_info:
|
590 |
st.markdown("""
|
591 |
-
<div style="background-color: white;
|
592 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
593 |
</div>
|
594 |
""", unsafe_allow_html=True)
|
595 |
-
# Display team members in a grid
|
596 |
-
team_col1, team_col2 = st.columns(2)
|
597 |
-
with team_col1:
|
598 |
-
st.markdown("""
|
599 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin: 10px 0; text-align: center;">
|
600 |
-
<img src="https://www.svgrepo.com/show/382106/female-avatar-girl-face-woman-user-5.svg" width="100" style="border-radius: 50%;">
|
601 |
-
<h3>Aditi Soni</h3>
|
602 |
-
<p>Project Lead & AI Integration</p>
|
603 |
-
<a href="https://www.linkedin.com/in/aditi-soni-259813285/" target="_blank">LinkedIn Profile</a>
|
604 |
-
</div>
|
605 |
-
""", unsafe_allow_html=True)
|
606 |
-
st.markdown("""
|
607 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin: 10px 0; text-align: center;">
|
608 |
-
<img src="https://www.svgrepo.com/show/382105/female-avatar-girl-face-woman-user-4.svg" width="100" style="border-radius: 50%;">
|
609 |
-
<h3>Aditi Lakhera</h3>
|
610 |
-
<p>Nutrition Science Expert</p>
|
611 |
-
<a href="https://www.linkedin.com/in/aditi-lakhera-b628802bb/" target="_blank">LinkedIn Profile</a>
|
612 |
-
</div>
|
613 |
-
""", unsafe_allow_html=True)
|
614 |
-
with team_col2:
|
615 |
-
st.markdown("""
|
616 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin: 10px 0; text-align: center;">
|
617 |
-
<img src="https://www.svgrepo.com/show/382101/female-avatar-girl-face-woman-user.svg" width="100" style="border-radius: 50%;">
|
618 |
-
<h3>Bhumika Patel</h3>
|
619 |
-
<p>Machine Learning Engineer</p>
|
620 |
-
<a href="https://www.linkedin.com/in/bhumika-patel-ml/" target="_blank">LinkedIn Profile</a>
|
621 |
-
</div>
|
622 |
-
""", unsafe_allow_html=True)
|
623 |
-
st.markdown("""
|
624 |
-
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin: 10px 0; text-align: center;">
|
625 |
-
<img src="https://www.svgrepo.com/show/382103/female-avatar-girl-face-woman-user-2.svg" width="100" style="border-radius: 50%;">
|
626 |
-
<h3>Anushri Tiwari</h3>
|
627 |
-
<p>UI/UX Designer</p>
|
628 |
-
<a href="https://www.linkedin.com/in/anushri-tiwari-916494300" target="_blank">LinkedIn Profile</a>
|
629 |
-
</div>
|
630 |
-
""", unsafe_allow_html=True)
|
631 |
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
<p>© 2025 AI Health & Wellness Planner. Current version: 2.1.0</p>
|
636 |
-
<p>Last updated: May 10, 2025</p>
|
637 |
-
</div>
|
638 |
-
""", unsafe_allow_html=True)
|
|
|
2 |
from dotenv import load_dotenv
|
3 |
from langchain_groq import ChatGroq
|
4 |
import os
|
5 |
+
import importlib.util
|
|
|
|
|
|
|
6 |
|
7 |
+
# Set page configuration
|
8 |
st.set_page_config(
|
9 |
+
page_title="Wellness Planner",
|
10 |
page_icon="🌿",
|
11 |
layout="wide",
|
12 |
initial_sidebar_state="expanded"
|
13 |
)
|
14 |
|
15 |
+
# Custom CSS for better styling
|
16 |
st.markdown("""
|
17 |
<style>
|
18 |
.main {
|
19 |
+
padding: 2rem;
|
20 |
+
}
|
21 |
+
.stApp {
|
22 |
background-color: #f8f9fa;
|
23 |
}
|
24 |
+
.css-18e3th9 {
|
25 |
+
padding-top: 2rem;
|
26 |
+
}
|
27 |
.stTabs [data-baseweb="tab-list"] {
|
28 |
+
gap: 2px;
|
29 |
}
|
30 |
.stTabs [data-baseweb="tab"] {
|
31 |
height: 50px;
|
32 |
white-space: pre-wrap;
|
33 |
+
background-color: #f0f2f6;
|
34 |
+
border-radius: 4px 4px 0 0;
|
35 |
+
gap: 1px;
|
36 |
+
padding-top: 10px;
|
37 |
+
padding-bottom: 10px;
|
38 |
}
|
39 |
.stTabs [aria-selected="true"] {
|
40 |
+
background-color: #4CAF50 !important;
|
41 |
+
color: white !important;
|
42 |
}
|
43 |
+
div.stButton > button:first-child {
|
44 |
+
background-color: #4CAF50;
|
|
|
|
|
|
|
45 |
color: white;
|
46 |
+
font-weight: bold;
|
47 |
+
padding: 0.5rem 1rem;
|
48 |
+
border-radius: 0.5rem;
|
49 |
+
border: none;
|
50 |
}
|
51 |
+
div.stButton > button:hover {
|
52 |
+
background-color: #45a049;
|
53 |
+
border: none;
|
54 |
}
|
55 |
+
.result-container {
|
56 |
background-color: white;
|
57 |
+
padding: 2rem;
|
58 |
+
border-radius: 0.5rem;
|
59 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
+
.info-box {
|
62 |
+
background-color: #e8f4f8;
|
63 |
+
padding: 1rem;
|
64 |
+
border-radius: 0.5rem;
|
65 |
+
margin-bottom: 1rem;
|
|
|
|
|
66 |
}
|
67 |
+
h1, h2, h3 {
|
68 |
+
color: #2E7D32;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
}
|
70 |
</style>
|
71 |
""", unsafe_allow_html=True)
|
72 |
|
73 |
+
# Check if team_info module exists and import it
|
74 |
try:
|
75 |
import team_info
|
76 |
has_team_info = True
|
77 |
except ImportError:
|
78 |
has_team_info = False
|
79 |
|
80 |
+
# Load environment variables
|
81 |
load_dotenv()
|
82 |
+
|
83 |
+
# Initialize the model
|
84 |
model = ChatGroq(model="llama3-8b-8192")
|
85 |
|
86 |
+
# Function to calculate daily calorie requirements
|
87 |
+
def calculate_calorie_requirements(age, gender, weight, height, fitness_goal):
|
88 |
if gender == "Male":
|
89 |
bmr = 10 * weight + 6.25 * height - 5 * age + 5
|
90 |
else:
|
91 |
bmr = 10 * weight + 6.25 * height - 5 * age - 161
|
92 |
|
93 |
+
if fitness_goal == "Weight Loss":
|
94 |
+
return bmr * 1.2
|
95 |
+
elif fitness_goal == "Weight Gain":
|
96 |
+
return bmr * 1.5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
else:
|
98 |
+
return bmr * 1.375
|
99 |
|
100 |
# Function to generate the plan
|
101 |
def generate_plan_with_prompt(metrics, prompt_template):
|
|
|
103 |
response = model.invoke(prompt)
|
104 |
return response
|
105 |
|
106 |
+
# Function to format the response neatly
|
107 |
def format_plan(response):
|
108 |
try:
|
109 |
content = response.content
|
110 |
+
sections = content.split("\n\n")
|
111 |
+
formatted = ""
|
112 |
+
for section in sections:
|
113 |
+
formatted += f"{section.strip()}\n\n"
|
114 |
+
return formatted
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
except Exception as e:
|
116 |
+
return f"Error formatting plan: {e}"
|
117 |
|
118 |
+
# Ayurvedic prompt template
|
119 |
ayurveda_prompt_template = """
|
120 |
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}).
|
121 |
+
|
122 |
Fitness Goal: {fitness_goal}.
|
123 |
Daily Calorie Requirement: {daily_calories} kcal.
|
124 |
Dietary Preference: {dietary_preference}.
|
|
|
126 |
Local Cuisine: {local_cuisine}.
|
127 |
Month: {month}.
|
128 |
Ayurvedic Consideration: True
|
129 |
+
|
130 |
Plan should include:
|
131 |
1. A daily diet plan with meal timings, calorie details, and meal alternatives.
|
132 |
2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
|
|
|
146 |
- Seasonal herbs and spices for balance.
|
147 |
- Daily routines (Dinacharya) for optimal health.
|
148 |
- Natural remedies complementing modern medicine.
|
149 |
+
|
150 |
Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
|
151 |
+
|
152 |
Return output as:
|
153 |
Day: {{weekday}}
|
154 |
- Breakfast: Time, Description, Calories, Ayurvedic Properties
|
|
|
162 |
- Ayurvedic Tips: Daily wellness practices based on dosha.
|
163 |
"""
|
164 |
|
165 |
+
# Regular prompt template
|
166 |
regular_prompt_template = """
|
167 |
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}).
|
168 |
+
|
169 |
Fitness Goal: {fitness_goal}.
|
170 |
Daily Calorie Requirement: {daily_calories} kcal.
|
171 |
Dietary Preference: {dietary_preference}.
|
172 |
Food Allergies: {food_allergies}.
|
173 |
Local Cuisine: {local_cuisine}.
|
174 |
Month: {month}.
|
175 |
+
|
176 |
Plan should include:
|
177 |
1. A daily diet plan with meal timings, calorie details, and meal alternatives.
|
178 |
2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
|
|
|
186 |
- Multi-restaurant meal aggregation for complete diet fulfillment.
|
187 |
- Location-based meal recommendations.
|
188 |
- Customizable meal delivery schedules.
|
189 |
+
|
190 |
Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
|
191 |
+
|
192 |
Return output as:
|
193 |
Day: {{weekday}}
|
194 |
- Breakfast: Time, Description, Calories
|
|
|
201 |
- Food Delivery: Suggested meal items and delivery options.
|
202 |
"""
|
203 |
|
204 |
+
# Main App Layout
|
205 |
+
def main():
|
206 |
+
# App Header
|
207 |
+
col1, col2 = st.columns([1, 3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
with col1:
|
209 |
+
st.image("https://img.icons8.com/color/96/000000/yoga.png", width=80)
|
210 |
+
with col2:
|
211 |
+
st.title("AI-Based Wellness Planner")
|
212 |
+
st.subheader("Personalized Diet & Exercise Plan with Ayurvedic Insights")
|
213 |
+
|
214 |
+
st.markdown("---")
|
215 |
+
|
216 |
+
# Sidebar content
|
217 |
+
with st.sidebar:
|
218 |
+
st.image("https://img.icons8.com/color/96/000000/natural-food.png", width=50)
|
219 |
+
st.header("About this Project")
|
220 |
+
st.markdown("""
|
221 |
+
<div class="info-box">
|
222 |
+
This app creates personalized wellness plans by integrating Ayurveda with modern medical science for comprehensive health insights.
|
223 |
+
</div>
|
224 |
+
""", unsafe_allow_html=True)
|
225 |
+
|
226 |
+
if has_team_info:
|
227 |
+
st.subheader("���� Team Members")
|
228 |
+
team_members = [
|
229 |
+
("Aditi Soni", "https://www.linkedin.com/in/aditi-soni-259813285/"),
|
230 |
+
("Bhumika Patel", "https://www.linkedin.com/in/bhumika-patel-ml/"),
|
231 |
+
("Aditi Lakhera", "https://www.linkedin.com/in/aditi-lakhera-b628802bb/"),
|
232 |
+
("Anushri Tiwari", "https://www.linkedin.com/in/anushri-tiwari-916494300")
|
233 |
+
]
|
234 |
+
|
235 |
+
for name, link in team_members:
|
236 |
+
st.markdown(f"- [{name}]({link})")
|
237 |
+
|
238 |
+
st.subheader("🔗 Project Links")
|
239 |
+
st.markdown("[GitHub Repository](https://github.com/Abs6187/AI_Health_v2)")
|
240 |
+
st.markdown("[Presentation](https://github.com/Abs6187/AI_Health_v2/blob/main/HackGirl_PPT_HackSRIT.pptx)")
|
241 |
+
st.markdown("[Hackathon](https://unstop.com/hackathons/hacksrit-shri-ram-group-of-institutions-jabalpur-1471613)")
|
242 |
+
|
243 |
+
st.markdown("---")
|
244 |
+
st.caption("© 2023 Wellness Planner")
|
245 |
+
|
246 |
+
# Main content
|
247 |
+
tab1, tab2 = st.tabs(["Create Your Plan", "About Ayurveda"])
|
248 |
+
|
249 |
+
with tab1:
|
250 |
+
# Input Form in two columns
|
251 |
+
st.header("Enter Your Details")
|
252 |
+
|
253 |
+
col1, col2 = st.columns(2)
|
254 |
+
|
255 |
+
with col1:
|
256 |
+
st.subheader("Personal Information")
|
257 |
+
name = st.text_input("Name", placeholder="Enter your name")
|
258 |
age = st.number_input("Age", min_value=1, max_value=120, value=25)
|
259 |
gender = st.selectbox("Gender", options=["Male", "Female", "Other"])
|
260 |
+
|
261 |
+
st.subheader("Physical Metrics")
|
262 |
+
weight = st.number_input("Weight (kg)", min_value=1.0, max_value=300.0, value=70.0, format="%.1f")
|
263 |
+
height = st.number_input("Height (cm)", min_value=1, max_value=250, value=170)
|
264 |
+
|
265 |
+
with col2:
|
266 |
+
st.subheader("Goals & Preferences")
|
267 |
fitness_goal = st.selectbox("Fitness Goal", options=["Weight Loss", "Weight Gain", "Maintenance"])
|
268 |
+
dietary_preference = st.selectbox("Dietary Preference",
|
269 |
+
options=["No Restrictions", "Vegetarian", "Vegan", "Keto", "Paleo", "Halal", "Gluten-Free"])
|
270 |
+
food_allergies = st.text_input("Food Allergies (if any)", placeholder="e.g., nuts, dairy, shellfish")
|
271 |
+
local_cuisine = st.text_input("Preferred Local Cuisine", placeholder="e.g., Indian, Italian, Chinese")
|
272 |
+
month = st.selectbox("Current Month",
|
273 |
+
options=["January", "February", "March", "April", "May", "June",
|
274 |
+
"July", "August", "September", "October", "November", "December"])
|
275 |
+
|
|
|
276 |
include_ayurveda = st.checkbox("Include Ayurvedic wellness insights", value=True)
|
277 |
+
|
278 |
+
# Calculate metrics
|
279 |
+
bmi = round(weight / (height / 100) ** 2, 2)
|
280 |
+
|
281 |
+
if bmi < 18.5:
|
282 |
+
health_status = "Underweight"
|
283 |
+
bmi_color = "orange"
|
284 |
+
elif bmi <= 24.9:
|
285 |
+
health_status = "Normal weight"
|
286 |
+
bmi_color = "green"
|
287 |
+
elif bmi <= 29.9:
|
288 |
+
health_status = "Overweight"
|
289 |
+
bmi_color = "orange"
|
290 |
+
else:
|
291 |
+
health_status = "Obese"
|
292 |
+
bmi_color = "red"
|
293 |
+
|
294 |
+
daily_calories = int(calculate_calorie_requirements(age, gender, weight, height, fitness_goal))
|
295 |
+
|
296 |
+
# Display metrics in a nice formatted box
|
297 |
+
st.markdown("### Your Health Metrics")
|
298 |
+
metrics_col1, metrics_col2 = st.columns(2)
|
299 |
+
|
300 |
+
with metrics_col1:
|
301 |
+
st.markdown(f"""
|
302 |
+
<div style="background-color: #e8f4f8; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
|
303 |
+
<h4 style="color: #1E88E5;">BMI Analysis</h4>
|
304 |
+
<p>Your BMI is <span style="font-weight: bold; color: {bmi_color};">{bmi}</span></p>
|
305 |
+
<p>Status: <span style="font-weight: bold; color: {bmi_color};">{health_status}</span></p>
|
306 |
+
</div>
|
307 |
+
""", unsafe_allow_html=True)
|
308 |
+
|
309 |
+
with metrics_col2:
|
310 |
+
st.markdown(f"""
|
311 |
+
<div style="background-color: #e8f4f8; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
|
312 |
+
<h4 style="color: #1E88E5;">Calorie Requirements</h4>
|
313 |
+
<p>Daily requirements: <span style="font-weight: bold;">{daily_calories} kcal</span></p>
|
314 |
+
<p>Goal: <span style="font-weight: bold;">{fitness_goal}</span></p>
|
315 |
+
</div>
|
316 |
+
""", unsafe_allow_html=True)
|
317 |
+
|
318 |
+
# User metrics dictionary
|
319 |
+
metrics = {
|
320 |
+
"name": name,
|
321 |
+
"age": age,
|
322 |
+
"gender": gender,
|
323 |
+
"bmi": bmi,
|
324 |
+
"health_status": health_status,
|
325 |
+
"fitness_goal": fitness_goal,
|
326 |
+
"dietary_preference": dietary_preference,
|
327 |
+
"food_allergies": food_allergies,
|
328 |
+
"daily_calories": daily_calories,
|
329 |
+
"local_cuisine": local_cuisine,
|
330 |
+
"weekdays": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
331 |
+
"month": month,
|
332 |
+
}
|
333 |
+
|
334 |
+
# Generate button
|
335 |
+
st.markdown("---")
|
336 |
+
generate_col1, generate_col2, generate_col3 = st.columns([1, 2, 1])
|
337 |
+
with generate_col2:
|
338 |
+
generate_plan = st.button("Generate Your Personalized Wellness Plan", use_container_width=True)
|
339 |
+
|
340 |
+
# Generate and display plan
|
341 |
+
if generate_plan:
|
342 |
+
if not name:
|
343 |
+
st.error("Please enter your name to generate a plan")
|
344 |
+
else:
|
345 |
+
with st.spinner("Crafting your personalized wellness plan..."):
|
346 |
try:
|
347 |
# Choose the appropriate prompt based on the Ayurveda option
|
348 |
selected_prompt = ayurveda_prompt_template if include_ayurveda else regular_prompt_template
|
349 |
+
plan = generate_plan_with_prompt(metrics, selected_prompt)
|
350 |
+
formatted_plan = format_plan(plan)
|
351 |
+
|
352 |
+
plan_type = "Integrated Ayurvedic & Modern Wellness Plan" if include_ayurveda else "Modern Wellness Plan"
|
353 |
+
|
354 |
+
st.success(f"Your personalized plan is ready!")
|
355 |
+
|
356 |
+
st.markdown(f"""
|
357 |
+
<div class="result-container">
|
358 |
+
<h2 style="text-align: center; color: #2E7D32;">{plan_type} for {name}</h2>
|
359 |
+
<h4 style="text-align: center; color: #666;">Month: {month}</h4>
|
360 |
+
<hr>
|
361 |
+
{formatted_plan.replace('\n', '<br>')}
|
362 |
+
</div>
|
363 |
+
""", unsafe_allow_html=True)
|
364 |
+
|
365 |
+
# Download option
|
366 |
+
plan_text = f"{plan_type} for {name}\nMonth: {month}\n\n{plan.content}"
|
367 |
+
st.download_button(
|
368 |
+
label="Download Your Plan",
|
369 |
+
data=plan_text,
|
370 |
+
file_name=f"{name}_wellness_plan.txt",
|
371 |
+
mime="text/plain"
|
372 |
+
)
|
373 |
+
|
374 |
except Exception as e:
|
375 |
st.error(f"Error generating the plan: {e}")
|
376 |
+
|
377 |
+
with tab2:
|
378 |
+
st.header("Ayurveda: Ancient Wisdom for Modern Wellness")
|
379 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
st.markdown("""
|
381 |
+
<div style="background-color: white; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
|
382 |
+
<p>Ayurveda is a traditional Indian system of medicine that dates back over 5,000 years. The term Ayurveda is derived from the Sanskrit words "ayur" (life) and "veda" (knowledge).</p>
|
383 |
+
|
384 |
+
<h3>The Three Doshas</h3>
|
385 |
+
<p>Ayurveda believes that each person has a unique mix of three energies or doshas:</p>
|
386 |
+
<ul>
|
387 |
+
<li><strong>Vata</strong> (Air & Space) - Controls movement and is associated with creativity and flexibility</li>
|
388 |
+
<li><strong>Pitta</strong> (Fire & Water) - Controls metabolism and is associated with intelligence and determination</li>
|
389 |
+
<li><strong>Kapha</strong> (Earth & Water) - Controls structure and is associated with stability and compassion</li>
|
390 |
+
</ul>
|
391 |
+
|
392 |
+
<h3>Ayurvedic Approach to Wellness</h3>
|
393 |
+
<p>Ayurveda takes a holistic approach to health that includes:</p>
|
394 |
+
<ul>
|
395 |
+
<li>Personalized nutrition based on your dosha</li>
|
396 |
+
<li>Lifestyle recommendations aligned with natural cycles</li>
|
397 |
+
<li>Herbal medicines and therapies</li>
|
398 |
+
<li>Mental wellness practices</li>
|
399 |
+
<li>Seasonal adjustments to maintain balance</li>
|
400 |
+
</ul>
|
401 |
+
|
402 |
+
<p>Our wellness planner integrates these ancient principles with modern health science to provide you with a truly holistic approach to health and wellness.</p>
|
403 |
</div>
|
404 |
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
+
if __name__ == "__main__":
|
407 |
+
main()
|
408 |
+
|
|
|
|
|
|
|
|