Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +28 -40
src/streamlit_app.py
CHANGED
|
@@ -73,71 +73,59 @@ with st.form("fitness_form"):
|
|
| 73 |
# -------------------------
|
| 74 |
# SUBMIT BUTTON
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
|
|
|
| 80 |
st.error("Please enter your name.")
|
| 81 |
-
|
| 82 |
-
elif height <= 0 or weight <= 0:
|
| 83 |
|
|
|
|
| 84 |
st.error("Please enter valid height and weight.")
|
| 85 |
-
|
| 86 |
-
elif not equipment:
|
| 87 |
|
|
|
|
| 88 |
st.error("Please select at least one equipment option.")
|
| 89 |
-
|
| 90 |
else:
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
bmi_status =
|
| 95 |
|
| 96 |
equipment_list = ", ".join(equipment)
|
| 97 |
-
|
| 98 |
-
prompt = f"""
|
| 99 |
|
|
|
|
| 100 |
You are a certified professional fitness trainer.
|
| 101 |
-
|
| 102 |
-
Create a detailed 5-day workout plan.
|
| 103 |
-
|
| 104 |
-
User Information:
|
| 105 |
-
|
| 106 |
-
- Gender: {gender}
|
| 107 |
|
| 108 |
-
-
|
| 109 |
|
|
|
|
|
|
|
|
|
|
| 110 |
- Goal: {goal}
|
| 111 |
-
|
| 112 |
-
- Fitness Level: {fitness_level}
|
| 113 |
-
|
| 114 |
- Equipment Available: {equipment_list}
|
| 115 |
-
|
| 116 |
Start directly with:
|
| 117 |
-
|
| 118 |
-
Day 1:
|
| 119 |
|
|
|
|
| 120 |
"""
|
| 121 |
-
|
| 122 |
with st.spinner("Generating your AI workout plan..."):
|
| 123 |
-
|
| 124 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 125 |
-
|
| 126 |
-
outputs = model.generate(
|
| 127 |
|
|
|
|
| 128 |
**inputs,
|
| 129 |
-
|
| 130 |
-
max_new_tokens=900,
|
| 131 |
-
|
| 132 |
temperature=0.7,
|
| 133 |
-
|
| 134 |
do_sample=True
|
| 135 |
-
|
| 136 |
)
|
| 137 |
-
|
| 138 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
| 139 |
-
|
| 140 |
-
st.subheader(" Your Personalized Workout Plan")
|
| 141 |
|
| 142 |
-
st.
|
| 143 |
-
|
|
|
|
| 73 |
# -------------------------
|
| 74 |
# SUBMIT BUTTON
|
| 75 |
|
| 76 |
+
# -------------------------
|
| 77 |
+
# HANDLE SUBMISSION
|
| 78 |
+
# -------------------------
|
| 79 |
+
|
| 80 |
+
if submit:
|
| 81 |
|
| 82 |
+
if not name:
|
| 83 |
st.error("Please enter your name.")
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
elif height <= 0 or weight <= 0:
|
| 86 |
st.error("Please enter valid height and weight.")
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
elif not equipment:
|
| 89 |
st.error("Please select at least one equipment option.")
|
| 90 |
+
|
| 91 |
else:
|
| 92 |
+
st.success("Profile Submitted Successfully!")
|
| 93 |
|
| 94 |
+
# ✅ Calculate BMI
|
| 95 |
+
bmi = calculate_bmi(weight, height)
|
| 96 |
+
bmi_status = get_category(bmi)
|
| 97 |
|
| 98 |
equipment_list = ", ".join(equipment)
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
prompt = f"""
|
| 101 |
You are a certified professional fitness trainer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
Create a detailed 5-day workout plan.
|
| 104 |
|
| 105 |
+
User Information:
|
| 106 |
+
- Name: {name}
|
| 107 |
+
- BMI: {bmi} ({bmi_status})
|
| 108 |
- Goal: {goal}
|
| 109 |
+
- Fitness Level: {level}
|
|
|
|
|
|
|
| 110 |
- Equipment Available: {equipment_list}
|
| 111 |
+
|
| 112 |
Start directly with:
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
Day 1:
|
| 115 |
"""
|
| 116 |
+
|
| 117 |
with st.spinner("Generating your AI workout plan..."):
|
| 118 |
+
|
| 119 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
outputs = model.generate(
|
| 122 |
**inputs,
|
| 123 |
+
max_new_tokens=600,
|
|
|
|
|
|
|
| 124 |
temperature=0.7,
|
|
|
|
| 125 |
do_sample=True
|
|
|
|
| 126 |
)
|
| 127 |
+
|
| 128 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
|
|
|
|
|
|
| 129 |
|
| 130 |
+
st.subheader("Your Personalized Workout Plan")
|
| 131 |
+
st.write(result)
|