Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from database import create_tables, save_weight, get_weight_history, save_otp
|
|
@@ -7,7 +8,10 @@ from model_api import query_model
|
|
| 7 |
from prompt_builder import build_prompt
|
| 8 |
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
| 11 |
create_tables()
|
| 12 |
|
| 13 |
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
|
@@ -43,7 +47,7 @@ menu = st.sidebar.selectbox(
|
|
| 43 |
|
| 44 |
|
| 45 |
# -------------------------
|
| 46 |
-
# SIGNUP
|
| 47 |
# -------------------------
|
| 48 |
|
| 49 |
if menu == "Signup":
|
|
@@ -64,7 +68,7 @@ if menu == "Signup":
|
|
| 64 |
|
| 65 |
|
| 66 |
# -------------------------
|
| 67 |
-
# LOGIN
|
| 68 |
# -------------------------
|
| 69 |
|
| 70 |
if menu == "Login" and st.session_state.user is None:
|
|
@@ -74,7 +78,6 @@ if menu == "Login" and st.session_state.user is None:
|
|
| 74 |
email = st.text_input("Email")
|
| 75 |
password = st.text_input("Password", type="password")
|
| 76 |
|
| 77 |
-
# Step 1: Verify credentials
|
| 78 |
if st.button("Login"):
|
| 79 |
|
| 80 |
user = login_user(email, password)
|
|
@@ -110,7 +113,7 @@ if st.session_state.credentials_verified and not st.session_state.otp_sent:
|
|
| 110 |
|
| 111 |
|
| 112 |
# -------------------------
|
| 113 |
-
# VERIFY OTP
|
| 114 |
# -------------------------
|
| 115 |
|
| 116 |
if st.session_state.otp_sent:
|
|
@@ -119,20 +122,41 @@ if st.session_state.otp_sent:
|
|
| 119 |
|
| 120 |
otp_input = st.text_input("OTP")
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
if
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
| 131 |
|
| 132 |
-
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
# -------------------------
|
|
@@ -148,12 +172,18 @@ if st.session_state.user:
|
|
| 148 |
["Dashboard", "Weight Tracker", "Generate Fitness Plan"]
|
| 149 |
)
|
| 150 |
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
if page == "Dashboard":
|
| 153 |
|
| 154 |
st.header("Welcome to FitPlan AI")
|
| 155 |
|
| 156 |
-
st.write(
|
|
|
|
|
|
|
| 157 |
|
| 158 |
|
| 159 |
# -------------------------
|
|
@@ -164,21 +194,32 @@ if st.session_state.user:
|
|
| 164 |
|
| 165 |
st.header("Weight Tracker")
|
| 166 |
|
| 167 |
-
weight = st.number_input(
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
if st.button("Save Weight"):
|
| 170 |
|
| 171 |
-
save_weight(
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
st.success("Weight saved successfully")
|
| 174 |
|
| 175 |
st.subheader("Weight History")
|
| 176 |
|
| 177 |
-
history = get_weight_history(
|
|
|
|
|
|
|
| 178 |
|
| 179 |
if history:
|
|
|
|
| 180 |
st.table(history)
|
|
|
|
| 181 |
else:
|
|
|
|
| 182 |
st.info("No weight data available")
|
| 183 |
|
| 184 |
|
|
@@ -190,23 +231,51 @@ if st.session_state.user:
|
|
| 190 |
|
| 191 |
st.header("Generate Personalized Fitness Plan")
|
| 192 |
|
| 193 |
-
age = st.number_input(
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
goal = st.selectbox(
|
| 198 |
"Fitness Goal",
|
| 199 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
)
|
| 201 |
|
| 202 |
activity = st.selectbox(
|
| 203 |
"Activity Level",
|
| 204 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
)
|
| 206 |
|
| 207 |
if st.button("Generate Plan"):
|
| 208 |
|
| 209 |
-
prompt = build_prompt(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
with st.spinner("Generating AI plan..."):
|
| 212 |
|
|
@@ -228,4 +297,5 @@ if st.session_state.user:
|
|
| 228 |
st.session_state.credentials_verified = False
|
| 229 |
st.session_state.otp_sent = False
|
| 230 |
|
| 231 |
-
st.rerun()
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
from database import create_tables, save_weight, get_weight_history, save_otp
|
|
|
|
| 8 |
from prompt_builder import build_prompt
|
| 9 |
|
| 10 |
|
| 11 |
+
# -------------------------
|
| 12 |
+
# DATABASE INIT
|
| 13 |
+
# -------------------------
|
| 14 |
+
|
| 15 |
create_tables()
|
| 16 |
|
| 17 |
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
# -------------------------
|
| 50 |
+
# SIGNUP PAGE
|
| 51 |
# -------------------------
|
| 52 |
|
| 53 |
if menu == "Signup":
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
# -------------------------
|
| 71 |
+
# LOGIN PAGE
|
| 72 |
# -------------------------
|
| 73 |
|
| 74 |
if menu == "Login" and st.session_state.user is None:
|
|
|
|
| 78 |
email = st.text_input("Email")
|
| 79 |
password = st.text_input("Password", type="password")
|
| 80 |
|
|
|
|
| 81 |
if st.button("Login"):
|
| 82 |
|
| 83 |
user = login_user(email, password)
|
|
|
|
| 113 |
|
| 114 |
|
| 115 |
# -------------------------
|
| 116 |
+
# VERIFY + RESEND OTP
|
| 117 |
# -------------------------
|
| 118 |
|
| 119 |
if st.session_state.otp_sent:
|
|
|
|
| 122 |
|
| 123 |
otp_input = st.text_input("OTP")
|
| 124 |
|
| 125 |
+
col1, col2 = st.columns(2)
|
| 126 |
|
| 127 |
+
# VERIFY OTP
|
| 128 |
+
with col1:
|
| 129 |
|
| 130 |
+
if st.button("Verify OTP"):
|
| 131 |
|
| 132 |
+
verified = verify_user_otp(
|
| 133 |
+
st.session_state.email,
|
| 134 |
+
otp_input
|
| 135 |
+
)
|
| 136 |
|
| 137 |
+
if verified:
|
| 138 |
|
| 139 |
+
st.session_state.user = st.session_state.email
|
| 140 |
+
st.session_state.credentials_verified = False
|
| 141 |
+
st.session_state.otp_sent = False
|
| 142 |
+
|
| 143 |
+
st.success("Login successful")
|
| 144 |
+
|
| 145 |
+
else:
|
| 146 |
+
st.error("Invalid OTP")
|
| 147 |
+
|
| 148 |
+
# RESEND OTP
|
| 149 |
+
with col2:
|
| 150 |
+
|
| 151 |
+
if st.button("Resend OTP"):
|
| 152 |
+
|
| 153 |
+
otp = generate_otp()
|
| 154 |
+
|
| 155 |
+
save_otp(st.session_state.email, otp)
|
| 156 |
+
|
| 157 |
+
send_otp_email(st.session_state.email, otp)
|
| 158 |
+
|
| 159 |
+
st.success("New OTP sent to your email")
|
| 160 |
|
| 161 |
|
| 162 |
# -------------------------
|
|
|
|
| 172 |
["Dashboard", "Weight Tracker", "Generate Fitness Plan"]
|
| 173 |
)
|
| 174 |
|
| 175 |
+
|
| 176 |
+
# -------------------------
|
| 177 |
+
# DASHBOARD PAGE
|
| 178 |
+
# -------------------------
|
| 179 |
+
|
| 180 |
if page == "Dashboard":
|
| 181 |
|
| 182 |
st.header("Welcome to FitPlan AI")
|
| 183 |
|
| 184 |
+
st.write(
|
| 185 |
+
"Track your fitness progress and generate AI workout plans."
|
| 186 |
+
)
|
| 187 |
|
| 188 |
|
| 189 |
# -------------------------
|
|
|
|
| 194 |
|
| 195 |
st.header("Weight Tracker")
|
| 196 |
|
| 197 |
+
weight = st.number_input(
|
| 198 |
+
"Enter today's weight (kg)",
|
| 199 |
+
min_value=30.0
|
| 200 |
+
)
|
| 201 |
|
| 202 |
if st.button("Save Weight"):
|
| 203 |
|
| 204 |
+
save_weight(
|
| 205 |
+
st.session_state.user,
|
| 206 |
+
weight
|
| 207 |
+
)
|
| 208 |
|
| 209 |
st.success("Weight saved successfully")
|
| 210 |
|
| 211 |
st.subheader("Weight History")
|
| 212 |
|
| 213 |
+
history = get_weight_history(
|
| 214 |
+
st.session_state.user
|
| 215 |
+
)
|
| 216 |
|
| 217 |
if history:
|
| 218 |
+
|
| 219 |
st.table(history)
|
| 220 |
+
|
| 221 |
else:
|
| 222 |
+
|
| 223 |
st.info("No weight data available")
|
| 224 |
|
| 225 |
|
|
|
|
| 231 |
|
| 232 |
st.header("Generate Personalized Fitness Plan")
|
| 233 |
|
| 234 |
+
age = st.number_input(
|
| 235 |
+
"Age",
|
| 236 |
+
10,
|
| 237 |
+
80
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
height = st.number_input(
|
| 241 |
+
"Height (cm)",
|
| 242 |
+
100,
|
| 243 |
+
220
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
weight = st.number_input(
|
| 247 |
+
"Weight (kg)",
|
| 248 |
+
30,
|
| 249 |
+
150
|
| 250 |
+
)
|
| 251 |
|
| 252 |
goal = st.selectbox(
|
| 253 |
"Fitness Goal",
|
| 254 |
+
[
|
| 255 |
+
"Weight Loss",
|
| 256 |
+
"Muscle Gain",
|
| 257 |
+
"Maintain Fitness"
|
| 258 |
+
]
|
| 259 |
)
|
| 260 |
|
| 261 |
activity = st.selectbox(
|
| 262 |
"Activity Level",
|
| 263 |
+
[
|
| 264 |
+
"Beginner",
|
| 265 |
+
"Intermediate",
|
| 266 |
+
"Advanced"
|
| 267 |
+
]
|
| 268 |
)
|
| 269 |
|
| 270 |
if st.button("Generate Plan"):
|
| 271 |
|
| 272 |
+
prompt = build_prompt(
|
| 273 |
+
age,
|
| 274 |
+
height,
|
| 275 |
+
weight,
|
| 276 |
+
goal,
|
| 277 |
+
activity
|
| 278 |
+
)
|
| 279 |
|
| 280 |
with st.spinner("Generating AI plan..."):
|
| 281 |
|
|
|
|
| 297 |
st.session_state.credentials_verified = False
|
| 298 |
st.session_state.otp_sent = False
|
| 299 |
|
| 300 |
+
st.rerun()
|
| 301 |
+
```
|