Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,103 @@ 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:
|
@@ -18,36 +115,111 @@ load_dotenv()
|
|
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
else:
|
32 |
-
return
|
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
|
41 |
def format_plan(response):
|
|
|
42 |
try:
|
43 |
content = response.content
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
except Exception as e:
|
50 |
-
return f"Error formatting plan: {e}"
|
51 |
|
52 |
# Ayurvedic prompt template
|
53 |
ayurveda_prompt_template = """
|
@@ -127,76 +299,427 @@ Day: {{weekday}}
|
|
127 |
- Food Delivery: Suggested meal items and delivery options.
|
128 |
"""
|
129 |
|
130 |
-
#
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
|
|
138 |
if has_team_info:
|
139 |
-
st.
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
st.
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
3 |
from langchain_groq import ChatGroq
|
4 |
import os
|
5 |
import importlib.util
|
6 |
+
import pandas as pd
|
7 |
+
import altair as alt
|
8 |
+
import datetime
|
9 |
+
import random
|
10 |
+
|
11 |
+
# Set page config for the application
|
12 |
+
st.set_page_config(
|
13 |
+
page_title="AI Health & Wellness Planner",
|
14 |
+
page_icon="🌿",
|
15 |
+
layout="wide",
|
16 |
+
initial_sidebar_state="expanded"
|
17 |
+
)
|
18 |
+
|
19 |
+
# Apply custom CSS for enhanced styling
|
20 |
+
st.markdown("""
|
21 |
+
<style>
|
22 |
+
.main {
|
23 |
+
background-color: #f8f9fa;
|
24 |
+
}
|
25 |
+
.stTabs [data-baseweb="tab-list"] {
|
26 |
+
gap: 8px;
|
27 |
+
}
|
28 |
+
.stTabs [data-baseweb="tab"] {
|
29 |
+
height: 50px;
|
30 |
+
white-space: pre-wrap;
|
31 |
+
border-radius: 4px 4px 0px 0px;
|
32 |
+
padding: 10px 16px;
|
33 |
+
font-weight: 600;
|
34 |
+
}
|
35 |
+
.stTabs [aria-selected="true"] {
|
36 |
+
background-color: #f0f7ff;
|
37 |
+
border-bottom: 2px solid #4361ee;
|
38 |
+
}
|
39 |
+
.stButton>button {
|
40 |
+
width: 100%;
|
41 |
+
border-radius: 8px;
|
42 |
+
height: 3em;
|
43 |
+
background-color: #4361ee;
|
44 |
+
color: white;
|
45 |
+
font-weight: 600;
|
46 |
+
}
|
47 |
+
.stButton>button:hover {
|
48 |
+
background-color: #3a56d4;
|
49 |
+
color: white;
|
50 |
+
}
|
51 |
+
.metric-card {
|
52 |
+
background-color: white;
|
53 |
+
border-radius: 8px;
|
54 |
+
padding: 20px;
|
55 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
56 |
+
text-align: center;
|
57 |
+
}
|
58 |
+
.input-section {
|
59 |
+
background-color: white;
|
60 |
+
border-radius: 8px;
|
61 |
+
padding: 20px;
|
62 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
63 |
+
margin-bottom: 20px;
|
64 |
+
}
|
65 |
+
.header-section {
|
66 |
+
text-align: center;
|
67 |
+
padding: 10px;
|
68 |
+
margin-bottom: 20px;
|
69 |
+
}
|
70 |
+
.plan-section {
|
71 |
+
background-color: white;
|
72 |
+
border-radius: 8px;
|
73 |
+
padding: 20px;
|
74 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
75 |
+
margin-top: 20px;
|
76 |
+
}
|
77 |
+
.badge {
|
78 |
+
display: inline-block;
|
79 |
+
padding: 5px 10px;
|
80 |
+
border-radius: 15px;
|
81 |
+
font-size: 12px;
|
82 |
+
font-weight: 600;
|
83 |
+
margin-right: 5px;
|
84 |
+
}
|
85 |
+
.badge-green {
|
86 |
+
background-color: #d1fae5;
|
87 |
+
color: #065f46;
|
88 |
+
}
|
89 |
+
.badge-yellow {
|
90 |
+
background-color: #fef3c7;
|
91 |
+
color: #92400e;
|
92 |
+
}
|
93 |
+
.badge-red {
|
94 |
+
background-color: #fee2e2;
|
95 |
+
color: #b91c1c;
|
96 |
+
}
|
97 |
+
.badge-blue {
|
98 |
+
background-color: #dbeafe;
|
99 |
+
color: #1e40af;
|
100 |
+
}
|
101 |
+
</style>
|
102 |
+
""", unsafe_allow_html=True)
|
103 |
|
104 |
# Check if team_info module exists and import it
|
105 |
try:
|
|
|
115 |
model = ChatGroq(model="llama3-8b-8192")
|
116 |
|
117 |
# Function to calculate daily calorie requirements
|
118 |
+
def calculate_calorie_requirements(age, gender, weight, height, fitness_goal, activity_level):
|
119 |
+
"""Calculate daily calorie requirements based on user input."""
|
120 |
if gender == "Male":
|
121 |
bmr = 10 * weight + 6.25 * height - 5 * age + 5
|
122 |
else:
|
123 |
bmr = 10 * weight + 6.25 * height - 5 * age - 161
|
124 |
|
125 |
+
# Activity level multipliers
|
126 |
+
activity_multipliers = {
|
127 |
+
"Sedentary (little or no exercise)": 1.2,
|
128 |
+
"Lightly active (light exercise/sports 1-3 days/week)": 1.375,
|
129 |
+
"Moderately active (moderate exercise/sports 3-5 days/week)": 1.55,
|
130 |
+
"Very active (hard exercise/sports 6-7 days/week)": 1.725,
|
131 |
+
"Super active (very hard exercise & physical job or 2x training)": 1.9
|
132 |
+
}
|
133 |
+
|
134 |
+
# Goal adjustments
|
135 |
+
goal_adjustments = {
|
136 |
+
"Weight Loss": 0.8, # 20% calorie deficit
|
137 |
+
"Weight Gain": 1.15, # 15% calorie surplus
|
138 |
+
"Maintenance": 1.0 # No adjustment
|
139 |
+
}
|
140 |
+
|
141 |
+
return bmr * activity_multipliers[activity_level] * goal_adjustments[fitness_goal]
|
142 |
+
|
143 |
+
# Function to determine BMI category with a more detailed breakdown
|
144 |
+
def get_bmi_category(bmi):
|
145 |
+
"""Return the BMI category and associated badge color."""
|
146 |
+
if bmi < 16:
|
147 |
+
return "Severely Underweight", "red"
|
148 |
+
elif 16 <= bmi < 18.5:
|
149 |
+
return "Underweight", "yellow"
|
150 |
+
elif 18.5 <= bmi < 25:
|
151 |
+
return "Normal weight", "green"
|
152 |
+
elif 25 <= bmi < 30:
|
153 |
+
return "Overweight", "yellow"
|
154 |
+
elif 30 <= bmi < 35:
|
155 |
+
return "Obesity Class I", "red"
|
156 |
+
elif 35 <= bmi < 40:
|
157 |
+
return "Obesity Class II", "red"
|
158 |
else:
|
159 |
+
return "Obesity Class III", "red"
|
160 |
|
161 |
# Function to generate the plan
|
162 |
def generate_plan_with_prompt(metrics, prompt_template):
|
163 |
+
"""Generate a personalized health plan using the AI model."""
|
164 |
prompt = prompt_template.format(**metrics)
|
165 |
response = model.invoke(prompt)
|
166 |
return response
|
167 |
|
168 |
+
# Function to format the response in a more structured way
|
169 |
def format_plan(response):
|
170 |
+
"""Format the AI response into a structured plan format."""
|
171 |
try:
|
172 |
content = response.content
|
173 |
+
days = content.split("Day: ")
|
174 |
+
|
175 |
+
formatted_content = ""
|
176 |
+
|
177 |
+
for i, day in enumerate(days):
|
178 |
+
if i == 0: # Skip the first split which might be empty or contain introduction text
|
179 |
+
if day.strip():
|
180 |
+
formatted_content += f"<div class='plan-intro'>{day.strip()}</div>"
|
181 |
+
continue
|
182 |
+
|
183 |
+
# Create a card for each day
|
184 |
+
formatted_content += f"""
|
185 |
+
<div style='background-color: white; border-radius: 8px; padding: 15px; margin-bottom: 15px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);'>
|
186 |
+
<h3 style='color: #4361ee; border-bottom: 1px solid #e5e7eb; padding-bottom: 10px;'>Day: {day.split('\n', 1)[0].strip()}</h3>
|
187 |
+
<div style='padding: 10px 0;'>
|
188 |
+
"""
|
189 |
+
|
190 |
+
# Process each line of the day's content
|
191 |
+
sections = day.split('\n', 1)[1].split('\n - ')
|
192 |
+
for section in sections:
|
193 |
+
if not section.strip():
|
194 |
+
continue
|
195 |
+
|
196 |
+
# Add special formatting for each type of entry
|
197 |
+
if "Breakfast:" in section:
|
198 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🍳 Breakfast:</strong> {section.replace('Breakfast:', '').strip()}</div>"
|
199 |
+
elif "Lunch:" in section:
|
200 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🍲 Lunch:</strong> {section.replace('Lunch:', '').strip()}</div>"
|
201 |
+
elif "Snacks:" in section:
|
202 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🥨 Snacks:</strong> {section.replace('Snacks:', '').strip()}</div>"
|
203 |
+
elif "Dinner:" in section:
|
204 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🍽️ Dinner:</strong> {section.replace('Dinner:', '').strip()}</div>"
|
205 |
+
elif "Exercise:" in section:
|
206 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🏋️ Exercise:</strong> {section.replace('Exercise:', '').strip()}</div>"
|
207 |
+
elif "Wearable Tracking:" in section:
|
208 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>⌚ Wearable Tracking:</strong> {section.replace('Wearable Tracking:', '').strip()}</div>"
|
209 |
+
elif "Progress Monitoring:" in section:
|
210 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>📊 Progress Monitoring:</strong> {section.replace('Progress Monitoring:', '').strip()}</div>"
|
211 |
+
elif "Food Delivery:" in section:
|
212 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🚚 Food Delivery:</strong> {section.replace('Food Delivery:', '').strip()}</div>"
|
213 |
+
elif "Ayurvedic Tips:" in section:
|
214 |
+
formatted_content += f"<div style='margin-bottom: 10px;'><strong style='color: #4361ee;'>🌿 Ayurvedic Tips:</strong> {section.replace('Ayurvedic Tips:', '').strip()}</div>"
|
215 |
+
else:
|
216 |
+
formatted_content += f"<div style='margin-bottom: 10px;'>{section.strip()}</div>"
|
217 |
+
|
218 |
+
formatted_content += "</div></div>"
|
219 |
+
|
220 |
+
return formatted_content
|
221 |
except Exception as e:
|
222 |
+
return f"<div class='error'>Error formatting plan: {e}</div>"
|
223 |
|
224 |
# Ayurvedic prompt template
|
225 |
ayurveda_prompt_template = """
|
|
|
299 |
- Food Delivery: Suggested meal items and delivery options.
|
300 |
"""
|
301 |
|
302 |
+
# Initialize session state variables
|
303 |
+
if 'bmi' not in st.session_state:
|
304 |
+
st.session_state.bmi = 0
|
305 |
+
if 'daily_calories' not in st.session_state:
|
306 |
+
st.session_state.daily_calories = 0
|
307 |
+
if 'health_status' not in st.session_state:
|
308 |
+
st.session_state.health_status = ""
|
309 |
+
if 'status_color' not in st.session_state:
|
310 |
+
st.session_state.status_color = ""
|
311 |
+
if 'metrics' not in st.session_state:
|
312 |
+
st.session_state.metrics = {}
|
313 |
+
if 'plan_generated' not in st.session_state:
|
314 |
+
st.session_state.plan_generated = False
|
315 |
+
if 'plan_content' not in st.session_state:
|
316 |
+
st.session_state.plan_content = ""
|
317 |
+
|
318 |
+
# Generate sample progress data for demo purposes
|
319 |
+
def generate_sample_data(days=30):
|
320 |
+
"""Generate sample data for the progress charts."""
|
321 |
+
start_date = datetime.datetime.now() - datetime.timedelta(days=days)
|
322 |
+
dates = [start_date + datetime.timedelta(days=i) for i in range(days)]
|
323 |
+
|
324 |
+
# Generate weight data with a slight downward trend
|
325 |
+
initial_weight = 75
|
326 |
+
weights = [initial_weight - 0.1 * i + random.uniform(-0.5, 0.5) for i in range(days)]
|
327 |
+
|
328 |
+
# Generate calorie data with weekly patterns
|
329 |
+
calories = []
|
330 |
+
for i in range(days):
|
331 |
+
# Weekends tend to have higher calorie intake
|
332 |
+
if i % 7 >= 5: # Saturday and Sunday
|
333 |
+
calories.append(2200 + random.uniform(-200, 300))
|
334 |
+
else:
|
335 |
+
calories.append(1800 + random.uniform(-100, 200))
|
336 |
+
|
337 |
+
# Generate steps data
|
338 |
+
steps = [random.randint(6000, 12000) for _ in range(days)]
|
339 |
+
|
340 |
+
# Create a DataFrame
|
341 |
+
data = pd.DataFrame({
|
342 |
+
'date': dates,
|
343 |
+
'weight': weights,
|
344 |
+
'calories': calories,
|
345 |
+
'steps': steps
|
346 |
+
})
|
347 |
+
return data
|
348 |
+
|
349 |
+
# Create a responsive header
|
350 |
+
st.markdown("""
|
351 |
+
<div class="header-section">
|
352 |
+
<h1 style="color: #4361ee;">AI-Based Personalized Health & Wellness Planner</h1>
|
353 |
+
<p style="font-size: 18px;">Integrating modern science with Ayurvedic wisdom for holistic health</p>
|
354 |
+
</div>
|
355 |
+
""", unsafe_allow_html=True)
|
356 |
+
|
357 |
+
# Create tabs for different sections of the app
|
358 |
+
tabs = st.tabs(["📋 Profile & Plan", "📊 Analytics", "ℹ️ About"])
|
359 |
+
|
360 |
+
with tabs[0]:
|
361 |
+
# Create a two-column layout for input form and results
|
362 |
+
col1, col2 = st.columns([3, 2])
|
363 |
+
|
364 |
+
with col1:
|
365 |
+
st.markdown("""<div class="input-section">""", unsafe_allow_html=True)
|
366 |
+
st.subheader("Personal Details")
|
367 |
+
|
368 |
+
# Create multiple columns for compact form layout
|
369 |
+
detail_col1, detail_col2 = st.columns(2)
|
370 |
+
with detail_col1:
|
371 |
+
name = st.text_input("Your Name", placeholder="Enter your name")
|
372 |
+
age = st.number_input("Age", min_value=1, max_value=120, value=25)
|
373 |
+
gender = st.selectbox("Gender", options=["Male", "Female", "Other"])
|
374 |
+
|
375 |
+
with detail_col2:
|
376 |
+
weight = st.number_input("Weight (kg)", min_value=1.0, max_value=300.0, value=70.0)
|
377 |
+
height = st.number_input("Height (cm)", min_value=50.0, max_value=250.0, value=170.0)
|
378 |
+
|
379 |
+
st.subheader("Health Goals")
|
380 |
+
goal_col1, goal_col2 = st.columns(2)
|
381 |
+
with goal_col1:
|
382 |
+
fitness_goal = st.selectbox("Fitness Goal", options=["Weight Loss", "Weight Gain", "Maintenance"])
|
383 |
+
dietary_preference = st.selectbox("Dietary Preference", options=["None", "Vegetarian", "Vegan", "Keto", "Halal"])
|
384 |
+
|
385 |
+
with goal_col2:
|
386 |
+
activity_level = st.selectbox("Activity Level", options=[
|
387 |
+
"Sedentary (little or no exercise)",
|
388 |
+
"Lightly active (light exercise/sports 1-3 days/week)",
|
389 |
+
"Moderately active (moderate exercise/sports 3-5 days/week)",
|
390 |
+
"Very active (hard exercise/sports 6-7 days/week)",
|
391 |
+
"Super active (very hard exercise & physical job or 2x training)"
|
392 |
+
])
|
393 |
+
include_ayurveda = st.checkbox("Include Ayurvedic wellness insights", value=True)
|
394 |
+
|
395 |
+
with st.expander("Additional Preferences", expanded=False):
|
396 |
+
food_allergies = st.text_input("Food Allergies (if any)", placeholder="e.g., peanuts, shellfish")
|
397 |
+
local_cuisine = st.text_input("Preferred Local Cuisine", value="Indian", placeholder="e.g., Indian, Italian, Chinese")
|
398 |
+
month = st.selectbox("Select Month", options=[
|
399 |
+
"January", "February", "March", "April", "May", "June",
|
400 |
+
"July", "August", "September", "October", "November", "December"
|
401 |
+
], index=datetime.datetime.now().month - 1)
|
402 |
+
|
403 |
+
# Calculate BMI and calorie requirements
|
404 |
+
if st.button("Calculate Health Metrics", use_container_width=True):
|
405 |
+
st.session_state.bmi = round(weight / (height / 100) ** 2, 2)
|
406 |
+
st.session_state.health_status, st.session_state.status_color = get_bmi_category(st.session_state.bmi)
|
407 |
+
st.session_state.daily_calories = int(calculate_calorie_requirements(age, gender, weight, height, fitness_goal, activity_level))
|
408 |
+
|
409 |
+
# Store metrics in session state
|
410 |
+
st.session_state.metrics = {
|
411 |
+
"name": name,
|
412 |
+
"age": age,
|
413 |
+
"gender": gender,
|
414 |
+
"bmi": st.session_state.bmi,
|
415 |
+
"health_status": st.session_state.health_status,
|
416 |
+
"fitness_goal": fitness_goal,
|
417 |
+
"dietary_preference": dietary_preference,
|
418 |
+
"food_allergies": food_allergies,
|
419 |
+
"daily_calories": st.session_state.daily_calories,
|
420 |
+
"local_cuisine": local_cuisine,
|
421 |
+
"weekdays": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
422 |
+
"month": month,
|
423 |
+
"activity_level": activity_level
|
424 |
+
}
|
425 |
+
|
426 |
+
# Rerun to update the UI
|
427 |
+
st.rerun()
|
428 |
+
|
429 |
+
# Generate plan button (only enabled if metrics are calculated)
|
430 |
+
if st.session_state.bmi > 0:
|
431 |
+
if st.button("Generate Personalized Plan", type="primary", use_container_width=True):
|
432 |
+
with st.spinner("Creating your personalized health plan..."):
|
433 |
+
try:
|
434 |
+
# Choose the appropriate prompt based on the Ayurveda option
|
435 |
+
selected_prompt = ayurveda_prompt_template if include_ayurveda else regular_prompt_template
|
436 |
+
plan = generate_plan_with_prompt(st.session_state.metrics, selected_prompt)
|
437 |
+
st.session_state.plan_content = format_plan(plan)
|
438 |
+
st.session_state.plan_generated = True
|
439 |
+
|
440 |
+
# Show success message
|
441 |
+
st.success("Your personalized health plan has been generated!")
|
442 |
+
st.balloons()
|
443 |
+
|
444 |
+
# Rerun to update the UI
|
445 |
+
st.rerun()
|
446 |
+
except Exception as e:
|
447 |
+
st.error(f"Error generating the plan: {e}")
|
448 |
+
|
449 |
+
st.markdown("""</div>""", unsafe_allow_html=True)
|
450 |
+
|
451 |
+
with col2:
|
452 |
+
# Display health metrics if they have been calculated
|
453 |
+
if st.session_state.bmi > 0:
|
454 |
+
st.markdown("""
|
455 |
+
<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;">
|
456 |
+
<h3 style="margin-bottom: 20px;">Your Health Metrics</h3>
|
457 |
+
""", unsafe_allow_html=True)
|
458 |
+
|
459 |
+
metric_col1, metric_col2 = st.columns(2)
|
460 |
+
|
461 |
+
with metric_col1:
|
462 |
+
st.markdown(f"""
|
463 |
+
<div class="metric-card">
|
464 |
+
<h4>BMI</h4>
|
465 |
+
<h2 style="font-size: 2.5rem; margin: 10px 0;">{st.session_state.bmi}</h2>
|
466 |
+
<span class="badge badge-{st.session_state.status_color}">{st.session_state.health_status}</span>
|
467 |
+
</div>
|
468 |
+
""", unsafe_allow_html=True)
|
469 |
+
|
470 |
+
with metric_col2:
|
471 |
+
st.markdown(f"""
|
472 |
+
<div class="metric-card">
|
473 |
+
<h4>Daily Calories</h4>
|
474 |
+
<h2 style="font-size: 2.5rem; margin: 10px 0;">{st.session_state.daily_calories}</h2>
|
475 |
+
<span class="badge badge-blue">kcal</span>
|
476 |
+
</div>
|
477 |
+
""", unsafe_allow_html=True)
|
478 |
+
|
479 |
+
st.markdown("""</div>""", unsafe_allow_html=True)
|
480 |
+
|
481 |
+
# Display recommendations based on health status
|
482 |
+
st.markdown("""
|
483 |
+
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); margin-bottom: 20px;">
|
484 |
+
<h3>Health Recommendations</h3>
|
485 |
+
""", unsafe_allow_html=True)
|
486 |
+
|
487 |
+
if st.session_state.status_color == "green":
|
488 |
+
st.markdown("""
|
489 |
+
<p>✅ Your BMI is in the healthy range!</p>
|
490 |
+
<p>🔍 Focus on maintaining your current weight with a balanced diet and regular exercise.</p>
|
491 |
+
<p>💪 Strength training 2-3 times per week is recommended for muscle maintenance.</p>
|
492 |
+
<p>🥗 Continue eating a variety of nutritious foods to maintain your overall health.</p>
|
493 |
+
""", unsafe_allow_html=True)
|
494 |
+
elif st.session_state.status_color == "yellow":
|
495 |
+
st.markdown("""
|
496 |
+
<p>⚠️ Your BMI indicates you may benefit from some adjustments to your lifestyle.</p>
|
497 |
+
<p>🏃♂️ Regular cardio exercise (30-45 minutes, 4-5 days per week) is recommended.</p>
|
498 |
+
<p>🍽️ Focus on portion control and balanced nutrition.</p>
|
499 |
+
<p>📱 Consider tracking your food intake and exercise for better awareness.</p>
|
500 |
+
""", unsafe_allow_html=True)
|
501 |
+
elif st.session_state.status_color == "red":
|
502 |
+
st.markdown("""
|
503 |
+
<p>❗ Your BMI suggests you may benefit from consulting with a healthcare professional.</p>
|
504 |
+
<p>👨⚕️ Consider seeking advice from a physician or registered dietitian.</p>
|
505 |
+
<p>👣 Start with gentle, low-impact exercise like walking or swimming.</p>
|
506 |
+
<p>🥦 Focus on whole, unprocessed foods rich in nutrients.</p>
|
507 |
+
<p>🧘♀️ Stress management techniques may also support your health journey.</p>
|
508 |
+
""", unsafe_allow_html=True)
|
509 |
+
|
510 |
+
st.markdown("""</div>""", unsafe_allow_html=True)
|
511 |
+
|
512 |
+
# Display tips based on fitness goal
|
513 |
+
st.markdown(f"""
|
514 |
+
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);">
|
515 |
+
<h3>{st.session_state.metrics.get('fitness_goal', '')} Tips</h3>
|
516 |
+
""", unsafe_allow_html=True)
|
517 |
+
|
518 |
+
if st.session_state.metrics.get('fitness_goal') == "Weight Loss":
|
519 |
+
st.markdown("""
|
520 |
+
<p>🔻 Focus on creating a moderate calorie deficit (500-750 kcal/day).</p>
|
521 |
+
<p>⏱️ Consider intermittent fasting methods like 16:8 that may support your goals.</p>
|
522 |
+
<p>🚶♀️ Increase NEAT (Non-Exercise Activity Thermogenesis) through daily movement.</p>
|
523 |
+
<p>🧠 Manage stress as it can contribute to weight gain.</p>
|
524 |
+
""", unsafe_allow_html=True)
|
525 |
+
elif st.session_state.metrics.get('fitness_goal') == "Weight Gain":
|
526 |
+
st.markdown("""
|
527 |
+
<p>🔺 Aim for a calorie surplus of 300-500 kcal/day.</p>
|
528 |
+
<p>🏋️ Focus on progressive overload in strength training to build muscle.</p>
|
529 |
+
<p>🥛 Include protein-rich foods and consider protein supplementation if needed.</p>
|
530 |
+
<p>😴 Prioritize quality sleep as it's essential for muscle recovery and growth.</p>
|
531 |
+
""", unsafe_allow_html=True)
|
532 |
+
elif st.session_state.metrics.get('fitness_goal') == "Maintenance":
|
533 |
+
st.markdown("""
|
534 |
+
<p>⚖️ Monitor your weight weekly to ensure you're maintaining.</p>
|
535 |
+
<p>🏃♂️ Mix up your exercise routine to prevent plateaus and maintain interest.</p>
|
536 |
+
<p>🥗 Practice the 80/20 rule: 80% nutritious foods, 20% treats in moderation.</p>
|
537 |
+
<p>📊 Adjust calorie intake based on activity levels throughout the week.</p>
|
538 |
+
""", unsafe_allow_html=True)
|
539 |
+
|
540 |
+
st.markdown("""</div>""", unsafe_allow_html=True)
|
541 |
+
else:
|
542 |
+
# Display a welcome message if no metrics have been calculated yet
|
543 |
+
st.markdown("""
|
544 |
+
<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%;">
|
545 |
+
<img src="https://www.svgrepo.com/show/513354/yoga.svg" width="100">
|
546 |
+
<h2 style="margin: 20px 0;">Welcome to Your Health Journey</h2>
|
547 |
+
<p style="font-size: 16px; margin-bottom: 20px;">Fill in your details and click 'Calculate Health Metrics' to start your personalized wellness plan.</p>
|
548 |
+
<p style="font-style: italic;">"The greatest wealth is health." - Virgil</p>
|
549 |
+
</div>
|
550 |
+
""", unsafe_allow_html=True)
|
551 |
+
|
552 |
+
# Display the generated plan if available
|
553 |
+
if st.session_state.plan_generated:
|
554 |
+
st.markdown("""
|
555 |
+
<div class="plan-section">
|
556 |
+
<h2 style="text-align: center; margin-bottom: 20px;">Your Personalized Health Plan</h2>
|
557 |
+
""", unsafe_allow_html=True)
|
558 |
+
|
559 |
+
st.markdown(st.session_state.plan_content, unsafe_allow_html=True)
|
560 |
+
|
561 |
+
st.markdown("""</div>""", unsafe_allow_html=True)
|
562 |
+
|
563 |
+
with tabs[1]:
|
564 |
+
st.markdown("""
|
565 |
+
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin-bottom: 20px;">
|
566 |
+
<h2 style="text-align: center;">Health Progress Analytics</h2>
|
567 |
+
</div>
|
568 |
+
""", unsafe_allow_html=True)
|
569 |
+
|
570 |
+
# Generate sample data for demo purposes
|
571 |
+
sample_data = generate_sample_data()
|
572 |
+
|
573 |
+
# Choose analysis timeframe
|
574 |
+
timeframe = st.radio("Select Timeframe", options=["7 Days", "14 Days", "30 Days"], horizontal=True)
|
575 |
+
days = int(timeframe.split()[0])
|
576 |
+
filtered_data = sample_data.iloc[-days:]
|
577 |
+
|
578 |
+
# Create multiple charts
|
579 |
+
chart_col1, chart_col2 = st.columns(2)
|
580 |
+
|
581 |
+
with chart_col1:
|
582 |
+
st.subheader("Weight Progress")
|
583 |
+
weight_chart = alt.Chart(filtered_data).mark_line(point=True).encode(
|
584 |
+
x=alt.X('date:T', title='Date'),
|
585 |
+
y=alt.Y('weight:Q', title='Weight (kg)', scale=alt.Scale(zero=False)),
|
586 |
+
tooltip=['date:T', 'weight:Q']
|
587 |
+
).properties(height=300).interactive()
|
588 |
+
st.altair_chart(weight_chart, use_container_width=True)
|
589 |
+
|
590 |
+
with chart_col2:
|
591 |
+
st.subheader("Daily Calorie Intake")
|
592 |
+
calorie_chart = alt.Chart(filtered_data).mark_bar().encode(
|
593 |
+
x=alt.X('date:T', title='Date'),
|
594 |
+
y=alt.Y('calories:Q', title='Calories (kcal)'),
|
595 |
+
color=alt.condition(
|
596 |
+
alt.datum.calories > 2000,
|
597 |
+
alt.value('#ffaa00'),
|
598 |
+
alt.value('#4361ee')
|
599 |
+
),
|
600 |
+
tooltip=['date:T', 'calories:Q']
|
601 |
+
).properties(height=300).interactive()
|
602 |
+
st.altair_chart(calorie_chart, use_container_width=True)
|
603 |
+
|
604 |
+
st.subheader("Daily Steps")
|
605 |
+
steps_chart = alt.Chart(filtered_data).mark_area(
|
606 |
+
line={'color':'#4361ee'},
|
607 |
+
color=alt.Gradient(
|
608 |
+
gradient='linear',
|
609 |
+
stops=[alt.GradientStop(color='white', offset=0),
|
610 |
+
alt.GradientStop(color='#dbeafe', offset=1)],
|
611 |
+
x1=1,
|
612 |
+
x2=1,
|
613 |
+
y1=1,
|
614 |
+
y2=0
|
615 |
+
)
|
616 |
+
).encode(
|
617 |
+
x=alt.X('date:T', title='Date'),
|
618 |
+
y=alt.Y('steps:Q', title='Steps'),
|
619 |
+
tooltip=['date:T', 'steps:Q']
|
620 |
+
).properties(height=250).interactive()
|
621 |
+
st.altair_chart(steps_chart, use_container_width=True)
|
622 |
+
|
623 |
+
# Display key metrics
|
624 |
+
metric_cols = st.columns(4)
|
625 |
+
with metric_cols[0]:
|
626 |
+
st.metric("Average Weight", f"{filtered_data['weight'].mean():.1f} kg", f"{filtered_data['weight'].iloc[-1] - filtered_data['weight'].iloc[0]:.1f} kg")
|
627 |
+
with metric_cols[1]:
|
628 |
+
st.metric("Average Calories", f"{int(filtered_data['calories'].mean())} kcal")
|
629 |
+
with metric_cols[2]:
|
630 |
+
st.metric("Average Steps", f"{int(filtered_data['steps'].mean())}", f"{int(filtered_data['steps'].iloc[-1] - filtered_data['steps'].iloc[0])}")
|
631 |
+
with metric_cols[3]:
|
632 |
+
if st.session_state.daily_calories > 0:
|
633 |
+
calorie_diff = int(filtered_data['calories'].mean() - st.session_state.daily_calories)
|
634 |
+
st.metric("vs. Target Calories", f"{int(st.session_state.daily_calories)} kcal", f"{calorie_diff} kcal")
|
635 |
+
else:
|
636 |
+
st.metric("Calorie Goal Status", "Not set")
|
637 |
|
638 |
+
with tabs[2]:
|
639 |
+
st.markdown("""
|
640 |
+
<div style="background-color: white; border-radius: 8px; padding: 30px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin-bottom: 20px;">
|
641 |
+
<h2 style="text-align: center;">About This Project</h2>
|
642 |
+
<p style="font-size: 16px; margin: 20px 0;">
|
643 |
+
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. Our platform provides:
|
644 |
+
</p>
|
645 |
+
<ul style="margin-left: 20px; font-size: 16px;">
|
646 |
+
<li>Personalized diet and exercise recommendations based on your unique profile</li>
|
647 |
+
<li>Optional Ayurvedic insights tailored to your body type (dosha)</li>
|
648 |
+
<li>Integration with food delivery platforms for convenient meal ordering</li>
|
649 |
+
<li>Wearable device tracking to monitor your progress</li>
|
650 |
+
<li>Adaptive recommendations based on seasonal factors</li>
|
651 |
+
</ul>
|
652 |
+
<p style="font-size: 16px; margin: 20px 0;">
|
653 |
+
This application uses advanced AI technology to generate personalized plans that address individual health goals and preferences.
|
654 |
+
</p>
|
655 |
+
</div>
|
656 |
+
""", unsafe_allow_html=True)
|
657 |
|
658 |
+
# Display team information if available
|
659 |
if has_team_info:
|
660 |
+
st.markdown("""
|
661 |
+
<div style="background-color: white; border-radius: 8px; padding: 30px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);">
|
662 |
+
<h2 style="text-align: center;">Our Team</h2>
|
663 |
+
</div>
|
664 |
+
""", unsafe_allow_html=True)
|
665 |
+
|
666 |
+
# Display team members in a grid
|
667 |
+
team_col1, team_col2 = st.columns(2)
|
668 |
+
|
669 |
+
with team_col1:
|
670 |
+
st.markdown("""
|
671 |
+
<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;">
|
672 |
+
<img src="https://www.svgrepo.com/show/382106/female-avatar-girl-face-woman-user-5.svg" width="100" style="border-radius: 50%;">
|
673 |
+
<h3>Aditi Soni</h3>
|
674 |
+
<p>Project Lead & AI Integration</p>
|
675 |
+
<a href="https://www.linkedin.com/in/aditi-soni-259813285/" target="_blank">LinkedIn Profile</a>
|
676 |
+
</div>
|
677 |
+
""", unsafe_allow_html=True)
|
678 |
+
|
679 |
+
st.markdown("""
|
680 |
+
<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;">
|
681 |
+
<img src="https://www.svgrepo.com/show/382105/female-avatar-girl-face-woman-user-4.svg" width="100" style="border-radius: 50%;">
|
682 |
+
<h3>Aditi Lakhera</h3>
|
683 |
+
<p>Nutrition Science Expert</p>
|
684 |
+
<a href="https://www.linkedin.com/in/aditi-lakhera-b628802bb/" target="_blank">LinkedIn Profile</a>
|
685 |
+
</div>
|
686 |
+
""", unsafe_allow_html=True)
|
687 |
+
|
688 |
+
with team_col2:
|
689 |
+
st.markdown("""
|
690 |
+
<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;">
|
691 |
+
<img src="https://www.svgrepo.com/show/382101/female-avatar-girl-face-woman-user.svg" width="100" style="border-radius: 50%;">
|
692 |
+
<h3>Bhumika Patel</h3>
|
693 |
+
<p>Machine Learning Engineer</p>
|
694 |
+
<a href="https://www.linkedin.com/in/bhumika-patel-ml/" target="_blank">LinkedIn Profile</a>
|
695 |
+
</div>
|
696 |
+
""", unsafe_allow_html=True)
|
697 |
+
|
698 |
+
st.markdown("""
|
699 |
+
<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;">
|
700 |
+
<img src="https://www.svgrepo.com/show/382103/female-avatar-girl-face-woman-user-2.svg" width="100" style="border-radius: 50%;">
|
701 |
+
<h3>Anushri Tiwari</h3>
|
702 |
+
<p>UI/UX Designer</p>
|
703 |
+
<a href="https://www.linkedin.com/in/anushri-tiwari-916494300" target="_blank">LinkedIn Profile</a>
|
704 |
+
</div>
|
705 |
+
""", unsafe_allow_html=True)
|
706 |
+
|
707 |
+
# Project links
|
708 |
+
st.markdown("""
|
709 |
+
<div style="background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); margin-top: 20px; text-align: center;">
|
710 |
+
<h3>Project Links</h3>
|
711 |
+
<p>
|
712 |
+
<a href="https://github.com/Abs6187/AI_Health_v2" target="_blank" style="margin: 0 10px;">GitHub Repository</a>
|
713 |
+
<a href="https://github.com/Abs6187/AI_Health_v2/blob/main/HackGirl_PPT_HackSRIT.pptx" target="_blank" style="margin: 0 10px;">Presentation</a>
|
714 |
+
<a href="https://unstop.com/hackathons/hacksrit-shri-ram-group-of-institutions-jabalpur-1471613" target="_blank" style="margin: 0 10px;">Hackathon</a>
|
715 |
+
</p>
|
716 |
+
</div>
|
717 |
+
""", unsafe_allow_html=True)
|
718 |
+
|
719 |
+
# Add a custom footer
|
720 |
+
st.markdown("""
|
721 |
+
<div style="text-align: center; margin-top: 30px; padding: 20px; font-size: 14px; color: #6b7280;">
|
722 |
+
<p>© 2025 AI Health & Wellness Planner. Current version: 2.1.0</p>
|
723 |
+
<p>Last updated: May 10, 2025</p>
|
724 |
+
</div>
|
725 |
+
""", unsafe_allow_html=True)
|