Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,318 +1,197 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
|
| 5 |
-
# 1. Load
|
| 6 |
model = joblib.load('fitness_model.joblib')
|
| 7 |
|
| 8 |
-
# 2.
|
| 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 |
-
1.
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
"""
|
| 61 |
-
|
| 62 |
-
"Core Stability, Yoga & Walking": """
|
| 63 |
-
π― GOAL: Active Recovery & Back Health (Back Injury Safe)
|
| 64 |
-
|
| 65 |
-
WARM-UP:
|
| 66 |
-
- 5 min Slow Walk
|
| 67 |
-
|
| 68 |
-
YOGA FLOW (Hold each for 30-45 sec):
|
| 69 |
-
1. Cat-Cow Stretch (Mobilize spine)
|
| 70 |
-
2. Bird-Dog (Stabilize core): 3 sets x 10 per side
|
| 71 |
-
3. Child's Pose (Rest lower back)
|
| 72 |
-
4. Glute Bridges: 3 sets x 15 reps
|
| 73 |
-
5. Cobra Stretch (Gentle extension)
|
| 74 |
-
|
| 75 |
-
CARDIO:
|
| 76 |
-
- Walking: 30 minutes brisk pace (Outdoor or Treadmill 1% incline)
|
| 77 |
-
""",
|
| 78 |
-
|
| 79 |
-
# --- Strength & Muscle Building ---
|
| 80 |
-
"Push-Pull-Legs Split (Hypertrophy)": """
|
| 81 |
-
π― GOAL: Maximum Muscle Growth (Advanced)
|
| 82 |
-
|
| 83 |
-
TODAY'S SESSION: PUSH (Chest, Shoulders, Triceps)
|
| 84 |
-
1. Barbell Bench Press: 4 sets x 8 reps (Heavy)
|
| 85 |
-
2. Incline Dumbbell Press: 3 sets x 10 reps
|
| 86 |
-
3. Overhead Military Press: 3 sets x 10 reps
|
| 87 |
-
4. Lateral Raises (Dumbbells): 4 sets x 15 reps (Burnout)
|
| 88 |
-
5. Cable Tricep Pushdowns: 3 sets x 12 reps
|
| 89 |
-
""",
|
| 90 |
-
|
| 91 |
-
"5x5 Powerlifting Program": """
|
| 92 |
-
π― GOAL: Pure Strength (Powerlifting Style)
|
| 93 |
-
|
| 94 |
-
PROTOCOL: Rest 3-5 mins between sets. Lift Heavy.
|
| 95 |
-
|
| 96 |
-
THE BIG 3:
|
| 97 |
-
1. Barbell Squat: 5 sets x 5 reps
|
| 98 |
-
2. Bench Press: 5 sets x 5 reps
|
| 99 |
-
3. Deadlift: 1 set x 5 reps (Very Heavy)
|
| 100 |
-
|
| 101 |
-
ACCESSORY WORK:
|
| 102 |
-
- Pull-ups: 3 sets x Failure
|
| 103 |
-
- Dips: 3 sets x Failure
|
| 104 |
-
""",
|
| 105 |
-
|
| 106 |
-
"Starting Strength (3x5)": """
|
| 107 |
-
π― GOAL: Beginner Strength Foundation
|
| 108 |
-
|
| 109 |
-
PROTOCOL: Focus on perfect form. Add weight each workout.
|
| 110 |
-
|
| 111 |
-
THE WORKOUT:
|
| 112 |
-
1. Squat: 3 sets x 5 reps
|
| 113 |
-
2. Overhead Press: 3 sets x 5 reps
|
| 114 |
-
3. Deadlift: 1 set x 5 reps
|
| 115 |
-
""",
|
| 116 |
-
|
| 117 |
-
"Dumbbell Upper/Lower Split": """
|
| 118 |
-
π― GOAL: Balanced Physique with Dumbbells
|
| 119 |
-
|
| 120 |
-
TODAY: UPPER BODY
|
| 121 |
-
1. Dumbbell Floor Press: 3 sets x 10 reps
|
| 122 |
-
2. Single-Arm Dumbbell Row: 3 sets x 12 per side
|
| 123 |
-
3. Dumbbell Shoulder Press: 3 sets x 10 reps
|
| 124 |
-
4. Dumbbell Shrugs: 3 sets x 15 reps
|
| 125 |
-
5. Bicep Curls vs Skullcrushers (Superset): 3 sets x 12 reps
|
| 126 |
-
""",
|
| 127 |
-
|
| 128 |
-
"3-Day Full Body Compound Lifts": """
|
| 129 |
-
π― GOAL: Efficiency (3 days/week)
|
| 130 |
-
|
| 131 |
-
THE WORKOUT:
|
| 132 |
-
1. Goblet Squat: 3 sets x 10 reps
|
| 133 |
-
2. Push-ups: 3 sets x 15 reps
|
| 134 |
-
3. Dumbbell Lunges: 3 sets x 10 per leg
|
| 135 |
-
4. Dumbbell Shoulder Press: 3 sets x 10
|
| 136 |
-
5. Plank: 3 sets x 60 sec
|
| 137 |
-
""",
|
| 138 |
-
|
| 139 |
-
# --- Cardio & Athletic Performance ---
|
| 140 |
-
"Outdoor Running (5k-10k Prep)": """
|
| 141 |
-
π― GOAL: Endurance Running
|
| 142 |
-
|
| 143 |
-
TODAY'S RUN: Interval Training
|
| 144 |
-
- Warm-up: 5 min Brisk Walk + Dynamic Stretching
|
| 145 |
-
- Run 1 km Easy Pace
|
| 146 |
-
- Interval: 4 rounds of [500m Fast / 2 mins Walk]
|
| 147 |
-
- Run 1 km Easy Pace to finish
|
| 148 |
-
- Cool down: Static Stretching (Calves, Hamstrings)
|
| 149 |
-
|
| 150 |
-
TOTAL DISTANCE: Approx 4-5 km
|
| 151 |
-
""",
|
| 152 |
-
|
| 153 |
-
"Treadmill Intervals & Circuit Training": """
|
| 154 |
-
π― GOAL: Fat Burn & Cardio
|
| 155 |
-
|
| 156 |
-
TREADMILL BLOCK (15 mins):
|
| 157 |
-
- 5 min Warmup walk
|
| 158 |
-
- 10 rounds of: 30 sec Sprint / 30 sec Rest (Stand on rails)
|
| 159 |
-
|
| 160 |
-
CIRCUIT BLOCK (Repeat 3 times):
|
| 161 |
-
1. 15 Kettlebell/Dumbbell Swings
|
| 162 |
-
2. 10 Pushups
|
| 163 |
-
3. 15 Box Jumps (or Step ups)
|
| 164 |
-
4. Rest 1 min
|
| 165 |
-
""",
|
| 166 |
-
|
| 167 |
-
"Sprints & Plyometrics": """
|
| 168 |
-
π― GOAL: Explosive Speed & Power
|
| 169 |
-
|
| 170 |
-
WARM-UP (Critical): 10 mins jogging, high knees, butt kicks.
|
| 171 |
-
|
| 172 |
-
PLYOMETRICS:
|
| 173 |
-
1. Box Jumps: 3 sets x 6 reps (Max height)
|
| 174 |
-
2. Broad Jumps: 3 sets x 5 reps
|
| 175 |
-
|
| 176 |
-
SPRINTS:
|
| 177 |
-
- 4 x 40 meter sprints (100% effort)
|
| 178 |
-
- Rest 2 mins between sprints
|
| 179 |
-
""",
|
| 180 |
-
|
| 181 |
-
"Jump Rope & Burpee Intervals": """
|
| 182 |
-
π― GOAL: High Intensity Cardio (No Equipment)
|
| 183 |
-
|
| 184 |
-
FORMAT: 30 sec work / 15 sec rest. Repeat for 20 mins.
|
| 185 |
-
|
| 186 |
-
THE LOOPS:
|
| 187 |
-
1. Jump Rope (Regular bounce)
|
| 188 |
-
2. Burpees
|
| 189 |
-
3. Jump Rope (High knees)
|
| 190 |
-
4. Mountain Climbers
|
| 191 |
-
5. Jump Rope (Double unders or fast)
|
| 192 |
-
6. Air Squats
|
| 193 |
-
(Repeat cycle)
|
| 194 |
-
""",
|
| 195 |
-
|
| 196 |
-
"Metabolic Resistance Training (Weights + Cardio)": """
|
| 197 |
-
π― GOAL: Burn Fat while Toning
|
| 198 |
-
|
| 199 |
-
CIRCUIT (Do exercises back-to-back, rest 90s after full round. Do 4 Rounds):
|
| 200 |
-
1. Dumbbell Thrusters (Squat + Press): 15 reps
|
| 201 |
-
2. Renegade Rows (Plank + Row): 10 per side
|
| 202 |
-
3. Mountain Climbers: 30 reps
|
| 203 |
-
4. Kettlebell Swings: 20 reps
|
| 204 |
-
""",
|
| 205 |
-
|
| 206 |
-
# --- Functional & General Health ---
|
| 207 |
-
"Full Body Dumbbell Functional Flow": """
|
| 208 |
-
π― GOAL: Daily movement & health
|
| 209 |
-
|
| 210 |
-
THE WORKOUT:
|
| 211 |
-
1. Dumbbell Deadlifts: 3 sets x 12 reps
|
| 212 |
-
2. Z-Press (Seated on floor shoulder press): 3 sets x 10
|
| 213 |
-
3. Reverse Lunges: 3 sets x 10 per leg
|
| 214 |
-
4. Farmer's Carries: 3 sets x 40 steps
|
| 215 |
-
5. Bird-Dogs: 3 sets x 12 reps
|
| 216 |
-
""",
|
| 217 |
-
|
| 218 |
-
"Daily Yoga & Bodyweight Basics": """
|
| 219 |
-
π― GOAL: Flexibility & Core
|
| 220 |
-
|
| 221 |
-
FLOW SEQUENCE (Repeat 2 times):
|
| 222 |
-
1. Sun Salutation A (5 rounds)
|
| 223 |
-
2. Warrior II pose (Hold 30 sec per side)
|
| 224 |
-
3. Tree Pose (Balance): 30 sec per side
|
| 225 |
-
4. Bodyweight Squats: 15 reps
|
| 226 |
-
5. Downward Dog -> Plank flow: 10 reps
|
| 227 |
-
""",
|
| 228 |
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
-
|
|
|
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
EXERCISE 2: Dumbbell Push Press (4 mins)
|
| 250 |
-
-- Rest 1 min --
|
| 251 |
-
EXERCISE 3: Russian Twists (4 mins)
|
| 252 |
-
""",
|
| 253 |
-
|
| 254 |
-
"CrossFit Style WODs": """
|
| 255 |
-
π― GOAL: Functional Fitness
|
| 256 |
|
| 257 |
-
|
| 258 |
-
For Time (Complete as fast as possible):
|
| 259 |
-
- 50 Air Squats
|
| 260 |
-
- 40 Sit-ups
|
| 261 |
-
- 30 Dumbbell Snatches (alternate arms)
|
| 262 |
-
- 20 Push-ups
|
| 263 |
-
- 10 Burpees
|
| 264 |
|
| 265 |
-
|
| 266 |
"""
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
default_plan_text = "Please select a plan or adjust inputs."
|
| 270 |
|
| 271 |
-
# 3. Prediction
|
| 272 |
def predict_plan(age, gender, weight, height, goal, equipment, injury, experience):
|
| 273 |
-
#
|
| 274 |
input_data = pd.DataFrame({
|
| 275 |
'Age': [age], 'Gender': [gender], 'Weight_kg': [weight],
|
| 276 |
'Height_cm': [height], 'Goal': [goal], 'Equipment': [equipment],
|
| 277 |
'Injury': [injury], 'Experience': [experience]
|
| 278 |
})
|
| 279 |
-
|
| 280 |
-
# Predict Label
|
| 281 |
plan_name = model.predict(input_data)[0]
|
| 282 |
|
| 283 |
-
#
|
| 284 |
-
|
| 285 |
|
| 286 |
# Generate Tip
|
| 287 |
-
tip = f"
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
elif goal == 'Muscle Gain':
|
| 291 |
-
tip += "πͺ TIP: Eat 20g protein post-workout."
|
| 292 |
-
elif goal == 'Weight Loss':
|
| 293 |
-
tip += "π₯ TIP: Keep heart rate up during rests."
|
| 294 |
-
|
| 295 |
-
return full_routine, tip
|
| 296 |
|
| 297 |
# 4. Interface
|
| 298 |
iface = gr.Interface(
|
| 299 |
fn=predict_plan,
|
| 300 |
inputs=[
|
| 301 |
-
gr.Slider(18, 80, value=
|
| 302 |
gr.Radio(["Male", "Female"], label="Gender", value="Male"),
|
| 303 |
gr.Number(label="Weight (kg)", value=75),
|
| 304 |
gr.Number(label="Height (cm)", value=175),
|
| 305 |
-
gr.Dropdown(['Weight Loss', 'Muscle Gain', 'Endurance', 'General Health', 'Strength'
|
| 306 |
gr.Dropdown(['Gym Membership', 'Home Dumbbells', 'Bodyweight Only', 'Full Home Gym (Rack+Barbell)'], label="Equipment", value="Gym Membership"),
|
| 307 |
gr.Dropdown(['None', 'Knee', 'Back', 'Shoulder', 'Ankle'], label="Injury", value="None"),
|
| 308 |
gr.Radio(['Beginner', 'Intermediate', 'Advanced'], label="Experience", value="Intermediate")
|
| 309 |
],
|
| 310 |
outputs=[
|
| 311 |
-
gr.Textbox(label="Your
|
| 312 |
-
gr.Textbox(label="AI Coach
|
| 313 |
],
|
| 314 |
-
title="SmartFit AI
|
| 315 |
-
description="
|
| 316 |
theme="soft"
|
| 317 |
)
|
| 318 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
+
# 1. Load Model
|
| 7 |
model = joblib.load('fitness_model.joblib')
|
| 8 |
|
| 9 |
+
# 2. Smart Logic Generator
|
| 10 |
+
def generate_dynamic_workout(plan_category, age, gender, weight, height, goal, equipment, injury, experience):
|
| 11 |
+
|
| 12 |
+
# --- A. Setup Variables based on Profile ---
|
| 13 |
+
|
| 14 |
+
# 1. Calculate suggested starting weights (Estimates)
|
| 15 |
+
strength_base = weight * 0.4 if gender == "Male" else weight * 0.25
|
| 16 |
+
if experience == "Beginner": strength_base *= 0.6
|
| 17 |
+
if experience == "Advanced": strength_base *= 1.4
|
| 18 |
+
|
| 19 |
+
suggested_weight_db = f"{int(strength_base * 0.3)}kg" # Dumbbells
|
| 20 |
+
suggested_weight_bb = f"{int(strength_base * 0.8)}kg" # Barbell
|
| 21 |
+
|
| 22 |
+
if equipment == "Bodyweight Only":
|
| 23 |
+
weight_text = "Bodyweight"
|
| 24 |
+
elif equipment == "Home Dumbbells":
|
| 25 |
+
weight_text = f"Dumbbells (~{suggested_weight_db})"
|
| 26 |
+
else:
|
| 27 |
+
weight_text = f"Moderate Weight (~{suggested_weight_bb} Barbell / {suggested_weight_db} DBs)"
|
| 28 |
+
|
| 29 |
+
# 2. Adjust Volume (Sets/Reps) based on Goal
|
| 30 |
+
if goal == "Muscle Gain":
|
| 31 |
+
protocol = "4 sets x 8-12 reps"
|
| 32 |
+
rest = "90 sec rest"
|
| 33 |
+
focus = "Hypertrophy (Focus on the squeeze)"
|
| 34 |
+
elif goal == "Strength":
|
| 35 |
+
protocol = "5 sets x 5 reps"
|
| 36 |
+
rest = "3 min rest"
|
| 37 |
+
focus = "Max Force (Lift heavy safely)"
|
| 38 |
+
elif goal == "Weight Loss":
|
| 39 |
+
protocol = "3 sets x 15-20 reps"
|
| 40 |
+
rest = "30-45 sec rest"
|
| 41 |
+
focus = "High Heart Rate (Keep moving)"
|
| 42 |
+
else: # General Health / Endurance
|
| 43 |
+
protocol = "3 sets x 12 reps"
|
| 44 |
+
rest = "60 sec rest"
|
| 45 |
+
focus = "Consistency & Form"
|
| 46 |
+
|
| 47 |
+
# 3. Adjust for Age
|
| 48 |
+
warmup_duration = "5 mins"
|
| 49 |
+
if age > 50:
|
| 50 |
+
warmup_duration = "10-12 mins (Joint mobilization focus)"
|
| 51 |
+
rest += " + 30 sec extra for recovery"
|
| 52 |
+
|
| 53 |
+
# --- B. Build the Routine Components ---
|
| 54 |
+
|
| 55 |
+
# 1. Warmup
|
| 56 |
+
warmup = f"""
|
| 57 |
+
β±οΈ DURATION: {warmup_duration}
|
| 58 |
+
1. Joint Rotations (Neck, Shoulders, Hips, Ankles)
|
| 59 |
+
2. 3 min Light Cardio ({'Jumping Jacks' if injury != 'Knee' else 'March in place'})
|
| 60 |
+
3. Dynamic Stretch: {'Arm Circles' if 'Upper' in plan_category else 'Leg Swings'}
|
| 61 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# 2. Main Exercises Selection (Logic Tree)
|
| 64 |
+
exercises = []
|
| 65 |
+
|
| 66 |
+
# -- IF INJURED (Safety Priority) --
|
| 67 |
+
if injury == "Knee":
|
| 68 |
+
exercises = [
|
| 69 |
+
f"1. Glute Bridges (Floor): {protocol} (Safe for knees)",
|
| 70 |
+
f"2. Seated Overhead Press: {protocol} ({weight_text})",
|
| 71 |
+
f"3. Lat Pulldowns or Pull-ups: {protocol}",
|
| 72 |
+
f"4. Plank Hold: 3 sets x 45 sec"
|
| 73 |
+
]
|
| 74 |
+
elif injury == "Back":
|
| 75 |
+
exercises = [
|
| 76 |
+
f"1. Wall Sits: 3 sets x 45 sec (Spine neutral)",
|
| 77 |
+
f"2. Supported Single-Arm Row: {protocol} ({weight_text})",
|
| 78 |
+
f"3. Seated Chest Press/Pushups (Incline): {protocol}",
|
| 79 |
+
f"4. Bird-Dog: 3 sets x 12 reps (Stability)"
|
| 80 |
+
]
|
| 81 |
+
elif injury == "Shoulder":
|
| 82 |
+
exercises = [
|
| 83 |
+
f"1. Leg Press or Goblet Squat (Hands low): {protocol}",
|
| 84 |
+
f"2. Lunges: {protocol} (Bodyweight)",
|
| 85 |
+
f"3. Bicep Curls: {protocol} ({weight_text})",
|
| 86 |
+
f"4. Tricep Pushdowns (Elbows tucked): {protocol}"
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
# -- IF HEALTHY (Goal & Equipment Priority) --
|
| 90 |
+
else:
|
| 91 |
+
# Leg Exercise
|
| 92 |
+
if equipment == "Bodyweight Only": leg_ex = "Air Squats"
|
| 93 |
+
elif equipment == "Home Dumbbells": leg_ex = "Dumbbell Goblet Squats"
|
| 94 |
+
else: leg_ex = "Barbell Back Squats"
|
| 95 |
+
|
| 96 |
+
# Push Exercise
|
| 97 |
+
if equipment == "Bodyweight Only": push_ex = "Push-ups"
|
| 98 |
+
elif equipment == "Home Dumbbells": push_ex = "Dumbbell Bench Press"
|
| 99 |
+
else: push_ex = "Barbell Bench Press"
|
| 100 |
+
|
| 101 |
+
# Pull Exercise
|
| 102 |
+
if equipment == "Bodyweight Only": pull_ex = "Inverted Rows (using table)"
|
| 103 |
+
elif equipment == "Home Dumbbells": pull_ex = "Dumbbell Rows"
|
| 104 |
+
else: pull_ex = "Barbell Bent Over Row"
|
| 105 |
+
|
| 106 |
+
exercises = [
|
| 107 |
+
f"1. {leg_ex}: {protocol} using {weight_text}",
|
| 108 |
+
f"2. {push_ex}: {protocol}",
|
| 109 |
+
f"3. {pull_ex}: {protocol}",
|
| 110 |
+
f"4. {'Shoulder Press' if goal != 'Weight Loss' else 'Burpees'}: {protocol}"
|
| 111 |
+
]
|
| 112 |
+
|
| 113 |
+
# 3. Finisher (Core/Cardio)
|
| 114 |
+
if goal in ["Weight Loss", "Athletic Performance", "Endurance"]:
|
| 115 |
+
finisher = """
|
| 116 |
+
π₯ CARDIO FINISHER:
|
| 117 |
+
- 30 sec High Knees / Mountain Climbers
|
| 118 |
+
- 30 sec Rest
|
| 119 |
+
- Repeat 5 times
|
| 120 |
+
"""
|
| 121 |
+
else: # Muscle/Strength/Health
|
| 122 |
+
finisher = """
|
| 123 |
+
π§± CORE & STABILITY FINISHER:
|
| 124 |
+
- Plank: 3 sets x failure
|
| 125 |
+
- Russian Twists: 3 sets x 20 reps
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
# 4. Cooldown
|
| 129 |
+
cooldown = """
|
| 130 |
+
π§ COOLDOWN (Don't skip!):
|
| 131 |
+
1. Hamstring Stretch (30 sec per leg)
|
| 132 |
+
2. Chest Opener (Doorway stretch)
|
| 133 |
+
3. Child's Pose (Relieve back tension)
|
| 134 |
+
"""
|
| 135 |
|
| 136 |
+
# --- C. Assemble Final Text ---
|
| 137 |
+
full_text = f"""
|
| 138 |
+
π PERSONALIZED PLAN: {plan_category}
|
| 139 |
+
----------------------------------------------------
|
| 140 |
+
π€ PROFILE: {age}y/o {gender} | Goal: {goal} | Exp: {experience}
|
| 141 |
+
βοΈ REC. WEIGHTS: {weight_text}
|
| 142 |
+
π― FOCUS: {focus}
|
| 143 |
+
----------------------------------------------------
|
| 144 |
|
| 145 |
+
π₯ WARM-UP:
|
| 146 |
+
{warmup}
|
| 147 |
|
| 148 |
+
πͺ MAIN WORKOUT (Rest: {rest}):
|
| 149 |
+
{chr(10).join(exercises)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
{finisher}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
{cooldown}
|
| 154 |
"""
|
| 155 |
+
|
| 156 |
+
return full_text
|
|
|
|
| 157 |
|
| 158 |
+
# 3. Prediction Wrapper
|
| 159 |
def predict_plan(age, gender, weight, height, goal, equipment, injury, experience):
|
| 160 |
+
# Predict Category
|
| 161 |
input_data = pd.DataFrame({
|
| 162 |
'Age': [age], 'Gender': [gender], 'Weight_kg': [weight],
|
| 163 |
'Height_cm': [height], 'Goal': [goal], 'Equipment': [equipment],
|
| 164 |
'Injury': [injury], 'Experience': [experience]
|
| 165 |
})
|
|
|
|
|
|
|
| 166 |
plan_name = model.predict(input_data)[0]
|
| 167 |
|
| 168 |
+
# Generate Unique Text
|
| 169 |
+
routine = generate_dynamic_workout(plan_name, age, gender, weight, height, goal, equipment, injury, experience)
|
| 170 |
|
| 171 |
# Generate Tip
|
| 172 |
+
tip = f"AI Insight: We selected '{plan_name}' based on your safety needs, but customized the intensity for {goal}."
|
| 173 |
+
|
| 174 |
+
return routine, tip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
# 4. Interface
|
| 177 |
iface = gr.Interface(
|
| 178 |
fn=predict_plan,
|
| 179 |
inputs=[
|
| 180 |
+
gr.Slider(18, 80, value=25, label="Age"),
|
| 181 |
gr.Radio(["Male", "Female"], label="Gender", value="Male"),
|
| 182 |
gr.Number(label="Weight (kg)", value=75),
|
| 183 |
gr.Number(label="Height (cm)", value=175),
|
| 184 |
+
gr.Dropdown(['Weight Loss', 'Muscle Gain', 'Endurance', 'General Health', 'Strength'], label="Goal", value="Muscle Gain"),
|
| 185 |
gr.Dropdown(['Gym Membership', 'Home Dumbbells', 'Bodyweight Only', 'Full Home Gym (Rack+Barbell)'], label="Equipment", value="Gym Membership"),
|
| 186 |
gr.Dropdown(['None', 'Knee', 'Back', 'Shoulder', 'Ankle'], label="Injury", value="None"),
|
| 187 |
gr.Radio(['Beginner', 'Intermediate', 'Advanced'], label="Experience", value="Intermediate")
|
| 188 |
],
|
| 189 |
outputs=[
|
| 190 |
+
gr.Textbox(label="Your Custom Routine", lines=22),
|
| 191 |
+
gr.Textbox(label="AI Coach Note")
|
| 192 |
],
|
| 193 |
+
title="SmartFit AI Ultimate π",
|
| 194 |
+
description="A fully dynamic workout generator that calculates weights, sets, and exercises based on your exact profile.",
|
| 195 |
theme="soft"
|
| 196 |
)
|
| 197 |
|