Spaces:
Sleeping
Sleeping
Commit
·
2de204c
1
Parent(s):
43da9d3
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
|
@@ -6,15 +113,21 @@ from collections import OrderedDict
|
|
| 6 |
# Load models and encoders
|
| 7 |
food_model = joblib.load("goal_classifier.pkl")
|
| 8 |
exercise_model = joblib.load("exercise_classifier.pkl")
|
| 9 |
-
encoders = joblib.load("encoders.pkl")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
df = pd.read_csv("fitness_meal_plan_with_exercises.csv")
|
| 11 |
|
| 12 |
-
# Load individual encoders
|
| 13 |
-
le_gender = encoders['gender']
|
| 14 |
-
le_workout = encoders['workout']
|
| 15 |
-
le_goal = encoders['goal']
|
| 16 |
-
le_exercise = encoders['exercise']
|
| 17 |
-
preprocessor = encoders['preprocessor']
|
| 18 |
|
| 19 |
def calculate_bmi(weight_kg, height_cm):
|
| 20 |
return weight_kg / ((height_cm / 100) ** 2)
|
|
@@ -101,5 +214,8 @@ demo = gr.Interface(
|
|
| 101 |
)
|
| 102 |
|
| 103 |
if __name__ == "__main__":
|
| 104 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
| 105 |
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import pandas as pd
|
| 3 |
+
# import joblib
|
| 4 |
+
# from collections import OrderedDict
|
| 5 |
+
|
| 6 |
+
# # Load models and encoders
|
| 7 |
+
# food_model = joblib.load("goal_classifier.pkl")
|
| 8 |
+
# exercise_model = joblib.load("exercise_classifier.pkl")
|
| 9 |
+
# encoders = joblib.load("encoders.pkl")
|
| 10 |
+
# df = pd.read_csv("fitness_meal_plan_with_exercises.csv")
|
| 11 |
+
|
| 12 |
+
# # Load individual encoders
|
| 13 |
+
# le_gender = encoders['gender']
|
| 14 |
+
# le_workout = encoders['workout']
|
| 15 |
+
# le_goal = encoders['goal']
|
| 16 |
+
# le_exercise = encoders['exercise']
|
| 17 |
+
# preprocessor = encoders['preprocessor']
|
| 18 |
+
|
| 19 |
+
# def calculate_bmi(weight_kg, height_cm):
|
| 20 |
+
# return weight_kg / ((height_cm / 100) ** 2)
|
| 21 |
+
|
| 22 |
+
# def get_meal_plan(week, day):
|
| 23 |
+
# filtered = df[(df['Week'] == week) & (df['Day'] == day)]
|
| 24 |
+
# if not filtered.empty:
|
| 25 |
+
# row = filtered.iloc[0]
|
| 26 |
+
# return OrderedDict([
|
| 27 |
+
# ("Breakfast", {"Meal": row["Breakfast"], "Calories": int(row["Calories_Breakfast"])}),
|
| 28 |
+
# ("Snack_1", {"Meal": row["Snack_1"], "Calories": int(row["Calories_Snack_1"])}),
|
| 29 |
+
# ("Lunch", {"Meal": row["Lunch"], "Calories": int(row["Calories_Lunch"])}),
|
| 30 |
+
# ("Snack_2", {"Meal": row["Snack_2"], "Calories": int(row["Calories_Snack_2"])}),
|
| 31 |
+
# ("Dinner", {"Meal": row["Dinner"], "Calories": int(row["Calories_Dinner"])}),
|
| 32 |
+
# ])
|
| 33 |
+
# return OrderedDict()
|
| 34 |
+
|
| 35 |
+
# def get_exercise(week, day):
|
| 36 |
+
# filtered = df[(df['Week'] == week) & (df['Day'] == day)]
|
| 37 |
+
# if not filtered.empty:
|
| 38 |
+
# row = filtered.iloc[0]
|
| 39 |
+
# try:
|
| 40 |
+
# row['Exercise_Name'] = le_exercise.inverse_transform([row['Exercise_Name']])[0]
|
| 41 |
+
# except:
|
| 42 |
+
# pass
|
| 43 |
+
# return row[['Exercise_Name', 'Exercise_Description', 'Exercise_Duration']].to_dict()
|
| 44 |
+
# return {}
|
| 45 |
+
|
| 46 |
+
# def recommend(choice, gender, age, height_cm, weight_kg, workout_history, goal, week, day):
|
| 47 |
+
# try:
|
| 48 |
+
# # Encode inputs
|
| 49 |
+
# user_input = {
|
| 50 |
+
# 'Gender': le_gender.transform([gender])[0],
|
| 51 |
+
# 'Age': age,
|
| 52 |
+
# 'Height_cm': height_cm,
|
| 53 |
+
# 'Weight_kg': weight_kg,
|
| 54 |
+
# 'Workout_History': le_workout.transform([workout_history])[0],
|
| 55 |
+
# 'Goal': le_goal.transform([goal])[0],
|
| 56 |
+
# 'Week': week,
|
| 57 |
+
# 'Day': day
|
| 58 |
+
# }
|
| 59 |
+
|
| 60 |
+
# user_input['BMI'] = calculate_bmi(weight_kg, height_cm)
|
| 61 |
+
|
| 62 |
+
# # Prepare for prediction
|
| 63 |
+
# user_df = pd.DataFrame([user_input])
|
| 64 |
+
# user_X = preprocessor.transform(user_df)
|
| 65 |
+
|
| 66 |
+
# # Optionally use models (if needed for future logic)
|
| 67 |
+
# food_model.predict(user_X)
|
| 68 |
+
# exercise_model.predict(user_X)
|
| 69 |
+
|
| 70 |
+
# # Output
|
| 71 |
+
# if choice == "meal":
|
| 72 |
+
# meal_plan = get_meal_plan(week, day)
|
| 73 |
+
# return {
|
| 74 |
+
# "Meal_Plan": meal_plan,
|
| 75 |
+
# "Total_Calories": sum(meal["Calories"] for meal in meal_plan.values())
|
| 76 |
+
# }
|
| 77 |
+
# elif choice == "exercise":
|
| 78 |
+
# return {"Exercise": get_exercise(week, day)}
|
| 79 |
+
# else:
|
| 80 |
+
# return {"error": "Invalid choice. Must be 'meal' or 'exercise'"}
|
| 81 |
+
# except Exception as e:
|
| 82 |
+
# return {"error": str(e)}
|
| 83 |
+
|
| 84 |
+
# # Gradio interface
|
| 85 |
+
# demo = gr.Interface(
|
| 86 |
+
# fn=recommend,
|
| 87 |
+
# inputs=[
|
| 88 |
+
# gr.Radio(choices=["meal", "exercise"], label="Choice"),
|
| 89 |
+
# gr.Radio(choices=["Male", "Female"], label="Gender"),
|
| 90 |
+
# gr.Slider(10, 80, step=1, label="Age"),
|
| 91 |
+
# gr.Slider(100, 220, step=1, label="Height (cm)"),
|
| 92 |
+
# gr.Slider(30, 200, step=1, label="Weight (kg)"),
|
| 93 |
+
# gr.Dropdown(choices=le_workout.classes_.tolist(), label="Workout History"),
|
| 94 |
+
# gr.Dropdown(choices=le_goal.classes_.tolist(), label="Goal"),
|
| 95 |
+
# gr.Slider(1, 4, step=1, label="Week"),
|
| 96 |
+
# gr.Slider(1, 7, step=1, label="Day")
|
| 97 |
+
# ],
|
| 98 |
+
# outputs=gr.JSON(label="Recommendation"),
|
| 99 |
+
# title="Fitness Meal & Exercise Recommendation System",
|
| 100 |
+
# description="Select your info and receive a personalized meal plan or exercise for the chosen week & day."
|
| 101 |
+
# )
|
| 102 |
+
|
| 103 |
+
# if __name__ == "__main__":
|
| 104 |
+
# demo.launch()
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
import gradio as gr
|
| 109 |
import pandas as pd
|
| 110 |
import joblib
|
|
|
|
| 113 |
# Load models and encoders
|
| 114 |
food_model = joblib.load("goal_classifier.pkl")
|
| 115 |
exercise_model = joblib.load("exercise_classifier.pkl")
|
| 116 |
+
# encoders = joblib.load("encoders.pkl")
|
| 117 |
+
le_gender = joblib.load['gender']
|
| 118 |
+
le_workout = joblib.load['workout']
|
| 119 |
+
le_goal = joblib.load['goal']
|
| 120 |
+
le_exercise = joblib.load['exercise']
|
| 121 |
+
preprocessor = joblib.load['preprocessor']
|
| 122 |
+
|
| 123 |
df = pd.read_csv("fitness_meal_plan_with_exercises.csv")
|
| 124 |
|
| 125 |
+
# # Load individual encoders
|
| 126 |
+
# le_gender = encoders['gender']
|
| 127 |
+
# le_workout = encoders['workout']
|
| 128 |
+
# le_goal = encoders['goal']
|
| 129 |
+
# le_exercise = encoders['exercise']
|
| 130 |
+
# preprocessor = encoders['preprocessor']
|
| 131 |
|
| 132 |
def calculate_bmi(weight_kg, height_cm):
|
| 133 |
return weight_kg / ((height_cm / 100) ** 2)
|
|
|
|
| 214 |
)
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|
| 217 |
+
demo.launch()
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
|
| 221 |
|