Spaces:
Sleeping
Sleeping
File size: 6,946 Bytes
afd21fc 27367eb cf41e4c c26e94a 82314df 27367eb cf41e4c 54c31cb 27367eb 898e7f1 afd21fc 27367eb 4cff9d6 cf41e4c 82314df afd21fc 27367eb 4cff9d6 cf41e4c afd21fc 27367eb cf41e4c 27367eb cf41e4c afd21fc 27367eb 54c31cb 27367eb afd21fc 27367eb cf41e4c 4cff9d6 82314df 27367eb 82314df 27367eb 4cff9d6 27367eb 4cff9d6 27367eb 54c31cb 27367eb 4cff9d6 27367eb 4cff9d6 cf41e4c 4cff9d6 27367eb 82314df cf41e4c 82314df 27367eb 82314df 27367eb 82314df 27367eb cf41e4c 4cff9d6 cf41e4c 4cff9d6 27367eb cf41e4c 27367eb 898e7f1 27367eb 4cff9d6 27367eb 4cff9d6 cf41e4c 4cff9d6 cf41e4c 4cff9d6 54c31cb 4cff9d6 54c31cb 4cff9d6 54c31cb 4cff9d6 54c31cb 4cff9d6 54c31cb 4cff9d6 54c31cb 898e7f1 54c31cb 898e7f1 54c31cb 898e7f1 4cff9d6 afd21fc 27367eb 898e7f1 27367eb 82314df 27367eb afd21fc 82314df 898e7f1 27367eb 82314df 54c31cb 898e7f1 54c31cb 898e7f1 82314df 898e7f1 82314df 54c31cb 898e7f1 54c31cb 82314df 4cff9d6 898e7f1 82314df 898e7f1 82314df 898e7f1 82314df 898e7f1 82314df 54c31cb 898e7f1 54c31cb 898e7f1 54c31cb 27367eb 54c31cb 898e7f1 54c31cb 27367eb 898e7f1 54c31cb 27367eb 898e7f1 27367eb 898e7f1 54c31cb 898e7f1 54c31cb 898e7f1 54c31cb 27367eb 898e7f1 82314df cf41e4c 82314df 898e7f1 4cff9d6 cf41e4c 82314df 898e7f1 27367eb 898e7f1 afd21fc 898e7f1 afd21fc 898e7f1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | import streamlit as st
from database import create_tables, save_weight, get_weight_history, save_otp
from auth import signup_user, login_user, verify_user_otp, generate_otp
from email_utils import send_otp_email
from model_api import query_model
from prompt_builder import build_prompt
# -------------------------
# DATABASE INIT
# -------------------------
create_tables()
st.set_page_config(
page_title="FitPlan AI",
layout="centered"
)
st.title("🏋️ FitPlan AI - Personalized Fitness Planner")
# -------------------------
# SESSION STATE
# -------------------------
if "user" not in st.session_state:
st.session_state.user = None
if "email" not in st.session_state:
st.session_state.email = None
if "credentials_verified" not in st.session_state:
st.session_state.credentials_verified = False
if "otp_sent" not in st.session_state:
st.session_state.otp_sent = False
# -------------------------
# SIDEBAR MENU
# -------------------------
menu = st.sidebar.selectbox(
"Menu",
["Signup", "Login"]
)
# -------------------------
# SIGNUP PAGE
# -------------------------
if menu == "Signup":
st.header("Create Account")
email = st.text_input("Email")
password = st.text_input("Password", type="password")
if st.button("Signup"):
success = signup_user(email, password)
if success:
st.success("Account created successfully. Please login.")
else:
st.error("User already exists")
# -------------------------
# LOGIN PAGE
# -------------------------
if menu == "Login" and st.session_state.user is None:
st.header("Login")
email = st.text_input("Email")
password = st.text_input("Password", type="password")
if st.button("Login"):
user = login_user(email, password)
if user:
st.session_state.email = email
st.session_state.credentials_verified = True
st.success("Credentials verified. Click Send OTP.")
else:
st.error("Invalid email or password")
# -------------------------
# SEND OTP
# -------------------------
if st.session_state.credentials_verified and not st.session_state.otp_sent:
if st.button("Send OTP"):
otp = generate_otp()
save_otp(st.session_state.email, otp)
send_otp_email(st.session_state.email, otp)
st.session_state.otp_sent = True
st.success("OTP sent to your email")
# -------------------------
# VERIFY OTP
# -------------------------
if st.session_state.otp_sent:
st.subheader("Enter OTP")
otp_input = st.text_input("OTP")
col1, col2 = st.columns(2)
with col1:
if st.button("Verify OTP"):
verified = verify_user_otp(
st.session_state.email,
otp_input
)
if verified:
st.session_state.user = st.session_state.email
st.session_state.credentials_verified = False
st.session_state.otp_sent = False
st.success("Login successful")
st.rerun()
else:
st.error("Invalid OTP")
with col2:
if st.button("Resend OTP"):
otp = generate_otp()
save_otp(st.session_state.email, otp)
send_otp_email(st.session_state.email, otp)
st.success("New OTP sent")
# -------------------------
# MAIN APPLICATION
# -------------------------
if st.session_state.user:
st.sidebar.success(f"Logged in as {st.session_state.user}")
tabs = st.tabs(
[
"Dashboard",
"Profile",
"Workout Plan",
"Weight Tracker",
"Logout"
]
)
# -------------------------
# DASHBOARD
# -------------------------
with tabs[0]:
st.header("Dashboard")
st.write(
"Welcome to FitPlan AI. Generate personalized workout plans and track your fitness progress."
)
# -------------------------
# PROFILE
# -------------------------
with tabs[1]:
st.header("User Profile")
name = st.text_input("Name")
age = st.number_input(
"Age",
10,
80
)
gender = st.selectbox(
"Gender",
["Male", "Female", "Other"]
)
height = st.number_input(
"Height (cm)",
100,
220
)
# -------------------------
# WORKOUT PLAN GENERATOR
# -------------------------
with tabs[2]:
st.header("Generate Personalized Workout Plan")
weight = st.number_input(
"Weight (kg)",
30,
150
)
goal = st.selectbox(
"Fitness Goal",
[
"Lose Weight",
"Build Muscle",
"Maintain Fitness"
]
)
fitness_level = st.selectbox(
"Fitness Level",
[
"Beginner",
"Intermediate",
"Advanced"
]
)
equipment = st.multiselect(
"Available Equipment",
[
"Dumbbells",
"Barbell",
"Resistance Bands",
"Bodyweight",
"None"
]
)
if st.button("Generate AI Plan"):
prompt, bmi, bmi_status = build_prompt(
name,
age,
gender,
height,
weight,
goal,
fitness_level,
equipment
)
st.write(f"BMI: {bmi:.2f} ({bmi_status})")
with st.spinner("Generating workout plan..."):
result = query_model(prompt)
st.subheader("Your AI Workout Plan")
st.write(result)
# -------------------------
# WEIGHT TRACKER
# -------------------------
with tabs[3]:
st.header("Weight Tracker")
today_weight = st.number_input(
"Enter today's weight",
min_value=30.0
)
if st.button("Save Weight"):
save_weight(
st.session_state.user,
today_weight
)
st.success("Weight saved")
st.subheader("Weight History")
history = get_weight_history(
st.session_state.user
)
if history:
st.table(history)
else:
st.info("No weight records found")
# -------------------------
# LOGOUT
# -------------------------
with tabs[4]:
st.header("Logout")
if st.button("Logout"):
st.session_state.user = None
st.session_state.email = None
st.session_state.credentials_verified = False
st.session_state.otp_sent = False
st.rerun() |