File size: 3,548 Bytes
1cf42ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ecf138
1cf42ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8601c9
 
72d882d
4645e60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1cf42ec
 
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
import streamlit as st

from transformers import pipeline



# -------------------------

# PAGE CONFIG

# -------------------------

st.set_page_config(page_title="FitPlan-AI", page_icon="💪")



# -------------------------

# BMI FUNCTIONS

# -------------------------

def calculate_bmi(weight, height_cm):

    height_m = height_cm / 100

    return round(weight / (height_m ** 2), 2)



def get_category(bmi):

    if bmi < 18.5:

        return "Underweight"

    elif bmi < 24.9:

        return "Normal"

    elif bmi < 29.9:

        return "Overweight"

    else:

        return "Obese"



# -------------------------

# LOAD AI MODEL

# -------------------------

@st.cache_resource

def load_model():

    return pipeline(

        "text2text-generation",  # Correct for FLAN-T5

        model="google/flan-t5-base"

    )



generator = load_model()



# -------------------------

# UI STARTS

# -------------------------

st.title("💪 FitPlan-AI: Personalized Fitness Profile")



# Form to collect all inputs

with st.form("fitness_form"):



    st.subheader("Personal Information")

    name = st.text_input("Full Name*", placeholder="Enter your name")



    col1, col2 = st.columns(2)

    with col1:

        height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)

    with col2:

        weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)



    st.subheader("Fitness Details")

    goal = st.selectbox(

        "Fitness Goal",

        ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]

    )

    level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])

    equipment = st.multiselect(

        "Available Equipment",

        ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"]

    )



    # -------------------------

    # SUBMIT BUTTON AT BOTTOM

    # -------------------------

    submit = st.form_submit_button("Submit Profile")
    # -------------------------
    # HANDLE SUBMISSION
    # -------------------------
    if submit:
        # Validation (Indented from here downwards)
        if not name.strip():
            st.error("Please enter your name.")
        elif height <= 0 or weight <= 0:
            st.error("Height and Weight must be positive values.")
        elif not equipment:
            st.error("Please select at least one equipment option.")
        else:
            # Calculate BMI
            user_bmi = calculate_bmi(weight, height)
            bmi_status = get_category(user_bmi)

            st.success(f"✅ Profile Created Successfully for {name}!")
            st.metric("Your BMI", user_bmi)
            st.info(f"Health Category: **{bmi_status}**")

            equipment_list = ", ".join(equipment)

            # Prepare AI prompt
            prompt = f"""
            Create a professional 5-day structured workout plan.
            User Details:
            Name: {name}
            BMI: {user_bmi} ({bmi_status})
            Goal: {goal}
            Fitness Level: {level}
            Equipment: {equipment_list}
            Include:
            - Warm-up
            - Exercises with sets and reps
            - Rest time
            - Intensity adjustment
            - Day-wise structure
            """

            with st.spinner("Generating your AI workout plan..."):
                result = generator(prompt, max_new_tokens=400)[0]["generated_text"]

            st.subheader("🏋️ Your Personalized Workout Plan")
            st.write(result)