File size: 3,767 Bytes
341f0d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st

# Function to calculate Basal Metabolic Rate (BMR) using the Mifflin-St Jeor Equation
def calculate_bmr(gender, age, weight, height):
    if gender == 'Male':
        # Mifflin-St Jeor Equation for Men: BMR = 10 * weight + 6.25 * height - 5 * age + 5
        bmr = 10 * weight + 6.25 * height - 5 * age + 5
    else:
        # Mifflin-St Jeor Equation for Women: BMR = 10 * weight + 6.25 * height - 5 * age - 161
        bmr = 10 * weight + 6.25 * height - 5 * age - 161
    return bmr

# Function to calculate daily caloric needs based on activity level
def calculate_calories(bmr, activity_level):
    activity_factor = {
        'Sedentary (little or no exercise)': 1.2,
        'Lightly Active (light exercise or sports 1-3 days a week)': 1.375,
        'Moderately Active (moderate exercise or sports 3-5 days a week)': 1.55,
        'Very Active (hard exercise or sports 6-7 days a week)': 1.725,
        'Super Active (very hard exercise or physical job)': 1.9
    }
    calories = bmr * activity_factor[activity_level]
    return calories

# Function to suggest a basic diet plan based on caloric needs
def generate_diet_plan(calories):
    if calories < 1800:
        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"
    elif calories < 2500:
        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"
    else:
        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"

# Streamlit UI setup
st.title("Diet Plan Generator")

st.markdown("""
    This application generates a personalized diet plan based on your gender, age, weight, height, and activity level.
    Please enter your details to get started!
""")

# Sidebar for input values
st.sidebar.header("Input Your Details")
gender = st.sidebar.selectbox("Gender", ["Male", "Female"])
age = st.sidebar.number_input("Age", min_value=18, max_value=100, value=25)
weight = st.sidebar.number_input("Weight (in kg)", min_value=30, max_value=200, value=70)
height = st.sidebar.number_input("Height (in cm)", min_value=100, max_value=250, value=170)

activity_level = st.sidebar.selectbox(
    "Activity Level",
    ['Sedentary (little or no exercise)', 'Lightly Active (light exercise or sports 1-3 days a week)', 
     'Moderately Active (moderate exercise or sports 3-5 days a week)', 
     'Very Active (hard exercise or sports 6-7 days a week)', 'Super Active (very hard exercise or physical job)']
)

# Calculate BMR and Daily Caloric Needs
bmr = calculate_bmr(gender, age, weight, height)
daily_calories = calculate_calories(bmr, activity_level)

# Generate Diet Plan
diet_plan = generate_diet_plan(daily_calories)

# Create interactive columns for a clean layout
col1, col2 = st.columns(2)

with col1:
    st.subheader("Your Profile")
    st.write(f"**Gender**: {gender}")
    st.write(f"**Age**: {age} years")
    st.write(f"**Weight**: {weight} kg")
    st.write(f"**Height**: {height} cm")
    st.write(f"**Activity Level**: {activity_level}")
    
with col2:
    st.subheader("Your Estimated Daily Caloric Needs")
    st.write(f"**BMR (Basal Metabolic Rate)**: {bmr:.2f} kcal/day")
    st.write(f"**Total Daily Calories**: {daily_calories:.2f} kcal/day")
    
# Display the suggested diet plan
st.subheader("Suggested Diet Plan:")
st.write(diet_plan)