AlaaElsayed commited on
Commit
cd20d52
·
1 Parent(s): db9559c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -110,18 +110,22 @@ import pandas as pd
110
  import joblib
111
  from collections import OrderedDict
112
 
113
- # Load models
114
  food_model = joblib.load("goal_classifier.pkl")
115
  exercise_model = joblib.load("exercise_classifier.pkl")
116
 
 
 
 
 
 
 
117
 
118
- le_gender = joblib.load['gender.pkl']
119
- le_workout = joblib.load['workout.pkl']
120
- le_goal = joblib.load['goal.pkl']
121
- le_exercise = joblib.load['exercise.pkl']
122
- preprocessor = joblib.load['preprocessor.pkl']
123
 
124
- df = pd.read_csv("monthly_fitness_dataset_user200.csv")
 
125
 
126
  def calculate_bmi(weight_kg, height_cm):
127
  return weight_kg / ((height_cm / 100) ** 2)
@@ -143,16 +147,17 @@ def get_exercise(week, day):
143
  filtered = df[(df['Week'] == week) & (df['Day'] == day)]
144
  if not filtered.empty:
145
  row = filtered.iloc[0]
146
- try:
147
- row['Exercise_Name'] = le_exercise.inverse_transform([row['Exercise_Name']])[0]
148
- except:
149
- pass
150
- return row[['Exercise_Name', 'Exercise_Description', 'Exercise_Duration']].to_dict()
 
 
151
  return {}
152
 
153
  def recommend(choice, gender, age, height_cm, weight_kg, workout_history, goal, week, day):
154
  try:
155
- # Encode inputs
156
  user_input = {
157
  'Gender': le_gender.transform([gender])[0],
158
  'Age': age,
@@ -170,11 +175,10 @@ def recommend(choice, gender, age, height_cm, weight_kg, workout_history, goal,
170
  user_df = pd.DataFrame([user_input])
171
  user_X = preprocessor.transform(user_df)
172
 
173
- # Optionally use models (if needed for future logic)
174
- food_model.predict(user_X)
175
- exercise_model.predict(user_X)
176
 
177
- # Output
178
  if choice == "meal":
179
  meal_plan = get_meal_plan(week, day)
180
  return {
@@ -204,11 +208,12 @@ demo = gr.Interface(
204
  ],
205
  outputs=gr.JSON(label="Recommendation"),
206
  title="Fitness Meal & Exercise Recommendation System",
207
- description="Select your info and receive a personalized meal plan or exercise for the chosen week & day."
208
  )
209
 
210
  if __name__ == "__main__":
211
- demo.launch()
 
212
 
213
 
214
 
 
110
  import joblib
111
  from collections import OrderedDict
112
 
113
+ # Load models
114
  food_model = joblib.load("goal_classifier.pkl")
115
  exercise_model = joblib.load("exercise_classifier.pkl")
116
 
117
+ # Load individual encoders & preprocessor
118
+ le_gender = joblib.load("le_gender.pkl")
119
+ le_workout = joblib.load("le_workout.pkl")
120
+ le_goal = joblib.load("le_goal.pkl")
121
+ le_exercise = joblib.load("exercise.pkl")
122
+ preprocessor = joblib.load("preprocessor.pkl")
123
 
124
+ # Load dataset
125
+ df = pd.read_csv("fitness_meal_plan_with_exercises.csv")
 
 
 
126
 
127
+ # Reverse map exercise ID to name
128
+ exercise_reverse_mapping = {v: k for k, v in le_exercise.items()}
129
 
130
  def calculate_bmi(weight_kg, height_cm):
131
  return weight_kg / ((height_cm / 100) ** 2)
 
147
  filtered = df[(df['Week'] == week) & (df['Day'] == day)]
148
  if not filtered.empty:
149
  row = filtered.iloc[0]
150
+ exercise_id = row['Exercise_ID']
151
+ exercise_name = exercise_reverse_mapping.get(exercise_id, "Unknown Exercise")
152
+ return {
153
+ "Exercise_Name": exercise_name,
154
+ "Exercise_Description": row["Exercise_Description"],
155
+ "Exercise_Duration": row["Exercise_Duration"]
156
+ }
157
  return {}
158
 
159
  def recommend(choice, gender, age, height_cm, weight_kg, workout_history, goal, week, day):
160
  try:
 
161
  user_input = {
162
  'Gender': le_gender.transform([gender])[0],
163
  'Age': age,
 
175
  user_df = pd.DataFrame([user_input])
176
  user_X = preprocessor.transform(user_df)
177
 
178
+ # Predict (not used yet, can be incorporated)
179
+ _ = food_model.predict(user_X)
180
+ _ = exercise_model.predict(user_X)
181
 
 
182
  if choice == "meal":
183
  meal_plan = get_meal_plan(week, day)
184
  return {
 
208
  ],
209
  outputs=gr.JSON(label="Recommendation"),
210
  title="Fitness Meal & Exercise Recommendation System",
211
+ description="Select your details to receive a personalized meal or exercise plan for the selected week and day."
212
  )
213
 
214
  if __name__ == "__main__":
215
+ demo.launch()
216
+
217
 
218
 
219