Springboardmen commited on
Commit
4cff9d6
·
verified ·
1 Parent(s): 05ce217

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -33
app.py CHANGED
@@ -1,18 +1,25 @@
1
  import streamlit as st
2
- from database import create_tables, register_user, login_user, save_weight, get_weight_history
 
 
3
  from model_api import query_model
4
  from prompt_builder import build_prompt
5
 
6
- # ---------------- INIT DB ----------------
7
- create_tables()
8
-
9
  # ---------------- PAGE CONFIG ----------------
10
  st.set_page_config(page_title="FitPlan AI", layout="centered")
11
 
12
- # ---------------- SESSION ----------------
 
 
13
  if "user" not in st.session_state:
14
  st.session_state.user = None
15
 
 
 
 
 
 
 
16
 
17
  # =========================================================
18
  # LOGIN / SIGNUP PAGE
@@ -20,54 +27,92 @@ if "user" not in st.session_state:
20
 
21
  if st.session_state.user is None:
22
 
23
- st.title("🏋️ FitPlan AI Login")
24
-
25
  menu = ["Login", "Signup"]
26
  choice = st.sidebar.selectbox("Menu", menu)
27
 
 
 
28
  email = st.text_input("Email")
29
  password = st.text_input("Password", type="password")
30
 
31
  # ---------------- SIGNUP ----------------
32
  if choice == "Signup":
33
 
34
- if st.button("Create Account"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- if register_user(email, password):
37
- st.success("Account created successfully")
38
  else:
39
  st.error("User already exists")
40
 
41
  # ---------------- LOGIN ----------------
42
  if choice == "Login":
43
 
44
- if st.button("Login"):
45
 
46
  user = login_user(email, password)
47
 
48
  if user:
49
- st.session_state.user = email
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  st.success("Login successful")
51
  st.rerun()
 
52
  else:
53
- st.error("Invalid email or password")
54
 
55
 
56
  # =========================================================
57
- # MAIN APP
58
  # =========================================================
59
 
60
  else:
61
 
62
- st.title("🏋️ FitPlan AI — Personalized Workout Generator")
63
-
64
  st.sidebar.success(f"Logged in as {st.session_state.user}")
65
 
66
  if st.sidebar.button("Logout"):
67
  st.session_state.user = None
68
  st.rerun()
69
 
70
- st.write("Fill your fitness details to generate a workout plan.")
71
 
72
  # ---------------- USER INPUT ----------------
73
 
@@ -132,15 +177,15 @@ else:
132
 
133
  if st.button("View Weight History"):
134
 
135
- data = get_weight_history(st.session_state.user)
136
 
137
- if data:
138
- st.write("📊 Weight History")
139
- st.table(data)
140
  else:
141
- st.info("No weight history available")
142
 
143
- # ---------------- GENERATE WORKOUT ----------------
 
144
 
145
  if st.button("Generate Workout Plan"):
146
 
@@ -148,7 +193,7 @@ else:
148
  st.warning("Please enter your name")
149
 
150
  elif not equipment:
151
- st.warning("Select equipment")
152
 
153
  else:
154
 
@@ -163,20 +208,23 @@ else:
163
  equipment
164
  )
165
 
166
- with st.spinner("Generating AI workout plan..."):
167
  response = query_model(prompt)
168
 
169
- st.subheader("📋 Your Workout Plan")
 
170
  st.write(response)
171
 
172
- st.info(f"""
173
- **Profile Summary**
 
174
 
175
- BMI: {bmi:.2f} ({bmi_status})
176
 
177
- Goal: {goal}
178
 
179
- Fitness Level: {fitness_level}
180
 
181
- Equipment: {", ".join(equipment)}
182
- """)
 
 
1
  import streamlit as st
2
+ from auth import signup_user, login_user, verify_user_otp
3
+ from email_utils import generate_otp, send_otp_email
4
+ from database import save_weight, get_weight_history
5
  from model_api import query_model
6
  from prompt_builder import build_prompt
7
 
 
 
 
8
  # ---------------- PAGE CONFIG ----------------
9
  st.set_page_config(page_title="FitPlan AI", layout="centered")
10
 
11
+ st.title("🏋️ FitPlan AI")
12
+
13
+ # ---------------- SESSION STATE ----------------
14
  if "user" not in st.session_state:
15
  st.session_state.user = None
16
 
17
+ if "otp_sent" not in st.session_state:
18
+ st.session_state.otp_sent = False
19
+
20
+ if "otp_email" not in st.session_state:
21
+ st.session_state.otp_email = None
22
+
23
 
24
  # =========================================================
25
  # LOGIN / SIGNUP PAGE
 
27
 
28
  if st.session_state.user is None:
29
 
 
 
30
  menu = ["Login", "Signup"]
31
  choice = st.sidebar.selectbox("Menu", menu)
32
 
33
+ st.subheader(choice)
34
+
35
  email = st.text_input("Email")
36
  password = st.text_input("Password", type="password")
37
 
38
  # ---------------- SIGNUP ----------------
39
  if choice == "Signup":
40
 
41
+ if st.button("Register"):
42
+
43
+ success = signup_user(email, password)
44
+
45
+ if success:
46
+
47
+ otp = generate_otp()
48
+
49
+ send_otp_email(email, otp)
50
+
51
+ st.session_state.otp = otp
52
+ st.session_state.otp_email = email
53
+ st.session_state.otp_sent = True
54
+
55
+ st.success("OTP sent to email")
56
 
 
 
57
  else:
58
  st.error("User already exists")
59
 
60
  # ---------------- LOGIN ----------------
61
  if choice == "Login":
62
 
63
+ if st.button("Send OTP"):
64
 
65
  user = login_user(email, password)
66
 
67
  if user:
68
+
69
+ otp = generate_otp()
70
+
71
+ send_otp_email(email, otp)
72
+
73
+ st.session_state.otp = otp
74
+ st.session_state.otp_email = email
75
+ st.session_state.otp_sent = True
76
+
77
+ st.success("OTP sent to your email")
78
+
79
+ else:
80
+ st.error("Invalid email or password")
81
+
82
+
83
+ # ---------------- OTP VERIFICATION ----------------
84
+
85
+ if st.session_state.otp_sent:
86
+
87
+ otp_input = st.text_input("Enter OTP")
88
+
89
+ if st.button("Verify OTP"):
90
+
91
+ if otp_input == st.session_state.otp:
92
+
93
+ st.session_state.user = st.session_state.otp_email
94
+ st.session_state.otp_sent = False
95
+
96
  st.success("Login successful")
97
  st.rerun()
98
+
99
  else:
100
+ st.error("Invalid OTP")
101
 
102
 
103
  # =========================================================
104
+ # MAIN APPLICATION
105
  # =========================================================
106
 
107
  else:
108
 
 
 
109
  st.sidebar.success(f"Logged in as {st.session_state.user}")
110
 
111
  if st.sidebar.button("Logout"):
112
  st.session_state.user = None
113
  st.rerun()
114
 
115
+ st.header("Generate Your Workout Plan")
116
 
117
  # ---------------- USER INPUT ----------------
118
 
 
177
 
178
  if st.button("View Weight History"):
179
 
180
+ history = get_weight_history(st.session_state.user)
181
 
182
+ if history:
183
+ st.table(history)
 
184
  else:
185
+ st.info("No history available")
186
 
187
+
188
+ # ---------------- GENERATE WORKOUT PLAN ----------------
189
 
190
  if st.button("Generate Workout Plan"):
191
 
 
193
  st.warning("Please enter your name")
194
 
195
  elif not equipment:
196
+ st.warning("Select at least one equipment")
197
 
198
  else:
199
 
 
208
  equipment
209
  )
210
 
211
+ with st.spinner("Generating workout plan..."):
212
  response = query_model(prompt)
213
 
214
+ st.subheader("📋 Your Personalized Workout Plan")
215
+
216
  st.write(response)
217
 
218
+ st.info(
219
+ f"""
220
+ **Profile Summary**
221
 
222
+ BMI: {bmi:.2f} ({bmi_status})
223
 
224
+ Goal: {goal}
225
 
226
+ Fitness Level: {fitness_level}
227
 
228
+ Equipment: {", ".join(equipment)}
229
+ """
230
+ )