Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +27 -104
src/streamlit_app.py
CHANGED
|
@@ -1,67 +1,44 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
# ---------------------------------------------------
|
| 5 |
# PAGE CONFIG
|
| 6 |
# ---------------------------------------------------
|
| 7 |
-
st.set_page_config(page_title="FitPlan AI", layout="
|
| 8 |
|
| 9 |
-
st.title("
|
| 10 |
|
| 11 |
# ---------------------------------------------------
|
| 12 |
-
#
|
| 13 |
-
# ---------------------------------------------------
|
| 14 |
-
@st.cache_resource
|
| 15 |
-
def load_model():
|
| 16 |
-
return pipeline(
|
| 17 |
-
"text-generation",
|
| 18 |
-
model="google/flan-t5-base"
|
| 19 |
-
)
|
| 20 |
-
|
| 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
|
| 34 |
|
| 35 |
with col2:
|
| 36 |
-
weight = st.number_input("Weight (in kg)", min_value=30, max_value=200
|
| 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 |
|
|
@@ -79,7 +56,7 @@ goal = st.selectbox(
|
|
| 79 |
# ---------------------------------------------------
|
| 80 |
# EQUIPMENT
|
| 81 |
# ---------------------------------------------------
|
| 82 |
-
st.subheader("
|
| 83 |
|
| 84 |
col1, col2 = st.columns(2)
|
| 85 |
|
|
@@ -88,17 +65,12 @@ with col1:
|
|
| 88 |
resistance_band = st.checkbox("Resistance Band")
|
| 89 |
yoga_mat = st.checkbox("Yoga Mat")
|
| 90 |
no_equipment = st.checkbox("No Equipment")
|
| 91 |
-
inclined_bench = st.checkbox("Inclined Bench")
|
| 92 |
-
treadmill = st.checkbox("Treadmill")
|
| 93 |
-
cycle = st.checkbox("Cycle")
|
| 94 |
|
| 95 |
with col2:
|
| 96 |
-
|
| 97 |
-
|
| 98 |
pullups_bar = st.checkbox("Pullups Bar")
|
| 99 |
weight_plates = st.checkbox("Weight Plates")
|
| 100 |
-
hula_hoop = st.checkbox("Hula Hoop Ring")
|
| 101 |
-
bosu_ball = st.checkbox("Bosu Ball")
|
| 102 |
|
| 103 |
equipment = []
|
| 104 |
|
|
@@ -107,15 +79,10 @@ equipment_map = {
|
|
| 107 |
"Resistance Band": resistance_band,
|
| 108 |
"Yoga Mat": yoga_mat,
|
| 109 |
"No Equipment": no_equipment,
|
| 110 |
-
"Inclined Bench": inclined_bench,
|
| 111 |
"Treadmill": treadmill,
|
| 112 |
"Cycle": cycle,
|
| 113 |
-
"Skipping Rope": skipping_rope,
|
| 114 |
-
"Hand Gripper": hand_gripper,
|
| 115 |
"Pullups Bar": pullups_bar,
|
| 116 |
"Weight Plates": weight_plates,
|
| 117 |
-
"Hula Hoop Ring": hula_hoop,
|
| 118 |
-
"Bosu Ball": bosu_ball,
|
| 119 |
}
|
| 120 |
|
| 121 |
for item, selected in equipment_map.items():
|
|
@@ -134,66 +101,22 @@ fitness_level = st.radio(
|
|
| 134 |
)
|
| 135 |
|
| 136 |
# ---------------------------------------------------
|
| 137 |
-
#
|
| 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
|
| 157 |
-
- Sets and reps
|
| 158 |
-
- Rest time
|
| 159 |
-
- Warm-up and cool-down
|
| 160 |
-
"""
|
| 161 |
-
|
| 162 |
-
return prompt
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
# ---------------------------------------------------
|
| 166 |
-
# GENERATE PLAN BUTTON
|
| 167 |
# ---------------------------------------------------
|
| 168 |
-
if st.button("
|
| 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 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 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)
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
# ---------------------------------------------------
|
| 4 |
# PAGE CONFIG
|
| 5 |
# ---------------------------------------------------
|
| 6 |
+
st.set_page_config(page_title="FitPlan AI", layout="wide")
|
| 7 |
|
| 8 |
+
st.title(" FitPlan AI β User Fitness Profile")
|
| 9 |
|
| 10 |
# ---------------------------------------------------
|
| 11 |
+
# PERSONAL INFORMATION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# ---------------------------------------------------
|
| 13 |
st.subheader("π€ Personal Information")
|
| 14 |
|
| 15 |
name = st.text_input("Enter Your Name")
|
| 16 |
|
| 17 |
+
gender = st.selectbox(
|
| 18 |
+
"Gender",
|
| 19 |
+
["Male", "Female", "Other"]
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
col1, col2 = st.columns(2)
|
| 23 |
|
| 24 |
with col1:
|
| 25 |
+
height = st.number_input("Height (in cm)", min_value=100, max_value=250)
|
| 26 |
|
| 27 |
with col2:
|
| 28 |
+
weight = st.number_input("Weight (in kg)", min_value=30, max_value=200)
|
| 29 |
|
| 30 |
# ---------------------------------------------------
|
| 31 |
+
# BMI CALCULATION (Basic Logic Only)
|
| 32 |
# ---------------------------------------------------
|
| 33 |
bmi = None
|
|
|
|
| 34 |
|
| 35 |
if height > 0 and weight > 0:
|
| 36 |
height_m = height / 100
|
| 37 |
bmi = weight / (height_m ** 2)
|
|
|
|
| 38 |
st.write(f"### π Your BMI: {bmi:.2f}")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# ---------------------------------------------------
|
| 41 |
+
# FITNESS GOAL
|
| 42 |
# ---------------------------------------------------
|
| 43 |
st.subheader("π― Fitness Goal")
|
| 44 |
|
|
|
|
| 56 |
# ---------------------------------------------------
|
| 57 |
# EQUIPMENT
|
| 58 |
# ---------------------------------------------------
|
| 59 |
+
st.subheader("Available Equipment")
|
| 60 |
|
| 61 |
col1, col2 = st.columns(2)
|
| 62 |
|
|
|
|
| 65 |
resistance_band = st.checkbox("Resistance Band")
|
| 66 |
yoga_mat = st.checkbox("Yoga Mat")
|
| 67 |
no_equipment = st.checkbox("No Equipment")
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
with col2:
|
| 70 |
+
treadmill = st.checkbox("Treadmill")
|
| 71 |
+
cycle = st.checkbox("Cycle")
|
| 72 |
pullups_bar = st.checkbox("Pullups Bar")
|
| 73 |
weight_plates = st.checkbox("Weight Plates")
|
|
|
|
|
|
|
| 74 |
|
| 75 |
equipment = []
|
| 76 |
|
|
|
|
| 79 |
"Resistance Band": resistance_band,
|
| 80 |
"Yoga Mat": yoga_mat,
|
| 81 |
"No Equipment": no_equipment,
|
|
|
|
| 82 |
"Treadmill": treadmill,
|
| 83 |
"Cycle": cycle,
|
|
|
|
|
|
|
| 84 |
"Pullups Bar": pullups_bar,
|
| 85 |
"Weight Plates": weight_plates,
|
|
|
|
|
|
|
| 86 |
}
|
| 87 |
|
| 88 |
for item, selected in equipment_map.items():
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
# ---------------------------------------------------
|
| 104 |
+
# SUBMIT BUTTON (Backend Receiving Data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# ---------------------------------------------------
|
| 106 |
+
if st.button("Submit Profile"):
|
| 107 |
|
| 108 |
if not name:
|
| 109 |
st.error("Please enter your name.")
|
| 110 |
elif not equipment:
|
| 111 |
st.error("Please select at least one equipment option.")
|
|
|
|
|
|
|
| 112 |
else:
|
| 113 |
+
st.success("β
Profile Submitted Successfully!")
|
| 114 |
+
|
| 115 |
+
st.json({
|
| 116 |
+
"Name": name,
|
| 117 |
+
"Gender": gender,
|
| 118 |
+
"BMI": round(bmi, 2) if bmi else None,
|
| 119 |
+
"Goal": goal,
|
| 120 |
+
"Fitness Level": fitness_level,
|
| 121 |
+
"Equipment": equipment
|
| 122 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|