srustik123 commited on
Commit
aae77cb
·
verified ·
1 Parent(s): 58cc220

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -74
app.py CHANGED
@@ -8,6 +8,12 @@ import os
8
  st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
9
  st.title("💪 FitPlan-AI: Personalized Fitness Profile")
10
 
 
 
 
 
 
 
11
  # -------------------------
12
  # LOAD HF CLIENT (CACHED)
13
  # -------------------------
@@ -41,62 +47,54 @@ def get_category(bmi):
41
  return "Obese"
42
 
43
  # -------------------------
44
- # PROMPT BUILDER
45
  # -------------------------
46
- def build_prompt(name, height, weight, goal, level, equipment, bmi, bmi_status):
47
  equipment_list = ", ".join(equipment)
48
 
49
  prompt = f"""
50
  You are a certified professional fitness trainer.
51
-
52
  IMPORTANT:
53
  - Do NOT write introduction.
54
  - Do NOT write explanation.
55
  - Do NOT give nutrition advice.
56
  - Output ONLY the workout plan.
57
  - Keep it concise.
58
-
59
  Client Details:
60
  Name: {name}
 
61
  Height: {height} cm
62
  Weight: {weight} kg
63
  BMI: {bmi} ({bmi_status})
64
  Goal: {goal}
65
  Fitness Level: {level}
66
  Available Equipment: {equipment_list}
67
-
68
  STRICT FORMAT:
69
-
70
  Day 1:
71
  Warm-up:
72
  Main Workout (sets x reps):
73
  Rest:
74
  Cooldown:
75
-
76
  Day 2:
77
  Warm-up:
78
  Main Workout (sets x reps):
79
  Rest:
80
  Cooldown:
81
-
82
  Day 3:
83
  Warm-up:
84
  Main Workout (sets x reps):
85
  Rest:
86
  Cooldown:
87
-
88
  Day 4:
89
  Warm-up:
90
  Main Workout (sets x reps):
91
  Rest:
92
  Cooldown:
93
-
94
  Day 5:
95
  Warm-up:
96
  Main Workout (sets x reps):
97
  Rest:
98
  Cooldown:
99
-
100
  Each day must contain 4–5 exercises only.
101
  Keep total response under 900 words.
102
  """
@@ -124,79 +122,118 @@ def query_model(prompt):
124
  except Exception as e:
125
  return f"⚠️ Model Error: {str(e)}"
126
 
127
- # -------------------------
128
- # FORM
129
- # -------------------------
130
- with st.form("fitness_form"):
131
 
132
- st.subheader("Personal Information")
133
 
134
- name = st.text_input("Full Name*", placeholder="Enter your name")
135
 
136
- col1, col2 = st.columns(2)
137
- with col1:
138
- height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
139
- with col2:
140
- weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
141
 
142
- st.subheader("Fitness Details")
143
 
144
- goal = st.selectbox(
145
- "Fitness Goal",
146
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexibility"]
147
- )
 
148
 
149
- level = st.radio(
150
- "Fitness Level",
151
- ["Beginner", "Intermediate", "Advanced"]
152
- )
153
 
154
- equipment = st.multiselect(
155
- "Available Equipment",
156
- ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment",
157
- "Kettlebell", "Pull-up Bar"]
158
- )
159
 
160
- submit = st.form_submit_button("Submit Profile")
 
 
 
161
 
162
- # -------------------------
163
- # HANDLE SUBMISSION
164
- # -------------------------
165
- if submit:
 
166
 
167
- if not name:
168
- st.error("Please enter your name.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
- elif height <= 0 or weight <= 0:
171
- st.error("Please enter valid height and weight.")
172
 
173
- elif not equipment:
174
- st.error("Please select at least one equipment option.")
175
 
176
- else:
177
- st.success("Profile Submitted Successfully!")
178
-
179
- # BMI Calculation
180
- bmi = calculate_bmi(weight, height)
181
- bmi_status = get_category(bmi)
182
-
183
- st.write(f"### 📊 Your BMI: {bmi} ({bmi_status})")
184
-
185
- # Generate Plan
186
- with st.spinner("Generating your 5-day workout plan..."):
187
- prompt = build_prompt(
188
- name=name,
189
- height=height,
190
- weight=weight,
191
- goal=goal,
192
- level=level,
193
- equipment=equipment,
194
- bmi=bmi,
195
- bmi_status=bmi_status
196
- )
197
-
198
- full_plan = query_model(prompt)
199
-
200
- # Display Plan
201
- st.subheader("🏋️ Your Personalized 5-Day Workout Plan")
202
- st.write(full_plan)
 
8
  st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
9
  st.title("💪 FitPlan-AI: Personalized Fitness Profile")
10
 
11
+ # -------------------------
12
+ # SESSION STATE FOR PAGE NAVIGATION
13
+ # -------------------------
14
+ if "page" not in st.session_state:
15
+ st.session_state.page = "form"
16
+
17
  # -------------------------
18
  # LOAD HF CLIENT (CACHED)
19
  # -------------------------
 
47
  return "Obese"
48
 
49
  # -------------------------
50
+ # PROMPT BUILDER (AGE ADDED)
51
  # -------------------------
52
+ def build_prompt(name, age, height, weight, goal, level, equipment, bmi, bmi_status):
53
  equipment_list = ", ".join(equipment)
54
 
55
  prompt = f"""
56
  You are a certified professional fitness trainer.
 
57
  IMPORTANT:
58
  - Do NOT write introduction.
59
  - Do NOT write explanation.
60
  - Do NOT give nutrition advice.
61
  - Output ONLY the workout plan.
62
  - Keep it concise.
 
63
  Client Details:
64
  Name: {name}
65
+ Age: {age}
66
  Height: {height} cm
67
  Weight: {weight} kg
68
  BMI: {bmi} ({bmi_status})
69
  Goal: {goal}
70
  Fitness Level: {level}
71
  Available Equipment: {equipment_list}
 
72
  STRICT FORMAT:
 
73
  Day 1:
74
  Warm-up:
75
  Main Workout (sets x reps):
76
  Rest:
77
  Cooldown:
 
78
  Day 2:
79
  Warm-up:
80
  Main Workout (sets x reps):
81
  Rest:
82
  Cooldown:
 
83
  Day 3:
84
  Warm-up:
85
  Main Workout (sets x reps):
86
  Rest:
87
  Cooldown:
 
88
  Day 4:
89
  Warm-up:
90
  Main Workout (sets x reps):
91
  Rest:
92
  Cooldown:
 
93
  Day 5:
94
  Warm-up:
95
  Main Workout (sets x reps):
96
  Rest:
97
  Cooldown:
 
98
  Each day must contain 4–5 exercises only.
99
  Keep total response under 900 words.
100
  """
 
122
  except Exception as e:
123
  return f"⚠️ Model Error: {str(e)}"
124
 
125
+ # =========================
126
+ # PAGE 1 → FORM
127
+ # =========================
128
+ if st.session_state.page == "form":
129
 
130
+ with st.form("fitness_form"):
131
 
132
+ st.subheader("Personal Information")
133
 
134
+ name = st.text_input("Full Name*", placeholder="Enter your name")
 
 
 
 
135
 
136
+ age = st.number_input("Age*", min_value=18, max_value=65, step=1)
137
 
138
+ col1, col2 = st.columns(2)
139
+ with col1:
140
+ height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
141
+ with col2:
142
+ weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
143
 
144
+ st.subheader("Fitness Details")
 
 
 
145
 
146
+ goal = st.selectbox(
147
+ "Fitness Goal",
148
+ ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexibility"]
149
+ )
 
150
 
151
+ level = st.radio(
152
+ "Fitness Level",
153
+ ["Beginner", "Intermediate", "Advanced"]
154
+ )
155
 
156
+ equipment = st.multiselect(
157
+ "Available Equipment",
158
+ ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment",
159
+ "Kettlebell", "Pull-up Bar"]
160
+ )
161
 
162
+ submit = st.form_submit_button("Submit Profile")
163
+
164
+ # -------------------------
165
+ # HANDLE SUBMISSION
166
+ # -------------------------
167
+ if submit:
168
+
169
+ if not name:
170
+ st.error("Please enter your name.")
171
+
172
+ elif height <= 0 or weight <= 0:
173
+ st.error("Please enter valid height and weight.")
174
+
175
+ elif not equipment:
176
+ st.error("Please select at least one equipment option.")
177
+
178
+ else:
179
+ # Store in session
180
+ st.session_state.name = name
181
+ st.session_state.age = age
182
+ st.session_state.height = height
183
+ st.session_state.weight = weight
184
+ st.session_state.goal = goal
185
+ st.session_state.level = level
186
+ st.session_state.equipment = equipment
187
+
188
+ st.session_state.page = "result"
189
+ st.rerun()
190
+
191
+ # =========================
192
+ # PAGE 2 → RESULT
193
+ # =========================
194
+ if st.session_state.page == "result":
195
+
196
+ name = st.session_state.name
197
+ age = st.session_state.age
198
+ height = st.session_state.height
199
+ weight = st.session_state.weight
200
+ goal = st.session_state.goal
201
+ level = st.session_state.level
202
+ equipment = st.session_state.equipment
203
+
204
+ st.success("Profile Submitted Successfully!")
205
+
206
+ bmi = calculate_bmi(weight, height)
207
+ bmi_status = get_category(bmi)
208
+
209
+ st.write("## 📋 Your Personal Information")
210
+ st.write(f"**Name:** {name}")
211
+ st.write(f"**Age:** {age}")
212
+ st.write(f"**Height:** {height} cm")
213
+ st.write(f"**Weight:** {weight} kg")
214
+ st.write(f"**BMI:** {bmi} ({bmi_status})")
215
+ st.write(f"**Goal:** {goal}")
216
+ st.write(f"**Fitness Level:** {level}")
217
+ st.write(f"**Equipment:** {', '.join(equipment)}")
218
+
219
+ with st.spinner("Generating your 5-day workout plan..."):
220
+ prompt = build_prompt(
221
+ name=name,
222
+ age=age,
223
+ height=height,
224
+ weight=weight,
225
+ goal=goal,
226
+ level=level,
227
+ equipment=equipment,
228
+ bmi=bmi,
229
+ bmi_status=bmi_status
230
+ )
231
 
232
+ full_plan = query_model(prompt)
 
233
 
234
+ st.subheader("🏋️ Your Personalized 5-Day Workout Plan")
235
+ st.write(full_plan)
236
 
237
+ if st.button("⬅️ Back"):
238
+ st.session_state.page = "form"
239
+ st.rerun()