Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +49 -80
src/streamlit_app.py
CHANGED
|
@@ -1,81 +1,50 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
# -------------------------
|
| 21 |
-
|
| 22 |
-
st.subheader("Fitness Details")
|
| 23 |
-
|
| 24 |
-
goal = st.selectbox(
|
| 25 |
-
"Select Your Fitness Goal",
|
| 26 |
-
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
equipment = st.multiselect(
|
| 30 |
-
"Available Equipment (Select multiple if available)",
|
| 31 |
-
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
fitness_level = st.radio(
|
| 35 |
-
"Select Your Fitness Level",
|
| 36 |
-
["Beginner", "Intermediate", "Advanced"]
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
# -------------------------
|
| 40 |
-
# BMI Calculation Function
|
| 41 |
-
# -------------------------
|
| 42 |
-
|
| 43 |
-
def calculate_bmi(weight, height_cm):
|
| 44 |
-
height_m = height_cm / 100 # Convert cm to meters
|
| 45 |
-
bmi = weight / (height_m ** 2)
|
| 46 |
-
return round(bmi, 2)
|
| 47 |
-
|
| 48 |
-
def bmi_category(bmi):
|
| 49 |
-
if bmi < 18.5:
|
| 50 |
-
return "Underweight"
|
| 51 |
-
elif 18.5 <= bmi < 24.9:
|
| 52 |
-
return "Normal"
|
| 53 |
-
elif 25 <= bmi < 29.9:
|
| 54 |
-
return "Overweight"
|
| 55 |
else:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
st.
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def load_model():
|
| 2 |
+
return pipeline(
|
| 3 |
+
"text-generation",
|
| 4 |
+
model="google/flan-t5-base"
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
generator = load_model()
|
| 8 |
+
from transformers import pipeline
|
| 9 |
+
if st.button("Submit Profile"):
|
| 10 |
+
|
| 11 |
+
if not name:
|
| 12 |
+
st.error("Please enter your name.")
|
| 13 |
+
|
| 14 |
+
elif not equipment:
|
| 15 |
+
st.error("Please select at least one equipment option.")
|
| 16 |
+
|
| 17 |
+
elif bmi is None:
|
| 18 |
+
st.error("Please enter valid height and weight.")
|
| 19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
else:
|
| 21 |
+
st.success("โ
Profile Submitted Successfully!")
|
| 22 |
+
|
| 23 |
+
bmi_status = bmi_category(bmi)
|
| 24 |
+
equipment_list = ", ".join(equipment)
|
| 25 |
+
|
| 26 |
+
prompt = f"""
|
| 27 |
+
Generate a 5-day structured workout plan.
|
| 28 |
+
|
| 29 |
+
User Details:
|
| 30 |
+
Name: {name}
|
| 31 |
+
Gender: {gender}
|
| 32 |
+
BMI: {bmi:.2f} ({bmi_status})
|
| 33 |
+
Goal: {goal}
|
| 34 |
+
Fitness Level: {fitness_level}
|
| 35 |
+
Available Equipment: {equipment_list}
|
| 36 |
+
|
| 37 |
+
Requirements:
|
| 38 |
+
- Include warmup
|
| 39 |
+
- Include exercises with sets and reps
|
| 40 |
+
- Include rest time
|
| 41 |
+
- Adjust intensity based on BMI and fitness level
|
| 42 |
+
- Keep it structured day-wise
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
with st.spinner("Generating your AI workout plan..."):
|
| 46 |
+
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 47 |
+
|
| 48 |
+
st.subheader("๐๏ธ Your Personalized Workout Plan")
|
| 49 |
+
st.write(result)
|
| 50 |
+
|