Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +48 -40
src/streamlit_app.py
CHANGED
|
@@ -13,6 +13,7 @@ def load_model():
|
|
| 13 |
|
| 14 |
tokenizer, model = load_model()
|
| 15 |
|
|
|
|
| 16 |
# TITLE
|
| 17 |
st.title(" FitPlan AI – User Fitness Profile")
|
| 18 |
|
|
@@ -129,63 +130,70 @@ fitness_level = st.radio(
|
|
| 129 |
horizontal=True
|
| 130 |
)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
if st.button(" Submit Profile"):
|
| 134 |
-
|
| 135 |
-
if not name:
|
| 136 |
-
st.error("Please enter your name.")
|
| 137 |
|
| 138 |
-
|
| 139 |
-
st.error("Please enter valid height and weight.")
|
| 140 |
|
| 141 |
-
|
| 142 |
-
st.error("Please select at least one equipment option.")
|
| 143 |
-
|
| 144 |
-
else:
|
| 145 |
-
st.success(" Profile Submitted Successfully!")
|
| 146 |
-
|
| 147 |
-
bmi_status = bmi_category(bmi)
|
| 148 |
-
equipment_list = ", ".join(equipment)
|
| 149 |
-
|
| 150 |
-
prompt = f"""
|
| 151 |
Instruction:
|
|
|
|
|
|
|
| 152 |
Generate a structured 5-day workout plan.
|
| 153 |
|
| 154 |
-
User:
|
| 155 |
Gender: {gender}
|
| 156 |
BMI: {bmi:.2f} ({bmi_status})
|
| 157 |
Goal: {goal}
|
| 158 |
-
Level: {
|
| 159 |
-
Equipment: {equipment_list}
|
| 160 |
|
| 161 |
Rules:
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
| 170 |
|
| 171 |
Start directly with:
|
| 172 |
Day 1:
|
| 173 |
"""
|
| 174 |
|
|
|
|
| 175 |
|
| 176 |
-
|
| 177 |
|
| 178 |
-
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
|
|
|
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
|
|
|
| 13 |
|
| 14 |
tokenizer, model = load_model()
|
| 15 |
|
| 16 |
+
|
| 17 |
# TITLE
|
| 18 |
st.title(" FitPlan AI – User Fitness Profile")
|
| 19 |
|
|
|
|
| 130 |
horizontal=True
|
| 131 |
)
|
| 132 |
|
| 133 |
+
def create_prompt(gender, bmi, bmi_status, goal, level, equipment):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
equipment_list = ", ".join(equipment)
|
|
|
|
| 136 |
|
| 137 |
+
prompt = f"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
Instruction:
|
| 139 |
+
You are a certified professional fitness trainer.
|
| 140 |
+
|
| 141 |
Generate a structured 5-day workout plan.
|
| 142 |
|
| 143 |
+
User Information:
|
| 144 |
Gender: {gender}
|
| 145 |
BMI: {bmi:.2f} ({bmi_status})
|
| 146 |
Goal: {goal}
|
| 147 |
+
Fitness Level: {level}
|
| 148 |
+
Equipment Available: {equipment_list}
|
| 149 |
|
| 150 |
Rules:
|
| 151 |
+
1. Only generate Day 1 to Day 5.
|
| 152 |
+
2. Each day must include:
|
| 153 |
+
- Focus
|
| 154 |
+
- 4 exercises
|
| 155 |
+
- Sets x Reps
|
| 156 |
+
- Rest time
|
| 157 |
+
3. Do not repeat days.
|
| 158 |
+
4. Do not generate explanations.
|
| 159 |
+
5. Keep output clean and professional.
|
| 160 |
|
| 161 |
Start directly with:
|
| 162 |
Day 1:
|
| 163 |
"""
|
| 164 |
|
| 165 |
+
return prompt
|
| 166 |
|
| 167 |
+
def generate_workout_plan(prompt):
|
| 168 |
|
| 169 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 170 |
|
| 171 |
+
outputs = model.generate(
|
| 172 |
+
**inputs,
|
| 173 |
+
max_new_tokens=400,
|
| 174 |
+
num_beams=4,
|
| 175 |
+
early_stopping=True,
|
| 176 |
+
no_repeat_ngram_size=3
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 180 |
+
|
| 181 |
+
return result
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
if st.button("Submit Profile"):
|
| 185 |
+
|
| 186 |
+
prompt = create_prompt(
|
| 187 |
+
gender,
|
| 188 |
+
bmi,
|
| 189 |
+
bmi_status,
|
| 190 |
+
goal,
|
| 191 |
+
fitness_level,
|
| 192 |
+
equipment
|
| 193 |
+
)
|
| 194 |
|
| 195 |
+
with st.spinner("Generating AI workout plan..."):
|
| 196 |
+
result = generate_workout_plan(prompt)
|
| 197 |
|
| 198 |
+
st.subheader("Your Personalized Workout Plan")
|
| 199 |
+
st.write(result)
|