Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +65 -12
src/streamlit_app.py
CHANGED
|
@@ -21,15 +21,52 @@ def load_model():
|
|
| 21 |
generator = load_model()
|
| 22 |
|
| 23 |
# ---------------------------------------------------
|
| 24 |
-
# USER
|
| 25 |
# ---------------------------------------------------
|
|
|
|
|
|
|
| 26 |
name = st.text_input("Enter Your Name")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# ---------------------------------------------------
|
| 29 |
-
#
|
| 30 |
# ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
goal = st.selectbox(
|
| 32 |
-
"
|
| 33 |
[
|
| 34 |
"Flexible",
|
| 35 |
"Weight Loss",
|
|
@@ -42,7 +79,7 @@ goal = st.selectbox(
|
|
| 42 |
# ---------------------------------------------------
|
| 43 |
# EQUIPMENT
|
| 44 |
# ---------------------------------------------------
|
| 45 |
-
st.subheader("Available Equipment")
|
| 46 |
|
| 47 |
col1, col2 = st.columns(2)
|
| 48 |
|
|
@@ -88,7 +125,7 @@ for item, selected in equipment_map.items():
|
|
| 88 |
# ---------------------------------------------------
|
| 89 |
# FITNESS LEVEL
|
| 90 |
# ---------------------------------------------------
|
| 91 |
-
st.subheader("Fitness Level")
|
| 92 |
|
| 93 |
fitness_level = st.radio(
|
| 94 |
"",
|
|
@@ -99,16 +136,21 @@ fitness_level = st.radio(
|
|
| 99 |
# ---------------------------------------------------
|
| 100 |
# PROMPT BUILDER
|
| 101 |
# ---------------------------------------------------
|
| 102 |
-
def build_prompt(name, goal, fitness_level, equipment):
|
| 103 |
equipment_text = ", ".join(equipment)
|
| 104 |
|
| 105 |
prompt = f"""
|
| 106 |
-
Generate a detailed 5-day workout plan
|
| 107 |
|
|
|
|
| 108 |
Goal: {goal}
|
| 109 |
Fitness Level: {fitness_level}
|
|
|
|
|
|
|
| 110 |
Available Equipment: {equipment_text}
|
| 111 |
|
|
|
|
|
|
|
| 112 |
Include:
|
| 113 |
- Day-wise workout split
|
| 114 |
- Exercises
|
|
@@ -121,26 +163,37 @@ def build_prompt(name, goal, fitness_level, equipment):
|
|
| 121 |
|
| 122 |
|
| 123 |
# ---------------------------------------------------
|
| 124 |
-
#
|
| 125 |
# ---------------------------------------------------
|
| 126 |
-
if st.button("Generate
|
| 127 |
|
| 128 |
if not name:
|
| 129 |
st.error("Please enter your name.")
|
| 130 |
elif not equipment:
|
| 131 |
st.error("Please select at least one equipment option.")
|
|
|
|
|
|
|
| 132 |
else:
|
| 133 |
with st.spinner("Generating your AI workout plan..."):
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
result = generator(
|
| 137 |
prompt,
|
| 138 |
-
max_length=
|
| 139 |
do_sample=True,
|
| 140 |
temperature=0.7
|
| 141 |
)
|
| 142 |
|
| 143 |
plan = result[0]["generated_text"]
|
| 144 |
|
| 145 |
-
st.success(f"Plan Generated Successfully, {name}!
|
|
|
|
| 146 |
st.write(plan)
|
|
|
|
| 21 |
generator = load_model()
|
| 22 |
|
| 23 |
# ---------------------------------------------------
|
| 24 |
+
# USER DETAILS
|
| 25 |
# ---------------------------------------------------
|
| 26 |
+
st.subheader("π€ Personal Information")
|
| 27 |
+
|
| 28 |
name = st.text_input("Enter Your Name")
|
| 29 |
|
| 30 |
+
col1, col2 = st.columns(2)
|
| 31 |
+
|
| 32 |
+
with col1:
|
| 33 |
+
height = st.number_input("Height (in cm)", min_value=100, max_value=250, value=170)
|
| 34 |
+
|
| 35 |
+
with col2:
|
| 36 |
+
weight = st.number_input("Weight (in kg)", min_value=30, max_value=200, value=70)
|
| 37 |
+
|
| 38 |
# ---------------------------------------------------
|
| 39 |
+
# BMI CALCULATION
|
| 40 |
# ---------------------------------------------------
|
| 41 |
+
bmi = None
|
| 42 |
+
bmi_category = ""
|
| 43 |
+
|
| 44 |
+
if height > 0 and weight > 0:
|
| 45 |
+
height_m = height / 100
|
| 46 |
+
bmi = weight / (height_m ** 2)
|
| 47 |
+
|
| 48 |
+
st.write(f"### π Your BMI: {bmi:.2f}")
|
| 49 |
+
|
| 50 |
+
if bmi < 18.5:
|
| 51 |
+
bmi_category = "Underweight"
|
| 52 |
+
st.info("Category: Underweight")
|
| 53 |
+
elif 18.5 <= bmi < 24.9:
|
| 54 |
+
bmi_category = "Normal weight"
|
| 55 |
+
st.success("Category: Normal weight")
|
| 56 |
+
elif 25 <= bmi < 29.9:
|
| 57 |
+
bmi_category = "Overweight"
|
| 58 |
+
st.warning("Category: Overweight")
|
| 59 |
+
else:
|
| 60 |
+
bmi_category = "Obese"
|
| 61 |
+
st.error("Category: Obese")
|
| 62 |
+
|
| 63 |
+
# ---------------------------------------------------
|
| 64 |
+
# GOAL
|
| 65 |
+
# ---------------------------------------------------
|
| 66 |
+
st.subheader("π― Fitness Goal")
|
| 67 |
+
|
| 68 |
goal = st.selectbox(
|
| 69 |
+
"",
|
| 70 |
[
|
| 71 |
"Flexible",
|
| 72 |
"Weight Loss",
|
|
|
|
| 79 |
# ---------------------------------------------------
|
| 80 |
# EQUIPMENT
|
| 81 |
# ---------------------------------------------------
|
| 82 |
+
st.subheader("ποΈ Available Equipment")
|
| 83 |
|
| 84 |
col1, col2 = st.columns(2)
|
| 85 |
|
|
|
|
| 125 |
# ---------------------------------------------------
|
| 126 |
# FITNESS LEVEL
|
| 127 |
# ---------------------------------------------------
|
| 128 |
+
st.subheader("π Fitness Level")
|
| 129 |
|
| 130 |
fitness_level = st.radio(
|
| 131 |
"",
|
|
|
|
| 136 |
# ---------------------------------------------------
|
| 137 |
# PROMPT BUILDER
|
| 138 |
# ---------------------------------------------------
|
| 139 |
+
def build_prompt(name, goal, fitness_level, equipment, bmi, bmi_category):
|
| 140 |
equipment_text = ", ".join(equipment)
|
| 141 |
|
| 142 |
prompt = f"""
|
| 143 |
+
Generate a detailed 5-day personalized workout plan.
|
| 144 |
|
| 145 |
+
Name: {name}
|
| 146 |
Goal: {goal}
|
| 147 |
Fitness Level: {fitness_level}
|
| 148 |
+
BMI: {bmi:.2f}
|
| 149 |
+
BMI Category: {bmi_category}
|
| 150 |
Available Equipment: {equipment_text}
|
| 151 |
|
| 152 |
+
Adjust workout intensity according to BMI and fitness level.
|
| 153 |
+
|
| 154 |
Include:
|
| 155 |
- Day-wise workout split
|
| 156 |
- Exercises
|
|
|
|
| 163 |
|
| 164 |
|
| 165 |
# ---------------------------------------------------
|
| 166 |
+
# GENERATE PLAN BUTTON
|
| 167 |
# ---------------------------------------------------
|
| 168 |
+
if st.button("π Generate Personalized Plan"):
|
| 169 |
|
| 170 |
if not name:
|
| 171 |
st.error("Please enter your name.")
|
| 172 |
elif not equipment:
|
| 173 |
st.error("Please select at least one equipment option.")
|
| 174 |
+
elif bmi is None:
|
| 175 |
+
st.error("Please enter valid height and weight.")
|
| 176 |
else:
|
| 177 |
with st.spinner("Generating your AI workout plan..."):
|
| 178 |
+
|
| 179 |
+
prompt = build_prompt(
|
| 180 |
+
name,
|
| 181 |
+
goal,
|
| 182 |
+
fitness_level,
|
| 183 |
+
equipment,
|
| 184 |
+
bmi,
|
| 185 |
+
bmi_category
|
| 186 |
+
)
|
| 187 |
|
| 188 |
result = generator(
|
| 189 |
prompt,
|
| 190 |
+
max_length=600,
|
| 191 |
do_sample=True,
|
| 192 |
temperature=0.7
|
| 193 |
)
|
| 194 |
|
| 195 |
plan = result[0]["generated_text"]
|
| 196 |
|
| 197 |
+
st.success(f"β
Plan Generated Successfully, {name}!")
|
| 198 |
+
st.markdown("## π Your Personalized Workout Plan")
|
| 199 |
st.write(plan)
|