Spaces:
Running
Running
Commit
·
7c6de6f
1
Parent(s):
7d83587
feat: create workout fitness model
Browse files
models-server/models/fitness_model.py
CHANGED
|
@@ -252,6 +252,7 @@ class FitnessModel:
|
|
| 252 |
|
| 253 |
@classmethod
|
| 254 |
def load(cls):
|
|
|
|
| 255 |
with open(FITNESS_MODEL_PATH, "rb") as f:
|
| 256 |
fitness_model = pickle.load(f)
|
| 257 |
|
|
|
|
| 252 |
|
| 253 |
@classmethod
|
| 254 |
def load(cls):
|
| 255 |
+
|
| 256 |
with open(FITNESS_MODEL_PATH, "rb") as f:
|
| 257 |
fitness_model = pickle.load(f)
|
| 258 |
|
src/configs/config.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface Config {
|
|
| 14 |
expiresIn: string;
|
| 15 |
};
|
| 16 |
saltRounds: number;
|
|
|
|
| 17 |
}
|
| 18 |
|
| 19 |
export const config: Config = {
|
|
@@ -28,4 +29,5 @@ export const config: Config = {
|
|
| 28 |
expiresIn: Env.get("JWT_EXPIRES_IN").toString(),
|
| 29 |
},
|
| 30 |
saltRounds: Env.get("SALT_ROUNDS", 5).toNumber(),
|
|
|
|
| 31 |
};
|
|
|
|
| 14 |
expiresIn: string;
|
| 15 |
};
|
| 16 |
saltRounds: number;
|
| 17 |
+
modelsServerUrl: string;
|
| 18 |
}
|
| 19 |
|
| 20 |
export const config: Config = {
|
|
|
|
| 29 |
expiresIn: Env.get("JWT_EXPIRES_IN").toString(),
|
| 30 |
},
|
| 31 |
saltRounds: Env.get("SALT_ROUNDS", 5).toNumber(),
|
| 32 |
+
modelsServerUrl: `${Env.get("MODELS_HOST", 'http://127.0.0.1').toString()}:${Env.get("MODELS_PORT", '3030').toString()}`,
|
| 33 |
};
|
src/lib/models/fitness-model.ts
CHANGED
|
@@ -1,6 +1,59 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
const modelPath = `${__dirname}/../../resources/models/fitness_model.pkl`
|
| 5 |
|
| 6 |
-
export
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { FitnessGoal } from "@common/enums/fitness-goal.enum";
|
| 2 |
+
import { FitnessLevel } from "@common/enums/fitness-level.enum";
|
| 3 |
+
import { Gender } from "@common/enums/gender.enum";
|
| 4 |
+
import { config } from "@configs/config";
|
| 5 |
|
| 6 |
+
const endpoint = '/fitness';
|
|
|
|
| 7 |
|
| 8 |
+
export interface IFitnessPredictionItem {
|
| 9 |
+
bodyPart: string;
|
| 10 |
+
equipment: string;
|
| 11 |
+
name: string;
|
| 12 |
+
repetitions: number;
|
| 13 |
+
sets: number;
|
| 14 |
+
target: string;
|
| 15 |
+
type: string;
|
| 16 |
+
weights_or_duration: number;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
// Fitness Workout Params
|
| 20 |
+
export interface IFWParams {
|
| 21 |
+
home_or_gym: 0 | 1; // 0 for home, 1 for gym
|
| 22 |
+
level: FitnessLevel;
|
| 23 |
+
goal: FitnessGoal;
|
| 24 |
+
gender: Gender;
|
| 25 |
+
age: number;
|
| 26 |
+
feedback: boolean;
|
| 27 |
+
old_weight: number;
|
| 28 |
+
equipments: string[];
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export class FitnessModel {
|
| 32 |
+
public static async predictWorkout(
|
| 33 |
+
params: IFWParams
|
| 34 |
+
): Promise<IFitnessPredictionItem[][]> {
|
| 35 |
+
params.level = params.level.split(' ').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ') as FitnessLevel;
|
| 36 |
+
params.goal = params.goal.split(' ').map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ') as FitnessGoal;
|
| 37 |
+
params.gender = params.gender.toUpperCase() as Gender;
|
| 38 |
+
|
| 39 |
+
const response = await fetch(
|
| 40 |
+
`${config.modelsServerUrl}${endpoint}`,
|
| 41 |
+
{
|
| 42 |
+
method: "POST",
|
| 43 |
+
headers: {
|
| 44 |
+
"Content-Type": "application/json",
|
| 45 |
+
},
|
| 46 |
+
body: JSON.stringify(params),
|
| 47 |
+
}
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
if (!response.ok) {
|
| 51 |
+
console.error(await response.text());
|
| 52 |
+
throw new Error("Failed to fetch data from the server");
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return response.json().then((data) => {
|
| 56 |
+
return data.result;
|
| 57 |
+
});
|
| 58 |
+
}
|
| 59 |
+
}
|