Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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',
|
| 141 |
-
.contains('suitable_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)
|