File size: 5,384 Bytes
1f6d7ba
7f56c8a
1f6d7ba
7f56c8a
 
 
8d6f3e2
1f6d7ba
7f56c8a
c704836
7f56c8a
 
 
 
 
 
 
 
 
 
 
 
 
850b633
7f56c8a
850b633
 
7f56c8a
 
850b633
 
 
 
 
 
 
 
7f56c8a
850b633
7f56c8a
850b633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d6f3e2
850b633
8d6f3e2
 
 
 
 
 
 
 
 
7f56c8a
8d6f3e2
7f56c8a
850b633
c704836
8d6f3e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f56c8a
8d6f3e2
7f56c8a
850b633
8d6f3e2
 
 
 
 
 
 
7f56c8a
 
 
850b633
7f56c8a
 
 
850b633
7f56c8a
850b633
7f56c8a
 
850b633
 
7f56c8a
 
850b633
 
7f56c8a
 
 
 
 
 
 
 
 
 
 
 
850b633
7f56c8a
850b633
7f56c8a
 
 
 
8d6f3e2
850b633
 
8d6f3e2
7f56c8a
850b633
 
 
 
 
 
 
 
 
7f56c8a
 
 
850b633
7f56c8a
 
 
 
 
 
850b633
 
7f56c8a
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
import streamlit as st
from transformers import pipeline

# ---------------------------------------------------
# PAGE CONFIG
# ---------------------------------------------------
st.set_page_config(page_title="FitPlan AI", layout="centered")

st.title("πŸ‹οΈ FitPlan AI – Personalized Fitness Plan")

# ---------------------------------------------------
# LOAD MODEL (Cached)
# ---------------------------------------------------
@st.cache_resource
def load_model():
    return pipeline(
        "text-generation",
        model="google/flan-t5-base"
    )

generator = load_model()

# ---------------------------------------------------
# USER DETAILS
# ---------------------------------------------------
st.subheader("πŸ‘€ Personal Information")

name = st.text_input("Enter Your Name")

col1, col2 = st.columns(2)

with col1:
    height = st.number_input("Height (in cm)", min_value=100, max_value=250, value=170)

with col2:
    weight = st.number_input("Weight (in kg)", min_value=30, max_value=200, value=70)

# ---------------------------------------------------
# BMI CALCULATION
# ---------------------------------------------------
bmi = None
bmi_category = ""

if height > 0 and weight > 0:
    height_m = height / 100
    bmi = weight / (height_m ** 2)

    st.write(f"### πŸ“Š Your BMI: {bmi:.2f}")

    if bmi < 18.5:
        bmi_category = "Underweight"
        st.info("Category: Underweight")
    elif 18.5 <= bmi < 24.9:
        bmi_category = "Normal weight"
        st.success("Category: Normal weight")
    elif 25 <= bmi < 29.9:
        bmi_category = "Overweight"
        st.warning("Category: Overweight")
    else:
        bmi_category = "Obese"
        st.error("Category: Obese")

# ---------------------------------------------------
# GOAL
# ---------------------------------------------------
st.subheader("🎯 Fitness Goal")

goal = st.selectbox(
    "",
    [
        "Flexible",
        "Weight Loss",
        "Build Muscle",
        "Strength Gaining",
        "Abs Building"
    ]
)

# ---------------------------------------------------
# EQUIPMENT
# ---------------------------------------------------
st.subheader("πŸ‹οΈ Available Equipment")

col1, col2 = st.columns(2)

with col1:
    dumbbells = st.checkbox("Dumbbells")
    resistance_band = st.checkbox("Resistance Band")
    yoga_mat = st.checkbox("Yoga Mat")
    no_equipment = st.checkbox("No Equipment")
    inclined_bench = st.checkbox("Inclined Bench")
    treadmill = st.checkbox("Treadmill")
    cycle = st.checkbox("Cycle")

with col2:
    skipping_rope = st.checkbox("Skipping Rope")
    hand_gripper = st.checkbox("Hand Gripper")
    pullups_bar = st.checkbox("Pullups Bar")
    weight_plates = st.checkbox("Weight Plates")
    hula_hoop = st.checkbox("Hula Hoop Ring")
    bosu_ball = st.checkbox("Bosu Ball")

equipment = []

equipment_map = {
    "Dumbbells": dumbbells,
    "Resistance Band": resistance_band,
    "Yoga Mat": yoga_mat,
    "No Equipment": no_equipment,
    "Inclined Bench": inclined_bench,
    "Treadmill": treadmill,
    "Cycle": cycle,
    "Skipping Rope": skipping_rope,
    "Hand Gripper": hand_gripper,
    "Pullups Bar": pullups_bar,
    "Weight Plates": weight_plates,
    "Hula Hoop Ring": hula_hoop,
    "Bosu Ball": bosu_ball,
}

for item, selected in equipment_map.items():
    if selected:
        equipment.append(item)

# ---------------------------------------------------
# FITNESS LEVEL
# ---------------------------------------------------
st.subheader("πŸ“ˆ Fitness Level")

fitness_level = st.radio(
    "",
    ["Beginner", "Intermediate", "Advanced"],
    horizontal=True
)

# ---------------------------------------------------
# PROMPT BUILDER
# ---------------------------------------------------
def build_prompt(name, goal, fitness_level, equipment, bmi, bmi_category):
    equipment_text = ", ".join(equipment)

    prompt = f"""
    Generate a detailed 5-day personalized workout plan.

    Name: {name}
    Goal: {goal}
    Fitness Level: {fitness_level}
    BMI: {bmi:.2f}
    BMI Category: {bmi_category}
    Available Equipment: {equipment_text}

    Adjust workout intensity according to BMI and fitness level.

    Include:
    - Day-wise workout split
    - Exercises
    - Sets and reps
    - Rest time
    - Warm-up and cool-down
    """

    return prompt


# ---------------------------------------------------
# GENERATE PLAN BUTTON
# ---------------------------------------------------
if st.button("πŸš€ Generate Personalized Plan"):

    if not name:
        st.error("Please enter your name.")
    elif not equipment:
        st.error("Please select at least one equipment option.")
    elif bmi is None:
        st.error("Please enter valid height and weight.")
    else:
        with st.spinner("Generating your AI workout plan..."):

            prompt = build_prompt(
                name,
                goal,
                fitness_level,
                equipment,
                bmi,
                bmi_category
            )

            result = generator(
                prompt,
                max_length=600,
                do_sample=True,
                temperature=0.7
            )

            plan = result[0]["generated_text"]

        st.success(f"βœ… Plan Generated Successfully, {name}!")
        st.markdown("## πŸ“ Your Personalized Workout Plan")
        st.write(plan)