Update src/streamlit_app.py
Browse files- src/streamlit_app.py +31 -55
src/streamlit_app.py
CHANGED
|
@@ -2,19 +2,6 @@ import streamlit as st
|
|
| 2 |
|
| 3 |
# 1. Basic Configuration
|
| 4 |
st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
|
| 5 |
-
frpm transformers import pipeline
|
| 6 |
-
def load_model():
|
| 7 |
-
|
| 8 |
-
return pipeline(
|
| 9 |
-
|
| 10 |
-
"text-generation",
|
| 11 |
-
|
| 12 |
-
model="google/flan-t5-base"
|
| 13 |
-
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
generator = load_model()
|
| 17 |
-
|
| 18 |
|
| 19 |
# 2. Enhanced CSS
|
| 20 |
st.markdown("""
|
|
@@ -120,48 +107,37 @@ with st.form("fitness_form", clear_on_submit=False):
|
|
| 120 |
|
| 121 |
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
st.error("Please enter valid height and weight.")
|
| 133 |
-
|
| 134 |
else:
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
equipment_list = ", ".join(equipment)
|
| 139 |
-
|
| 140 |
-
prompt = f"""
|
| 141 |
-
Generate a 5-day structured workout plan.
|
| 142 |
-
|
| 143 |
-
User Details:
|
| 144 |
-
Name: {name}
|
| 145 |
-
Gender: {gender}
|
| 146 |
-
BMI: {bmi:.2f} ({bmi_status})
|
| 147 |
-
Goal: {goal}
|
| 148 |
-
Fitness Level: {fitness_level}
|
| 149 |
-
Available Equipment: {equipment_list}
|
| 150 |
-
|
| 151 |
-
Requirements:
|
| 152 |
-
- Include warmup
|
| 153 |
-
- Include exercises with sets and reps
|
| 154 |
-
- Include rest time
|
| 155 |
-
- Adjust intensity based on BMI and fitness level
|
| 156 |
-
- Keep it structured day-wise
|
| 157 |
-
"""
|
| 158 |
-
|
| 159 |
-
with st.spinner("Generating your AI workout plan..."):
|
| 160 |
-
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 161 |
-
|
| 162 |
-
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 163 |
-
st.write(result)
|
| 164 |
-
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# 1. Basic Configuration
|
| 4 |
st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# 2. Enhanced CSS
|
| 7 |
st.markdown("""
|
|
|
|
| 107 |
|
| 108 |
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
|
| 109 |
|
| 110 |
+
# Submission Button
|
| 111 |
+
submit = st.form_submit_button("GENERATE MY PLAN")
|
| 112 |
+
|
| 113 |
+
# --------------------------------------------------
|
| 114 |
+
# Logic & Calculation
|
| 115 |
+
# --------------------------------------------------
|
| 116 |
+
if submit:
|
| 117 |
+
if not name.strip() or height <= 50 or weight <= 10:
|
| 118 |
+
st.error("🚨 Please provide a valid name, height, and weight.")
|
|
|
|
|
|
|
| 119 |
else:
|
| 120 |
+
# BMI Calculation
|
| 121 |
+
height_m = height / 100
|
| 122 |
+
bmi = round(weight / (height_m ** 2), 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
if bmi < 18.5:
|
| 125 |
+
cat, color = "Underweight", "blue"
|
| 126 |
+
elif 18.5 <= bmi < 25:
|
| 127 |
+
cat, color = "Normal", "green"
|
| 128 |
+
elif 25 <= bmi < 30:
|
| 129 |
+
cat, color = "Overweight", "orange"
|
| 130 |
+
else:
|
| 131 |
+
cat, color = "Obese", "red"
|
| 132 |
|
| 133 |
+
# Results Display
|
| 134 |
+
st.balloons()
|
| 135 |
+
st.success(f"✅ Profile created for {name}")
|
| 136 |
+
|
| 137 |
+
c1, c2 = st.columns(2)
|
| 138 |
+
with c1:
|
| 139 |
+
st.metric("Calculated BMI", bmi)
|
| 140 |
+
with c2:
|
| 141 |
+
st.markdown(f"### Status: :{color}[{cat}]")
|
| 142 |
+
|
| 143 |
+
st.info(f"*Goal:* {goal} | *Experience:* {level}")
|