Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from typing import List, Literal, Tuple
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"You’re doing great—one step at a time! 💪",
|
| 5 |
"Small habits, big results. Keep going. 🔁",
|
| 6 |
"Hydrate and move—your future self thanks you. 💧",
|
| 7 |
"Form first, weight second. You’ve got this. 🧠",
|
| 8 |
"Consistency beats intensity. Show up today. ✅",
|
| 9 |
-
]
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# -------------------------------
|
| 14 |
# Helpers: BMI / BMR / TDEE
|
| 15 |
# -------------------------------
|
|
@@ -28,7 +45,7 @@ def bmi_category(bmi: float) -> str:
|
|
| 28 |
return "Obese"
|
| 29 |
|
| 30 |
def bmr_mifflin(sex: Literal["male","female"], age: int, height_cm: float, weight_kg: float) -> float:
|
| 31 |
-
# Mifflin
|
| 32 |
s = 5 if sex == "male" else -161
|
| 33 |
return 10*weight_kg + 6.25*height_cm - 5*age + s
|
| 34 |
|
|
@@ -40,35 +57,34 @@ ACTIVITY = {
|
|
| 40 |
"Athlete (2x/day)": 1.9,
|
| 41 |
}
|
| 42 |
|
| 43 |
-
def tdee(sex: str, age: int, height_cm: float, weight_kg: float, activity: str) -> Tuple[
|
| 44 |
base = bmr_mifflin(sex, age, height_cm, weight_kg)
|
| 45 |
factor = ACTIVITY.get(activity, 1.2)
|
| 46 |
maintenance = round(base * factor)
|
| 47 |
-
cut = maintenance - 500
|
| 48 |
-
bulk = maintenance + 300
|
| 49 |
return maintenance, cut, bulk
|
| 50 |
|
| 51 |
def water_intake_ml(weight_kg: float) -> int:
|
| 52 |
-
#
|
| 53 |
return int(weight_kg * 35)
|
| 54 |
|
| 55 |
# -------------------------------
|
| 56 |
# Agent 1: BMI & TDEE
|
| 57 |
# -------------------------------
|
| 58 |
-
def agent_bmi_tdee(
|
| 59 |
-
sex, age, height_cm, weight_kg, activity, goal
|
| 60 |
-
):
|
| 61 |
bmi = bmi_value(height_cm, weight_kg)
|
| 62 |
cat = bmi_category(bmi)
|
| 63 |
maint, cut, bulk = tdee(sex, age, height_cm, weight_kg, activity)
|
| 64 |
target = {"Lose fat": cut, "Maintain": maint, "Build muscle": bulk}[goal]
|
| 65 |
water = water_intake_ml(weight_kg)
|
|
|
|
| 66 |
|
| 67 |
md = f"""### 📊 BMI & TDEE
|
| 68 |
- **BMI:** `{bmi}` → **{cat}**
|
| 69 |
- **Maintenance Calories:** **{maint} kcal/day**
|
| 70 |
- **Target for goal ({goal}):** **{target} kcal/day**
|
| 71 |
-
- **Water recommendation:** ~ **{
|
| 72 |
|
| 73 |
> *These are estimates, not medical advice. Adjust by ±100–150 kcal based on weekly progress.*
|
| 74 |
"""
|
|
@@ -80,12 +96,11 @@ def agent_bmi_tdee(
|
|
| 80 |
GOAL_SPLITS = {
|
| 81 |
"Lose fat": ["FBW", "FBW", "LISS Cardio", "Mobility"],
|
| 82 |
"Maintain": ["Upper", "Lower", "Full Body", "HIIT/Cardio", "Mobility"],
|
| 83 |
-
"Build muscle": ["Push", "Pull", "Legs", "Upper", "Lower", "Mobility"]
|
| 84 |
}
|
| 85 |
|
| 86 |
-
|
| 87 |
def session_template(name: str, level: str, equipment: str) -> List[str]:
|
| 88 |
-
#
|
| 89 |
if name == "FBW":
|
| 90 |
return [
|
| 91 |
"Goblet Squat 3x8-10",
|
|
@@ -110,15 +125,15 @@ def session_template(name: str, level: str, equipment: str) -> List[str]:
|
|
| 110 |
"Calf Raise 3x12-15",
|
| 111 |
"Core: Deadbug 3x10",
|
| 112 |
]
|
| 113 |
-
if name == "Push":
|
| 114 |
return [
|
| 115 |
"DB Bench Press 4x6-10",
|
| 116 |
"Incline Push-ups 3x10",
|
| 117 |
"DB Shoulder Press 3x8-10",
|
| 118 |
"Lateral Raise 3x12-15",
|
| 119 |
-
"Triceps
|
| 120 |
]
|
| 121 |
-
if name == "Pull":
|
| 122 |
return [
|
| 123 |
"Lat Pulldown / Assisted Pull-ups 4x6-10",
|
| 124 |
"Seated Row / One-arm Row 3x10",
|
|
@@ -135,11 +150,11 @@ def session_template(name: str, level: str, equipment: str) -> List[str]:
|
|
| 135 |
"Core: Side Plank 3x30s/side",
|
| 136 |
]
|
| 137 |
if name == "HIIT/Cardio":
|
| 138 |
-
return ["20–25 min intervals (1
|
| 139 |
if name == "LISS Cardio":
|
| 140 |
return ["30–45 min easy jog/bike/walk (Zone 2)"]
|
| 141 |
if name == "Mobility":
|
| 142 |
-
return ["15–20 min
|
| 143 |
return ["Rest / Light activity (walk 6–8k steps)"]
|
| 144 |
|
| 145 |
def agent_workout(level: str, days_per_week: int, goal: str, equipment: str):
|
|
@@ -154,19 +169,18 @@ def agent_workout(level: str, days_per_week: int, goal: str, equipment: str):
|
|
| 154 |
md = "### 🏋️ Weekly Plan\n"
|
| 155 |
for title, items in plan:
|
| 156 |
md += f"\n**{title}**\n" + "\n".join([f"- {x}" for x in items]) + "\n"
|
| 157 |
-
md += "\n*Rest
|
| 158 |
return md
|
| 159 |
|
| 160 |
# -------------------------------
|
| 161 |
# Agent 3: Nutrition & Meal Plan
|
| 162 |
# -------------------------------
|
| 163 |
-
PROTEIN_PER_KG = 1.6
|
| 164 |
-
FAT_MIN_G_PER_KG = 0.6
|
| 165 |
|
| 166 |
-
def macros_for_calories(weight_kg: float, calories: int) -> Tuple[int,int,int]:
|
| 167 |
protein_g = int(round(PROTEIN_PER_KG * weight_kg))
|
| 168 |
fat_g = int(round(FAT_MIN_G_PER_KG * weight_kg))
|
| 169 |
-
# احسبي الكارب من الباقي
|
| 170 |
cals_from_p = protein_g * 4
|
| 171 |
cals_from_f = fat_g * 9
|
| 172 |
carbs_g = max(0, int(round((calories - cals_from_p - cals_from_f) / 4)))
|
|
@@ -197,16 +211,17 @@ def agent_nutrition(weight_kg: float, target_kcal: int, liked_csv: str, avoid_cs
|
|
| 197 |
|
| 198 |
p, c, f = macros_for_calories(weight_kg, target_kcal)
|
| 199 |
per_meal = max(1, meals)
|
| 200 |
-
p_m, c_m, f_m = p//per_meal, c//per_meal, f//per_meal
|
| 201 |
|
| 202 |
sample_day = [
|
| 203 |
-
f"Meal {i+1}: {proteins[i % len(proteins)]} + {carbs[i % len(carbs)]}
|
|
|
|
| 204 |
for i in range(per_meal)
|
| 205 |
]
|
| 206 |
|
| 207 |
md = f"""### 🥗 Nutrition Plan
|
| 208 |
- **Target:** **{target_kcal} kcal/day**
|
| 209 |
-
- **Macros (approx.):** Protein **{p} g**, Carbs **{c} g**, Fat **{f} g**
|
| 210 |
- **Preferred foods used:** {", ".join(proteins[:3])} …
|
| 211 |
|
| 212 |
**Sample Day:**
|
|
@@ -218,33 +233,27 @@ def agent_nutrition(weight_kg: float, target_kcal: int, liked_csv: str, avoid_cs
|
|
| 218 |
- Fats: {", ".join(fats)}
|
| 219 |
- Veggies: {", ".join(vegs)}
|
| 220 |
|
| 221 |
-
> Tips: add 20–
|
| 222 |
"""
|
| 223 |
return md
|
| 224 |
|
| 225 |
# -------------------------------
|
| 226 |
-
# All-in-
|
| 227 |
# -------------------------------
|
| 228 |
def coach_all_in_one(
|
| 229 |
sex, age, height_cm, weight_kg, activity, goal,
|
| 230 |
level, days, equipment,
|
| 231 |
liked_csv, avoid_csv, meals
|
| 232 |
):
|
| 233 |
-
# 1) BMI & TDEE
|
| 234 |
report = agent_bmi_tdee(sex, age, height_cm, weight_kg, activity, goal)
|
| 235 |
-
|
| 236 |
-
target = {"Lose fat": cut, "Maintain":
|
| 237 |
-
|
| 238 |
-
# 2) Workout
|
| 239 |
w = agent_workout(level, days, goal, equipment)
|
| 240 |
-
|
| 241 |
-
# 3) Nutrition
|
| 242 |
n = agent_nutrition(weight_kg, target, liked_csv, avoid_csv, meals)
|
| 243 |
-
|
| 244 |
return report + "\n---\n" + w + "\n---\n" + n
|
| 245 |
|
| 246 |
# -------------------------------
|
| 247 |
-
# UI
|
| 248 |
# -------------------------------
|
| 249 |
with gr.Blocks(
|
| 250 |
title="Beginner Gym Coach — Multi-Agent",
|
|
@@ -255,105 +264,92 @@ with gr.Blocks(
|
|
| 255 |
padding:10px 14px;
|
| 256 |
border-radius:8px;
|
| 257 |
font-size:16px;
|
|
|
|
| 258 |
}
|
| 259 |
"""
|
| 260 |
) as demo:
|
| 261 |
gr.Markdown("## 🏋️ Beginner Gym Coach — Multi-Agent\nGive me your basics and I’ll coach you.")
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
)
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
with gr.
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
days2 = gr.Slider(2, 6, value=4, step=1, label="Days/week")
|
| 344 |
-
equipment2 = gr.Dropdown(["Gym (machines/dumbbells)","Home (bands/db)","Bodyweight only"],
|
| 345 |
-
value="Gym (machines/dumbbells)", label="Equipment")
|
| 346 |
-
liked2 = gr.Textbox(label="Preferred foods", placeholder="chicken, eggs, rice, potatoes")
|
| 347 |
-
avoid2 = gr.Textbox(label="Allergies / avoid", placeholder="nuts, shrimp")
|
| 348 |
-
meals2 = gr.Slider(2, 6, value=3, step=1, label="Meals/day")
|
| 349 |
-
btn4 = gr.Button("Get My Full Plan 🚀")
|
| 350 |
-
out4 = gr.Markdown()
|
| 351 |
-
btn4.click(
|
| 352 |
-
coach_all_in_one,
|
| 353 |
-
[sex2, age2, height2, weight2, activity2, goal2, level2, days2, equipment2, liked2, avoid2, meals2],
|
| 354 |
-
out4
|
| 355 |
-
)
|
| 356 |
-
|
| 357 |
|
| 358 |
if __name__ == "__main__":
|
| 359 |
demo.launch()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
from typing import List, Literal, Tuple
|
| 4 |
+
|
| 5 |
+
# -------------------------------
|
| 6 |
+
# Motivation banner (rotates every 10s via JS)
|
| 7 |
+
# -------------------------------
|
| 8 |
+
MOTIVATION_JS = """
|
| 9 |
+
<div id="motivation" class="motivation">Let’s begin strong! 🚀</div>
|
| 10 |
+
<script>
|
| 11 |
+
const MOTIVATION = [
|
| 12 |
"You’re doing great—one step at a time! 💪",
|
| 13 |
"Small habits, big results. Keep going. 🔁",
|
| 14 |
"Hydrate and move—your future self thanks you. 💧",
|
| 15 |
"Form first, weight second. You’ve got this. 🧠",
|
| 16 |
"Consistency beats intensity. Show up today. ✅",
|
| 17 |
+
];
|
| 18 |
+
let i = 0;
|
| 19 |
+
function tick(){
|
| 20 |
+
const el = document.getElementById("motivation");
|
| 21 |
+
if (!el) return;
|
| 22 |
+
el.textContent = MOTIVATION[i % MOTIVATION.length];
|
| 23 |
+
i++;
|
| 24 |
+
}
|
| 25 |
+
tick(); // first line immediately
|
| 26 |
+
setInterval(tick, 10000); // then every 10s
|
| 27 |
+
</script>
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
# -------------------------------
|
| 31 |
# Helpers: BMI / BMR / TDEE
|
| 32 |
# -------------------------------
|
|
|
|
| 45 |
return "Obese"
|
| 46 |
|
| 47 |
def bmr_mifflin(sex: Literal["male","female"], age: int, height_cm: float, weight_kg: float) -> float:
|
| 48 |
+
# Mifflin–St Jeor
|
| 49 |
s = 5 if sex == "male" else -161
|
| 50 |
return 10*weight_kg + 6.25*height_cm - 5*age + s
|
| 51 |
|
|
|
|
| 57 |
"Athlete (2x/day)": 1.9,
|
| 58 |
}
|
| 59 |
|
| 60 |
+
def tdee(sex: str, age: int, height_cm: float, weight_kg: float, activity: str) -> Tuple[int, int, int]:
|
| 61 |
base = bmr_mifflin(sex, age, height_cm, weight_kg)
|
| 62 |
factor = ACTIVITY.get(activity, 1.2)
|
| 63 |
maintenance = round(base * factor)
|
| 64 |
+
cut = maintenance - 500 # gentle fat loss
|
| 65 |
+
bulk = maintenance + 300 # lean bulk
|
| 66 |
return maintenance, cut, bulk
|
| 67 |
|
| 68 |
def water_intake_ml(weight_kg: float) -> int:
|
| 69 |
+
# 35 ml per kg (simple guideline)
|
| 70 |
return int(weight_kg * 35)
|
| 71 |
|
| 72 |
# -------------------------------
|
| 73 |
# Agent 1: BMI & TDEE
|
| 74 |
# -------------------------------
|
| 75 |
+
def agent_bmi_tdee(sex, age, height_cm, weight_kg, activity, goal):
|
|
|
|
|
|
|
| 76 |
bmi = bmi_value(height_cm, weight_kg)
|
| 77 |
cat = bmi_category(bmi)
|
| 78 |
maint, cut, bulk = tdee(sex, age, height_cm, weight_kg, activity)
|
| 79 |
target = {"Lose fat": cut, "Maintain": maint, "Build muscle": bulk}[goal]
|
| 80 |
water = water_intake_ml(weight_kg)
|
| 81 |
+
water_l = round(water / 1000, 1)
|
| 82 |
|
| 83 |
md = f"""### 📊 BMI & TDEE
|
| 84 |
- **BMI:** `{bmi}` → **{cat}**
|
| 85 |
- **Maintenance Calories:** **{maint} kcal/day**
|
| 86 |
- **Target for goal ({goal}):** **{target} kcal/day**
|
| 87 |
+
- **Water recommendation:** ~ **{water_l} L/day** (≈ {water} ml)
|
| 88 |
|
| 89 |
> *These are estimates, not medical advice. Adjust by ±100–150 kcal based on weekly progress.*
|
| 90 |
"""
|
|
|
|
| 96 |
GOAL_SPLITS = {
|
| 97 |
"Lose fat": ["FBW", "FBW", "LISS Cardio", "Mobility"],
|
| 98 |
"Maintain": ["Upper", "Lower", "Full Body", "HIIT/Cardio", "Mobility"],
|
| 99 |
+
"Build muscle": ["Push", "Pull", "Legs", "Upper", "Lower", "Mobility"],
|
| 100 |
}
|
| 101 |
|
|
|
|
| 102 |
def session_template(name: str, level: str, equipment: str) -> List[str]:
|
| 103 |
+
# Compact, beginner-friendly templates
|
| 104 |
if name == "FBW":
|
| 105 |
return [
|
| 106 |
"Goblet Squat 3x8-10",
|
|
|
|
| 125 |
"Calf Raise 3x12-15",
|
| 126 |
"Core: Deadbug 3x10",
|
| 127 |
]
|
| 128 |
+
if name == "Push":
|
| 129 |
return [
|
| 130 |
"DB Bench Press 4x6-10",
|
| 131 |
"Incline Push-ups 3x10",
|
| 132 |
"DB Shoulder Press 3x8-10",
|
| 133 |
"Lateral Raise 3x12-15",
|
| 134 |
+
"Triceps Extensions 3x10-12",
|
| 135 |
]
|
| 136 |
+
if name == "Pull":
|
| 137 |
return [
|
| 138 |
"Lat Pulldown / Assisted Pull-ups 4x6-10",
|
| 139 |
"Seated Row / One-arm Row 3x10",
|
|
|
|
| 150 |
"Core: Side Plank 3x30s/side",
|
| 151 |
]
|
| 152 |
if name == "HIIT/Cardio":
|
| 153 |
+
return ["20–25 min intervals (1 fast / 1 easy) OR 30–40 min brisk walk"]
|
| 154 |
if name == "LISS Cardio":
|
| 155 |
return ["30–45 min easy jog/bike/walk (Zone 2)"]
|
| 156 |
if name == "Mobility":
|
| 157 |
+
return ["15–20 min mobility + light stretching & breathing"]
|
| 158 |
return ["Rest / Light activity (walk 6–8k steps)"]
|
| 159 |
|
| 160 |
def agent_workout(level: str, days_per_week: int, goal: str, equipment: str):
|
|
|
|
| 169 |
md = "### 🏋️ Weekly Plan\n"
|
| 170 |
for title, items in plan:
|
| 171 |
md += f"\n**{title}**\n" + "\n".join([f"- {x}" for x in items]) + "\n"
|
| 172 |
+
md += "\n*Rest 60–90s between sets. Aim for ~2 reps in reserve (RIR 2).*"
|
| 173 |
return md
|
| 174 |
|
| 175 |
# -------------------------------
|
| 176 |
# Agent 3: Nutrition & Meal Plan
|
| 177 |
# -------------------------------
|
| 178 |
+
PROTEIN_PER_KG = 1.6 # g/kg for beginners
|
| 179 |
+
FAT_MIN_G_PER_KG = 0.6 # g/kg
|
| 180 |
|
| 181 |
+
def macros_for_calories(weight_kg: float, calories: int) -> Tuple[int, int, int]:
|
| 182 |
protein_g = int(round(PROTEIN_PER_KG * weight_kg))
|
| 183 |
fat_g = int(round(FAT_MIN_G_PER_KG * weight_kg))
|
|
|
|
| 184 |
cals_from_p = protein_g * 4
|
| 185 |
cals_from_f = fat_g * 9
|
| 186 |
carbs_g = max(0, int(round((calories - cals_from_p - cals_from_f) / 4)))
|
|
|
|
| 211 |
|
| 212 |
p, c, f = macros_for_calories(weight_kg, target_kcal)
|
| 213 |
per_meal = max(1, meals)
|
| 214 |
+
p_m, c_m, f_m = p // per_meal, c // per_meal, f // per_meal
|
| 215 |
|
| 216 |
sample_day = [
|
| 217 |
+
f"Meal {i+1}: {proteins[i % len(proteins)]} + {carbs[i % len(carbs)]} "
|
| 218 |
+
f"+ {vegs[i % len(vegs)]} + {fats[i % len(fats)]}"
|
| 219 |
for i in range(per_meal)
|
| 220 |
]
|
| 221 |
|
| 222 |
md = f"""### 🥗 Nutrition Plan
|
| 223 |
- **Target:** **{target_kcal} kcal/day**
|
| 224 |
+
- **Macros (approx.):** Protein **{p} g**, Carbs **{c} g**, Fat **{f} g** → per meal ≈ **{p_m}/{c_m}/{f_m} g**
|
| 225 |
- **Preferred foods used:** {", ".join(proteins[:3])} …
|
| 226 |
|
| 227 |
**Sample Day:**
|
|
|
|
| 233 |
- Fats: {", ".join(fats)}
|
| 234 |
- Veggies: {", ".join(vegs)}
|
| 235 |
|
| 236 |
+
> Tips: add 20–30 g protein each meal, plenty of veggies, and 1–2 pieces of fruit/day.
|
| 237 |
"""
|
| 238 |
return md
|
| 239 |
|
| 240 |
# -------------------------------
|
| 241 |
+
# Chained: All-in-One Coach
|
| 242 |
# -------------------------------
|
| 243 |
def coach_all_in_one(
|
| 244 |
sex, age, height_cm, weight_kg, activity, goal,
|
| 245 |
level, days, equipment,
|
| 246 |
liked_csv, avoid_csv, meals
|
| 247 |
):
|
|
|
|
| 248 |
report = agent_bmi_tdee(sex, age, height_cm, weight_kg, activity, goal)
|
| 249 |
+
maint, cut, bulk = tdee(sex, age, height_cm, weight_kg, activity)
|
| 250 |
+
target = {"Lose fat": cut, "Maintain": maint, "Build muscle": bulk}[goal]
|
|
|
|
|
|
|
| 251 |
w = agent_workout(level, days, goal, equipment)
|
|
|
|
|
|
|
| 252 |
n = agent_nutrition(weight_kg, target, liked_csv, avoid_csv, meals)
|
|
|
|
| 253 |
return report + "\n---\n" + w + "\n---\n" + n
|
| 254 |
|
| 255 |
# -------------------------------
|
| 256 |
+
# UI
|
| 257 |
# -------------------------------
|
| 258 |
with gr.Blocks(
|
| 259 |
title="Beginner Gym Coach — Multi-Agent",
|
|
|
|
| 264 |
padding:10px 14px;
|
| 265 |
border-radius:8px;
|
| 266 |
font-size:16px;
|
| 267 |
+
margin-bottom:10px;
|
| 268 |
}
|
| 269 |
"""
|
| 270 |
) as demo:
|
| 271 |
gr.Markdown("## 🏋️ Beginner Gym Coach — Multi-Agent\nGive me your basics and I’ll coach you.")
|
| 272 |
+
gr.HTML(MOTIVATION_JS)
|
| 273 |
+
|
| 274 |
+
with gr.Tabs():
|
| 275 |
+
# -------- BMI & TDEE --------
|
| 276 |
+
with gr.Tab("BMI & TDEE"):
|
| 277 |
+
with gr.Row():
|
| 278 |
+
with gr.Column(scale=1):
|
| 279 |
+
sex = gr.Radio(["male","female"], value="female", label="Sex")
|
| 280 |
+
age = gr.Slider(15, 70, value=24, step=1, label="Age")
|
| 281 |
+
height = gr.Slider(130, 210, value=165, step=1, label="Height (cm)")
|
| 282 |
+
weight = gr.Slider(35, 160, value=60, step=0.5, label="Weight (kg)")
|
| 283 |
+
activity = gr.Dropdown(list(ACTIVITY.keys()),
|
| 284 |
+
value="Light (1-3x/wk)", label="Activity")
|
| 285 |
+
goal = gr.Radio(["Lose fat","Maintain","Build muscle"],
|
| 286 |
+
value="Maintain", label="Goal")
|
| 287 |
+
btn1 = gr.Button("Calculate")
|
| 288 |
+
with gr.Column(scale=1):
|
| 289 |
+
out1 = gr.Markdown()
|
| 290 |
+
btn1.click(agent_bmi_tdee, [sex, age, height, weight, activity, goal], out1)
|
| 291 |
+
|
| 292 |
+
# -------- Workout Plan --------
|
| 293 |
+
with gr.Tab("Workout Plan"):
|
| 294 |
+
with gr.Row():
|
| 295 |
+
with gr.Column(scale=1):
|
| 296 |
+
level = gr.Radio(["Beginner","Intermediate"], value="Beginner", label="Level")
|
| 297 |
+
days = gr.Slider(2, 6, value=4, step=1, label="Days/week")
|
| 298 |
+
goal_w = gr.Radio(["Lose fat","Maintain","Build muscle"],
|
| 299 |
+
value="Build muscle", label="Goal")
|
| 300 |
+
equipment = gr.Dropdown(["Gym (machines/dumbbells)",
|
| 301 |
+
"Home (bands/db)", "Bodyweight only"],
|
| 302 |
+
value="Gym (machines/dumbbells)", label="Equipment")
|
| 303 |
+
btn2 = gr.Button("Generate Plan")
|
| 304 |
+
with gr.Column(scale=1):
|
| 305 |
+
out2 = gr.Markdown()
|
| 306 |
+
btn2.click(agent_workout, [level, days, goal_w, equipment], out2)
|
| 307 |
+
|
| 308 |
+
# -------- Nutrition --------
|
| 309 |
+
with gr.Tab("Nutrition"):
|
| 310 |
+
with gr.Row():
|
| 311 |
+
with gr.Column(scale=1):
|
| 312 |
+
target_kcal = gr.Number(value=1900, label="Target calories (kcal)")
|
| 313 |
+
weight_n = gr.Number(value=60, label="Weight (kg)")
|
| 314 |
+
liked = gr.Textbox(label="Preferred foods (comma-separated)",
|
| 315 |
+
placeholder="chicken, eggs, rice, oats, salad, laban")
|
| 316 |
+
avoid = gr.Textbox(label="Allergies / avoid (comma-separated)",
|
| 317 |
+
placeholder="nuts, shrimp, gluten")
|
| 318 |
+
meals = gr.Slider(2, 6, value=3, step=1, label="Meals/day")
|
| 319 |
+
btn3 = gr.Button("Build Meal Plan")
|
| 320 |
+
with gr.Column(scale=1):
|
| 321 |
+
out3 = gr.Markdown()
|
| 322 |
+
btn3.click(agent_nutrition, [weight_n, target_kcal, liked, avoid, meals], out3)
|
| 323 |
+
|
| 324 |
+
# -------- All-in-One --------
|
| 325 |
+
with gr.Tab("All-in-One Coach"):
|
| 326 |
+
with gr.Row():
|
| 327 |
+
with gr.Column(scale=1):
|
| 328 |
+
sex2 = gr.Radio(["male","female"], value="female", label="Sex")
|
| 329 |
+
age2 = gr.Slider(15, 70, value=24, step=1, label="Age")
|
| 330 |
+
height2 = gr.Slider(130, 210, value=165, step=1, label="Height (cm)")
|
| 331 |
+
weight2 = gr.Slider(35, 160, value=60, step=0.5, label="Weight (kg)")
|
| 332 |
+
activity2 = gr.Dropdown(list(ACTIVITY.keys()),
|
| 333 |
+
value="Light (1-3x/wk)", label="Activity")
|
| 334 |
+
goal2 = gr.Radio(["Lose fat","Maintain","Build muscle"],
|
| 335 |
+
value="Build muscle", label="Goal")
|
| 336 |
+
level2 = gr.Radio(["Beginner","Intermediate"], value="Beginner", label="Level")
|
| 337 |
+
days2 = gr.Slider(2, 6, value=4, step=1, label="Days/week")
|
| 338 |
+
equipment2 = gr.Dropdown(["Gym (machines/dumbbells)",
|
| 339 |
+
"Home (bands/db)", "Bodyweight only"],
|
| 340 |
+
value="Gym (machines/dumbbells)", label="Equipment")
|
| 341 |
+
liked2 = gr.Textbox(label="Preferred foods", placeholder="chicken, eggs, rice, potatoes")
|
| 342 |
+
avoid2 = gr.Textbox(label="Allergies / avoid", placeholder="nuts, shrimp")
|
| 343 |
+
meals2 = gr.Slider(2, 6, value=3, step=1, label="Meals/day")
|
| 344 |
+
btn4 = gr.Button("Get My Full Plan 🚀")
|
| 345 |
+
with gr.Column(scale=1):
|
| 346 |
+
out4 = gr.Markdown()
|
| 347 |
+
btn4.click(
|
| 348 |
+
coach_all_in_one,
|
| 349 |
+
[sex2, age2, height2, weight2, activity2, goal2,
|
| 350 |
+
level2, days2, equipment2, liked2, avoid2, meals2],
|
| 351 |
+
out4
|
| 352 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
if __name__ == "__main__":
|
| 355 |
demo.launch()
|