Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,27 @@ st.set_page_config(
|
|
| 9 |
layout="centered"
|
| 10 |
)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
st.title("💪 FIT Plan AI – Personalized Fitness Profile")
|
| 13 |
st.markdown("---")
|
| 14 |
|
| 15 |
-
# Test API connection on startup
|
| 16 |
if "api_status" not in st.session_state:
|
| 17 |
with st.spinner("Checking API connection..."):
|
| 18 |
api_ok, api_message = test_api_connection()
|
|
@@ -210,13 +227,14 @@ with tab2:
|
|
| 210 |
# Call the model API from model_api.py
|
| 211 |
workout_plan = query_model(st.session_state.prompt)
|
| 212 |
st.session_state.workout_plan = workout_plan
|
|
|
|
| 213 |
|
| 214 |
# Display workout plan if generated
|
| 215 |
if st.session_state.workout_plan:
|
| 216 |
st.markdown("---")
|
| 217 |
st.subheader("📋 Your 5-Day Workout Plan")
|
| 218 |
|
| 219 |
-
# Check if plan is complete
|
| 220 |
is_complete, message = verify_workout_plan(st.session_state.workout_plan)
|
| 221 |
if not is_complete:
|
| 222 |
st.warning(f"⚠️ {message}. You can regenerate the plan if needed.")
|
|
@@ -291,21 +309,4 @@ Generated by FIT Plan AI
|
|
| 291 |
|
| 292 |
# Footer
|
| 293 |
st.markdown("---")
|
| 294 |
-
st.caption("FIT Plan AI - Milestone 1 | Powered by Mistral-7B")
|
| 295 |
-
|
| 296 |
-
# Helper function to verify workout plan
|
| 297 |
-
def verify_workout_plan(plan_text):
|
| 298 |
-
"""Check if the workout plan contains all 5 days"""
|
| 299 |
-
if not plan_text or plan_text.startswith("Error"):
|
| 300 |
-
return False, "No valid plan generated"
|
| 301 |
-
|
| 302 |
-
days_present = []
|
| 303 |
-
for i in range(1, 6):
|
| 304 |
-
if f"Day {i}" in plan_text:
|
| 305 |
-
days_present.append(i)
|
| 306 |
-
|
| 307 |
-
if len(days_present) == 5:
|
| 308 |
-
return True, "Complete 5-day plan"
|
| 309 |
-
else:
|
| 310 |
-
missing_days = set(range(1,6)) - set(days_present)
|
| 311 |
-
return False, f"Missing day(s): {', '.join(map(str, missing_days))}"
|
|
|
|
| 9 |
layout="centered"
|
| 10 |
)
|
| 11 |
|
| 12 |
+
# Helper function to verify workout plan - MUST be defined before it's used
|
| 13 |
+
def verify_workout_plan(plan_text):
|
| 14 |
+
"""Check if the workout plan contains all 5 days"""
|
| 15 |
+
if not plan_text or plan_text.startswith("Error"):
|
| 16 |
+
return False, "No valid plan generated"
|
| 17 |
+
|
| 18 |
+
days_present = []
|
| 19 |
+
for i in range(1, 6):
|
| 20 |
+
if f"Day {i}" in plan_text:
|
| 21 |
+
days_present.append(i)
|
| 22 |
+
|
| 23 |
+
if len(days_present) == 5:
|
| 24 |
+
return True, "Complete 5-day plan"
|
| 25 |
+
else:
|
| 26 |
+
missing_days = set(range(1,6)) - set(days_present)
|
| 27 |
+
return False, f"Missing day(s): {', '.join(map(str, missing_days))}"
|
| 28 |
+
|
| 29 |
st.title("💪 FIT Plan AI – Personalized Fitness Profile")
|
| 30 |
st.markdown("---")
|
| 31 |
|
| 32 |
+
# Test API connection on startup
|
| 33 |
if "api_status" not in st.session_state:
|
| 34 |
with st.spinner("Checking API connection..."):
|
| 35 |
api_ok, api_message = test_api_connection()
|
|
|
|
| 227 |
# Call the model API from model_api.py
|
| 228 |
workout_plan = query_model(st.session_state.prompt)
|
| 229 |
st.session_state.workout_plan = workout_plan
|
| 230 |
+
st.rerun()
|
| 231 |
|
| 232 |
# Display workout plan if generated
|
| 233 |
if st.session_state.workout_plan:
|
| 234 |
st.markdown("---")
|
| 235 |
st.subheader("📋 Your 5-Day Workout Plan")
|
| 236 |
|
| 237 |
+
# Check if plan is complete - Now verify_workout_plan is defined
|
| 238 |
is_complete, message = verify_workout_plan(st.session_state.workout_plan)
|
| 239 |
if not is_complete:
|
| 240 |
st.warning(f"⚠️ {message}. You can regenerate the plan if needed.")
|
|
|
|
| 309 |
|
| 310 |
# Footer
|
| 311 |
st.markdown("---")
|
| 312 |
+
st.caption("FIT Plan AI - Milestone 1 | Powered by Mistral-7B")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|