Spaces:
Sleeping
Sleeping
Returning suitable exercises
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from pydantic import BaseModel
|
|
|
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import torch.nn as nn
|
|
@@ -70,6 +71,19 @@ class PredictResponse(BaseModel):
|
|
| 70 |
mood_conf: float
|
| 71 |
soreness: str
|
| 72 |
soreness_conf: float
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
@app.get("/")
|
| 75 |
def greet_json():
|
|
@@ -119,7 +133,12 @@ def predict(request: PredictRequest):
|
|
| 119 |
predicted_mood = mood_label_map[mood_logits.argmax().item()]
|
| 120 |
predicted_soreness = soreness_label_map[soreness_logits.argmax().item()]
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
return PredictResponse(
|
| 124 |
workout = predicted_workout,
|
| 125 |
workout_conf = round(workout_conf.item() * 100, 1),
|
|
@@ -127,5 +146,6 @@ def predict(request: PredictRequest):
|
|
| 127 |
mood_conf = round(mood_conf.item() * 100, 1),
|
| 128 |
soreness = predicted_soreness,
|
| 129 |
soreness_conf = round(soreness_conf.item() * 100, 1),
|
|
|
|
| 130 |
)
|
| 131 |
|
|
|
|
| 2 |
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from pydantic import BaseModel
|
| 5 |
+
from supabase import create_client
|
| 6 |
|
| 7 |
import torch
|
| 8 |
import torch.nn as nn
|
|
|
|
| 71 |
mood_conf: float
|
| 72 |
soreness: str
|
| 73 |
soreness_conf: float
|
| 74 |
+
|
| 75 |
+
def get_suitable_exercises(workout_type: int, mood: int, soreness: int):
|
| 76 |
+
supabase = create_client(os.getenv('SUPA_URL'), os.getenv('SUPA_KEY'))
|
| 77 |
+
|
| 78 |
+
response = (
|
| 79 |
+
supabase.table('exercises')
|
| 80 |
+
.select('*')
|
| 81 |
+
.eq('workout_type', workout_type)
|
| 82 |
+
.contains('suitable_moods', [mood])
|
| 83 |
+
.contains('suitable_soreness', [soreness])
|
| 84 |
+
.execute()
|
| 85 |
+
)
|
| 86 |
+
return response.data
|
| 87 |
|
| 88 |
@app.get("/")
|
| 89 |
def greet_json():
|
|
|
|
| 133 |
predicted_mood = mood_label_map[mood_logits.argmax().item()]
|
| 134 |
predicted_soreness = soreness_label_map[soreness_logits.argmax().item()]
|
| 135 |
|
| 136 |
+
# Fetch suitable exercises from Supabase
|
| 137 |
+
suitable_exercises = get_suitable_exercises(
|
| 138 |
+
workout_type = workout_logits.argmax().item(),
|
| 139 |
+
mood = mood_logits.argmax().item(),
|
| 140 |
+
soreness = soreness_logits.argmax().item()
|
| 141 |
+
)
|
| 142 |
return PredictResponse(
|
| 143 |
workout = predicted_workout,
|
| 144 |
workout_conf = round(workout_conf.item() * 100, 1),
|
|
|
|
| 146 |
mood_conf = round(mood_conf.item() * 100, 1),
|
| 147 |
soreness = predicted_soreness,
|
| 148 |
soreness_conf = round(soreness_conf.item() * 100, 1),
|
| 149 |
+
exercises = suitable_exercises
|
| 150 |
)
|
| 151 |
|