Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,10 @@ from prompt_builder import build_prompt
|
|
| 13 |
|
| 14 |
create_tables()
|
| 15 |
|
| 16 |
-
st.set_page_config(
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
st.title("🏋️ FitPlan AI - Personalized Fitness Planner")
|
| 19 |
|
|
@@ -112,7 +115,7 @@ if st.session_state.credentials_verified and not st.session_state.otp_sent:
|
|
| 112 |
|
| 113 |
|
| 114 |
# -------------------------
|
| 115 |
-
# VERIFY
|
| 116 |
# -------------------------
|
| 117 |
|
| 118 |
if st.session_state.otp_sent:
|
|
@@ -123,7 +126,6 @@ if st.session_state.otp_sent:
|
|
| 123 |
|
| 124 |
col1, col2 = st.columns(2)
|
| 125 |
|
| 126 |
-
# VERIFY OTP
|
| 127 |
with col1:
|
| 128 |
|
| 129 |
if st.button("Verify OTP"):
|
|
@@ -141,10 +143,12 @@ if st.session_state.otp_sent:
|
|
| 141 |
|
| 142 |
st.success("Login successful")
|
| 143 |
|
|
|
|
|
|
|
| 144 |
else:
|
|
|
|
| 145 |
st.error("Invalid OTP")
|
| 146 |
|
| 147 |
-
# RESEND OTP
|
| 148 |
with col2:
|
| 149 |
|
| 150 |
if st.button("Resend OTP"):
|
|
@@ -155,80 +159,50 @@ if st.session_state.otp_sent:
|
|
| 155 |
|
| 156 |
send_otp_email(st.session_state.email, otp)
|
| 157 |
|
| 158 |
-
st.success("New OTP sent
|
| 159 |
|
| 160 |
|
| 161 |
# -------------------------
|
| 162 |
-
#
|
| 163 |
# -------------------------
|
| 164 |
|
| 165 |
if st.session_state.user:
|
| 166 |
|
| 167 |
st.sidebar.success(f"Logged in as {st.session_state.user}")
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
)
|
| 173 |
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
| 180 |
|
| 181 |
-
st.header("
|
| 182 |
|
| 183 |
st.write(
|
| 184 |
-
"
|
| 185 |
-
)
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
# -------------------------
|
| 189 |
-
# WEIGHT TRACKER
|
| 190 |
-
# -------------------------
|
| 191 |
-
|
| 192 |
-
if page == "Weight Tracker":
|
| 193 |
-
|
| 194 |
-
st.header("Weight Tracker")
|
| 195 |
-
|
| 196 |
-
weight = st.number_input(
|
| 197 |
-
"Enter today's weight (kg)",
|
| 198 |
-
min_value=30.0
|
| 199 |
-
)
|
| 200 |
-
|
| 201 |
-
if st.button("Save Weight"):
|
| 202 |
-
|
| 203 |
-
save_weight(
|
| 204 |
-
st.session_state.user,
|
| 205 |
-
weight
|
| 206 |
-
)
|
| 207 |
-
|
| 208 |
-
st.success("Weight saved successfully")
|
| 209 |
-
|
| 210 |
-
st.subheader("Weight History")
|
| 211 |
-
|
| 212 |
-
history = get_weight_history(
|
| 213 |
-
st.session_state.user
|
| 214 |
)
|
| 215 |
|
| 216 |
-
if history:
|
| 217 |
-
|
| 218 |
-
st.table(history)
|
| 219 |
-
|
| 220 |
-
else:
|
| 221 |
-
|
| 222 |
-
st.info("No weight data available")
|
| 223 |
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
-
|
| 226 |
-
# AI FITNESS PLAN
|
| 227 |
-
# -------------------------
|
| 228 |
|
| 229 |
-
|
| 230 |
|
| 231 |
-
st.
|
| 232 |
|
| 233 |
age = st.number_input(
|
| 234 |
"Age",
|
|
@@ -236,12 +210,26 @@ if st.session_state.user:
|
|
| 236 |
80
|
| 237 |
)
|
| 238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
height = st.number_input(
|
| 240 |
"Height (cm)",
|
| 241 |
100,
|
| 242 |
220
|
| 243 |
)
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
weight = st.number_input(
|
| 246 |
"Weight (kg)",
|
| 247 |
30,
|
|
@@ -251,14 +239,14 @@ if st.session_state.user:
|
|
| 251 |
goal = st.selectbox(
|
| 252 |
"Fitness Goal",
|
| 253 |
[
|
| 254 |
-
"
|
| 255 |
-
"
|
| 256 |
"Maintain Fitness"
|
| 257 |
]
|
| 258 |
)
|
| 259 |
|
| 260 |
-
|
| 261 |
-
"
|
| 262 |
[
|
| 263 |
"Beginner",
|
| 264 |
"Intermediate",
|
|
@@ -266,34 +254,91 @@ if st.session_state.user:
|
|
| 266 |
]
|
| 267 |
)
|
| 268 |
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
| 272 |
age,
|
|
|
|
| 273 |
height,
|
| 274 |
weight,
|
| 275 |
goal,
|
| 276 |
-
|
|
|
|
| 277 |
)
|
| 278 |
|
| 279 |
-
|
|
|
|
|
|
|
| 280 |
|
| 281 |
result = query_model(prompt)
|
| 282 |
|
| 283 |
-
st.subheader("Your AI
|
| 284 |
|
| 285 |
st.write(result)
|
| 286 |
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
-
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
|
| 299 |
-
|
|
|
|
| 13 |
|
| 14 |
create_tables()
|
| 15 |
|
| 16 |
+
st.set_page_config(
|
| 17 |
+
page_title="FitPlan AI",
|
| 18 |
+
layout="centered"
|
| 19 |
+
)
|
| 20 |
|
| 21 |
st.title("🏋️ FitPlan AI - Personalized Fitness Planner")
|
| 22 |
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
# -------------------------
|
| 118 |
+
# VERIFY OTP
|
| 119 |
# -------------------------
|
| 120 |
|
| 121 |
if st.session_state.otp_sent:
|
|
|
|
| 126 |
|
| 127 |
col1, col2 = st.columns(2)
|
| 128 |
|
|
|
|
| 129 |
with col1:
|
| 130 |
|
| 131 |
if st.button("Verify OTP"):
|
|
|
|
| 143 |
|
| 144 |
st.success("Login successful")
|
| 145 |
|
| 146 |
+
st.rerun()
|
| 147 |
+
|
| 148 |
else:
|
| 149 |
+
|
| 150 |
st.error("Invalid OTP")
|
| 151 |
|
|
|
|
| 152 |
with col2:
|
| 153 |
|
| 154 |
if st.button("Resend OTP"):
|
|
|
|
| 159 |
|
| 160 |
send_otp_email(st.session_state.email, otp)
|
| 161 |
|
| 162 |
+
st.success("New OTP sent")
|
| 163 |
|
| 164 |
|
| 165 |
# -------------------------
|
| 166 |
+
# MAIN APPLICATION
|
| 167 |
# -------------------------
|
| 168 |
|
| 169 |
if st.session_state.user:
|
| 170 |
|
| 171 |
st.sidebar.success(f"Logged in as {st.session_state.user}")
|
| 172 |
|
| 173 |
+
tabs = st.tabs(
|
| 174 |
+
[
|
| 175 |
+
"Dashboard",
|
| 176 |
+
"Profile",
|
| 177 |
+
"Workout Plan",
|
| 178 |
+
"Weight Tracker",
|
| 179 |
+
"Logout"
|
| 180 |
+
]
|
| 181 |
)
|
| 182 |
|
| 183 |
|
| 184 |
+
# -------------------------
|
| 185 |
+
# DASHBOARD
|
| 186 |
+
# -------------------------
|
| 187 |
|
| 188 |
+
with tabs[0]:
|
| 189 |
|
| 190 |
+
st.header("Dashboard")
|
| 191 |
|
| 192 |
st.write(
|
| 193 |
+
"Welcome to FitPlan AI. Generate personalized workout plans and track your fitness progress."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
+
# -------------------------
|
| 198 |
+
# PROFILE
|
| 199 |
+
# -------------------------
|
| 200 |
|
| 201 |
+
with tabs[1]:
|
|
|
|
|
|
|
| 202 |
|
| 203 |
+
st.header("User Profile")
|
| 204 |
|
| 205 |
+
name = st.text_input("Name")
|
| 206 |
|
| 207 |
age = st.number_input(
|
| 208 |
"Age",
|
|
|
|
| 210 |
80
|
| 211 |
)
|
| 212 |
|
| 213 |
+
gender = st.selectbox(
|
| 214 |
+
"Gender",
|
| 215 |
+
["Male", "Female", "Other"]
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
height = st.number_input(
|
| 219 |
"Height (cm)",
|
| 220 |
100,
|
| 221 |
220
|
| 222 |
)
|
| 223 |
|
| 224 |
+
|
| 225 |
+
# -------------------------
|
| 226 |
+
# WORKOUT PLAN GENERATOR
|
| 227 |
+
# -------------------------
|
| 228 |
+
|
| 229 |
+
with tabs[2]:
|
| 230 |
+
|
| 231 |
+
st.header("Generate Personalized Workout Plan")
|
| 232 |
+
|
| 233 |
weight = st.number_input(
|
| 234 |
"Weight (kg)",
|
| 235 |
30,
|
|
|
|
| 239 |
goal = st.selectbox(
|
| 240 |
"Fitness Goal",
|
| 241 |
[
|
| 242 |
+
"Lose Weight",
|
| 243 |
+
"Build Muscle",
|
| 244 |
"Maintain Fitness"
|
| 245 |
]
|
| 246 |
)
|
| 247 |
|
| 248 |
+
fitness_level = st.selectbox(
|
| 249 |
+
"Fitness Level",
|
| 250 |
[
|
| 251 |
"Beginner",
|
| 252 |
"Intermediate",
|
|
|
|
| 254 |
]
|
| 255 |
)
|
| 256 |
|
| 257 |
+
equipment = st.multiselect(
|
| 258 |
+
"Available Equipment",
|
| 259 |
+
[
|
| 260 |
+
"Dumbbells",
|
| 261 |
+
"Barbell",
|
| 262 |
+
"Resistance Bands",
|
| 263 |
+
"Bodyweight",
|
| 264 |
+
"None"
|
| 265 |
+
]
|
| 266 |
+
)
|
| 267 |
|
| 268 |
+
if st.button("Generate AI Plan"):
|
| 269 |
+
|
| 270 |
+
prompt, bmi, bmi_status = build_prompt(
|
| 271 |
+
name,
|
| 272 |
age,
|
| 273 |
+
gender,
|
| 274 |
height,
|
| 275 |
weight,
|
| 276 |
goal,
|
| 277 |
+
fitness_level,
|
| 278 |
+
equipment
|
| 279 |
)
|
| 280 |
|
| 281 |
+
st.write(f"BMI: {bmi:.2f} ({bmi_status})")
|
| 282 |
+
|
| 283 |
+
with st.spinner("Generating workout plan..."):
|
| 284 |
|
| 285 |
result = query_model(prompt)
|
| 286 |
|
| 287 |
+
st.subheader("Your AI Workout Plan")
|
| 288 |
|
| 289 |
st.write(result)
|
| 290 |
|
| 291 |
|
| 292 |
+
# -------------------------
|
| 293 |
+
# WEIGHT TRACKER
|
| 294 |
+
# -------------------------
|
| 295 |
+
|
| 296 |
+
with tabs[3]:
|
| 297 |
+
|
| 298 |
+
st.header("Weight Tracker")
|
| 299 |
+
|
| 300 |
+
today_weight = st.number_input(
|
| 301 |
+
"Enter today's weight",
|
| 302 |
+
min_value=30.0
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
if st.button("Save Weight"):
|
| 306 |
+
|
| 307 |
+
save_weight(
|
| 308 |
+
st.session_state.user,
|
| 309 |
+
today_weight
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
st.success("Weight saved")
|
| 313 |
+
|
| 314 |
+
st.subheader("Weight History")
|
| 315 |
+
|
| 316 |
+
history = get_weight_history(
|
| 317 |
+
st.session_state.user
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
if history:
|
| 321 |
+
|
| 322 |
+
st.table(history)
|
| 323 |
+
|
| 324 |
+
else:
|
| 325 |
+
|
| 326 |
+
st.info("No weight records found")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
# -------------------------
|
| 330 |
+
# LOGOUT
|
| 331 |
+
# -------------------------
|
| 332 |
+
|
| 333 |
+
with tabs[4]:
|
| 334 |
+
|
| 335 |
+
st.header("Logout")
|
| 336 |
|
| 337 |
+
if st.button("Logout"):
|
| 338 |
|
| 339 |
+
st.session_state.user = None
|
| 340 |
+
st.session_state.email = None
|
| 341 |
+
st.session_state.credentials_verified = False
|
| 342 |
+
st.session_state.otp_sent = False
|
| 343 |
|
| 344 |
+
st.rerun()
|