Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- README.md +7 -5
- app.py +133 -0
- env +1 -0
- gitattributes +35 -0
- requirements.txt +6 -0
README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
---
|
2 |
-
title: AI
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
|
|
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
|
|
1 |
---
|
2 |
+
title: AI-Health Advisor
|
3 |
+
emoji: π
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: purple
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.41.1
|
8 |
+
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
app.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from langchain_groq import ChatGroq
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Load environment variables
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Initialize the model
|
11 |
+
model = ChatGroq(model="llama3-8b-8192")
|
12 |
+
|
13 |
+
# Function to calculate daily calorie requirements
|
14 |
+
def calculate_calorie_requirements(age, gender, weight, height, fitness_goal):
|
15 |
+
if gender == "Male":
|
16 |
+
bmr = 10 * weight + 6.25 * height - 5 * age + 5
|
17 |
+
else:
|
18 |
+
bmr = 10 * weight + 6.25 * height - 5 * age - 161
|
19 |
+
|
20 |
+
if fitness_goal == "Weight Loss":
|
21 |
+
return bmr * 1.2
|
22 |
+
elif fitness_goal == "Weight Gain":
|
23 |
+
return bmr * 1.5
|
24 |
+
else:
|
25 |
+
return bmr * 1.375
|
26 |
+
|
27 |
+
# Function to generate the plan
|
28 |
+
def generate_plan_with_prompt(metrics, prompt_template):
|
29 |
+
prompt = prompt_template.format(**metrics)
|
30 |
+
response = model.invoke(prompt)
|
31 |
+
return response
|
32 |
+
|
33 |
+
# Function to format the response neatly
|
34 |
+
def format_plan(response):
|
35 |
+
try:
|
36 |
+
content = response.content
|
37 |
+
sections = content.split("\n\n")
|
38 |
+
formatted = ""
|
39 |
+
for section in sections:
|
40 |
+
formatted += f"**{section.strip()}**\n\n"
|
41 |
+
return formatted
|
42 |
+
except Exception as e:
|
43 |
+
return f"Error formatting plan: {e}"
|
44 |
+
|
45 |
+
# Prompt template
|
46 |
+
prompt_template = """
|
47 |
+
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}).
|
48 |
+
|
49 |
+
Fitness Goal: {fitness_goal}.
|
50 |
+
Daily Calorie Requirement: {daily_calories} kcal.
|
51 |
+
Dietary Preference: {dietary_preference}.
|
52 |
+
Food Allergies: {food_allergies}.
|
53 |
+
Local Cuisine: {local_cuisine}.
|
54 |
+
Month: {month}.
|
55 |
+
|
56 |
+
Plan should include:
|
57 |
+
1. A daily diet plan with meal timings, calorie details, and meal alternatives.
|
58 |
+
2. Exercise routines based on goals, incorporating cardio, strength, and flexibility.
|
59 |
+
3. Dynamic plan adjustments based on month and local cuisine preferences.
|
60 |
+
4. Wearable integration for tracking steps, heart rate, and calorie burn.
|
61 |
+
5. Progress monitoring for daily calorie burn and weight tracking.
|
62 |
+
6. **Food Delivery Integration**:
|
63 |
+
- Meal suggestions based on diet plans.
|
64 |
+
- Integration with food delivery platforms (Uber Eats, DoorDash).
|
65 |
+
- Searching menu items that fit calorie and dietary preferences.
|
66 |
+
- Multi-restaurant meal aggregation for complete diet fulfillment.
|
67 |
+
- Location-based meal recommendations.
|
68 |
+
- Customizable meal delivery schedules.
|
69 |
+
|
70 |
+
Provide a detailed plan for each weekday: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
|
71 |
+
|
72 |
+
Return output as:
|
73 |
+
Day: {{weekday}}
|
74 |
+
- Breakfast: Time, Description, Calories
|
75 |
+
- Lunch: Time, Description, Calories
|
76 |
+
- Snacks: Time, Description, Calories
|
77 |
+
- Dinner: Time, Description, Calories
|
78 |
+
- Exercise: Description, Duration
|
79 |
+
- Wearable Tracking: Steps, Heart Rate, Calories Burned
|
80 |
+
- Progress Monitoring: Daily calorie intake vs. burn.
|
81 |
+
- Food Delivery: Suggested meal items and delivery options.
|
82 |
+
"""
|
83 |
+
|
84 |
+
# Streamlit app
|
85 |
+
st.title("AI-Based Personalized Weekly Diet and Exercise Planner")
|
86 |
+
|
87 |
+
# Input fields
|
88 |
+
st.header("Enter Your Details")
|
89 |
+
name = st.text_input("Name")
|
90 |
+
age = st.number_input("Age", min_value=1, value=25)
|
91 |
+
weight = st.number_input("Weight (kg)", min_value=1, value=70)
|
92 |
+
height = st.number_input("Height (cm)", min_value=1, value=170)
|
93 |
+
gender = st.selectbox("Gender", options=["Male", "Female", "Other"])
|
94 |
+
fitness_goal = st.selectbox("Fitness Goal", options=["Weight Loss", "Weight Gain", "Maintenance"])
|
95 |
+
dietary_preference = st.selectbox("Dietary Preference", options=["Vegetarian", "Vegan", "Keto", "Halal", "None"])
|
96 |
+
food_allergies = st.text_input("Food Allergies (if any)")
|
97 |
+
local_cuisine = st.text_input("Preferred Local Cuisine (e.g., Indian, Italian, Chinese)")
|
98 |
+
month = st.selectbox("Select Month", options=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"])
|
99 |
+
|
100 |
+
bmi = round(weight / (height / 100) ** 2, 2)
|
101 |
+
health_status = "Underweight" if bmi < 18.5 else "Normal weight" if bmi <= 24.9 else "Overweight"
|
102 |
+
daily_calories = calculate_calorie_requirements(age, gender, weight, height, fitness_goal)
|
103 |
+
|
104 |
+
st.write(f"Your BMI is {bmi}, which indicates {health_status}.")
|
105 |
+
st.write(f"Your daily calorie requirement is approximately {int(daily_calories)} kcal.")
|
106 |
+
|
107 |
+
# User metrics
|
108 |
+
metrics = {
|
109 |
+
"name": name,
|
110 |
+
"age": age,
|
111 |
+
"gender": gender,
|
112 |
+
"bmi": bmi,
|
113 |
+
"health_status": health_status,
|
114 |
+
"fitness_goal": fitness_goal,
|
115 |
+
"dietary_preference": dietary_preference,
|
116 |
+
"food_allergies": food_allergies,
|
117 |
+
"daily_calories": int(daily_calories),
|
118 |
+
"local_cuisine": local_cuisine,
|
119 |
+
"weekdays": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
120 |
+
"month": month,
|
121 |
+
}
|
122 |
+
|
123 |
+
# Generate and display plan
|
124 |
+
if st.button("Generate Plan"):
|
125 |
+
with st.spinner("Generating your plan..."):
|
126 |
+
try:
|
127 |
+
plan = generate_plan_with_prompt(metrics, prompt_template)
|
128 |
+
formatted_plan = format_plan(plan)
|
129 |
+
st.header(f"Generated Diet and Exercise Plan for {month}")
|
130 |
+
st.markdown(formatted_plan)
|
131 |
+
except Exception as e:
|
132 |
+
st.error(f"Error generating the plan: {e}")
|
133 |
+
|
env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
GROQ_API_KEY="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"
|
gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
langchain-core
|
3 |
+
langchain-groq
|
4 |
+
python-dotenv
|
5 |
+
torch
|
6 |
+
|