Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +43 -33
src/streamlit_app.py
CHANGED
|
@@ -7,6 +7,8 @@ import torch
|
|
| 7 |
# -------------------------
|
| 8 |
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 9 |
|
|
|
|
|
|
|
| 10 |
# -------------------------
|
| 11 |
# BMI FUNCTIONS
|
| 12 |
# -------------------------
|
|
@@ -25,7 +27,7 @@ def get_category(bmi):
|
|
| 25 |
return "Obese"
|
| 26 |
|
| 27 |
# -------------------------
|
| 28 |
-
# LOAD
|
| 29 |
# -------------------------
|
| 30 |
@st.cache_resource
|
| 31 |
def load_model():
|
|
@@ -36,10 +38,8 @@ def load_model():
|
|
| 36 |
tokenizer, model = load_model()
|
| 37 |
|
| 38 |
# -------------------------
|
| 39 |
-
#
|
| 40 |
# -------------------------
|
| 41 |
-
st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
| 42 |
-
|
| 43 |
with st.form("fitness_form"):
|
| 44 |
|
| 45 |
st.subheader("Personal Information")
|
|
@@ -66,7 +66,8 @@ with st.form("fitness_form"):
|
|
| 66 |
|
| 67 |
equipment = st.multiselect(
|
| 68 |
"Available Equipment",
|
| 69 |
-
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment",
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
submit = st.form_submit_button("Submit Profile")
|
|
@@ -92,51 +93,60 @@ if submit:
|
|
| 92 |
bmi = calculate_bmi(weight, height)
|
| 93 |
bmi_status = get_category(bmi)
|
| 94 |
|
| 95 |
-
st.write(f"
|
| 96 |
|
| 97 |
equipment_list = ", ".join(equipment)
|
| 98 |
|
| 99 |
-
#
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
You are a certified professional fitness trainer.
|
| 102 |
|
| 103 |
-
Create a
|
| 104 |
|
| 105 |
-
|
| 106 |
-
-
|
| 107 |
-
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
- Sets and reps
|
| 111 |
-
- Cool down
|
| 112 |
-
- Do NOT stop after Day 1.
|
| 113 |
-
- Write all 5 days clearly.
|
| 114 |
|
| 115 |
-
User
|
| 116 |
-
Name: {name}
|
| 117 |
BMI: {bmi} ({bmi_status})
|
| 118 |
Goal: {goal}
|
| 119 |
Fitness Level: {level}
|
| 120 |
Equipment Available: {equipment_list}
|
| 121 |
|
| 122 |
-
Start
|
| 123 |
|
| 124 |
-
Day
|
| 125 |
"""
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
do_sample=True,
|
| 136 |
-
repetition_penalty=1.1
|
| 137 |
-
)
|
| 138 |
|
| 139 |
-
|
| 140 |
|
|
|
|
|
|
|
|
|
|
| 141 |
st.subheader("🏋️ Your Personalized 5-Day Workout Plan")
|
| 142 |
-
st.write(
|
|
|
|
| 7 |
# -------------------------
|
| 8 |
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 9 |
|
| 10 |
+
st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
| 11 |
+
|
| 12 |
# -------------------------
|
| 13 |
# BMI FUNCTIONS
|
| 14 |
# -------------------------
|
|
|
|
| 27 |
return "Obese"
|
| 28 |
|
| 29 |
# -------------------------
|
| 30 |
+
# LOAD MODEL
|
| 31 |
# -------------------------
|
| 32 |
@st.cache_resource
|
| 33 |
def load_model():
|
|
|
|
| 38 |
tokenizer, model = load_model()
|
| 39 |
|
| 40 |
# -------------------------
|
| 41 |
+
# FORM
|
| 42 |
# -------------------------
|
|
|
|
|
|
|
| 43 |
with st.form("fitness_form"):
|
| 44 |
|
| 45 |
st.subheader("Personal Information")
|
|
|
|
| 66 |
|
| 67 |
equipment = st.multiselect(
|
| 68 |
"Available Equipment",
|
| 69 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment",
|
| 70 |
+
"Kettlebell", "Pull-up Bar"]
|
| 71 |
)
|
| 72 |
|
| 73 |
submit = st.form_submit_button("Submit Profile")
|
|
|
|
| 93 |
bmi = calculate_bmi(weight, height)
|
| 94 |
bmi_status = get_category(bmi)
|
| 95 |
|
| 96 |
+
st.write(f"### 📊 Your BMI: {bmi} ({bmi_status})")
|
| 97 |
|
| 98 |
equipment_list = ", ".join(equipment)
|
| 99 |
|
| 100 |
+
# -------------------------
|
| 101 |
+
# GENERATE 5-DAY PLAN (LOOP METHOD)
|
| 102 |
+
# -------------------------
|
| 103 |
+
with st.spinner("Generating your 5-day workout plan..."):
|
| 104 |
+
|
| 105 |
+
full_plan = ""
|
| 106 |
+
|
| 107 |
+
for day in range(1, 6):
|
| 108 |
+
|
| 109 |
+
prompt = f"""
|
| 110 |
You are a certified professional fitness trainer.
|
| 111 |
|
| 112 |
+
Create a detailed workout plan for Day {day}.
|
| 113 |
|
| 114 |
+
Include:
|
| 115 |
+
- Warm-up
|
| 116 |
+
- 4 to 6 exercises
|
| 117 |
+
- Sets and reps
|
| 118 |
+
- Cool down
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
User Details:
|
|
|
|
| 121 |
BMI: {bmi} ({bmi_status})
|
| 122 |
Goal: {goal}
|
| 123 |
Fitness Level: {level}
|
| 124 |
Equipment Available: {equipment_list}
|
| 125 |
|
| 126 |
+
Start with:
|
| 127 |
|
| 128 |
+
Day {day}:
|
| 129 |
"""
|
| 130 |
|
| 131 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 132 |
|
| 133 |
+
outputs = model.generate(
|
| 134 |
+
**inputs,
|
| 135 |
+
max_new_tokens=350,
|
| 136 |
+
temperature=0.8,
|
| 137 |
+
do_sample=True,
|
| 138 |
+
repetition_penalty=1.1
|
| 139 |
+
)
|
| 140 |
|
| 141 |
+
result = tokenizer.decode(
|
| 142 |
+
outputs[0],
|
| 143 |
+
skip_special_tokens=True
|
| 144 |
+
).strip()
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
+
full_plan += result + "\n\n"
|
| 147 |
|
| 148 |
+
# -------------------------
|
| 149 |
+
# DISPLAY PLAN
|
| 150 |
+
# -------------------------
|
| 151 |
st.subheader("🏋️ Your Personalized 5-Day Workout Plan")
|
| 152 |
+
st.write(full_plan)
|