jflo commited on
Commit
ad20b81
Β·
verified Β·
1 Parent(s): ff9254c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -128,19 +128,28 @@ class PredictResponse(BaseModel):
128
  soreness_conf: float
129
  exercises: List[ExerciseResponse]
130
 
 
 
 
 
 
131
  # ── Supabase Helper ───────────────────────────────────────────────────────────
132
  def get_suitable_exercises(workout_type: int, mood: int, soreness: int) -> List[ExerciseResponse]:
133
  try:
 
 
134
  print("DATA")
135
- print(workout_type,mood,soreness)
136
  response = (
137
  state.supabase.table('exerciseai')
138
  .select('*')
139
  .eq('workout_type', workout_type)
140
- .contains('suitable_moods', [string(mood)])
141
- .contains('suitable_soreness', [string(soreness)])
142
  .execute()
143
  )
 
 
 
144
  return [ExerciseResponse(**exercise) for exercise in response.data]
145
 
146
  except Exception as e:
@@ -159,7 +168,7 @@ def health_check():
159
  # ── Predict Endpoint ──────────────────────────────────────────────────────────
160
  @app.post("/predict", response_model=PredictResponse)
161
  def predict(request: PredictRequest):
162
-
163
  # ── Input validation ──────────────────────────────────────────────────────
164
  if not request.user_input.strip():
165
  raise HTTPException(status_code=400, detail="user_input cannot be empty")
@@ -182,7 +191,7 @@ def predict(request: PredictRequest):
182
  workout_logits, mood_logits, soreness_logits = state.model(
183
  input_ids, attention_mask
184
  )
185
-
186
  # ── Softmax + confidence ──────────────────────────────────────────────
187
  workout_probs = torch.softmax(workout_logits, dim=1)
188
  mood_probs = torch.softmax(mood_logits, dim=1)
 
128
  soreness_conf: float
129
  exercises: List[ExerciseResponse]
130
 
131
+ def format_pg_array(values: list) -> str:
132
+ """Convert a Python list to PostgreSQL array literal format"""
133
+ return '{' + ','.join(str(v) for v in values) + '}'
134
+
135
+
136
  # ── Supabase Helper ───────────────────────────────────────────────────────────
137
  def get_suitable_exercises(workout_type: int, mood: int, soreness: int) -> List[ExerciseResponse]:
138
  try:
139
+ logger.info(f"Querying exercises β€” workout_type: {workout_type}, mood: {mood}, soreness: {soreness}")
140
+
141
  print("DATA")
 
142
  response = (
143
  state.supabase.table('exerciseai')
144
  .select('*')
145
  .eq('workout_type', workout_type)
146
+ .contains('suitable_moods', format_pg_array([mood]))
147
+ .contains('suitable_soreness', format_pg_array([soreness]))
148
  .execute()
149
  )
150
+
151
+ logger.info(f"Supabase returned {len(response.data)} exercises")
152
+
153
  return [ExerciseResponse(**exercise) for exercise in response.data]
154
 
155
  except Exception as e:
 
168
  # ── Predict Endpoint ──────────────────────────────────────────────────────────
169
  @app.post("/predict", response_model=PredictResponse)
170
  def predict(request: PredictRequest):
171
+ print("HERE")
172
  # ── Input validation ──────────────────────────────────────────────────────
173
  if not request.user_input.strip():
174
  raise HTTPException(status_code=400, detail="user_input cannot be empty")
 
191
  workout_logits, mood_logits, soreness_logits = state.model(
192
  input_ids, attention_mask
193
  )
194
+ print("HERE2")
195
  # ── Softmax + confidence ──────────────────────────────────────────────
196
  workout_probs = torch.softmax(workout_logits, dim=1)
197
  mood_probs = torch.softmax(mood_logits, dim=1)