Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +88 -22
src/streamlit_app.py
CHANGED
|
@@ -1,7 +1,41 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# -----------------------------------
|
| 4 |
-
# PAGE CONFIG
|
| 5 |
# -----------------------------------
|
| 6 |
st.set_page_config(
|
| 7 |
page_title="FitPlan AI",
|
|
@@ -9,8 +43,9 @@ st.set_page_config(
|
|
| 9 |
layout="wide"
|
| 10 |
)
|
| 11 |
|
|
|
|
| 12 |
# -----------------------------------
|
| 13 |
-
# CUSTOM CSS (
|
| 14 |
# -----------------------------------
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
|
@@ -46,12 +81,14 @@ body {
|
|
| 46 |
</style>
|
| 47 |
""", unsafe_allow_html=True)
|
| 48 |
|
|
|
|
| 49 |
# -----------------------------------
|
| 50 |
-
# SIDEBAR NAVIGATION
|
| 51 |
# -----------------------------------
|
| 52 |
st.sidebar.title("πͺ FitPlan AI")
|
| 53 |
page = st.sidebar.radio("Navigate", ["π Fitness Form", "π BMI Result"])
|
| 54 |
|
|
|
|
| 55 |
# -----------------------------------
|
| 56 |
# PAGE 1: FITNESS FORM
|
| 57 |
# -----------------------------------
|
|
@@ -59,7 +96,6 @@ if page == "π Fitness Form":
|
|
| 59 |
|
| 60 |
st.markdown("<div class='title'>FitPlan AI</div>", unsafe_allow_html=True)
|
| 61 |
st.write("### Milestone 1: Fitness Profile & BMI Calculator")
|
| 62 |
-
st.write("")
|
| 63 |
|
| 64 |
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 65 |
|
|
@@ -87,7 +123,7 @@ if page == "π Fitness Form":
|
|
| 87 |
)
|
| 88 |
|
| 89 |
equipment = st.multiselect(
|
| 90 |
-
"Available Equipment
|
| 91 |
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
|
| 92 |
)
|
| 93 |
|
|
@@ -95,35 +131,37 @@ if page == "π Fitness Form":
|
|
| 95 |
|
| 96 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
if submit:
|
| 99 |
|
| 100 |
-
# Validation
|
| 101 |
if not name.strip():
|
| 102 |
st.error("Name is required.")
|
|
|
|
| 103 |
elif height_cm <= 0:
|
| 104 |
st.error("Height must be greater than zero.")
|
|
|
|
| 105 |
elif weight_kg <= 0:
|
| 106 |
st.error("Weight must be greater than zero.")
|
|
|
|
| 107 |
else:
|
| 108 |
-
|
| 109 |
-
bmi = weight_kg
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
category = "Underweight"
|
| 114 |
-
elif 18.5 <= bmi < 24.9:
|
| 115 |
-
category = "Normal"
|
| 116 |
-
elif 25 <= bmi < 29.9:
|
| 117 |
-
category = "Overweight"
|
| 118 |
-
else:
|
| 119 |
-
category = "Obese"
|
| 120 |
-
|
| 121 |
-
# Save in session
|
| 122 |
st.session_state["name"] = name
|
| 123 |
st.session_state["bmi"] = bmi
|
| 124 |
st.session_state["category"] = category
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
st.success("BMI Calculated! Go to 'BMI Result' page.")
|
| 127 |
|
| 128 |
# -----------------------------------
|
| 129 |
# PAGE 2: RESULT PAGE
|
|
@@ -131,11 +169,13 @@ if page == "π Fitness Form":
|
|
| 131 |
elif page == "π BMI Result":
|
| 132 |
|
| 133 |
st.markdown("<div class='title'>Your BMI Report</div>", unsafe_allow_html=True)
|
| 134 |
-
st.write("")
|
| 135 |
|
| 136 |
if "bmi" not in st.session_state:
|
|
|
|
| 137 |
st.warning("Please fill the form first.")
|
|
|
|
| 138 |
else:
|
|
|
|
| 139 |
st.markdown(f"""
|
| 140 |
<div class='result-card'>
|
| 141 |
<h2>Hello, {st.session_state['name']} π</h2>
|
|
@@ -144,4 +184,30 @@ elif page == "π BMI Result":
|
|
| 144 |
</div>
|
| 145 |
""", unsafe_allow_html=True)
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
st.balloons()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import streamlit.components.v1 as components
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# -------------------------
|
| 7 |
+
# ADD THIS (BMI FUNCTIONS)
|
| 8 |
+
# -------------------------
|
| 9 |
+
def calculate_bmi(weight, height_cm):
|
| 10 |
+
height_m = height_cm / 100
|
| 11 |
+
return round(weight / (height_m ** 2), 2)
|
| 12 |
+
|
| 13 |
+
def get_category(bmi):
|
| 14 |
+
if bmi < 18.5:
|
| 15 |
+
return "Underweight"
|
| 16 |
+
elif bmi < 24.9:
|
| 17 |
+
return "Normal"
|
| 18 |
+
elif bmi < 29.9:
|
| 19 |
+
return "Overweight"
|
| 20 |
+
else:
|
| 21 |
+
return "Obese"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# -------------------------
|
| 25 |
+
# YOUR MODEL (NO CHANGE)
|
| 26 |
+
# -------------------------
|
| 27 |
+
@st.cache_resource
|
| 28 |
+
def load_model():
|
| 29 |
+
return pipeline(
|
| 30 |
+
"text-generation",
|
| 31 |
+
model="google/flan-t5-base"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
generator = load_model()
|
| 35 |
+
|
| 36 |
|
| 37 |
# -----------------------------------
|
| 38 |
+
# PAGE CONFIG (NO CHANGE)
|
| 39 |
# -----------------------------------
|
| 40 |
st.set_page_config(
|
| 41 |
page_title="FitPlan AI",
|
|
|
|
| 43 |
layout="wide"
|
| 44 |
)
|
| 45 |
|
| 46 |
+
|
| 47 |
# -----------------------------------
|
| 48 |
+
# CUSTOM CSS (NO CHANGE)
|
| 49 |
# -----------------------------------
|
| 50 |
st.markdown("""
|
| 51 |
<style>
|
|
|
|
| 81 |
</style>
|
| 82 |
""", unsafe_allow_html=True)
|
| 83 |
|
| 84 |
+
|
| 85 |
# -----------------------------------
|
| 86 |
+
# SIDEBAR NAVIGATION (NO CHANGE)
|
| 87 |
# -----------------------------------
|
| 88 |
st.sidebar.title("πͺ FitPlan AI")
|
| 89 |
page = st.sidebar.radio("Navigate", ["π Fitness Form", "π BMI Result"])
|
| 90 |
|
| 91 |
+
|
| 92 |
# -----------------------------------
|
| 93 |
# PAGE 1: FITNESS FORM
|
| 94 |
# -----------------------------------
|
|
|
|
| 96 |
|
| 97 |
st.markdown("<div class='title'>FitPlan AI</div>", unsafe_allow_html=True)
|
| 98 |
st.write("### Milestone 1: Fitness Profile & BMI Calculator")
|
|
|
|
| 99 |
|
| 100 |
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 101 |
|
|
|
|
| 123 |
)
|
| 124 |
|
| 125 |
equipment = st.multiselect(
|
| 126 |
+
"Available Equipment",
|
| 127 |
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
|
| 128 |
)
|
| 129 |
|
|
|
|
| 131 |
|
| 132 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 133 |
|
| 134 |
+
|
| 135 |
+
# -------------------------
|
| 136 |
+
# MODIFY THIS PART
|
| 137 |
+
# -------------------------
|
| 138 |
if submit:
|
| 139 |
|
|
|
|
| 140 |
if not name.strip():
|
| 141 |
st.error("Name is required.")
|
| 142 |
+
|
| 143 |
elif height_cm <= 0:
|
| 144 |
st.error("Height must be greater than zero.")
|
| 145 |
+
|
| 146 |
elif weight_kg <= 0:
|
| 147 |
st.error("Weight must be greater than zero.")
|
| 148 |
+
|
| 149 |
else:
|
| 150 |
+
|
| 151 |
+
bmi = calculate_bmi(weight_kg, height_cm)
|
| 152 |
+
|
| 153 |
+
category = get_category(bmi)
|
| 154 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
st.session_state["name"] = name
|
| 156 |
st.session_state["bmi"] = bmi
|
| 157 |
st.session_state["category"] = category
|
| 158 |
+
st.session_state["goal"] = goal
|
| 159 |
+
st.session_state["level"] = fitness_level
|
| 160 |
+
st.session_state["equipment"] = equipment
|
| 161 |
+
|
| 162 |
+
st.success("BMI Calculated! Go to Result page.")
|
| 163 |
+
|
| 164 |
|
|
|
|
| 165 |
|
| 166 |
# -----------------------------------
|
| 167 |
# PAGE 2: RESULT PAGE
|
|
|
|
| 169 |
elif page == "π BMI Result":
|
| 170 |
|
| 171 |
st.markdown("<div class='title'>Your BMI Report</div>", unsafe_allow_html=True)
|
|
|
|
| 172 |
|
| 173 |
if "bmi" not in st.session_state:
|
| 174 |
+
|
| 175 |
st.warning("Please fill the form first.")
|
| 176 |
+
|
| 177 |
else:
|
| 178 |
+
|
| 179 |
st.markdown(f"""
|
| 180 |
<div class='result-card'>
|
| 181 |
<h2>Hello, {st.session_state['name']} π</h2>
|
|
|
|
| 184 |
</div>
|
| 185 |
""", unsafe_allow_html=True)
|
| 186 |
|
| 187 |
+
|
| 188 |
+
# -------------------------
|
| 189 |
+
# ADD THIS AI PART
|
| 190 |
+
# -------------------------
|
| 191 |
+
|
| 192 |
+
prompt = f"""
|
| 193 |
+
Create a 5 day workout plan.
|
| 194 |
+
|
| 195 |
+
BMI: {st.session_state['bmi']}
|
| 196 |
+
Category: {st.session_state['category']}
|
| 197 |
+
Goal: {st.session_state['goal']}
|
| 198 |
+
Fitness Level: {st.session_state['level']}
|
| 199 |
+
Equipment: {st.session_state['equipment']}
|
| 200 |
+
"""
|
| 201 |
+
|
| 202 |
+
with st.spinner("Generating workout plan..."):
|
| 203 |
+
|
| 204 |
+
result = generator(
|
| 205 |
+
prompt,
|
| 206 |
+
max_new_tokens=300
|
| 207 |
+
)[0]["generated_text"]
|
| 208 |
+
|
| 209 |
+
st.subheader("ποΈ Your AI Workout Plan")
|
| 210 |
+
|
| 211 |
+
st.write(result)
|
| 212 |
+
|
| 213 |
st.balloons()
|