saiganesh2004 commited on
Commit
a0751c8
Β·
verified Β·
1 Parent(s): 6ef7ac6

Update utils/ai.py

Browse files
Files changed (1) hide show
  1. utils/ai.py +71 -29
utils/ai.py CHANGED
@@ -1,10 +1,41 @@
1
  """
2
- ai.py β€” Groq-powered workout + diet plan generation.
3
  """
4
  import os, time
5
 
6
  GROQ_MODEL = "llama-3.3-70b-versatile"
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def _groq_client():
9
  key = os.environ.get("GROQ_API_KEY", "").strip()
10
  if not key:
@@ -109,23 +140,25 @@ GOAL: {goal} | LEVEL: {level} | EQUIPMENT: {eq_str}
109
  {context}
110
 
111
  FORMAT β€” use EXACTLY this for each day:
112
- ## Day N β€” [Focus Area]
113
- **Warm-Up**
114
- - Exercise: 2Γ—10
115
- - Exercise: 2Γ—10
 
116
  **Main Workout**
117
  - Exercise Name β€” 3Γ—12 reps (rest 60s)
118
  - Exercise Name β€” 3Γ—12 reps (rest 60s)
119
  - Exercise Name β€” 3Γ—12 reps (rest 60s)
120
- - Exercise Name β€” 3Γ—12 reps (rest 60s)
121
- - Exercise Name β€” 3Γ—12 reps (rest 60s)
122
- **Cool-Down**
123
- - Stretch 1 β€” 30s each side
124
- - Stretch 2 β€” 30s
 
125
 
126
  RULES: {intensity} | BMI note: {advice} | Only use: {eq_str}
127
- {'End with one motivational line for '+name+'.' if end_day==days else 'No closing text β€” more days follow.'}
128
- Output ONLY Days {start_day}–{end_day}. No preamble."""
129
 
130
  chunk = _call_groq(prompt, max_tokens=1800)
131
  all_workout_chunks.append(chunk.strip())
@@ -134,7 +167,7 @@ Output ONLY Days {start_day}–{end_day}. No preamble."""
134
  time.sleep(1)
135
 
136
  if progress_cb:
137
- progress_cb(total_chunks, total_chunks, "Generating nutrition plan…")
138
 
139
  # Diet plan
140
  diet_prompt = f"""Create a detailed {days}-day nutrition plan for:
@@ -143,38 +176,47 @@ Output ONLY Days {start_day}–{end_day}. No preamble."""
143
  FORMAT:
144
  ## Daily Nutrition Targets
145
  - Calories: X kcal
146
- - Protein: Xg | Carbs: Xg | Fats: Xg
147
  - Water: X litres/day
 
148
 
149
  ## Sample Day Meal Plan
150
- **Breakfast** β€” [meal name]
151
- - Item: quantity/amount (Xcal, Xg protein)
 
152
 
153
- **Mid-Morning Snack**
154
- - Item: quantity
155
 
156
- **Lunch** β€” [meal name]
157
- - Item: quantity/amount (Xcal, Xg protein)
 
158
 
159
  **Pre-Workout** (if applicable)
160
- - Item: quantity
161
 
162
- **Dinner** β€” [meal name]
163
- - Item: quantity/amount (Xcal, Xg protein)
 
164
 
165
- **Evening Snack**
166
- - Item: quantity
167
 
168
  ## Key Supplements (optional)
169
- - Supplement: timing + dosage
170
 
171
  ## Foods to Prioritise
172
- - Food 1, Food 2, Food 3...
173
 
174
  ## Foods to Limit
175
- - Food 1, Food 2, Food 3...
 
 
 
 
 
176
 
177
- Be specific with quantities. Tailor everything to the {goal} goal and {bmi_cat} BMI status.
178
  Note: {advice}"""
179
 
180
  diet = _call_groq(diet_prompt, max_tokens=1500)
 
1
  """
2
+ ai.py β€” Groq-powered workout + diet plan generation with exercise descriptions.
3
  """
4
  import os, time
5
 
6
  GROQ_MODEL = "llama-3.3-70b-versatile"
7
 
8
+ # ── Exercise description database ─────────────────────────────────────────────
9
+ EXERCISE_DESCRIPTIONS = {
10
+ "push": "Keep body straight, lower chest to floor, push back up explosively.",
11
+ "pull": "Hang from bar, drive elbows down to pull chin above the bar.",
12
+ "squat": "Feet shoulder-width, push knees out, descend until thighs parallel.",
13
+ "deadlift": "Hinge hips back, grip bar outside knees, drive through heels to stand.",
14
+ "lunge": "Step forward, lower back knee toward floor, keep torso upright.",
15
+ "plank": "Forearms on floor, body in straight line, brace core throughout.",
16
+ "curl": "Upper arms fixed, curl weight toward shoulder, control the descent.",
17
+ "press": "Start at shoulders, press overhead until arms fully extended.",
18
+ "row": "Hinge forward, retract shoulder blade, pull elbow past torso.",
19
+ "fly": "Slight elbow bend, open arms wide, squeeze chest to close.",
20
+ "raise": "Keep slight bend in elbow, raise to shoulder height, lower slowly.",
21
+ "dip": "Grip parallel bars, lower until upper arm parallel, press back up.",
22
+ "crunch": "Feet flat, curl upper body off floor, exhale at the top.",
23
+ "leg raise": "Lie flat, raise legs to 90Β°, lower slowly without touching floor.",
24
+ "glute bridge": "Feet flat, drive hips up, squeeze glutes at the top for 1s.",
25
+ "mountain climber": "High plank, drive knees alternately toward chest at pace.",
26
+ "burpee": "Squat to floor, jump feet back, push-up, jump feet in, leap up.",
27
+ "jump": "Load hips, explode upward, land softly with bent knees.",
28
+ "stretch": "Ease into position, hold without bouncing, breathe steadily.",
29
+ "band": "Anchor band, maintain tension throughout full range of motion.",
30
+ }
31
+
32
+ def get_exercise_description(name):
33
+ name_lower = name.lower()
34
+ for key, desc in EXERCISE_DESCRIPTIONS.items():
35
+ if key in name_lower:
36
+ return desc
37
+ return "Perform with controlled movement through full range of motion."
38
+
39
  def _groq_client():
40
  key = os.environ.get("GROQ_API_KEY", "").strip()
41
  if not key:
 
140
  {context}
141
 
142
  FORMAT β€” use EXACTLY this for each day:
143
+ ## Day N β€” [Focus Area e.g. Chest & Triceps]
144
+ **Warm-Up** (5–8 min)
145
+ - Exercise Name β€” 2Γ—10 reps (rest 30s)
146
+ - Exercise Name β€” 2Γ—10 reps (rest 30s)
147
+
148
  **Main Workout**
149
  - Exercise Name β€” 3Γ—12 reps (rest 60s)
150
  - Exercise Name β€” 3Γ—12 reps (rest 60s)
151
  - Exercise Name β€” 3Γ—12 reps (rest 60s)
152
+ - Exercise Name β€” 3Γ—10 reps (rest 75s)
153
+ - Exercise Name β€” 3Γ—15 reps (rest 45s)
154
+
155
+ **Cool-Down & Stretching**
156
+ - Stretch Name β€” hold 30s each side
157
+ - Stretch Name β€” hold 30s
158
 
159
  RULES: {intensity} | BMI note: {advice} | Only use: {eq_str}
160
+ {'End with one short motivational sentence for '+name+'.' if end_day==days else 'No closing text β€” more days follow.'}
161
+ Output ONLY Days {start_day}–{end_day}. No preamble. No extra text."""
162
 
163
  chunk = _call_groq(prompt, max_tokens=1800)
164
  all_workout_chunks.append(chunk.strip())
 
167
  time.sleep(1)
168
 
169
  if progress_cb:
170
+ progress_cb(total_chunks, total_chunks, "Generating personalised nutrition plan…")
171
 
172
  # Diet plan
173
  diet_prompt = f"""Create a detailed {days}-day nutrition plan for:
 
176
  FORMAT:
177
  ## Daily Nutrition Targets
178
  - Calories: X kcal
179
+ - Protein: Xg | Carbs: Xg | Fats: Xg | Fibre: Xg
180
  - Water: X litres/day
181
+ - Meal timing: brief note
182
 
183
  ## Sample Day Meal Plan
184
+ **Breakfast** β€” [Meal name] (~Xcal)
185
+ - Food item: quantity (Xcal, Xg protein)
186
+ - Food item: quantity
187
 
188
+ **Mid-Morning Snack** (~Xcal)
189
+ - Food item: quantity
190
 
191
+ **Lunch** β€” [Meal name] (~Xcal)
192
+ - Food item: quantity (Xcal, Xg protein)
193
+ - Food item: quantity
194
 
195
  **Pre-Workout** (if applicable)
196
+ - Food item: quantity
197
 
198
+ **Post-Workout / Dinner** β€” [Meal name] (~Xcal)
199
+ - Food item: quantity (Xcal, Xg protein)
200
+ - Food item: quantity
201
 
202
+ **Evening Snack** (~Xcal)
203
+ - Food item: quantity
204
 
205
  ## Key Supplements (optional)
206
+ - Supplement: timing + dosage + benefit
207
 
208
  ## Foods to Prioritise
209
+ - List 6–8 foods with brief reasons
210
 
211
  ## Foods to Limit
212
+ - List 4–6 foods with brief reasons
213
+
214
+ ## Weekly Meal Prep Tips
215
+ - Tip 1
216
+ - Tip 2
217
+ - Tip 3
218
 
219
+ Be specific with quantities. Tailor everything to the {goal} goal and {bmi_cat} BMI.
220
  Note: {advice}"""
221
 
222
  diet = _call_groq(diet_prompt, max_tokens=1500)