Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Function to calculate Basal Metabolic Rate (BMR) using the Mifflin-St Jeor Equation
|
4 |
+
def calculate_bmr(gender, age, weight, height):
|
5 |
+
if gender == 'Male':
|
6 |
+
# Mifflin-St Jeor Equation for Men: BMR = 10 * weight + 6.25 * height - 5 * age + 5
|
7 |
+
bmr = 10 * weight + 6.25 * height - 5 * age + 5
|
8 |
+
else:
|
9 |
+
# Mifflin-St Jeor Equation for Women: BMR = 10 * weight + 6.25 * height - 5 * age - 161
|
10 |
+
bmr = 10 * weight + 6.25 * height - 5 * age - 161
|
11 |
+
return bmr
|
12 |
+
|
13 |
+
# Function to calculate daily caloric needs based on activity level
|
14 |
+
def calculate_calories(bmr, activity_level):
|
15 |
+
activity_factor = {
|
16 |
+
'Sedentary (little or no exercise)': 1.2,
|
17 |
+
'Lightly Active (light exercise or sports 1-3 days a week)': 1.375,
|
18 |
+
'Moderately Active (moderate exercise or sports 3-5 days a week)': 1.55,
|
19 |
+
'Very Active (hard exercise or sports 6-7 days a week)': 1.725,
|
20 |
+
'Super Active (very hard exercise or physical job)': 1.9
|
21 |
+
}
|
22 |
+
calories = bmr * activity_factor[activity_level]
|
23 |
+
return calories
|
24 |
+
|
25 |
+
# Function to suggest a basic diet plan based on caloric needs
|
26 |
+
def generate_diet_plan(calories):
|
27 |
+
if calories < 1800:
|
28 |
+
return "Suggested Diet Plan: \n- Breakfast: Oatmeal with fruits \n- Snack: Yogurt with nuts \n- Lunch: Grilled chicken with vegetables \n- Snack: Fruits \n- Dinner: Salmon with steamed broccoli"
|
29 |
+
elif calories < 2500:
|
30 |
+
return "Suggested Diet Plan: \n- Breakfast: Scrambled eggs with toast and avocado \n- Snack: Protein shake \n- Lunch: Turkey and quinoa salad \n- Snack: Hummus with carrot sticks \n- Dinner: Grilled steak with sweet potatoes"
|
31 |
+
else:
|
32 |
+
return "Suggested Diet Plan: \n- Breakfast: Protein pancakes with berries \n- Snack: Mixed nuts and protein bar \n- Lunch: Grilled chicken with rice and veggies \n- Snack: Cottage cheese with fruit \n- Dinner: Beef stir-fry with vegetables and noodles"
|
33 |
+
|
34 |
+
# Streamlit UI setup
|
35 |
+
st.title("Diet Plan Generator")
|
36 |
+
|
37 |
+
st.markdown("""
|
38 |
+
This application generates a personalized diet plan based on your gender, age, weight, height, and activity level.
|
39 |
+
Please enter your details to get started!
|
40 |
+
""")
|
41 |
+
|
42 |
+
# Sidebar for input values
|
43 |
+
st.sidebar.header("Input Your Details")
|
44 |
+
gender = st.sidebar.selectbox("Gender", ["Male", "Female"])
|
45 |
+
age = st.sidebar.number_input("Age", min_value=18, max_value=100, value=25)
|
46 |
+
weight = st.sidebar.number_input("Weight (in kg)", min_value=30, max_value=200, value=70)
|
47 |
+
height = st.sidebar.number_input("Height (in cm)", min_value=100, max_value=250, value=170)
|
48 |
+
|
49 |
+
activity_level = st.sidebar.selectbox(
|
50 |
+
"Activity Level",
|
51 |
+
['Sedentary (little or no exercise)', 'Lightly Active (light exercise or sports 1-3 days a week)',
|
52 |
+
'Moderately Active (moderate exercise or sports 3-5 days a week)',
|
53 |
+
'Very Active (hard exercise or sports 6-7 days a week)', 'Super Active (very hard exercise or physical job)']
|
54 |
+
)
|
55 |
+
|
56 |
+
# Calculate BMR and Daily Caloric Needs
|
57 |
+
bmr = calculate_bmr(gender, age, weight, height)
|
58 |
+
daily_calories = calculate_calories(bmr, activity_level)
|
59 |
+
|
60 |
+
# Generate Diet Plan
|
61 |
+
diet_plan = generate_diet_plan(daily_calories)
|
62 |
+
|
63 |
+
# Create interactive columns for a clean layout
|
64 |
+
col1, col2 = st.columns(2)
|
65 |
+
|
66 |
+
with col1:
|
67 |
+
st.subheader("Your Profile")
|
68 |
+
st.write(f"**Gender**: {gender}")
|
69 |
+
st.write(f"**Age**: {age} years")
|
70 |
+
st.write(f"**Weight**: {weight} kg")
|
71 |
+
st.write(f"**Height**: {height} cm")
|
72 |
+
st.write(f"**Activity Level**: {activity_level}")
|
73 |
+
|
74 |
+
with col2:
|
75 |
+
st.subheader("Your Estimated Daily Caloric Needs")
|
76 |
+
st.write(f"**BMR (Basal Metabolic Rate)**: {bmr:.2f} kcal/day")
|
77 |
+
st.write(f"**Total Daily Calories**: {daily_calories:.2f} kcal/day")
|
78 |
+
|
79 |
+
# Display the suggested diet plan
|
80 |
+
st.subheader("Suggested Diet Plan:")
|
81 |
+
st.write(diet_plan)
|